X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FMenu.h;h=172c3184d4e57d7912083a4f3b4f78eb3a9caacc;hb=859750479ac0c8febfaf4eb603fc599aef4571ca;hp=decd99dac3bc423d23ac1717a8020a0ddc9d1764;hpb=428ae9a4a106e54f300e95544f78044b24b7e31a;p=l2e.git diff --git a/src/graphics/Menu.h b/src/graphics/Menu.h index decd99d..172c318 100644 --- a/src/graphics/Menu.h +++ b/src/graphics/Menu.h @@ -27,12 +27,12 @@ class Menu { public: Menu(); - Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, int charsPerEntry, int rows, int rowGap = 0, int cols = 1, int colGap = 0); + Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, int charsPerEntry, int rows, int rowGap = 0, int iconSpace = 0, int cols = 1, int colGap = 0); public: int Width() const; int Height() const; - int ColWidth() const { return font->CharWidth() * charsPerEntry; } + int ColWidth() const { return iconSpace + font->CharWidth() * charsPerEntry; } int RowHeight() const { return font->CharHeight() + rowGap; } T &Selected() { return entries[selected].value; } @@ -79,6 +79,7 @@ private: int charsPerEntry; int rows; int rowGap; + int iconSpace; int cols; int colGap; int selected; @@ -95,6 +96,7 @@ Menu::Menu() , charsPerEntry(0) , rows(0) , rowGap(0) +, iconSpace(0) , cols(0) , colGap(0) , selected(0) @@ -103,13 +105,14 @@ Menu::Menu() } template -Menu::Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, int charsPerEntry, int rows, int rowGap, int cols, int colGap) +Menu::Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, int charsPerEntry, int rows, int rowGap, int iconSpace, int cols, int colGap) : font(font) , disabledFont(disabledFont ? disabledFont : font) , cursor(cursor) , charsPerEntry(charsPerEntry) , rows(rows) , rowGap(rowGap) +, iconSpace(iconSpace) , cols(cols) , colGap(colGap) , selected(0) @@ -168,13 +171,17 @@ void Menu::Draw(SDL_Surface *dest, geometry::Point position) const { int items(entries.size() - start); int end(start + (items < slots ? items : slots)); for (int i(0), count(end - start); i < count; ++i) { - geometry::Vector offset( + geometry::Vector iconOffset( (i % cols) * (ColWidth() + colGap), (i / cols) * RowHeight()); + if (entries[start + i].icon) { + entries[start + i].icon->Draw(dest, position + iconOffset); + } + geometry::Vector labelOffset(iconOffset.X() + + iconSpace, iconOffset.Y()); if (entries[start + i].enabled) { - font->DrawString(entries[start + i].title, dest, position + offset, charsPerEntry); + font->DrawString(entries[start + i].title, dest, position + labelOffset, charsPerEntry); } else { - disabledFont->DrawString(entries[start + i].title, dest, position + offset, charsPerEntry); + disabledFont->DrawString(entries[start + i].title, dest, position + labelOffset, charsPerEntry); } } geometry::Vector cursorOffset(