* CMessageBox: Buttons draw better

- Improved button layout
- Alignment either left / right / center


git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-beta@2069 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
micha-bbg
2012-01-20 16:28:21 +00:00
parent 211ed92473
commit 6593d693e4
2 changed files with 113 additions and 100 deletions

View File

@@ -42,39 +42,43 @@
CMessageBox::CMessageBox(const neutrino_locale_t Caption, const char * const Text, const int Width, const char * const Icon, const CMessageBox::result_ Default, const uint32_t ShowButtons) : CHintBoxExt(Caption, Text, Width, Icon) CMessageBox::CMessageBox(const neutrino_locale_t Caption, const char * const Text, const int Width, const char * const Icon, const CMessageBox::result_ Default, const uint32_t ShowButtons) : CHintBoxExt(Caption, Text, Width, Icon)
{ {
returnDefaultOnTimeout = false; Init(Default, ShowButtons);
m_height += (m_fheight << 1);
result = Default;
showbuttons = ShowButtons;
int MaxButtonTextWidth = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(g_Locale->getText(LOCALE_MESSAGEBOX_CANCEL), true); // UTF-8
int ButtonWidth = 20 + 33 + MaxButtonTextWidth + 5;
int num = 0;
if (showbuttons & mbYes)
num++;
if (showbuttons & mbNo)
num++;
if (showbuttons & (mbCancel | mbBack | mbOk))
num++;
int new_width = 15 + num*ButtonWidth;
if(new_width > m_width)
m_width = new_width;
} }
CMessageBox::CMessageBox(const neutrino_locale_t Caption, ContentLines& Lines, const int Width, const char * const Icon, const CMessageBox::result_ Default, const uint32_t ShowButtons) : CHintBoxExt(Caption, Lines, Width, Icon) CMessageBox::CMessageBox(const neutrino_locale_t Caption, ContentLines& Lines, const int Width, const char * const Icon, const CMessageBox::result_ Default, const uint32_t ShowButtons) : CHintBoxExt(Caption, Lines, Width, Icon)
{
Init(Default, ShowButtons);
}
void CMessageBox::Init(const CMessageBox::result_ Default, const uint32_t ShowButtons)
{ {
returnDefaultOnTimeout = false; returnDefaultOnTimeout = false;
ButtonSpacing = 15;
m_height += (m_fheight << 1); #define BtnCount 3
int w = 0, h = 0, ih = 0;
i_maxw = 0;
std::string Btns[BtnCount] = {NEUTRINO_ICON_BUTTON_RED, NEUTRINO_ICON_BUTTON_GREEN, NEUTRINO_ICON_BUTTON_HOME};
for (int i = 0; i < BtnCount; i++) {
CFrameBuffer::getInstance()->getIconSize(Btns[i].c_str(), &w, &h);
ih = std::max(h, ih);
i_maxw = std::max(w, i_maxw);
}
fh = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight();
b_height = std::max(fh, ih) + 8 + (RADIUS_LARGE / 2);
bb_height = b_height + fh/2 + ButtonSpacing;
m_height += bb_height;
result = Default; result = Default;
int ButtonWidth = getButtonWidth() + 5;
if (ShowButtons & CMessageBox::mbBtnAlignCenter)
mbBtnAlign = CMessageBox::mbBtnAlignCenter;
else if (ShowButtons & CMessageBox::mbBtnAlignLeft)
mbBtnAlign = CMessageBox::mbBtnAlignLeft;
else if (ShowButtons & CMessageBox::mbBtnAlignRight)
mbBtnAlign = CMessageBox::mbBtnAlignRight;
else
mbBtnAlign = CMessageBox::mbBtnAlignCenter; // or g_settings.mbBtnAlign? ;-)
showbuttons = ShowButtons & 0xFF;
showbuttons = ShowButtons;
int MaxButtonTextWidth = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(g_Locale->getText(LOCALE_MESSAGEBOX_CANCEL), true); // UTF-8
int ButtonWidth = 20 + 33 + MaxButtonTextWidth + 5;
int num = 0; int num = 0;
if (showbuttons & mbYes) if (showbuttons & mbYes)
num++; num++;
@@ -92,87 +96,78 @@ void CMessageBox::returnDefaultValueOnTimeout(bool returnDefault)
returnDefaultOnTimeout = returnDefault; returnDefaultOnTimeout = returnDefault;
} }
int CMessageBox::getButtonWidth()
{
#define localeMsgCount 3
neutrino_locale_t localeMsg[localeMsgCount] = {LOCALE_MESSAGEBOX_YES, LOCALE_MESSAGEBOX_NO, LOCALE_MESSAGEBOX_CANCEL};
int MaxButtonTextWidth = 0;
for (int i = 0; i < localeMsgCount; i++)
MaxButtonTextWidth = std::max(g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(g_Locale->getText(localeMsg[i]), true), MaxButtonTextWidth);
return MaxButtonTextWidth + i_maxw + 31 + (RADIUS_LARGE / 2);
}
void CMessageBox::paintButtons() void CMessageBox::paintButtons()
{ {
uint8_t color; #define MaxButtons 3
fb_pixel_t color;
fb_pixel_t bgcolor; fb_pixel_t bgcolor;
struct mbButtons Buttons[MaxButtons];
int ButtonCount = 0;
m_window->paintBoxRel(0, m_height - (m_fheight << 1) - RADIUS_LARGE, m_width, (m_fheight << 1) + RADIUS_LARGE, (CFBWindow::color_t)COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM); int ButtonWidth = getButtonWidth();
//irgendwann alle vergleichen - aber cancel ist sicher der l<>ngste if (showbuttons & mbYes) {
int MaxButtonTextWidth = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(g_Locale->getText(LOCALE_MESSAGEBOX_CANCEL), true); // UTF-8 Buttons[ButtonCount].active = true;
Buttons[ButtonCount].def = (result == mbrYes) ? true : false;
Buttons[ButtonCount].icon = NEUTRINO_ICON_BUTTON_RED;
Buttons[ButtonCount].text = g_Locale->getText(LOCALE_MESSAGEBOX_YES);
ButtonCount++;
}
if (showbuttons & mbNo) {
Buttons[ButtonCount].active = true;
Buttons[ButtonCount].def = (result == mbrNo) ? true : false;
Buttons[ButtonCount].icon = NEUTRINO_ICON_BUTTON_GREEN;
Buttons[ButtonCount].text = g_Locale->getText(LOCALE_MESSAGEBOX_NO);
ButtonCount++;
}
if (showbuttons & (mbCancel | mbBack | mbOk)) {
Buttons[ButtonCount].active = true;
Buttons[ButtonCount].def = (result >= mbrCancel) ? true : false;
Buttons[ButtonCount].icon = NEUTRINO_ICON_BUTTON_HOME;
Buttons[ButtonCount].text = g_Locale->getText((showbuttons & mbCancel) ? LOCALE_MESSAGEBOX_CANCEL : (showbuttons & mbOk) ? LOCALE_MESSAGEBOX_OK : LOCALE_MESSAGEBOX_BACK);
ButtonCount++;
}
int ButtonWidth = 20 + 33 + MaxButtonTextWidth;
int ButtonSpacing = (m_width - 20 - (ButtonWidth * 3)) / 2;
if(ButtonSpacing <= 5) ButtonSpacing = 5;
int xpos = 10;
int iw, ih; int iw, ih;
int fh = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight(); int ButtonbarWidth = ButtonWidth * ButtonCount + ButtonSpacing * (ButtonCount - 1);
const int noname = 20; int xpos = (m_width - ButtonbarWidth) / 2;
if (showbuttons & mbYes) if (mbBtnAlign == CMessageBox::mbBtnAlignCenter)
{ xpos = (m_width - ButtonbarWidth) / 2;
if (result == mbrYes) else if (mbBtnAlign == CMessageBox::mbBtnAlignLeft)
{ xpos = ButtonSpacing;
else if (mbBtnAlign == CMessageBox::mbBtnAlignRight)
xpos = m_width - ButtonbarWidth - ButtonSpacing;
int ypos = (m_height - bb_height) + fh/2;
m_window->paintBoxRel(0, m_height - bb_height, m_width, bb_height, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM);
for (int i = 0; i < ButtonCount; i++) {
if (Buttons[i].def) {
color = COL_MENUCONTENTSELECTED; color = COL_MENUCONTENTSELECTED;
bgcolor = COL_MENUCONTENTSELECTED_PLUS_0; bgcolor = COL_MENUCONTENTSELECTED_PLUS_0;
} } else {
else
{
color = COL_INFOBAR_SHADOW; color = COL_INFOBAR_SHADOW;
bgcolor = COL_INFOBAR_SHADOW_PLUS_0; bgcolor = COL_INFOBAR_SHADOW_PLUS_0;
} }
CFrameBuffer::getInstance()->getIconSize(NEUTRINO_ICON_BUTTON_RED, &iw, &ih); CFrameBuffer::getInstance()->getIconSize(Buttons[i].icon, &iw, &ih);
m_window->paintBoxRel(xpos, m_height - m_fheight - noname, ButtonWidth, m_fheight, (CFBWindow::color_t)bgcolor, RADIUS_LARGE);//round m_window->paintBoxRel(xpos, ypos, ButtonWidth, b_height, (CFBWindow::color_t)bgcolor, RADIUS_LARGE);
//m_window->paintIcon(NEUTRINO_ICON_BUTTON_RED, xpos + 14, m_height - m_fheight - 15); m_window->paintIcon(Buttons[i].icon, xpos + ((b_height - ih) / 2), ypos + ((b_height - ih) / 2), ih);
//m_window->RenderString(g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL], xpos + 43, m_height-m_fheight+4, ButtonWidth- 53, g_Locale->getText(LOCALE_MESSAGEBOX_YES), (CFBWindow::color_t)color, 0, true); // UTF-8 m_window->RenderString(g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL], xpos + iw + 17, ypos + fh + ((b_height - fh) / 2),
m_window->paintIcon(NEUTRINO_ICON_BUTTON_RED, xpos + 14, m_height - m_fheight - noname, m_fheight); ButtonWidth - (iw + 21), Buttons[i].text, (CFBWindow::color_t)color, 0, true);
m_window->RenderString(g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL], xpos + 43, (m_height - noname)-(m_fheight-fh)/2, ButtonWidth- 53, g_Locale->getText(LOCALE_MESSAGEBOX_YES), (CFBWindow::color_t)color, 0, true); // UTF-8
xpos += ButtonWidth + ButtonSpacing; xpos += ButtonWidth + ButtonSpacing;
} }
if (showbuttons & mbNo)
{
if (result == mbrNo)
{
color = COL_MENUCONTENTSELECTED;
bgcolor = COL_MENUCONTENTSELECTED_PLUS_0;
}
else
{
color = COL_INFOBAR_SHADOW;
bgcolor = COL_INFOBAR_SHADOW_PLUS_0;
}
m_window->paintBoxRel(xpos, m_height-m_fheight-noname, ButtonWidth, m_fheight, (CFBWindow::color_t)bgcolor, RADIUS_LARGE);//round
//m_window->paintIcon(NEUTRINO_ICON_BUTTON_GREEN, xpos+14, m_height-m_fheight-15);
m_window->paintIcon(NEUTRINO_ICON_BUTTON_GREEN, xpos+14, m_height-m_fheight - noname, m_fheight);
m_window->RenderString(g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL], xpos + 43, (m_height - noname)-(m_fheight-fh)/2, ButtonWidth- 53, g_Locale->getText(LOCALE_MESSAGEBOX_NO), (CFBWindow::color_t)color, 0, true); // UTF-8
xpos += ButtonWidth + ButtonSpacing;
}
if (showbuttons & (mbCancel | mbBack | mbOk))
{
if (result >= mbrCancel)
{
color = COL_MENUCONTENTSELECTED;
bgcolor = COL_MENUCONTENTSELECTED_PLUS_0;
}
else
{
color = COL_INFOBAR_SHADOW;
bgcolor = COL_INFOBAR_SHADOW_PLUS_0;
}
m_window->paintBoxRel(xpos, m_height-m_fheight-noname, ButtonWidth, m_fheight, (CFBWindow::color_t)bgcolor, RADIUS_LARGE);//round
//m_window->paintIcon(NEUTRINO_ICON_BUTTON_HOME, xpos+10, m_height-m_fheight-19);
m_window->paintIcon(NEUTRINO_ICON_BUTTON_HOME, xpos+14, m_height-m_fheight - noname, m_fheight);
m_window->RenderString(g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL], xpos + 43, (m_height - noname)-(m_fheight-fh)/2, ButtonWidth- 53,
g_Locale->getText((showbuttons & mbCancel) ? LOCALE_MESSAGEBOX_CANCEL : (showbuttons & mbOk) ? LOCALE_MESSAGEBOX_OK : LOCALE_MESSAGEBOX_BACK),
(CFBWindow::color_t)color, 0, true); // UTF-8
}
} }
int CMessageBox::exec(int timeout) int CMessageBox::exec(int timeout)

View File

@@ -42,11 +42,23 @@
class CMessageBox : public CHintBoxExt class CMessageBox : public CHintBoxExt
{ {
private: private:
struct mbButtons
{
bool active;
bool def;
const char* icon;
const char* text;
};
int showbuttons; int showbuttons;
bool returnDefaultOnTimeout; bool returnDefaultOnTimeout;
int mbBtnAlign;
int ButtonSpacing;
int fh, i_maxw;
int b_height, bb_height;
void paintButtons(); void paintButtons();
int getButtonWidth();
public: public:
enum result_ enum result_
@@ -65,7 +77,10 @@ class CMessageBox : public CHintBoxExt
mbCancel = 0x04, mbCancel = 0x04,
mbAll = 0x07, mbAll = 0x07,
mbBack = 0x08, mbBack = 0x08,
mbOk = 0x10 mbOk = 0x10,
mbBtnAlignCenter = 0x0100,
mbBtnAlignLeft = 0x0200,
mbBtnAlignRight = 0x0400
} buttons; } buttons;
// Text & Caption are always UTF-8 encoded // Text & Caption are always UTF-8 encoded
@@ -75,6 +90,9 @@ class CMessageBox : public CHintBoxExt
int exec(int timeout = -1); int exec(int timeout = -1);
void returnDefaultValueOnTimeout(bool returnDefault); void returnDefaultValueOnTimeout(bool returnDefault);
private:
void Init(const CMessageBox::result_ Default, const uint32_t ShowButtons);
}; };
// Text is always UTF-8 encoded // Text is always UTF-8 encoded