1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-12-26 19:35:30 +02:00

MessageBox: Use arrays instead of vectors for buttons.

There is no need for the overhead of std::vector if we know the number
of elements at compile time.
This shaves off about 2 kB of the stripped binary size.
This commit is contained in:
Maarten ter Huurne 2011-10-23 11:24:20 +02:00
parent 28f6cd2122
commit 3252c777c3
2 changed files with 17 additions and 22 deletions

View File

@ -30,13 +30,10 @@ MessageBox::MessageBox(GMenu2X *gmenu2x, const string &text, const string &icon)
this->text = text;
this->icon = icon;
buttons.resize(19);
buttonLabels.resize(19);
buttonPositions.resize(19);
for (uint x=0; x<buttons.size(); x++) {
buttons[x] = "";
buttonLabels[x] = "";
buttonPositions[x].h = gmenu2x->font->getHeight();
for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) {
buttons[i] = "";
buttonLabels[i] = "";
buttonPositions[i].h = gmenu2x->font->getHeight();
}
//Default enabled button
@ -57,8 +54,8 @@ MessageBox::MessageBox(GMenu2X *gmenu2x, const string &text, const string &icon)
buttonLabels[InputManager::VOLDOWN] = "vol-";
}
void MessageBox::setButton(int action, const string &btn) {
buttons[action] = btn;
void MessageBox::setButton(InputManager::Button button, const string &label) {
buttons[button] = label;
}
int MessageBox::exec() {
@ -83,7 +80,7 @@ int MessageBox::exec() {
bg.write( gmenu2x->font, text, box.x+(gmenu2x->sc[icon] != NULL ? 47 : 10), box.y+gmenu2x->font->getHeight()+3, ASFont::HAlignLeft, ASFont::VAlignMiddle );
int btnX = gmenu2x->halfX+box.w/2-6;
for (uint i=0; i<buttons.size(); i++) {
for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) {
if (buttons[i] != "") {
buttonPositions[i].y = box.y+box.h-4;
buttonPositions[i].w = btnX;
@ -104,13 +101,12 @@ int MessageBox::exec() {
#ifdef PLATFORM_GP2X
//touchscreen
if (gmenu2x->f200) {
if (gmenu2x->ts.poll()) {
for (uint i=0; i<buttons.size(); i++)
if (buttons[i]!="" && gmenu2x->ts.inRect(buttonPositions[i])) {
result = i;
i = buttons.size();
}
if (gmenu2x->f200 && gmenu2x->ts.poll()) {
for (uint i = 0; i < BUTTON_TYPE_SIZE; i++) {
if (buttons[i] != "" && gmenu2x->ts.inRect(buttonPositions[i])) {
result = i;
break;
}
}
}
#endif

View File

@ -30,19 +30,18 @@
#include "gmenu2x.h"
using std::string;
using std::vector;
class MessageBox {
private:
string text, icon;
GMenu2X *gmenu2x;
vector<string> buttons;
vector<string> buttonLabels;
vector<SDL_Rect> buttonPositions;
string buttons[BUTTON_TYPE_SIZE];
string buttonLabels[BUTTON_TYPE_SIZE];
SDL_Rect buttonPositions[BUTTON_TYPE_SIZE];
public:
MessageBox(GMenu2X *gmenu2x, const string &text, const string &icon="");
void setButton(int action, const string &btn);
void setButton(InputManager::Button button, const string &label);
int exec();
};