From bac622fc39701bd5337fe9697b339109f19d76e2 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Thu, 24 Jul 2014 06:08:54 +0000 Subject: [PATCH] Cap the width of setting names in SettingDialog to the width of the longest Setting values are now displayed 10 pixels to the right of setting names, as passed to MenuSetting::draw. This commit also contains the following cleanups: * The height of a row is passed to MenuSetting's draw and touchscreen methods. * MenuSettingRGBA's magic constant (36) to separate the text for a color's four components is now a named constant. * MenuSettingRGBA's color preview squares are now rowHeight - 2 pixels tall, and have a white border surrounded by a black border to help view the color it contains in both light and dark themes. * The rectangle behind the selected setting's name is now drawn by that setting's drawSelected method. --- src/menusetting.cpp | 10 +++++++--- src/menusetting.h | 7 ++++--- src/menusettingbool.cpp | 6 +++--- src/menusettingbool.h | 2 +- src/menusettingint.cpp | 6 +++--- src/menusettingint.h | 2 +- src/menusettingrgba.cpp | 36 ++++++++++++++++++----------------- src/menusettingrgba.h | 7 +++---- src/menusettingstringbase.cpp | 6 +++--- src/menusettingstringbase.h | 2 +- src/settingsdialog.cpp | 21 ++++++++------------ 11 files changed, 53 insertions(+), 52 deletions(-) diff --git a/src/menusetting.cpp b/src/menusetting.cpp index db6cee8..26d5c3a 100644 --- a/src/menusetting.cpp +++ b/src/menusetting.cpp @@ -39,17 +39,21 @@ MenuSetting::~MenuSetting() { } -void MenuSetting::draw(int y) +void MenuSetting::draw(int /*valueX*/, int y, int /*h*/) { gmenu2x->s->write( gmenu2x->font, name, 5, y, Font::HAlignLeft, Font::VAlignTop ); } -void MenuSetting::handleTS() +void MenuSetting::handleTS(int /*valueX*/, int /*y*/, int /*h*/) { buttonBox.handleTS(); } -void MenuSetting::drawSelected(int /*y*/) +void MenuSetting::drawSelected(int valueX, int y, int h) { + // The selection rectangle + gmenu2x->s->box(0, y, valueX - 5, h, + gmenu2x->skinConfColors[COLOR_SELECTION_BG]); + buttonBox.paint(gmenu2x->s, 5); } diff --git a/src/menusetting.h b/src/menusetting.h index 75cc528..7b2aa09 100644 --- a/src/menusetting.h +++ b/src/menusetting.h @@ -44,13 +44,14 @@ public: const std::string &description); virtual ~MenuSetting(); - virtual void draw(int y); - virtual void handleTS(); + virtual void draw(int valueX, int y, int h); + virtual void handleTS(int valueX, int y, int h); virtual bool handleButtonPress(InputManager::Button button) = 0; - virtual void drawSelected(int y); + virtual void drawSelected(int valueX, int y, int h); virtual bool edited() = 0; + const std::string &getName() { return name; } const std::string &getDescription() { return description; } }; diff --git a/src/menusettingbool.cpp b/src/menusettingbool.cpp index 1e3258b..3909824 100644 --- a/src/menusettingbool.cpp +++ b/src/menusettingbool.cpp @@ -65,10 +65,10 @@ void MenuSettingBool::initButton() buttonBox.add(btn); } -void MenuSettingBool::draw(int y) +void MenuSettingBool::draw(int valueX, int y, int h) { - MenuSetting::draw(y); - gmenu2x->s->write( gmenu2x->font, strvalue, 155, y, Font::HAlignLeft, Font::VAlignTop ); + MenuSetting::draw(valueX, y, h); + gmenu2x->s->write( gmenu2x->font, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop ); } bool MenuSettingBool::handleButtonPress(InputManager::Button button) diff --git a/src/menusettingbool.h b/src/menusettingbool.h index c5059ba..f816fb2 100644 --- a/src/menusettingbool.h +++ b/src/menusettingbool.h @@ -48,7 +48,7 @@ public: int *value); virtual ~MenuSettingBool() {} - virtual void draw(int y); + virtual void draw(int valueX, int y, int h); virtual bool handleButtonPress(InputManager::Button button); virtual bool edited(); diff --git a/src/menusettingint.cpp b/src/menusettingint.cpp index 7ddbb22..c6356df 100644 --- a/src/menusettingint.cpp +++ b/src/menusettingint.cpp @@ -67,10 +67,10 @@ MenuSettingInt::MenuSettingInt( buttonBox.add(btn); } -void MenuSettingInt::draw(int y) +void MenuSettingInt::draw(int valueX, int y, int h) { - MenuSetting::draw(y); - gmenu2x->s->write(gmenu2x->font, strvalue, 155, y, Font::HAlignLeft, Font::VAlignTop); + MenuSetting::draw(valueX, y, h); + gmenu2x->s->write(gmenu2x->font, strvalue, valueX, y, Font::HAlignLeft, Font::VAlignTop); } bool MenuSettingInt::handleButtonPress(InputManager::Button button) diff --git a/src/menusettingint.h b/src/menusettingint.h index 8cd6248..62e9519 100644 --- a/src/menusettingint.h +++ b/src/menusettingint.h @@ -44,7 +44,7 @@ public: virtual ~MenuSettingInt() {} virtual bool handleButtonPress(InputManager::Button button); - virtual void draw(int); + virtual void draw(int valueX, int y, int h); virtual bool edited(); virtual void setValue(int value); diff --git a/src/menusettingrgba.cpp b/src/menusettingrgba.cpp index 0993efb..f7da467 100644 --- a/src/menusettingrgba.cpp +++ b/src/menusettingrgba.cpp @@ -30,6 +30,8 @@ using std::string; using std::stringstream; +constexpr unsigned int COMPONENT_WIDTH = 36; + MenuSettingRGBA::MenuSettingRGBA( GMenu2X *gmenu2x, Touchscreen &ts_, const string &name, const string &description, RGBAColor *value) @@ -49,28 +51,28 @@ MenuSettingRGBA::MenuSettingRGBA( updateButtonBox(); } -void MenuSettingRGBA::draw(int y) { - this->y = y; - MenuSetting::draw(y); - gmenu2x->s->rectangle( 153, y+1, 11, 11, 0,0,0,255 ); - gmenu2x->s->box( 154, y+2, 9, 9, value() ); - gmenu2x->s->write( gmenu2x->font, "R: "+strR, 169, y, Font::HAlignLeft, Font::VAlignTop ); - gmenu2x->s->write( gmenu2x->font, "G: "+strG, 205, y, Font::HAlignLeft, Font::VAlignTop ); - gmenu2x->s->write( gmenu2x->font, "B: "+strB, 241, y, Font::HAlignLeft, Font::VAlignTop ); - gmenu2x->s->write( gmenu2x->font, "A: "+strA, 277, y, Font::HAlignLeft, Font::VAlignTop ); +void MenuSettingRGBA::draw(int valueX, int y, int h) { + MenuSetting::draw(valueX, y, h); + gmenu2x->s->rectangle( valueX, y + 1, h - 2, h - 2, 0,0,0,255 ); + gmenu2x->s->rectangle( valueX + 1, y + 2, h - 4, h - 4, 255,255,255,255 ); + gmenu2x->s->box( valueX + 2, y + 3, h - 6, h - 6, value() ); + gmenu2x->s->write( gmenu2x->font, "R: "+strR, valueX + h + 3, y, Font::HAlignLeft, Font::VAlignTop ); + gmenu2x->s->write( gmenu2x->font, "G: "+strG, valueX + h + 3 + COMPONENT_WIDTH, y, Font::HAlignLeft, Font::VAlignTop ); + gmenu2x->s->write( gmenu2x->font, "B: "+strB, valueX + h + 3 + COMPONENT_WIDTH * 2, y, Font::HAlignLeft, Font::VAlignTop ); + gmenu2x->s->write( gmenu2x->font, "A: "+strA, valueX + h + 3 + COMPONENT_WIDTH * 3, y, Font::HAlignLeft, Font::VAlignTop ); } -void MenuSettingRGBA::handleTS() { +void MenuSettingRGBA::handleTS(int valueX, int y, int h) { if (ts.pressed()) { for (int i=0; i<4; i++) { - if (i!=selPart && ts.inRect(166+i*36,y,36,14)) { + if (i!=selPart && ts.inRect(valueX + h + i * COMPONENT_WIDTH,y,COMPONENT_WIDTH,h)) { selPart = i; - i = 4; + break; } } } - MenuSetting::handleTS(); + MenuSetting::handleTS(valueX, y, h); } bool MenuSettingRGBA::handleButtonPress(InputManager::Button button) @@ -199,12 +201,12 @@ unsigned short MenuSettingRGBA::getSelPart() } } -void MenuSettingRGBA::drawSelected(int y) +void MenuSettingRGBA::drawSelected(int valueX, int y, int h) { - int x = 166+selPart*36; - gmenu2x->s->box( x, y, 36, 14, gmenu2x->skinConfColors[COLOR_SELECTION_BG] ); + int x = valueX + selPart * COMPONENT_WIDTH; + gmenu2x->s->box( x + h, y, COMPONENT_WIDTH, h, gmenu2x->skinConfColors[COLOR_SELECTION_BG] ); - MenuSetting::drawSelected(y); + MenuSetting::drawSelected(valueX, y, h); } bool MenuSettingRGBA::edited() diff --git a/src/menusettingrgba.h b/src/menusettingrgba.h index 097bbae..2860b2c 100644 --- a/src/menusettingrgba.h +++ b/src/menusettingrgba.h @@ -32,7 +32,6 @@ class MenuSettingRGBA : public MenuSetting { private: Touchscreen &ts; unsigned short selPart; - int y; std::string strR, strG, strB, strA; RGBAColor originalValue; RGBAColor *_value; @@ -53,10 +52,10 @@ public: RGBAColor *value); virtual ~MenuSettingRGBA() {}; - virtual void draw(int y); - virtual void handleTS(); + virtual void draw(int valueX, int y, int h); + virtual void handleTS(int valueX, int y, int h); virtual bool handleButtonPress(InputManager::Button button); - virtual void drawSelected(int y); + virtual void drawSelected(int valueX, int y, int h); virtual bool edited(); void setSelPart(unsigned short value); diff --git a/src/menusettingstringbase.cpp b/src/menusettingstringbase.cpp index 16ae01c..a5e19a7 100644 --- a/src/menusettingstringbase.cpp +++ b/src/menusettingstringbase.cpp @@ -37,10 +37,10 @@ MenuSettingStringBase::~MenuSettingStringBase() { } -void MenuSettingStringBase::draw(int y) +void MenuSettingStringBase::draw(int valueX, int y, int h) { - MenuSetting::draw(y); - gmenu2x->s->write(gmenu2x->font, value(), 155, y, + MenuSetting::draw(valueX, y, h); + gmenu2x->s->write(gmenu2x->font, value(), valueX, y, Font::HAlignLeft, Font::VAlignTop); } diff --git a/src/menusettingstringbase.h b/src/menusettingstringbase.h index 0becbf0..50e6524 100644 --- a/src/menusettingstringbase.h +++ b/src/menusettingstringbase.h @@ -37,7 +37,7 @@ public: const std::string &description, std::string *value); virtual ~MenuSettingStringBase(); - virtual void draw(int y); + virtual void draw(int valueX, int y, int h); virtual bool handleButtonPress(InputManager::Button button); virtual bool edited(); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index cd00b6c..f88f2f3 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -72,6 +72,11 @@ bool SettingsDialog::exec() { uint rowHeight = gmenu2x->font->getLineSpacing() + 1; // gp2x=15+1 / pandora=19+1 uint numRows = (gmenu2x->resY - topBarHeight - 20) / rowHeight; + uint maxNameWidth = 0; + for (auto it = voices.begin(); it != voices.end(); it++) { + maxNameWidth = max(maxNameWidth, (uint) gmenu2x->font->getTextWidth((*it)->getName())); + } + while (!close) { if (ts.available()) ts.poll(); @@ -89,19 +94,10 @@ bool SettingsDialog::exec() { //selection uint iY = topBarHeight + 2 + (sel - firstElement) * rowHeight; - gmenu2x->s->setClipRect(clipRect); - if (sels->box( - 1, iY, 148, rowHeight - 2, - gmenu2x->skinConfColors[COLOR_SELECTION_BG] - ); - } - gmenu2x->s->clearClipRect(); //selected option - voices[sel]->drawSelected(iY); + voices[sel]->drawSelected(maxNameWidth + 15, iY, rowHeight); - gmenu2x->s->setClipRect(clipRect); if (ts_pressed && !ts.pressed()) { ts_pressed = false; } @@ -110,7 +106,7 @@ bool SettingsDialog::exec() { } for (i=firstElement; idraw(iY * rowHeight + topBarHeight + 2); + voices[i]->draw(maxNameWidth + 15, iY * rowHeight + topBarHeight + 2, rowHeight); if (ts.available() && ts.pressed() && ts.inRect( touchRect.x, touchRect.y + (iY * rowHeight), touchRect.w, rowHeight @@ -119,7 +115,6 @@ bool SettingsDialog::exec() { sel = i; } } - gmenu2x->s->clearClipRect(); gmenu2x->drawScrollBar(numRows, voices.size(), firstElement); @@ -127,7 +122,7 @@ bool SettingsDialog::exec() { writeSubTitle(voices[sel]->getDescription()); gmenu2x->s->flip(); - voices[sel]->handleTS(); + voices[sel]->handleTS(maxNameWidth + 15, iY, rowHeight); InputManager::Button button = inputMgr.waitForPressedButton(); if (!voices[sel]->handleButtonPress(button)) {