CMenuWidget: implement CComponentsInfoBox functionality for text and icon

This commit is contained in:
2012-08-19 13:15:51 +02:00
parent 9090e41d5b
commit 53ff9cdddf
2 changed files with 39 additions and 109 deletions

View File

@@ -814,15 +814,15 @@ void CMenuWidget::calcSize()
}
#endif
}
hint_height = 0;
hint_height = 70; //TODO: rework calculation of hint_height
if(g_settings.show_menu_hints && has_hints) {
int fheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT]->getHeight();
hint_height = 10 + 2*fheight;
int h_tmp = 10 + 2*fheight;
/* assuming all hint icons has the same size ! */
int iw, ih;
frameBuffer->getIconSize(NEUTRINO_ICON_HINT_TVMODE, &iw, &ih);
if(hint_height < (ih+10))
hint_height = ih+10;
h_tmp = std::max(h_tmp, ih+10);
hint_height = std::max(h_tmp, hint_height);
}
/* set the max height to 9/10 of usable screen height
debatable, if the callers need a possibility to set this */
@@ -1113,7 +1113,6 @@ void CMenuWidget::paintHint(int pos)
return;
CMenuItem* item = items[pos];
//printf("paintHint: icon %s text %s\n", item->hintIcon.c_str(), g_Locale->getText(item->hint));
if (item->hintIcon.empty() && item->hint == NONEXISTANT_LOCALE) {
#if 0
@@ -1131,127 +1130,58 @@ void CMenuWidget::paintHint(int pos)
return;
}
hint_painted = true;
if (item->hint == NONEXISTANT_LOCALE)
return;
int iheight = item->getHeight();
//details line
//init details line and infobox dimensions
int ypos1 = item->getYPosition();
int ypos1a = ypos1 + (iheight/2)-2;
int ypos2a = ypos2 + (hint_height/2) - INFO_BOX_Y_OFFSET;
int markh = hint_height > rad*2 ? hint_height - rad*2 : hint_height;
int imarkh = iheight/2+1;
if (details_line == NULL){
//init details line
if (details_line == NULL)
details_line = new CComponentsDetailLine(xpos, ypos1a, ypos2a, imarkh, markh);
}else{
else{
details_line->setXPos(xpos);
details_line->setYPos(ypos1a);
details_line->setYPosDown(ypos2a);
details_line->setHMarkDown(markh);
details_line->syncSysColors();
details_line->setHMarkDown(markh);
}
details_line->syncSysColors();
#if 0
details_line->paint(savescreen);
#endif
details_line->paint();
//init infobox
if (info_box == NULL)
info_box = new CComponentsInfoBox(x, ypos2, iwidth, hint_height);
else {
info_box = new CComponentsInfoBox(x, ypos2, iwidth, hint_height, g_Locale->getText(item->hint), CTextBox::AUTO_WIDTH | CTextBox::AUTO_HIGH/*, g_Font[SNeutrinoSettings::FONT_TYPE_MENU_HINT]*/);
else{
info_box->setXPos(x);
info_box->setYPos(ypos2);
info_box->setWidth(iwidth);
info_box->setCornerRadius(RADIUS_LARGE);
info_box->syncSysColors();
info_box->setShadowOnOff(CC_SHADOW_ON);
info_box->setText(g_Locale->getText(item->hint));
}
info_box->setCornerRadius(RADIUS_LARGE);
info_box->syncSysColors();
info_box->setShadowOnOff(CC_SHADOW_ON);
info_box->setPicture(item->hintIcon);
#if 0
/* force full paint - menu-over i.e. option chooser with pulldown can overwrite */
info_box->paint(savescreen, true);
#endif
//paint result
details_line->paint();
info_box->paint();
hint_painted = true;
int offset = 10;
if (!item->hintIcon.empty()) {
int iw, ih;
frameBuffer->getIconSize(item->hintIcon.c_str(), &iw, &ih);
if (iw && ih) {
int ix = x + offset;
int iy = ypos2 + (hint_height - ih)/2;
frameBuffer->paintIcon(item->hintIcon.c_str(), ix, iy);
offset += iw + 10;
}
}
if (item->hint == NONEXISTANT_LOCALE)
return;
int HintFont = SNeutrinoSettings::FONT_TYPE_MENU_HINT;
int fheight = g_Font[HintFont]->getHeight();
std::string str1, str2;
std::string str = g_Locale->getText(item->hint);
std::string::size_type spos = str.find_first_of("\n");
if (spos != std::string::npos) {
str1 = str.substr(0, spos);
str2 = str.substr(spos+1);
}
else
str1 = str;
if ((!str1.empty()) || (!str1.empty())) {
int wBox = iwidth - 6 - offset;
int wStr1 = 0, wStr2 = 0;
if (!str1.empty())
wStr1 = g_Font[HintFont]->getRenderWidth(str1);
if (!str2.empty())
wStr2 = g_Font[HintFont]->getRenderWidth(str2);
if ((wStr1 > wBox) || (wStr2 > wBox)) {
str = g_Locale->getText(item->hint);
// replace "\n" with " "
spos = str.find_first_of("\n");
if (spos != std::string::npos)
str.replace(spos, 1, " ");
spos = str.length();
if (spos >= 1) {
std::string BreakChars = "+-/";
str1 = str;
wStr1 = g_Font[HintFont]->getRenderWidth(str1);
int count = 0;
std::string bChar;
while (wStr1 > wBox) {
spos = str1.find_last_of(BreakChars + " ");
if (spos != std::string::npos) {
str1 = str1.substr(0, spos+1);
// Last delimiter remember if it's not a whitespace
size_t len = str1.length();
size_t spos2 = str1.find_last_of(BreakChars);
if (len == spos2+1)
bChar = str1.substr(spos2, spos2+1);
else
bChar = "";
// Remove last delimiter
str1 = str1.substr(0, spos);
}
// Width of string with delimiter
wStr1 = g_Font[HintFont]->getRenderWidth(str1 + bChar);
count++;
if (count > 20)
break;
}
// Last delimiter append again
str1 += bChar;
str2 = str.substr(spos+1);
}
}
ypos2 += (hint_height-fheight*2)/2;
if (!str1.empty())
g_Font[HintFont]->RenderString(x+offset, ypos2+fheight, wBox, str1, COL_MENUCONTENT, 0, true); // UTF-8
if (!str2.empty())
g_Font[HintFont]->RenderString(x+offset, ypos2+fheight*2, wBox, str2, COL_MENUCONTENT, 0, true); // UTF-8
}
}
//-------------------------------------------------------------------------------------------------------------------------------

View File

@@ -425,6 +425,7 @@ class CMenuWidget : public CMenuTarget
CMenuGlobal *mglobal;
CComponentsDetailLine *details_line;
CComponentsInfoBox *info_box;
int hint_height;
protected:
std::string nameString;
@@ -448,7 +449,6 @@ class CMenuWidget : public CMenuTarget
fb_pixel_t *background;
int full_width, full_height;
bool savescreen;
int hint_height;
bool has_hints; // is any items has hints
bool hint_painted; // is hint painted