1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 13:44:04 +02:00

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.
This commit is contained in:
Maarten ter Huurne 2014-08-16 05:47:48 +02:00
parent e5a432cb6b
commit 428a316bc1
7 changed files with 13 additions and 24 deletions

View File

@ -18,7 +18,6 @@ BrowseDialog::BrowseDialog(
, title(title)
, subtitle(subtitle)
, ts_pressed(false)
, buttonBox(gmenu2x)
{
buttonBox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/left.png")));
unique_ptr<IconButton> 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);

View File

@ -6,10 +6,6 @@
using std::unique_ptr;
using std::move;
ButtonBox::ButtonBox(GMenu2X *gmenu2x) : gmenu2x(gmenu2x)
{
}
void ButtonBox::add(unique_ptr<IconButton> 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);

View File

@ -12,17 +12,14 @@ class Surface;
class ButtonBox
{
public:
ButtonBox(GMenu2X *gmenu2x);
void add(std::unique_ptr<IconButton> button);
void clear();
void paint(Surface& s, unsigned int x);
void paint(Surface& s, int x, int y);
void handleTS();
private:
std::vector<std::unique_ptr<IconButton>> buttons;
GMenu2X *gmenu2x;
};
#endif

View File

@ -97,26 +97,25 @@ InputDialog::InputDialog(GMenu2X *gmenu2x, InputManager &inputMgr_,
setKeyboard(0);
buttonbox = new ButtonBox(gmenu2x);
unique_ptr<IconButton> 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<IconButton> 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<IconButton> 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<IconButton> 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;

View File

@ -22,12 +22,12 @@
#define INPUTDIALOG_H
#include "dialog.h"
#include "buttonbox.h"
#include <SDL.h>
#include <string>
#include <vector>
class ButtonBox;
class InputManager;
class Touchscreen;
@ -59,7 +59,7 @@ private:
std::vector<std::string> *kb;
int kbLength, kbWidth, kbHeight, kbLeft;
SDL_Rect kbRect;
ButtonBox *buttonbox;
ButtonBox buttonbox;
std::string input;
};

View File

@ -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);
}

View File

@ -62,7 +62,7 @@ bool WallpaperDialog::exec()
uint i, selected = 0, firstElement = 0, iY;
ButtonBox buttonbox(gmenu2x);
ButtonBox buttonbox;
buttonbox.add(unique_ptr<IconButton>(new IconButton(gmenu2x, ts, "skin:imgs/buttons/accept.png", gmenu2x->tr["Select"])));
buttonbox.add(unique_ptr<IconButton>(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;