mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-08-29 08:21:12 +02:00
* CMessageBox: Buttons draw better
- New standard variant for centered display the buttons - optimized code git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-beta@2072 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
@@ -52,9 +52,9 @@ CMessageBox::CMessageBox(const neutrino_locale_t Caption, ContentLines& Lines, c
|
|||||||
|
|
||||||
void CMessageBox::Init(const CMessageBox::result_ Default, const uint32_t ShowButtons)
|
void CMessageBox::Init(const CMessageBox::result_ Default, const uint32_t ShowButtons)
|
||||||
{
|
{
|
||||||
|
#define BtnCount 3
|
||||||
returnDefaultOnTimeout = false;
|
returnDefaultOnTimeout = false;
|
||||||
ButtonSpacing = 15;
|
ButtonSpacing = 15;
|
||||||
#define BtnCount 3
|
|
||||||
int w = 0, h = 0, ih = 0;
|
int w = 0, h = 0, ih = 0;
|
||||||
i_maxw = 0;
|
i_maxw = 0;
|
||||||
std::string Btns[BtnCount] = {NEUTRINO_ICON_BUTTON_RED, NEUTRINO_ICON_BUTTON_GREEN, NEUTRINO_ICON_BUTTON_HOME};
|
std::string Btns[BtnCount] = {NEUTRINO_ICON_BUTTON_RED, NEUTRINO_ICON_BUTTON_GREEN, NEUTRINO_ICON_BUTTON_HOME};
|
||||||
@@ -68,27 +68,46 @@ void CMessageBox::Init(const CMessageBox::result_ Default, const uint32_t ShowBu
|
|||||||
bb_height = b_height + fh/2 + ButtonSpacing;
|
bb_height = b_height + fh/2 + ButtonSpacing;
|
||||||
m_height += bb_height;
|
m_height += bb_height;
|
||||||
result = Default;
|
result = Default;
|
||||||
int ButtonWidth = getButtonWidth() + 5;
|
b_width = getButtonWidth();
|
||||||
if (ShowButtons & CMessageBox::mbBtnAlignCenter)
|
if (ShowButtons & CMessageBox::mbBtnAlignCenter1)
|
||||||
mbBtnAlign = CMessageBox::mbBtnAlignCenter;
|
mbBtnAlign = CMessageBox::mbBtnAlignCenter1; // centered, large distances
|
||||||
else if (ShowButtons & CMessageBox::mbBtnAlignLeft)
|
else if (ShowButtons & CMessageBox::mbBtnAlignCenter2)
|
||||||
|
mbBtnAlign = CMessageBox::mbBtnAlignCenter2; // centered, small distances
|
||||||
|
else if (ShowButtons & CMessageBox::mbBtnAlignLeft)
|
||||||
mbBtnAlign = CMessageBox::mbBtnAlignLeft;
|
mbBtnAlign = CMessageBox::mbBtnAlignLeft;
|
||||||
else if (ShowButtons & CMessageBox::mbBtnAlignRight)
|
else if (ShowButtons & CMessageBox::mbBtnAlignRight)
|
||||||
mbBtnAlign = CMessageBox::mbBtnAlignRight;
|
mbBtnAlign = CMessageBox::mbBtnAlignRight;
|
||||||
else
|
else
|
||||||
mbBtnAlign = CMessageBox::mbBtnAlignCenter; // or g_settings.mbBtnAlign? ;-)
|
mbBtnAlign = CMessageBox::mbBtnAlignCenter1; // or g_settings.mbBtnAlign? ;-)
|
||||||
showbuttons = ShowButtons & 0xFF;
|
showbuttons = ShowButtons & 0xFF;
|
||||||
|
|
||||||
int num = 0;
|
ButtonCount = 0;
|
||||||
if (showbuttons & mbYes)
|
if (showbuttons & mbYes) {
|
||||||
num++;
|
Buttons[ButtonCount].def = (result == mbrYes) ? true : false;
|
||||||
if (showbuttons & mbNo)
|
Buttons[ButtonCount].icon = NEUTRINO_ICON_BUTTON_RED;
|
||||||
num++;
|
Buttons[ButtonCount].text = g_Locale->getText(LOCALE_MESSAGEBOX_YES);
|
||||||
if (showbuttons & (mbCancel | mbBack | mbOk))
|
ButtonCount++;
|
||||||
num++;
|
}
|
||||||
int new_width = 15 + num*ButtonWidth;
|
if (showbuttons & mbNo) {
|
||||||
if(new_width > m_width)
|
Buttons[ButtonCount].def = (result == mbrNo) ? true : false;
|
||||||
m_width = new_width;
|
Buttons[ButtonCount].icon = NEUTRINO_ICON_BUTTON_GREEN;
|
||||||
|
Buttons[ButtonCount].text = g_Locale->getText(LOCALE_MESSAGEBOX_NO);
|
||||||
|
ButtonCount++;
|
||||||
|
}
|
||||||
|
if (showbuttons & (mbCancel | mbBack | mbOk)) {
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ButtonDistance = ButtonSpacing;
|
||||||
|
bb_width = b_width * ButtonCount + ButtonDistance * (ButtonCount - 1);
|
||||||
|
if(bb_width > m_width)
|
||||||
|
m_width = bb_width;
|
||||||
|
else
|
||||||
|
if (mbBtnAlign == CMessageBox::mbBtnAlignCenter1)
|
||||||
|
ButtonDistance = (m_width - b_width * ButtonCount) / (ButtonCount + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMessageBox::returnDefaultValueOnTimeout(bool returnDefault)
|
void CMessageBox::returnDefaultValueOnTimeout(bool returnDefault)
|
||||||
@@ -98,56 +117,29 @@ void CMessageBox::returnDefaultValueOnTimeout(bool returnDefault)
|
|||||||
|
|
||||||
int CMessageBox::getButtonWidth()
|
int CMessageBox::getButtonWidth()
|
||||||
{
|
{
|
||||||
#define localeMsgCount 3
|
#define localeMsgCount 5
|
||||||
neutrino_locale_t localeMsg[localeMsgCount] = {LOCALE_MESSAGEBOX_YES, LOCALE_MESSAGEBOX_NO, LOCALE_MESSAGEBOX_CANCEL};
|
neutrino_locale_t localeMsg[localeMsgCount] = {LOCALE_MESSAGEBOX_YES, LOCALE_MESSAGEBOX_NO, LOCALE_MESSAGEBOX_CANCEL, LOCALE_MESSAGEBOX_OK, LOCALE_MESSAGEBOX_BACK};
|
||||||
int MaxButtonTextWidth = 0;
|
int MaxButtonTextWidth = 0;
|
||||||
for (int i = 0; i < localeMsgCount; i++)
|
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);
|
MaxButtonTextWidth = std::max(g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getRenderWidth(g_Locale->getText(localeMsg[i]), true), MaxButtonTextWidth);
|
||||||
|
return MaxButtonTextWidth + i_maxw + 36 + (RADIUS_LARGE / 2);
|
||||||
return MaxButtonTextWidth + i_maxw + 31 + (RADIUS_LARGE / 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMessageBox::paintButtons()
|
void CMessageBox::paintButtons()
|
||||||
{
|
{
|
||||||
#define MaxButtons 3
|
|
||||||
fb_pixel_t color;
|
fb_pixel_t color;
|
||||||
fb_pixel_t bgcolor;
|
fb_pixel_t bgcolor;
|
||||||
struct mbButtons Buttons[MaxButtons];
|
|
||||||
int ButtonCount = 0;
|
|
||||||
|
|
||||||
int ButtonWidth = getButtonWidth();
|
|
||||||
|
|
||||||
if (showbuttons & mbYes) {
|
|
||||||
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 iw, ih;
|
int iw, ih;
|
||||||
int ButtonbarWidth = ButtonWidth * ButtonCount + ButtonSpacing * (ButtonCount - 1);
|
int xpos = (m_width - bb_width) / 2;
|
||||||
int xpos = (m_width - ButtonbarWidth) / 2;
|
if (mbBtnAlign == CMessageBox::mbBtnAlignCenter1)
|
||||||
if (mbBtnAlign == CMessageBox::mbBtnAlignCenter)
|
xpos = ButtonDistance;
|
||||||
xpos = (m_width - ButtonbarWidth) / 2;
|
if (mbBtnAlign == CMessageBox::mbBtnAlignCenter2)
|
||||||
|
xpos = (m_width - bb_width) / 2;
|
||||||
else if (mbBtnAlign == CMessageBox::mbBtnAlignLeft)
|
else if (mbBtnAlign == CMessageBox::mbBtnAlignLeft)
|
||||||
xpos = ButtonSpacing;
|
xpos = ButtonSpacing;
|
||||||
else if (mbBtnAlign == CMessageBox::mbBtnAlignRight)
|
else if (mbBtnAlign == CMessageBox::mbBtnAlignRight)
|
||||||
xpos = m_width - ButtonbarWidth - ButtonSpacing;
|
xpos = m_width - bb_width - ButtonSpacing;
|
||||||
|
|
||||||
int ypos = (m_height - bb_height) + fh/2;
|
int ypos = (m_height - bb_height) + fh/2;
|
||||||
|
|
||||||
@@ -162,11 +154,11 @@ void CMessageBox::paintButtons()
|
|||||||
bgcolor = COL_INFOBAR_SHADOW_PLUS_0;
|
bgcolor = COL_INFOBAR_SHADOW_PLUS_0;
|
||||||
}
|
}
|
||||||
CFrameBuffer::getInstance()->getIconSize(Buttons[i].icon, &iw, &ih);
|
CFrameBuffer::getInstance()->getIconSize(Buttons[i].icon, &iw, &ih);
|
||||||
m_window->paintBoxRel(xpos, ypos, ButtonWidth, b_height, (CFBWindow::color_t)bgcolor, RADIUS_LARGE);
|
m_window->paintBoxRel(xpos, ypos, b_width, b_height, (CFBWindow::color_t)bgcolor, RADIUS_LARGE);
|
||||||
m_window->paintIcon(Buttons[i].icon, xpos + ((b_height - ih) / 2), ypos + ((b_height - ih) / 2), ih);
|
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 + iw + 17, ypos + fh + ((b_height - fh) / 2),
|
m_window->RenderString(g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL], xpos + iw + 17, ypos + fh + ((b_height - fh) / 2),
|
||||||
ButtonWidth - (iw + 21), Buttons[i].text, (CFBWindow::color_t)color, 0, true);
|
b_width - (iw + 21), Buttons[i].text, (CFBWindow::color_t)color, 0, true);
|
||||||
xpos += ButtonWidth + ButtonSpacing;
|
xpos += b_width + ButtonDistance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -38,24 +38,26 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#define MaxButtons 3
|
||||||
|
|
||||||
class CMessageBox : public CHintBoxExt
|
class CMessageBox : public CHintBoxExt
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
struct mbButtons
|
struct mbButtons
|
||||||
{
|
{
|
||||||
bool active;
|
|
||||||
bool def;
|
bool def;
|
||||||
const char* icon;
|
const char* icon;
|
||||||
const char* text;
|
const char* text;
|
||||||
};
|
};
|
||||||
|
struct mbButtons Buttons[MaxButtons];
|
||||||
|
|
||||||
int showbuttons;
|
int showbuttons;
|
||||||
bool returnDefaultOnTimeout;
|
bool returnDefaultOnTimeout;
|
||||||
int mbBtnAlign;
|
int mbBtnAlign;
|
||||||
int ButtonSpacing;
|
int ButtonSpacing, ButtonDistance;
|
||||||
int fh, i_maxw;
|
int fh, i_maxw;
|
||||||
int b_height, bb_height;
|
int b_height, b_width, bb_height, bb_width;
|
||||||
|
int ButtonCount;
|
||||||
|
|
||||||
void paintButtons();
|
void paintButtons();
|
||||||
int getButtonWidth();
|
int getButtonWidth();
|
||||||
@@ -72,15 +74,16 @@ class CMessageBox : public CHintBoxExt
|
|||||||
|
|
||||||
enum buttons_
|
enum buttons_
|
||||||
{
|
{
|
||||||
mbYes = 0x01,
|
mbYes = 0x01,
|
||||||
mbNo = 0x02,
|
mbNo = 0x02,
|
||||||
mbCancel = 0x04,
|
mbCancel = 0x04,
|
||||||
mbAll = 0x07,
|
mbAll = 0x07,
|
||||||
mbBack = 0x08,
|
mbBack = 0x08,
|
||||||
mbOk = 0x10,
|
mbOk = 0x10,
|
||||||
mbBtnAlignCenter = 0x0100,
|
mbBtnAlignCenter1 = 0x0100, /* centered, large distances */
|
||||||
mbBtnAlignLeft = 0x0200,
|
mbBtnAlignCenter2 = 0x0200, /* centered, small distances */
|
||||||
mbBtnAlignRight = 0x0400
|
mbBtnAlignLeft = 0x0400,
|
||||||
|
mbBtnAlignRight = 0x0800
|
||||||
} buttons;
|
} buttons;
|
||||||
|
|
||||||
// Text & Caption are always UTF-8 encoded
|
// Text & Caption are always UTF-8 encoded
|
||||||
|
Reference in New Issue
Block a user