1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-11-22 18:15:54 +02:00

Make ButtonBox deal with IconButtons instead of generic Buttons

Nowhere in the code do we actually mix IconButtons and Links (the other
Button subclass), so I'm thinking of breaking up this class hierarchy
or at least making the inheritance private.

Also switched to C++11 style loops.
This commit is contained in:
Maarten ter Huurne 2013-08-12 22:17:26 +02:00
parent 90afa096e7
commit 06ee35bb7a
4 changed files with 14 additions and 16 deletions

View File

@ -1,9 +1,8 @@
#include "button.h"
#include "gmenu2x.h"
#include "buttonbox.h" #include "buttonbox.h"
#include "gmenu2x.h"
#include "iconbutton.h"
ButtonBox::ButtonBox(GMenu2X *gmenu2x) : gmenu2x(gmenu2x) ButtonBox::ButtonBox(GMenu2X *gmenu2x) : gmenu2x(gmenu2x)
{ {
} }
@ -13,7 +12,7 @@ ButtonBox::~ButtonBox()
clear(); clear();
} }
void ButtonBox::add(Button *button) void ButtonBox::add(IconButton *button)
{ {
buttons.push_back(button); buttons.push_back(button);
} }
@ -25,12 +24,12 @@ void ButtonBox::clear()
void ButtonBox::paint(unsigned int posX) void ButtonBox::paint(unsigned int posX)
{ {
for (ButtonList::const_iterator it = buttons.begin(); it != buttons.end(); ++it) for (auto button : buttons)
posX = gmenu2x->drawButton(*it, posX); posX = gmenu2x->drawButton(button, posX);
} }
void ButtonBox::handleTS() void ButtonBox::handleTS()
{ {
for (ButtonList::iterator it = buttons.begin(); it != buttons.end(); ++it) for (auto button : buttons)
(*it)->handleTS(); button->handleTS();
} }

View File

@ -4,7 +4,7 @@
#include <vector> #include <vector>
class GMenu2X; class GMenu2X;
class Button; class IconButton;
class ButtonBox class ButtonBox
{ {
@ -12,15 +12,14 @@ public:
ButtonBox(GMenu2X *gmenu2x); ButtonBox(GMenu2X *gmenu2x);
~ButtonBox(); ~ButtonBox();
void add(Button *button); void add(IconButton *button);
void clear(); void clear();
void paint(unsigned int posX); void paint(unsigned int posX);
void handleTS(); void handleTS();
private:
typedef std::vector<Button*> ButtonList;
ButtonList buttons; private:
std::vector<IconButton*> buttons;
GMenu2X *gmenu2x; GMenu2X *gmenu2x;
}; };

View File

@ -1158,7 +1158,7 @@ string GMenu2X::getDiskFree(const char *path) {
return df; return df;
} }
int GMenu2X::drawButton(Button *btn, int x, int y) { int GMenu2X::drawButton(IconButton *btn, int x, int y) {
if (y<0) y = resY+y; if (y<0) y = resY+y;
btn->setPosition(x, y-7); btn->setPosition(x, y-7);
btn->paint(); btn->paint();

View File

@ -187,7 +187,7 @@ public:
void deleteSection(); void deleteSection();
void initBG(); void initBG();
int drawButton(Button *btn, int x=5, int y=-10); int drawButton(IconButton *btn, int x=5, int y=-10);
int drawButton(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10); int drawButton(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10);
int drawButtonRight(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10); int drawButtonRight(Surface *s, const std::string &btn, const std::string &text, int x=5, int y=-10);
void drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height); void drawScrollBar(uint pagesize, uint totalsize, uint pagepos, uint top, uint height);