filebrowser: simplify code using font pointers

Origin commit data
------------------
Branch: ni/coolstream
Commit: ceea712008
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2012-11-24 (Sat, 24 Nov 2012)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
Stefan Seyfried
2012-11-24 16:56:22 +01:00
parent 1e858a2c89
commit 0e76ae501f
2 changed files with 18 additions and 12 deletions

View File

@@ -360,6 +360,9 @@ CFileBrowser::CFileBrowser(const char * const _base, const tFileBrowserMode mode
void CFileBrowser::commonInit() void CFileBrowser::commonInit()
{ {
frameBuffer = CFrameBuffer::getInstance(); frameBuffer = CFrameBuffer::getInstance();
fnt_title = g_Font[SNeutrinoSettings::FONT_TYPE_EVENTLIST_TITLE];
fnt_item = g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM];
fnt_small = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL];
//shoutcast //shoutcast
sc_init_dir = "/legacy/genrelist?k=" + g_settings.shoutcast_dev_id; sc_init_dir = "/legacy/genrelist?k=" + g_settings.shoutcast_dev_id;
@@ -378,11 +381,11 @@ void CFileBrowser::commonInit()
width = (g_settings.screen_EndX - g_settings.screen_StartX - 40); width = (g_settings.screen_EndX - g_settings.screen_StartX - 40);
height = (g_settings.screen_EndY - g_settings.screen_StartY - 40); height = (g_settings.screen_EndY - g_settings.screen_StartY - 40);
theight = g_Font[SNeutrinoSettings::FONT_TYPE_EVENTLIST_TITLE]->getHeight(); theight = fnt_title->getHeight();
fheight = g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->getHeight(); fheight = fnt_item->getHeight();
if (fheight == 0) if (fheight == 0)
fheight = 1; /* avoid div by zero on invalid font */ fheight = 1; /* avoid div by zero on invalid font */
foheight = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight()+6; //initial height value for buttonbar; TODO get value from buttonbar foheight = fnt_small->getHeight()+6; //initial height value for buttonbar; TODO get value from buttonbar
liststart = 0; liststart = 0;
listmaxshow = std::max(1,(int)(height - theight - 2 * foheight)/fheight); listmaxshow = std::max(1,(int)(height - theight - 2 * foheight)/fheight);
@@ -1308,7 +1311,7 @@ void CFileBrowser::paintItem(unsigned int pos)
} }
frameBuffer->paintIcon(fileicon, x+5 , ypos + (fheight-16) / 2 ); frameBuffer->paintIcon(fileicon, x+5 , ypos + (fheight-16) / 2 );
g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35, ypos + fheight, colwidth1 - 10 , FILESYSTEM_ENCODING_TO_UTF8_STRING(actual_file->getFileName()), color, 0, true); // UTF-8 fnt_item->RenderString(x + 35, ypos + fheight, colwidth1 - 10 , FILESYSTEM_ENCODING_TO_UTF8_STRING(actual_file->getFileName()), color, 0, true); // UTF-8
if( S_ISREG(actual_file->Mode) ) if( S_ISREG(actual_file->Mode) )
{ {
@@ -1322,7 +1325,7 @@ void CFileBrowser::paintItem(unsigned int pos)
} }
modestring[9] = 0; modestring[9] = 0;
g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35 + colwidth1 , ypos+ fheight, colwidth2 - 10, modestring, color, 0, true); // UTF-8 fnt_item->RenderString(x + 35 + colwidth1 , ypos+ fheight, colwidth2 - 10, modestring, color, 0, true); // UTF-8
} }
#define GIGABYTE 1073741824LL #define GIGABYTE 1073741824LL
@@ -1355,7 +1358,7 @@ void CFileBrowser::paintItem(unsigned int pos)
else else
snprintf(tmpstr,sizeof(tmpstr),"%d", (int)actual_file->Size); snprintf(tmpstr,sizeof(tmpstr),"%d", (int)actual_file->Size);
g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35 + colwidth1 + colwidth2, ypos+ fheight, colwidth3 - 10, tmpstr, color); fnt_item->RenderString(x + 35 + colwidth1 + colwidth2, ypos+ fheight, colwidth3 - 10, tmpstr, color);
} }
if( S_ISDIR(actual_file->Mode) ) if( S_ISDIR(actual_file->Mode) )
@@ -1366,7 +1369,7 @@ void CFileBrowser::paintItem(unsigned int pos)
rawtime = actual_file->Time; rawtime = actual_file->Time;
strftime(timestring, 18, "%d-%m-%Y %H:%M", gmtime(&rawtime)); strftime(timestring, 18, "%d-%m-%Y %H:%M", gmtime(&rawtime));
g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->RenderString(x + 35 + colwidth1_dir, ypos+ fheight, colwidth2_dir - 10, timestring, color); fnt_item->RenderString(x + 35 + colwidth1_dir, ypos+ fheight, colwidth2_dir - 10, timestring, color);
} }
} }
} }
@@ -1397,17 +1400,17 @@ void CFileBrowser::paintHead()
/* too long? Leave out the "Filebrowser" or "Shoutcast" prefix /* too long? Leave out the "Filebrowser" or "Shoutcast" prefix
* the allocated space is sufficient since it is surely shorter than before */ * the allocated space is sufficient since it is surely shorter than before */
if (g_Font[SNeutrinoSettings::FONT_TYPE_EVENTLIST_TITLE]->getRenderWidth(l_name) > width - 11) if (fnt_title->getRenderWidth(l_name) > width - 11)
l = sprintf(l_name, "%s", FILESYSTEM_ENCODING_TO_UTF8_STRING(name).c_str()); l = sprintf(l_name, "%s", FILESYSTEM_ENCODING_TO_UTF8_STRING(name).c_str());
if (l_name[l - 1] == '/') if (l_name[l - 1] == '/')
l_name[--l] = '\0'; l_name[--l] = '\0';
/* still too long? the last part is probably more interesting than the first part... */ /* still too long? the last part is probably more interesting than the first part... */
while ((g_Font[SNeutrinoSettings::FONT_TYPE_EVENTLIST_TITLE]->getRenderWidth(&l_name[i]) > width - 11) while ((fnt_title->getRenderWidth(&l_name[i]) > width - 11)
&& (i < l)) && (i < l))
i++; i++;
g_Font[SNeutrinoSettings::FONT_TYPE_EVENTLIST_TITLE]->RenderString(x+10,y+theight+1, width-11, &l_name[i], COL_MENUHEAD, 0, true); fnt_title->RenderString(x+10,y+theight+1, width-11, &l_name[i], COL_MENUHEAD, 0, true);
free(l_name); free(l_name);
} }
@@ -1503,8 +1506,8 @@ void CFileBrowser::paintFoot()
{ {
char cKey[2]={m_SMSKeyInput.getOldKey(),0}; char cKey[2]={m_SMSKeyInput.getOldKey(),0};
cKey[0] = toupper(cKey[0]); cKey[0] = toupper(cKey[0]);
int len = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(cKey); int len = fnt_small->getRenderWidth(cKey);
g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->RenderString(x + width - 10 - len, by2 + foheight, len, cKey, COL_MENUHEAD, 0, true); fnt_small->RenderString(x + width - 10 - len, by2 + foheight, len, cKey, COL_MENUHEAD, 0, true);
} }
} }
} }

View File

@@ -146,6 +146,9 @@ class CFileBrowser
{ {
private: private:
CFrameBuffer *frameBuffer; CFrameBuffer *frameBuffer;
Font *fnt_title;
Font *fnt_item;
Font *fnt_small;
CFileList selected_filelist; CFileList selected_filelist;
bool readDir(const std::string & dirname, CFileList* flist); bool readDir(const std::string & dirname, CFileList* flist);