Preparing the hintbox classes for Lua

- Add non locale variants for CHintBoxExt, CMessageBox, ShowMsgUTF
  THX Martii
This commit is contained in:
M. Liebmann
2014-01-19 02:50:31 +01:00
parent 31842369cc
commit df06f83a20
4 changed files with 90 additions and 23 deletions

View File

@@ -43,8 +43,6 @@
#include <iostream>
#define HINTBOXEXT_MAX_HEIGHT 420
CHintBoxExt::CHintBoxExt(const neutrino_locale_t Caption, const char * const Text, const int Width, const char * const Icon)
{
m_message = strdup(Text);
@@ -61,15 +59,44 @@ CHintBoxExt::CHintBoxExt(const neutrino_locale_t Caption, const char * const Tex
m_lines.push_back(oneLine);
begin = strtok(NULL, "\n");
}
init(Caption, Width, Icon);
m_bbheight = 0;
init(Caption, "", Width, Icon);
}
CHintBoxExt::CHintBoxExt(const std::string &CaptionString, const char * const Text, const int Width, const char * const Icon)
{
m_message = strdup(Text);
char *begin = m_message;
begin = strtok(m_message, "\n");
while (begin != NULL)
{
std::vector<Drawable*> oneLine;
std::string s(begin);
DText *d = new DText(s);
oneLine.push_back(d);
m_lines.push_back(oneLine);
begin = strtok(NULL, "\n");
}
m_bbheight = 0;
init(NONEXISTANT_LOCALE, CaptionString, Width, Icon);
}
CHintBoxExt::CHintBoxExt(const neutrino_locale_t Caption, ContentLines& lines, const int Width, const char * const Icon)
{
m_message = NULL;
m_lines = lines;
init(Caption, Width, Icon);
m_bbheight = 0;
init(Caption, "", Width, Icon);
}
CHintBoxExt::CHintBoxExt(const std::string &CaptionString, ContentLines& lines, const int Width, const char * const Icon)
{
m_message = NULL;
m_lines = lines;
m_bbheight = 0;
init(NONEXISTANT_LOCALE, CaptionString, Width, Icon);
}
CHintBoxExt::~CHintBoxExt(void)
@@ -97,7 +124,7 @@ CHintBoxExt::~CHintBoxExt(void)
}
}
void CHintBoxExt::init(const neutrino_locale_t Caption, const int Width, const char * const Icon)
void CHintBoxExt::init(const neutrino_locale_t Caption, const std::string &CaptionString, const int Width, const char * const Icon)
{
m_width = Width;
int nw = 0;
@@ -111,11 +138,14 @@ void CHintBoxExt::init(const neutrino_locale_t Caption, const int Width, const c
bgPainted = false;
m_caption = Caption;
m_captionString = CaptionString;
int page = 0;
int line = 0;
int maxWidth = m_width > 0 ? m_width : 0;
int maxOverallHeight = 0;
int screenheight = CFrameBuffer::getInstance()->getScreenHeight() * 9 / 10 - m_bbheight;
m_startEntryOfPage.clear();
m_startEntryOfPage.push_back(0);
for (ContentLines::iterator it = m_lines.begin(); it!=m_lines.end(); ++it)
{
@@ -134,7 +164,7 @@ void CHintBoxExt::init(const neutrino_locale_t Caption, const int Width, const c
if (lineWidth > maxWidth)
maxWidth = lineWidth;
m_height += maxHeight;
if (m_height > HINTBOXEXT_MAX_HEIGHT || pagebreak) {
if (m_height > screenheight || pagebreak) {
if (m_height-maxHeight > maxOverallHeight)
maxOverallHeight = m_height - maxHeight;
m_height = m_theight + m_fheight + maxHeight;
@@ -193,10 +223,18 @@ void CHintBoxExt::init(const neutrino_locale_t Caption, const int Width, const c
else
m_iconfile = "";
nw = additional_width + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(g_Locale->getText(m_caption), true); // UTF-8
const char *l_caption = (m_caption == NONEXISTANT_LOCALE) ? m_captionString.c_str() : g_Locale->getText(m_caption);
nw = additional_width + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(l_caption, true); // UTF-8
if (nw > m_width)
m_width = nw;
/* if the output does not fit, make sure we at least
* stay inside the screen... */
m_width = w_max(m_width ,SHADOW_OFFSET);
if (maxLineWidth + scrollWidth > m_width)
maxLineWidth = m_width - scrollWidth;
textStartX = (m_width - scrollWidth - maxLineWidth) / 2;
m_window = NULL;
@@ -216,11 +254,10 @@ void CHintBoxExt::paint(bool toround)
}
bgPainted = false;
CFrameBuffer* frameBuffer = CFrameBuffer::getInstance();
m_window = new CFBWindow(frameBuffer->getScreenX() + ((frameBuffer->getScreenWidth() - m_width ) >> 1),
frameBuffer->getScreenY() + ((frameBuffer->getScreenHeight() - m_height) >> 2),
m_width + SHADOW_OFFSET,
m_height + SHADOW_OFFSET);
m_window = new CFBWindow(getScreenStartX(m_width + SHADOW_OFFSET),
getScreenStartY(m_height + SHADOW_OFFSET),
m_width + SHADOW_OFFSET,
m_height + SHADOW_OFFSET);
refresh(toround);
}
@@ -243,7 +280,8 @@ void CHintBoxExt::refresh(bool toround)
// icon
int x_offset = 6, icon_space = x_offset, x_text;
std::string title_text = g_Locale->getText(m_caption);
const char *title_text = (m_caption == NONEXISTANT_LOCALE) ? m_captionString.c_str() : g_Locale->getText(m_caption);
if (!m_iconfile.empty())
{
int w, h;
@@ -257,7 +295,7 @@ void CHintBoxExt::refresh(bool toround)
x_text = x_offset;
// title text
m_window->RenderString(g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE], x_text, m_theight, m_width, title_text.c_str(), COL_MENUHEAD_TEXT, 0, true); // UTF-8
m_window->RenderString(g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE], x_text, m_theight, m_width, title_text, COL_MENUHEAD_TEXT, 0, true); // UTF-8
// background of text panel
m_window->paintBoxRel(0, m_theight, m_width, (m_maxEntriesPerPage + 1) * m_fheight, (CFBWindow::color_t)COL_MENUCONTENT_PLUS_0, toround ? RADIUS_LARGE : 0, CORNER_BOTTOM);//round

View File

@@ -55,11 +55,13 @@ class CHintBoxExt
int m_width;
int m_height;
int m_bbheight; /* a button bar at the bottom? */
int textStartX;
int m_fheight;
int m_theight;
neutrino_locale_t m_caption;
std::string m_captionString;
char * m_message;
ContentLines m_lines;
std::string m_iconfile;
@@ -69,12 +71,13 @@ class CHintBoxExt
public:
CHintBoxExt(const neutrino_locale_t Caption, const char * const Text, const int Width, const char * const Icon);
CHintBoxExt(const neutrino_locale_t Caption, ContentLines& lines, const int Width = 450, const char * const Icon = NEUTRINO_ICON_INFO);
CHintBoxExt(const std::string &Caption, const char * const Text, const int Width, const char * const Icon);
CHintBoxExt(const std::string &Caption, ContentLines& lines, const int Width = 450, const char * const Icon = NEUTRINO_ICON_INFO);
~CHintBoxExt(void);
void init(const neutrino_locale_t Caption, const int Width, const char * const Icon);
void init(const neutrino_locale_t Caption, const std::string &CaptionString, const int Width, const char * const Icon);
bool has_scrollbar(void);
void scroll_up(void);

View File

@@ -50,6 +50,16 @@ CMessageBox::CMessageBox(const neutrino_locale_t Caption, ContentLines& Lines, c
Init(Default, ShowButtons);
}
CMessageBox::CMessageBox(const std::string &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 std::string &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)
{
#define BtnCount 3
@@ -65,8 +75,7 @@ void CMessageBox::Init(const CMessageBox::result_ &Default, const uint32_t ShowB
}
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;
m_bbheight = b_height + fh/2 + ButtonSpacing;
result = Default;
b_width = getButtonWidth();
if (ShowButtons & CMessageBox::mbBtnAlignCenter1)
@@ -101,10 +110,14 @@ void CMessageBox::Init(const CMessageBox::result_ &Default, const uint32_t ShowB
ButtonDistance = ButtonSpacing;
bb_width = b_width * ButtonCount + ButtonDistance * (ButtonCount - 1);
if(bb_width > m_width)
m_width = bb_width;
m_width = bb_width; /* FIXME: what if bigger than screen area? */
else
if (mbBtnAlign == CMessageBox::mbBtnAlignCenter1)
ButtonDistance = (m_width - b_width * ButtonCount) / (ButtonCount + 1);
/* this is ugly: re-init (CHintBoxExt) to recalculate the number of lines and pages */
init(m_caption, m_captionString, m_width, m_iconfile == "" ? NULL : m_iconfile.c_str());
m_height += m_bbheight;
}
void CMessageBox::returnDefaultValueOnTimeout(bool returnDefault)
@@ -138,9 +151,9 @@ void CMessageBox::paintButtons()
else if (mbBtnAlign == CMessageBox::mbBtnAlignRight)
xpos = m_width - bb_width - ButtonSpacing;
int ypos = (m_height - bb_height) + fh/2;
int ypos = (m_height - m_bbheight) + fh/2;
m_window->paintBoxRel(0, m_height - bb_height, m_width, bb_height, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM);
m_window->paintBoxRel(0, m_height - m_bbheight, m_width, m_bbheight, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM);
i = 0;
if (showbuttons & mbYes) {
@@ -295,6 +308,17 @@ int ShowMsgUTF(const neutrino_locale_t Caption, const std::string & Text, const
return ShowMsgUTF(Caption, Text.c_str(), Default, ShowButtons, Icon, Width, timeout,returnDefaultOnTimeout);
}
int ShowMsgUTF(const std::string & 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)
{
CMessageBox* messageBox = new CMessageBox(Caption, Text.c_str(), Width, Icon, Default, ShowButtons);
messageBox->returnDefaultValueOnTimeout(returnDefaultOnTimeout);
messageBox->exec(timeout);
int res = messageBox->result;
delete messageBox;
return res;
}
void DisplayErrorMessage(const char * const ErrorMsg)
{
ShowMsgUTF(LOCALE_MESSAGEBOX_ERROR, ErrorMsg, CMessageBox::mbrCancel, CMessageBox::mbCancel, NEUTRINO_ICON_ERROR);

View File

@@ -56,7 +56,7 @@ class CMessageBox : public CHintBoxExt
int mbBtnAlign;
int ButtonSpacing, ButtonDistance;
int fh, i_maxw;
int b_height, b_width, bb_height, bb_width;
int b_height, b_width, bb_width;
int ButtonCount;
void paintButtons();
@@ -88,8 +88,9 @@ class CMessageBox : public CHintBoxExt
// Text & Caption are always UTF-8 encoded
CMessageBox(const neutrino_locale_t Caption, const char * const Text, const int Width = 500, const char * const Icon = NULL, const CMessageBox::result_ &Default = mbrYes, const uint32_t ShowButtons = mbAll);
CMessageBox(const std::string &Caption, const char * const Text, const int Width = 500, const char * const Icon = NULL, const CMessageBox::result_ &Default = mbrYes, const uint32_t ShowButtons = mbAll);
CMessageBox(const neutrino_locale_t Caption, ContentLines& Lines, const int Width = 500, const char * const Icon = NULL, const CMessageBox::result_ &Default = mbrYes, const uint32_t ShowButtons = mbAll);
CMessageBox(const std::string &Caption, ContentLines& Lines, const int Width = 500, const char * const Icon = NULL, const CMessageBox::result_ &Default = mbrYes, const uint32_t ShowButtons = mbAll);
int exec(int timeout = -1);
void returnDefaultValueOnTimeout(bool returnDefault);
@@ -102,6 +103,7 @@ class CMessageBox : public CHintBoxExt
int ShowLocalizedMessage(const neutrino_locale_t Caption, const neutrino_locale_t Text, const CMessageBox::result_ &Default, const uint32_t ShowButtons, const char * const Icon = NULL, const int Width = 450, const int timeout = -1, bool returnDefaultOnTimeout = false);
int ShowMsgUTF(const neutrino_locale_t Caption, const char * const Text, const CMessageBox::result_ &Default, const uint32_t ShowButtons, const char * const Icon = NULL, const int Width = 450, const int timeout = -1, bool returnDefaultOnTimeout = false); // UTF-8
int ShowMsgUTF(const neutrino_locale_t Caption, const std::string & Text, const CMessageBox::result_ &Default, const uint32_t ShowButtons, const char * const Icon = NULL, const int Width = 450, const int timeout = -1, bool returnDefaultOnTimeout = false); // UTF-8
int ShowMsgUTF(const std::string & Caption, const std::string & Text, const CMessageBox::result_ &Default, const uint32_t ShowButtons, const char * const Icon = NULL, const int Width = 450, const int timeout = -1, bool returnDefaultOnTimeout = false); // UTF-8
void DisplayErrorMessage(const char * const ErrorMsg); // UTF-8
void DisplayInfoMessage(const char * const InfoMsg); // UTF-8