From 3252c777c3725c1902f5c32f6a9d54df1e12b341 Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Sun, 23 Oct 2011 11:24:20 +0200 Subject: [PATCH] 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. --- src/messagebox.cpp | 30 +++++++++++++----------------- src/messagebox.h | 9 ++++----- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/messagebox.cpp b/src/messagebox.cpp index baf00c6..0b870af 100644 --- a/src/messagebox.cpp +++ b/src/messagebox.cpp @@ -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; xfont->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; if200) { - if (gmenu2x->ts.poll()) { - for (uint i=0; its.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 diff --git a/src/messagebox.h b/src/messagebox.h index 081adad..f0a6bc5 100644 --- a/src/messagebox.h +++ b/src/messagebox.h @@ -30,19 +30,18 @@ #include "gmenu2x.h" using std::string; -using std::vector; class MessageBox { private: string text, icon; GMenu2X *gmenu2x; - vector buttons; - vector buttonLabels; - vector 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(); };