]> git.localhorst.tv Git - l2e.git/blobdiff - src/graphics/Menu.h
added icons for item select
[l2e.git] / src / graphics / Menu.h
index decd99dac3bc423d23ac1717a8020a0ddc9d1764..172c3184d4e57d7912083a4f3b4f78eb3a9caacc 100644 (file)
@@ -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<T>::Menu()
 , charsPerEntry(0)
 , rows(0)
 , rowGap(0)
+, iconSpace(0)
 , cols(0)
 , colGap(0)
 , selected(0)
@@ -103,13 +105,14 @@ Menu<T>::Menu()
 }
 
 template<class T>
-Menu<T>::Menu(const Font *font, const Font *disabledFont, const Sprite *cursor, int charsPerEntry, int rows, int rowGap, int cols, int colGap)
+Menu<T>::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<T>::Draw(SDL_Surface *dest, geometry::Point<int> 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<int> offset(
+               geometry::Vector<int> iconOffset(
                                (i % cols) * (ColWidth() + colGap),
                                (i / cols) * RowHeight());
+               if (entries[start + i].icon) {
+                       entries[start + i].icon->Draw(dest, position + iconOffset);
+               }
+               geometry::Vector<int> 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<int> cursorOffset(