From fad249ebb53cf79fb396af285f7ddf8d71d6a0fd Mon Sep 17 00:00:00 2001 From: svenhoefer Date: Sat, 9 Mar 2013 15:06:10 +0100 Subject: [PATCH 1/2] - stringinput: rework dialogs * fix diplay with all fontsizefactors * dynamical height/width/position of dialogs * dynamical height of buttonbar --- src/gui/widget/stringinput.cpp | 208 +++++++++++++++-------------- src/gui/widget/stringinput.h | 16 +-- src/gui/widget/stringinput_ext.cpp | 140 +++++++++---------- src/gui/widget/stringinput_ext.h | 9 +- 4 files changed, 190 insertions(+), 183 deletions(-) diff --git a/src/gui/widget/stringinput.cpp b/src/gui/widget/stringinput.cpp index 276cc131c..01c02843e 100644 --- a/src/gui/widget/stringinput.cpp +++ b/src/gui/widget/stringinput.cpp @@ -4,13 +4,6 @@ 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 @@ -50,7 +43,6 @@ CStringInput::CStringInput(const neutrino_locale_t Name, char* Value, const int min_value, const int max_value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon) { - frameBuffer = CFrameBuffer::getInstance(); name = Name; head = NULL; value = Value; @@ -70,7 +62,6 @@ CStringInput::CStringInput(const neutrino_locale_t Name, char* Value, const int CStringInput::CStringInput(const neutrino_locale_t Name, char* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon) { - frameBuffer = CFrameBuffer::getInstance(); name = Name; head = NULL; value = Value; @@ -91,7 +82,6 @@ CStringInput::CStringInput(const neutrino_locale_t Name, char* Value, int Size, CStringInput::CStringInput(const neutrino_locale_t Name, std::string* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon) { - frameBuffer = CFrameBuffer::getInstance(); name = Name; head = NULL; value = new char[Size+1]; @@ -113,7 +103,6 @@ CStringInput::CStringInput(const neutrino_locale_t Name, std::string* Value, int CStringInput::CStringInput(char * Head, char* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon) { - frameBuffer = CFrameBuffer::getInstance(); head = strdup(Head); value = Value; valueString = NULL; @@ -141,46 +130,63 @@ CStringInput::~CStringInput() } } +#define CStringInputSMSButtonsCount 2 +const struct button_label CStringInputSMSButtons[CStringInputSMSButtonsCount] = +{ + { NEUTRINO_ICON_BUTTON_RED , LOCALE_STRINGINPUT_CAPS }, + { NEUTRINO_ICON_BUTTON_YELLOW, LOCALE_STRINGINPUT_CLEAR } +}; + void CStringInput::init() { - width = (size*20)+40; - - if (width<420) - width = 420; - - int neededWidth; - if(head) { - neededWidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(head, true); // UTF-8 - } - else - neededWidth = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(g_Locale->getText(name), true); // UTF-8 - - if (!(iconfile.empty())) - neededWidth += 28; - if (neededWidth+20> width) - width = neededWidth+20; + frameBuffer = CFrameBuffer::getInstance(); hheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); + iheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->getHeight(); + fheight = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight() + 6; // init min buttonbar height + input_h = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight() + 2; // font height + border + input_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth("M") + 2; // hack font width + border + offset = 20; + + width = std::max(size*input_w + 2*offset, (int) frameBuffer->getScreenWidth() / 100 * 45); + + int tmp_w = 0; + if (head) + tmp_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(head, true); // UTF-8 + else + tmp_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(g_Locale->getText(name), true); // UTF-8 + if (!(iconfile.empty())) { int icol_w, icol_h; frameBuffer->getIconSize(iconfile.c_str(), &icol_w, &icol_h); - hheight = std::max(hheight, icol_h+4); + hheight = std::max(hheight, icol_h + (offset/4)); + tmp_w += icol_w + (offset/2); } - mheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); - iheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->getHeight(); - //footerHeight = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight()+8; //initial height value for buttonbar - height = hheight+ mheight + 50; - if (hint_1 != NONEXISTANT_LOCALE) + width = std::max(width, tmp_w + offset); + + bheight = input_h + 2*offset; + if ((hint_1 != NONEXISTANT_LOCALE) || (hint_2 != NONEXISTANT_LOCALE)) { - height += iheight; + if (hint_1 != NONEXISTANT_LOCALE) + { + tmp_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->getRenderWidth(g_Locale->getText(hint_1), true); + width = std::max(width, tmp_w + 2*offset); + bheight += iheight; + } if (hint_2 != NONEXISTANT_LOCALE) - height += iheight; + { + tmp_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->getRenderWidth(g_Locale->getText(hint_2), true); + width = std::max(width, tmp_w + 2*offset); + bheight += iheight; + } + bheight += offset; } - height += g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight()+6; //buttonbar; + + height = hheight+ bheight; // space for the possible numpad and the buttonbar will be added in initSMS() - x = frameBuffer->getScreenX() + ((frameBuffer->getScreenWidth() - width)>>1); - y = frameBuffer->getScreenY() + ((frameBuffer->getScreenHeight()-height)>>1); + x = getScreenStartX(width); + y = getScreenStartY(height); selected = 0; } @@ -382,8 +388,7 @@ int CStringInput::exec( CMenuTarget* parent, const std::string & ) paint(); - uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings -::TIMING_MENU]); + uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]); bool loop=true; while (loop) @@ -398,8 +403,7 @@ int CStringInput::exec( CMenuTarget* parent, const std::string & ) g_RCInput->getMsgAbsoluteTimeout(&msg, &data, &timeoutEnd, true ); if ( msg <= CRCInput::RC_MaxRC ) - timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings -::TIMING_MENU]); + timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]); if (msg==CRCInput::RC_left) { @@ -525,58 +529,64 @@ int CStringInput::handleOthers(const neutrino_msg_t /*msg*/, const neutrino_msg_ void CStringInput::hide() { - frameBuffer->paintBackgroundBoxRel(x, y, width, height + hheight); + frameBuffer->paintBackgroundBoxRel(x, y, width, height); } -const char * CStringInput::getHint1(void) +void CStringInput::paint(bool sms) { - return g_Locale->getText(hint_1); -} - -void CStringInput::paint(bool buttons) -{ - int iconoffset; - int icol_w, icol_h; - int radius; - - /* if there's a button bar below the stringinput (SMS), no rounded corners */ - if (buttons) - radius = 0; - else - radius = RADIUS_LARGE; - frameBuffer->paintBoxRel(x, y, width, hheight, COL_MENUHEAD_PLUS_0, RADIUS_LARGE, CORNER_TOP); //round - frameBuffer->paintBoxRel(x, y + hheight, width, height - hheight, COL_MENUCONTENT_PLUS_0, radius, CORNER_BOTTOM); + frameBuffer->paintBoxRel(x, y + hheight, width, bheight, COL_MENUCONTENT_PLUS_0, sms ? 0 : RADIUS_LARGE, CORNER_BOTTOM); + int icol_w = 0, icol_h = 0, icol_o = 0; if (!(iconfile.empty())) { frameBuffer->getIconSize(iconfile.c_str(), &icol_w, &icol_h); - frameBuffer->paintIcon(iconfile, x + 8, y, hheight); - iconoffset = icol_w + 10; + frameBuffer->paintIcon(iconfile, x + (offset/2), y, hheight); + icol_o = icol_w + (offset/2); } - else - iconoffset = 0; - g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(x+ 10+ iconoffset, y+ hheight, width- 10- iconoffset, head ? head : g_Locale->getText(name), COL_MENUHEAD, 0, true); // UTF-8 + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(x+ (offset/2)+ icol_o, y+ hheight, width- (offset/2)- icol_o, head ? head : g_Locale->getText(name), COL_MENUHEAD, 0, true); // UTF-8 - if (hint_1 != NONEXISTANT_LOCALE) + int tmp_y = y+ hheight+ offset+ input_h+ offset; + if ((hint_1 != NONEXISTANT_LOCALE) || (hint_2 != NONEXISTANT_LOCALE)) { - g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->RenderString(x+ 20, y+ hheight+ mheight+ iheight+ 40, width- 20, getHint1(), COL_MENUCONTENT, 0, true); // UTF-8 + if (hint_1 != NONEXISTANT_LOCALE) + { + tmp_y += iheight; + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->RenderString(x+ offset, tmp_y, width- 2*offset, g_Locale->getText(hint_1), COL_MENUCONTENT, 0, true); // UTF-8 + } if (hint_2 != NONEXISTANT_LOCALE) - g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->RenderString(x+ 20, y+ hheight+ mheight+ iheight* 2+ 40, width- 20, g_Locale->getText(hint_2), COL_MENUCONTENT, 0, true); // UTF-8 + { + tmp_y += iheight; + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->RenderString(x+ offset, tmp_y, width- 2*offset, g_Locale->getText(hint_2), COL_MENUCONTENT, 0, true); // UTF-8 + } + tmp_y += offset; + } + + icol_w = icol_h = 0; + if (sms) + { + frameBuffer->getIconSize(NEUTRINO_ICON_NUMERIC_PAD, &icol_w, &icol_h); + frameBuffer->paintIcon(NEUTRINO_ICON_NUMERIC_PAD, x + (width/2) - (icol_w/2), tmp_y, 0, COL_MENUCONTENT); + + //buttonbar + ::paintButtons(x, y+ hheight+ bheight, width, CStringInputSMSButtonsCount, CStringInputSMSButtons, fheight); } for (int count=0;countpaintBoxRel(xpos, ypos, xs, ys, COL_MENUCONTENT_PLUS_4); - frameBuffer->paintBoxRel(xpos+ 1, ypos+ 1, xs- 2, ys- 2, bgcolor); + frameBuffer->paintBoxRel(xpos, ypos, input_w, input_h, COL_MENUCONTENT_PLUS_2); + frameBuffer->paintBoxRel(xpos+ 1, ypos+ 1, input_w- 2, input_h- 2, bgcolor); - int xfpos = xpos + ((xs- g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(ch))>>1); - - g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xfpos,ypos+ys, width, ch, color); -} - -void CStringInput::paintChar(int pos) -{ - if(pos<(int)strlen(value)) - paintChar(pos, value[pos]); + int ch_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(ch); + int ch_x = xpos + std::max(input_w/2 - ch_w/2, 0); + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(ch_x, ypos+ input_h, ch_w, ch, color); } CStringInputSMS::CStringInputSMS(const neutrino_locale_t Name, std::string* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon) @@ -616,7 +620,7 @@ CStringInputSMS::CStringInputSMS(const neutrino_locale_t Name, std::string* Valu CStringInputSMS::CStringInputSMS(const neutrino_locale_t Name, char* Value, int Size, const neutrino_locale_t Hint_1, const neutrino_locale_t Hint_2, const char * const Valid_Chars, CChangeObserver* Observ, const char * const Icon) : CStringInput(Name, Value, Size, Hint_1, Hint_2, Valid_Chars, Observ, Icon) - { +{ initSMS(Valid_Chars); } @@ -645,8 +649,23 @@ void CStringInputSMS::initSMS(const char * const Valid_Chars) arraySizes[i] = j; } - height+=260; - y = ((500-height)>>1); + int icol_w = 0, icol_h = 0; + frameBuffer->getIconSize(NEUTRINO_ICON_NUMERIC_PAD, &icol_w, &icol_h); + bheight += icol_h + offset; + + icol_w = icol_h = 0; + for (int i = 0; i < CStringInputSMSButtonsCount; i++) + { + // get max iconsize in buttonbar + int w = 0, h = 0; + frameBuffer->getIconSize(CStringInputSMSButtons[i].button, &w, &h); + icol_w = std::max(icol_w, w); + icol_h = std::max(icol_h, h); + } + fheight = std::max(fheight, icol_h + offset/5); + + height = hheight + bheight + fheight; + y = getScreenStartY(height); } void CStringInputSMS::NormalKeyPressed(const neutrino_msg_t key) @@ -745,22 +764,9 @@ void CStringInputSMS::keyRightPressed() CStringInput::keyRightPressed(); } -const struct button_label CStringInputSMSButtons[2] = -{ - { NEUTRINO_ICON_BUTTON_RED , LOCALE_STRINGINPUT_CAPS }, - { NEUTRINO_ICON_BUTTON_YELLOW, LOCALE_STRINGINPUT_CLEAR } -}; - void CStringInputSMS::paint(bool /*unused*/) { - CStringInput::paint(true); - - int w = 0, h = 0; - frameBuffer->getIconSize(NEUTRINO_ICON_NUMERIC_PAD, &w, &h); - frameBuffer->paintIcon(NEUTRINO_ICON_NUMERIC_PAD, x + (width/2) - (w/2), y+ hheight+ mheight+ iheight* 3+ 30, 0, COL_MENUCONTENT); - - //buttonbar - ::paintButtons(x, y + height, width, 2, CStringInputSMSButtons); + CStringInput::paint(true /* sms */); } void CPINInput::paintChar(int pos) @@ -877,7 +883,7 @@ const char * CPLPINInput::getHint1(void) if (fsk == 0x100) { hint_1 = LOCALE_PARENTALLOCK_LOCKEDCHANNEL; - return CStringInput::getHint1(); + return g_Locale->getText(hint_1); } else { diff --git a/src/gui/widget/stringinput.h b/src/gui/widget/stringinput.h index 8834f3914..97c577ac0 100644 --- a/src/gui/widget/stringinput.h +++ b/src/gui/widget/stringinput.h @@ -4,13 +4,6 @@ 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 @@ -49,8 +42,12 @@ class CStringInput : public CMenuTarget int width; int height; int hheight; // head font height - int mheight; // menu font height int iheight; + int bheight; // body height + int fheight; // footer height + int input_h; // input field height + int input_w; // input field width + int offset; int lower_bound; int upper_bound; @@ -66,9 +63,8 @@ class CStringInput : public CMenuTarget CChangeObserver * observ; virtual void init(); - virtual const char * getHint1(void); - virtual void paint(bool buttons = false); + virtual void paint(bool sms = false); virtual void paintChar(int pos, char c); virtual void paintChar(int pos); diff --git a/src/gui/widget/stringinput_ext.cpp b/src/gui/widget/stringinput_ext.cpp index 44f29523f..e523881d7 100644 --- a/src/gui/widget/stringinput_ext.cpp +++ b/src/gui/widget/stringinput_ext.cpp @@ -4,13 +4,6 @@ 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 @@ -37,6 +30,7 @@ #include #include +#include #include @@ -61,22 +55,41 @@ CExtendedInput::CExtendedInput(const neutrino_locale_t Name, char* Value, const void CExtendedInput::Init(void) { - frameBuffer = CFrameBuffer::getInstance(); + hheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); - mheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); iheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->getHeight(); + input_h = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight() + 2; // font height + border + input_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth("M") + 2; // hack font width + border + offset = 20; - width = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(g_Locale->getText(name), true) + 20; // UTF-8 - height = hheight+ mheight+ 20; + width = frameBuffer->getScreenWidth() / 100 * 45; - if (hint_1 != NONEXISTANT_LOCALE) - height += iheight; - if (hint_2 != NONEXISTANT_LOCALE) - height += iheight; + int tmp_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getRenderWidth(g_Locale->getText(name), true); // UTF-8 + width = std::max(width, tmp_w + offset); - x = frameBuffer->getScreenX() + ((frameBuffer->getScreenWidth() - width)>>1); - y = frameBuffer->getScreenY() + ((frameBuffer->getScreenHeight() - height)>>1); + bheight = input_h + 2*offset; + if ((hint_1 != NONEXISTANT_LOCALE) || (hint_2 != NONEXISTANT_LOCALE)) + { + if (hint_1 != NONEXISTANT_LOCALE) + { + tmp_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->getRenderWidth(g_Locale->getText(hint_1), true); + width = std::max(width, tmp_w + 2*offset); + bheight += iheight; + } + if (hint_2 != NONEXISTANT_LOCALE) + { + tmp_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->getRenderWidth(g_Locale->getText(hint_2), true); + width = std::max(width, tmp_w + 2*offset); + bheight += iheight; + } + bheight += offset; + } + + height = hheight+ bheight; + + x = getScreenStartX(width); + y = getScreenStartY(height); } CExtendedInput::~CExtendedInput() @@ -107,32 +120,15 @@ void CExtendedInput::calculateDialog() { selectedChar = i; } - maxX = ix > maxX ? ix : maxX; - maxY = iy > maxY ? iy : maxY; + maxX = std::max(ix, maxX); + maxY = std::max(iy, maxY); } - width = width > maxX+40 ? width : maxX+40; - height = height > maxY + hheight + mheight ? height : maxY + hheight + mheight; + width = std::max(width, maxX + 2*offset); + height = std::max(height, maxY + bheight); - hintPosY = height -10; - - if (hint_1 != NONEXISTANT_LOCALE) { - height += iheight; - int hw = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->getRenderWidth(g_Locale->getText(hint_1), true); - if(width < hw + 40) - width = hw + 40; - } - if (hint_2 != NONEXISTANT_LOCALE) { - height += iheight; - int hw = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->getRenderWidth(g_Locale->getText(hint_2), true); - if(width < hw) - width = hw; - } - - x = frameBuffer->getScreenX() + ((frameBuffer->getScreenWidth() - width)>>1); - y = frameBuffer->getScreenY() + ((frameBuffer->getScreenHeight() - height)>>1); - - hintPosY += y; + x = getScreenStartX(width); + y = getScreenStartY(height); } @@ -162,8 +158,7 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & ) strcpy(dispval, value); paint(); - uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings -::TIMING_MENU]); + uint64_t timeoutEnd = CRCInput::calcTimeoutEnd(g_settings.timing[SNeutrinoSettings::TIMING_MENU] == 0 ? 0xFFFF : g_settings.timing[SNeutrinoSettings::TIMING_MENU]); bool loop=true; while (loop) @@ -198,8 +193,8 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & ) } } if(found) { - inputFields[oldSelectedChar]->paint( x+20, y+hheight +20, false ); - inputFields[selectedChar]->paint( x+20, y+hheight +20, true ); + inputFields[oldSelectedChar]->paint(x+ offset, y+ hheight+ offset, false ); + inputFields[selectedChar]->paint(x+ offset, y+ hheight+ offset, true ); std::string tmp = value; CVFD::getInstance()->showMenuText(1, tmp.c_str(), selectedChar+1); } @@ -226,8 +221,8 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & ) } } if(found) { - inputFields[oldSelectedChar]->paint( x+20, y+hheight +20, false ); - inputFields[selectedChar]->paint( x+20, y+hheight +20, true ); + inputFields[oldSelectedChar]->paint(x+ offset, y+ hheight+ offset, false ); + inputFields[selectedChar]->paint(x+ offset, y+ hheight+ offset, true ); std::string tmp = value; CVFD::getInstance()->showMenuText(1, tmp.c_str(), selectedChar+1); } @@ -236,7 +231,7 @@ int CExtendedInput::exec( CMenuTarget* parent, const std::string & ) || (msg == CRCInput::RC_up) || (msg == CRCInput::RC_down)) { inputFields[selectedChar]->keyPressed(msg); - inputFields[selectedChar]->paint( x+20, y+hheight +20, true ); + inputFields[selectedChar]->paint(x+ offset, y+ hheight+ offset, true ); } else if (msg==CRCInput::RC_ok) { @@ -301,23 +296,29 @@ void CExtendedInput::hide() void CExtendedInput::paint() { frameBuffer->paintBoxRel(x, y, width, hheight, COL_MENUHEAD_PLUS_0, RADIUS_LARGE, CORNER_TOP); - frameBuffer->paintBoxRel(x, y + hheight, width, height - hheight, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM); + frameBuffer->paintBoxRel(x, y + hheight, width, bheight, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM); - g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(x+ 10, y+ hheight, width- 10, g_Locale->getText(name), COL_MENUHEAD, 0, true); // UTF-8 + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(x+ (offset/2), y+ hheight, width- (offset/2), g_Locale->getText(name), COL_MENUHEAD, 0, true); // UTF-8 - if (hint_1 != NONEXISTANT_LOCALE) + int tmp_y = y+ hheight+ offset+ input_h+ offset; + + if ((hint_1 != NONEXISTANT_LOCALE) || (hint_2 != NONEXISTANT_LOCALE)) { - g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->RenderString(x+ 20, hintPosY, width- 20, g_Locale->getText(hint_1), COL_MENUCONTENT, 0, true); // UTF-8 + if (hint_1 != NONEXISTANT_LOCALE) + { + tmp_y += iheight; + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->RenderString(x+ offset, tmp_y, width- 2*offset, g_Locale->getText(hint_1), COL_MENUCONTENT, 0, true); // UTF-8 + } if (hint_2 != NONEXISTANT_LOCALE) - g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->RenderString(x+ 20, hintPosY + iheight, width- 20, g_Locale->getText(hint_2), COL_MENUCONTENT, 0, true); // UTF-8 + { + tmp_y += iheight; + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_INFO]->RenderString(x+ offset, tmp_y, width- 2*offset, g_Locale->getText(hint_2), COL_MENUCONTENT, 0, true); // UTF-8 + } + tmp_y += offset; } for(unsigned int i=0; ipaint( x+20, y+hheight +20, (i== (unsigned int) selectedChar) ); - } - - + inputFields[i]->paint(x+ offset, y+ hheight+ offset, (i== (unsigned int) selectedChar) ); } //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -326,8 +327,8 @@ void CExtendedInput::paint() CExtendedInput_Item_Char::CExtendedInput_Item_Char(const std::string & Chars, bool Selectable ) { frameBuffer = CFrameBuffer::getInstance(); - idx = 20; - idy = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); + input_h = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight() + 2; // font height + border + input_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth("M") + 2; // hack font width + border allowedChars = Chars; selectable = Selectable; } @@ -336,7 +337,7 @@ void CExtendedInput_Item_Char::init(int &x, int &y) { ix = x; iy = y; - x += idx; + x += input_w; } void CExtendedInput_Item_Char::setAllowedChars( const std::string & ac ) @@ -346,8 +347,10 @@ void CExtendedInput_Item_Char::setAllowedChars( const std::string & ac ) void CExtendedInput_Item_Char::paint(int x, int y, bool focusGained ) { - int startx = ix + x; - int starty = iy + y; + int xpos = ix + x; + int ypos = iy + y; + + char ch[2] = {*data, 0}; uint8_t color; fb_pixel_t bgcolor; @@ -363,15 +366,12 @@ void CExtendedInput_Item_Char::paint(int x, int y, bool focusGained ) bgcolor = COL_MENUCONTENT_PLUS_0; } - frameBuffer->paintBoxRel( startx, starty, idx, idy, COL_MENUCONTENT_PLUS_4); - frameBuffer->paintBoxRel( startx+1, starty+1, idx-2, idy-2, bgcolor); + frameBuffer->paintBoxRel(xpos, ypos, input_w, input_h, COL_MENUCONTENT_PLUS_2); + frameBuffer->paintBoxRel(xpos+ 1, ypos+ 1, input_w- 2, input_h- 2, bgcolor); - char text[2]; - text[0] = *data; - text[1] = 0; - int xfpos = startx + 1 + ((idx- g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth( text ))>>1); - - g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(xfpos,starty+idy, idx, text, color); + int ch_w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(ch); + int ch_x = xpos + std::max(input_w/2 - ch_w/2, 0); + g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(ch_x, ypos+ input_h, ch_w, ch, color); } bool CExtendedInput_Item_Char::isAllowedChar( char ch ) diff --git a/src/gui/widget/stringinput_ext.h b/src/gui/widget/stringinput_ext.h index af11089f1..2fe9d7fea 100644 --- a/src/gui/widget/stringinput_ext.h +++ b/src/gui/widget/stringinput_ext.h @@ -53,8 +53,11 @@ class CExtendedInput : public CMenuTarget int height; int hintPosY; int hheight; // head font height - int mheight; // menu font height int iheight; + int bheight; // body height + int input_h; // input field height + int input_w; // input field width + int offset; std::vector inputFields; int selectedChar; @@ -88,7 +91,9 @@ class CExtendedInput_Item { protected: CFrameBuffer *frameBuffer; - int ix, iy, idx, idy; + int input_h; // input field height + int input_w; // input field width + int ix, iy; char* data; public: From 983e33f96d7608080080697c9c9a617562ad2d53 Mon Sep 17 00:00:00 2001 From: svenhoefer Date: Sat, 9 Mar 2013 15:17:08 +0100 Subject: [PATCH 2/2] - stringinput: fix width of menutitle in dialogs --- src/gui/widget/stringinput.cpp | 2 +- src/gui/widget/stringinput_ext.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/widget/stringinput.cpp b/src/gui/widget/stringinput.cpp index 01c02843e..dfa2dc329 100644 --- a/src/gui/widget/stringinput.cpp +++ b/src/gui/widget/stringinput.cpp @@ -545,7 +545,7 @@ void CStringInput::paint(bool sms) icol_o = icol_w + (offset/2); } - g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(x+ (offset/2)+ icol_o, y+ hheight, width- (offset/2)- icol_o, head ? head : g_Locale->getText(name), COL_MENUHEAD, 0, true); // UTF-8 + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(x+ (offset/2)+ icol_o, y+ hheight, width- offset- icol_o, head ? head : g_Locale->getText(name), COL_MENUHEAD, 0, true); // UTF-8 int tmp_y = y+ hheight+ offset+ input_h+ offset; if ((hint_1 != NONEXISTANT_LOCALE) || (hint_2 != NONEXISTANT_LOCALE)) diff --git a/src/gui/widget/stringinput_ext.cpp b/src/gui/widget/stringinput_ext.cpp index e523881d7..70e36bd26 100644 --- a/src/gui/widget/stringinput_ext.cpp +++ b/src/gui/widget/stringinput_ext.cpp @@ -298,7 +298,7 @@ void CExtendedInput::paint() frameBuffer->paintBoxRel(x, y, width, hheight, COL_MENUHEAD_PLUS_0, RADIUS_LARGE, CORNER_TOP); frameBuffer->paintBoxRel(x, y + hheight, width, bheight, COL_MENUCONTENT_PLUS_0, RADIUS_LARGE, CORNER_BOTTOM); - g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(x+ (offset/2), y+ hheight, width- (offset/2), g_Locale->getText(name), COL_MENUHEAD, 0, true); // UTF-8 + g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->RenderString(x+ (offset/2), y+ hheight, width- offset, g_Locale->getText(name), COL_MENUHEAD, 0, true); // UTF-8 int tmp_y = y+ hheight+ offset+ input_h+ offset;