From 06ee35bb7aaa32e69fb754d7ce022a852e1ac691 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Mon, 12 Aug 2013 22:17:26 +0200 Subject: [PATCH] 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. --- src/buttonbox.cpp | 17 ++++++++--------- src/buttonbox.h | 9 ++++----- src/gmenu2x.cpp | 2 +- src/gmenu2x.h | 2 +- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/buttonbox.cpp b/src/buttonbox.cpp index af2791f..9ace08a 100644 --- a/src/buttonbox.cpp +++ b/src/buttonbox.cpp @@ -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(); } diff --git a/src/buttonbox.h b/src/buttonbox.h index 52a8e4b..e4b639e 100644 --- a/src/buttonbox.h +++ b/src/buttonbox.h @@ -4,7 +4,7 @@ #include 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 ButtonList; - ButtonList buttons; +private: + std::vector buttons; GMenu2X *gmenu2x; }; diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index a0b1406..35c772b 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -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(); diff --git a/src/gmenu2x.h b/src/gmenu2x.h index 8d36428..de9cf88 100644 --- a/src/gmenu2x.h +++ b/src/gmenu2x.h @@ -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);