Files
recycled-ni-neutrino/src/gui/widget/messagebox.cpp
Michael Liebmann bd2ae2da5c 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


Origin commit data
------------------
Branch: ni/coolstream
Commit: 6593d693e4
Author: Michael Liebmann <tuxcode.bbg@gmail.com>
Date: 2012-01-20 (Fri, 20 Jan 2012)

Origin message was:
------------------
* 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 was generated by Migit
2012-01-20 16:28:21 +00:00

306 lines
9.8 KiB
C++

/*
Neutrino-GUI - DBoxII-Project
Copyright (C) 2001 Steffen Hehn 'McClean'
Homepage: http://dbox.cyberphoria.org/
Kommentar:
Diese GUI wurde von Grund auf neu programmiert und sollte nun vom
Aufbau und auch den Ausbaumoeglichkeiten gut aussehen. Neutrino basiert
auf der Client-Server Idee, diese GUI ist also von der direkten DBox-
Steuerung getrennt. Diese wird dann von Daemons uebernommen.
License: GPL
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gui/widget/messagebox.h>
#include <gui/widget/icons.h>
#include <driver/screen_max.h>
#include <global.h>
#include <neutrino.h>
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)
{
Init(Default, ShowButtons);
}
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;
ButtonSpacing = 15;
#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;
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;
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;
}
void CMessageBox::returnDefaultValueOnTimeout(bool 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()
{
#define MaxButtons 3
fb_pixel_t color;
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 ButtonbarWidth = ButtonWidth * ButtonCount + ButtonSpacing * (ButtonCount - 1);
int xpos = (m_width - ButtonbarWidth) / 2;
if (mbBtnAlign == CMessageBox::mbBtnAlignCenter)
xpos = (m_width - ButtonbarWidth) / 2;
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;
bgcolor = COL_MENUCONTENTSELECTED_PLUS_0;
} else {
color = COL_INFOBAR_SHADOW;
bgcolor = COL_INFOBAR_SHADOW_PLUS_0;
}
CFrameBuffer::getInstance()->getIconSize(Buttons[i].icon, &iw, &ih);
m_window->paintBoxRel(xpos, ypos, ButtonWidth, 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->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);
xpos += ButtonWidth + ButtonSpacing;
}
}
int CMessageBox::exec(int timeout)
{
neutrino_msg_t msg;
neutrino_msg_data_t data;
int res = menu_return::RETURN_REPAINT;
CHintBoxExt::paint(0);
if (m_window == NULL)
{
return res; /* out of memory */
}
paintButtons();
if ( timeout == -1 )
timeout = g_settings.timing[SNeutrinoSettings::TIMING_EPG];
uint64_t timeoutEnd = CRCInput::calcTimeoutEnd( timeout );
bool loop=true;
while (loop)
{
g_RCInput->getMsgAbsoluteTimeout( &msg, &data, &timeoutEnd );
if (msg == CRCInput::RC_timeout && returnDefaultOnTimeout)
{
// return default
loop = false;
}
else if (((msg == CRCInput::RC_timeout) ||
(msg == (neutrino_msg_t)g_settings.key_channelList_cancel)) &&
(showbuttons & (mbCancel | mbBack | mbOk)))
{
result = (showbuttons & mbCancel) ? mbrCancel : (showbuttons & mbOk) ? mbrOk: mbrBack;
loop = false;
}
else if ((msg == CRCInput::RC_green) && (showbuttons & mbNo))
{
result = mbrNo;
loop = false;
}
else if ((msg == CRCInput::RC_red) && (showbuttons & mbYes))
{
result = mbrYes;
loop = false;
}
else if(msg==CRCInput::RC_right)
{
bool ok = false;
while (!ok)
{
result = (CMessageBox::result_)((result + 1) & 3);
ok = showbuttons & (1 << result);
}
paintButtons();
}
else if (has_scrollbar() && ((msg == CRCInput::RC_up) || (msg == CRCInput::RC_down)))
{
if (msg == CRCInput::RC_up)
{
scroll_up();
paintButtons();
}
else
{
scroll_down();
paintButtons();
}
}
else if(msg==CRCInput::RC_left)
{
bool ok = false;
while (!ok)
{
result = (CMessageBox::result_)((result - 1) & 3);
ok = showbuttons & (1 << result);
}
paintButtons();
}
else if(msg == CRCInput::RC_ok)
{
loop = false;
}
else if((msg == CRCInput::RC_sat) || (msg == CRCInput::RC_favorites))
{
}
else if (CNeutrinoApp::getInstance()->handleMsg(msg, data) & messages_return::cancel_all)
{
res = menu_return::RETURN_EXIT_ALL;
loop = false;
}
}
hide();
return res;
}
int ShowMsgUTF(const neutrino_locale_t Caption, const char * const Text, const CMessageBox::result_ Default, const uint32_t ShowButtons, const char * const Icon, const int Width, const int timeout, bool returnDefaultOnTimeout)
{
CMessageBox* messageBox = new CMessageBox(Caption, Text, Width, Icon, Default, ShowButtons);
messageBox->returnDefaultValueOnTimeout(returnDefaultOnTimeout);
messageBox->exec(timeout);
int res = messageBox->result;
delete messageBox;
return res;
}
int ShowLocalizedMessage(const neutrino_locale_t Caption, const neutrino_locale_t Text, const CMessageBox::result_ Default, const uint32_t ShowButtons, const char * const Icon, const int Width, const int timeout, bool returnDefaultOnTimeout)
{
return ShowMsgUTF(Caption, g_Locale->getText(Text), Default, ShowButtons, Icon, Width, timeout,returnDefaultOnTimeout);
}
int ShowMsgUTF(const neutrino_locale_t Caption, const std::string & Text, const CMessageBox::result_ Default, const uint32_t ShowButtons, const char * const Icon, const int Width, const int timeout, bool returnDefaultOnTimeout)
{
return ShowMsgUTF(Caption, Text.c_str(), Default, ShowButtons, Icon, Width, timeout,returnDefaultOnTimeout);
}
void DisplayErrorMessage(const char * const ErrorMsg)
{
ShowMsgUTF(LOCALE_MESSAGEBOX_ERROR, ErrorMsg, CMessageBox::mbrCancel, CMessageBox::mbCancel, NEUTRINO_ICON_ERROR);
}
void DisplayInfoMessage(const char * const ErrorMsg)
{
ShowMsgUTF(LOCALE_MESSAGEBOX_INFO, ErrorMsg, CMessageBox::mbrBack, CMessageBox::mbBack, NEUTRINO_ICON_INFO);
}