1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-28 00:56:47 +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 "gmenu2x.h"
#include "iconbutton.h"
ButtonBox::ButtonBox(GMenu2X *gmenu2x) : gmenu2x(gmenu2x)
{
}
@ -13,7 +12,7 @@ ButtonBox::~ButtonBox()
clear();
}
void ButtonBox::add(Button *button)
void ButtonBox::add(IconButton *button)
{
buttons.push_back(button);
}
@ -25,12 +24,12 @@ void ButtonBox::clear()
void ButtonBox::paint(unsigned int posX)
{
for (ButtonList::const_iterator it = buttons.begin(); it != buttons.end(); ++it)
posX = gmenu2x->drawButton(*it, posX);
for (auto button : buttons)
posX = gmenu2x->drawButton(button, posX);
}
void ButtonBox::handleTS()
{
for (ButtonList::iterator it = buttons.begin(); it != buttons.end(); ++it)
(*it)->handleTS();
for (auto button : buttons)
button->handleTS();
}

View File

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

View File

@ -1158,7 +1158,7 @@ string GMenu2X::getDiskFree(const char *path) {
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;
btn->setPosition(x, y-7);
btn->paint();

View File

@ -187,7 +187,7 @@ public:
void deleteSection();
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 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);