From 428a316bc1674840f0cb824f720e05921a479a32 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sat, 16 Aug 2014 05:47:48 +0200 Subject: [PATCH] Removed GMenu2X pointer from ButtonBox It was only used to fetch resY, so I replaced that by taking the y-coordinate as an argument. That is also more consistent with the x-coordinate which was already an argument. The x-coordinate was changed to a signed int, since that is the norm for paint coordinates. It can be useful for drawing widgets that are partially off screen, for example during a (dis)appear animation. In InputDialog, the ButtonBox field was changed from a pointer to a plain data member. There was no need to dynamically allocate it. --- src/browsedialog.cpp | 3 +-- src/buttonbox.cpp | 7 +------ src/buttonbox.h | 5 +---- src/inputdialog.cpp | 11 +++++------ src/inputdialog.h | 4 ++-- src/menusetting.cpp | 3 +-- src/wallpaperdialog.cpp | 4 ++-- 7 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/browsedialog.cpp b/src/browsedialog.cpp index cc0e712..03ac73f 100644 --- a/src/browsedialog.cpp +++ b/src/browsedialog.cpp @@ -18,7 +18,6 @@ BrowseDialog::BrowseDialog( , title(title) , subtitle(subtitle) , ts_pressed(false) - , buttonBox(gmenu2x) { buttonBox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png"))); unique_ptr btnUp(new IconButton( @@ -233,7 +232,7 @@ void BrowseDialog::paint() drawTitleIcon(bg, "icons/explorer.png", true); writeTitle(bg, title); writeSubTitle(bg, subtitle); - buttonBox.paint(bg, 5); + buttonBox.paint(bg, 5, gmenu2x->resY - 1); bg.convertToDisplayFormat(); bg.blit(s, 0, 0); diff --git a/src/buttonbox.cpp b/src/buttonbox.cpp index 06e5b7d..3655914 100644 --- a/src/buttonbox.cpp +++ b/src/buttonbox.cpp @@ -6,10 +6,6 @@ using std::unique_ptr; using std::move; -ButtonBox::ButtonBox(GMenu2X *gmenu2x) : gmenu2x(gmenu2x) -{ -} - void ButtonBox::add(unique_ptr button) { buttons.push_back(move(button)); @@ -20,9 +16,8 @@ void ButtonBox::clear() buttons.clear(); } -void ButtonBox::paint(Surface& s, unsigned int x) +void ButtonBox::paint(Surface& s, int x, int y) { - const int y = gmenu2x->resY - 1; for (auto& button : buttons) { auto rect = button->getRect(); button->setPosition(x, y - rect.h); diff --git a/src/buttonbox.h b/src/buttonbox.h index 7b68f9d..b3c42ca 100644 --- a/src/buttonbox.h +++ b/src/buttonbox.h @@ -12,17 +12,14 @@ class Surface; class ButtonBox { public: - ButtonBox(GMenu2X *gmenu2x); - void add(std::unique_ptr button); void clear(); - void paint(Surface& s, unsigned int x); + void paint(Surface& s, int x, int y); void handleTS(); private: std::vector> buttons; - GMenu2X *gmenu2x; }; #endif diff --git a/src/inputdialog.cpp b/src/inputdialog.cpp index 286b2a4..68b3e1e 100644 --- a/src/inputdialog.cpp +++ b/src/inputdialog.cpp @@ -97,26 +97,25 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_, setKeyboard(0); - buttonbox = new ButtonBox(gmenu2x); unique_ptr btnBackspace(new IconButton( gmenu2x, ts, "skin:imgs/buttons/l.png", gmenu2x->tr["Backspace"])); btnBackspace->setAction(BIND(&InputDialog::backspace)); - buttonbox->add(move(btnBackspace)); + buttonbox.add(move(btnBackspace)); unique_ptr btnSpace( new IconButton(gmenu2x, ts, "skin:imgs/buttons/r.png", gmenu2x->tr["Space"])); btnSpace->setAction(BIND(&InputDialog::space)); - buttonbox->add(move(btnSpace)); + buttonbox.add(move(btnSpace)); unique_ptr btnConfirm(new IconButton( gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Confirm"])); btnConfirm->setAction(BIND(&InputDialog::confirm)); - buttonbox->add(move(btnConfirm)); + buttonbox.add(move(btnConfirm)); unique_ptr btnChangeKeys(new IconButton( gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Change keys"])); btnChangeKeys->setAction(BIND(&InputDialog::changeKeys)); - buttonbox->add(move(btnChangeKeys)); + buttonbox.add(move(btnChangeKeys)); } void InputDialog::setKeyboard(int kb) { @@ -153,7 +152,7 @@ bool InputDialog::exec() { drawTitleIcon(bg, icon, false); writeTitle(bg, title); writeSubTitle(bg, text); - buttonbox->paint(bg, 5); + buttonbox.paint(bg, 5, gmenu2x->resY - 1); bg.convertToDisplayFormat(); close = false; diff --git a/src/inputdialog.h b/src/inputdialog.h index 77cec8d..998ee45 100644 --- a/src/inputdialog.h +++ b/src/inputdialog.h @@ -22,12 +22,12 @@ #define INPUTDIALOG_H #include "dialog.h" +#include "buttonbox.h" #include #include #include -class ButtonBox; class InputManager; class Touchscreen; @@ -59,7 +59,7 @@ private: std::vector *kb; int kbLength, kbWidth, kbHeight, kbLeft; SDL_Rect kbRect; - ButtonBox *buttonbox; + ButtonBox buttonbox; std::string input; }; diff --git a/src/menusetting.cpp b/src/menusetting.cpp index 46c8c42..4f48b2d 100644 --- a/src/menusetting.cpp +++ b/src/menusetting.cpp @@ -29,7 +29,6 @@ using std::string; MenuSetting::MenuSetting(GMenu2X *gmenu2x, const string &name, const string &description) : gmenu2x(gmenu2x) - , buttonBox(gmenu2x) , name(name) , description(description) { @@ -58,5 +57,5 @@ void MenuSetting::drawSelected(int valueX, int y, int h) s.box(0, y, valueX - 5, h, gmenu2x->skinConfColors[COLOR_SELECTION_BG]); - buttonBox.paint(s, 5); + buttonBox.paint(s, 5, gmenu2x->resY - 1); } diff --git a/src/wallpaperdialog.cpp b/src/wallpaperdialog.cpp index 0009cfe..8648307 100644 --- a/src/wallpaperdialog.cpp +++ b/src/wallpaperdialog.cpp @@ -62,7 +62,7 @@ bool WallpaperDialog::exec() uint i, selected = 0, firstElement = 0, iY; - ButtonBox buttonbox(gmenu2x); + ButtonBox buttonbox; buttonbox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Select"]))); buttonbox.add(unique_ptr(new IconButton(gmenu2x, ts, "skin:imgs/buttons/cancel.png", gmenu2x->tr["Exit"]))); @@ -90,7 +90,7 @@ bool WallpaperDialog::exec() writeTitle(s, gmenu2x->tr["Wallpaper selection"]); writeSubTitle(s, gmenu2x->tr["Select a wallpaper from the list"]); - buttonbox.paint(s, 5); + buttonbox.paint(s, 5, gmenu2x->resY - 1); //Selection iY = selected - firstElement;