From c4dfb269fcc459a3a84b82ead577da1aa492f5cf Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Sat, 7 Jul 2012 21:10:10 +0200 Subject: [PATCH] biggest chan number in list (revised) Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/441cba7d4a94dede2283b2258c0e69644de10e5a Author: Jacek Jendrzej Date: 2012-07-07 (Sat, 07 Jul 2012) --- src/driver/pictureviewer/pictureviewer.cpp | 2 +- src/gui/channellist.cpp | 39 ++++++++++++---------- src/gui/channellist.h | 1 + 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/driver/pictureviewer/pictureviewer.cpp b/src/driver/pictureviewer/pictureviewer.cpp index c4be92485..39ca3203d 100644 --- a/src/driver/pictureviewer/pictureviewer.cpp +++ b/src/driver/pictureviewer/pictureviewer.cpp @@ -587,7 +587,7 @@ fb_pixel_t * CPictureViewer::int_getImage(const std::string & name, int *width, if (buffer == NULL) { printf("%s: Error: malloc\n", mode_str.c_str()); - return false; + return 0; } #ifdef FBV_SUPPORT_PNG if ((name.find(".png") == (name.length() - 4)) && (fh_png_id(name.c_str()))) diff --git a/src/gui/channellist.cpp b/src/gui/channellist.cpp index e2d859cd9..32a111e61 100644 --- a/src/gui/channellist.cpp +++ b/src/gui/channellist.cpp @@ -1209,8 +1209,9 @@ int CChannelList::numericZap(int key) } return res; } - - int sx = 4 * g_Font[SNeutrinoSettings::FONT_TYPE_CHANNEL_NUM_ZAP]->getRenderWidth(widest_number) + 14; + size_t maxchansize = MaxChanNr().size(); + int fw = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNEL_NUM_ZAP]->getRenderWidth(widest_number); + int sx = maxchansize * fw + (fw/2); int sy = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNEL_NUM_ZAP]->getHeight() + 6; int ox = frameBuffer->getScreenX() + (frameBuffer->getScreenWidth() - sx)/2; @@ -1225,14 +1226,14 @@ int CChannelList::numericZap(int key) while(1) { if (lastchan != chn) { snprintf((char*) &valstr, sizeof(valstr), "%d", chn); - while(strlen(valstr) < 4) - strcat(valstr,"-"); //"_" + while(strlen(valstr) < maxchansize) + strcat(valstr,"-"); //"_" frameBuffer->paintBoxRel(ox, oy, sx, sy, COL_INFOBAR_PLUS_0); - for (int i = 3; i >= 0; i--) { + for (int i = maxchansize-1; i >= 0; i--) { valstr[i+ 1] = 0; - g_Font[SNeutrinoSettings::FONT_TYPE_CHANNEL_NUM_ZAP]->RenderString(ox+7+ i*((sx-14)>>2), oy+sy-3, sx, &valstr[i], COL_INFOBAR); + g_Font[SNeutrinoSettings::FONT_TYPE_CHANNEL_NUM_ZAP]->RenderString(ox+fw/3+ i*fw, oy+sy-3, sx, &valstr[i], COL_INFOBAR); } showInfo(chn); @@ -1955,17 +1956,7 @@ void CChannelList::paintHead() void CChannelList::paint() { - zapit_list_it_t chan_it; - std::stringstream ss; - std::string chan_width; - int chan_nr_max = 1; - unsigned int nr = 0; - for (chan_it=chanlist.begin(); chan_it!=chanlist.end(); ++chan_it) { - chan_nr_max = std::max(chan_nr_max, chanlist[nr++]->number); - } - ss << chan_nr_max; - ss >> chan_width; - numwidth = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNELLIST_NUMBER]->getRenderWidth(chan_width.c_str()); + numwidth = g_Font[SNeutrinoSettings::FONT_TYPE_CHANNELLIST_NUMBER]->getRenderWidth(MaxChanNr().c_str()); liststart = (selected/listmaxshow)*listmaxshow; updateEvents(this->historyMode ? 0:liststart, this->historyMode ? 0:(liststart + listmaxshow)); @@ -2029,3 +2020,17 @@ bool CChannelList::SameTP(CZapitChannel * channel) } return iscurrent; } +std::string CChannelList::MaxChanNr() +{ + zapit_list_it_t chan_it; + std::stringstream ss; + std::string maxchansize; + int chan_nr_max = 1; + unsigned int nr = 0; + for (chan_it=chanlist.begin(); chan_it!=chanlist.end(); ++chan_it) { + chan_nr_max = std::max(chan_nr_max, chanlist[nr++]->number); + } + ss << chan_nr_max; + ss >> maxchansize; + return maxchansize; +} diff --git a/src/gui/channellist.h b/src/gui/channellist.h index e723ac72a..1159d6646 100644 --- a/src/gui/channellist.h +++ b/src/gui/channellist.h @@ -96,6 +96,7 @@ private: void hide(); void showChannelLogo(); void calcSize(); + std::string MaxChanNr(); public: CChannelList(const char * const Name, bool historyMode = false, bool _vlist = false, bool new_mode_active = false );