]> git.localhorst.tv Git - l2e.git/blobdiff - src/graphics/Menu.h
added ability to disable menu entries
[l2e.git] / src / graphics / Menu.h
index 0a4a69885d7ff6dd81b2b1ceb63bbe8c1b8ff777..083e741864b552b161173f5b117ed09c9d4f8f34 100644 (file)
@@ -20,11 +20,14 @@ namespace graphics {
 
 class Sprite;
 
+// TODO: alternate font for disabled entries
+// TODO: sprite for the cursor
+// TODO: animation when top row changes
 template<class T>
 class Menu {
 
 public:
-       Menu(const Font *font, int charsPerEntry, int rows, int rowGap = 0, int cols = 1, int colGap = 0);
+       explicit Menu(const Font *font = NULL, int charsPerEntry = 16, int rows = 1, int rowGap = 0, int cols = 1, int colGap = 0);
 
 public:
        int Width() const;
@@ -35,6 +38,7 @@ public:
        T &Selected() { return entries[selected].value; }
        const T &Selected() const { return entries[selected].value; }
        const char *SelectedTitle() const { return entries[selected].title; }
+       bool SelectedIsEnabled() const { return entries[selected].enabled; }
 
        void NextItem();
        void PreviousItem();
@@ -42,7 +46,13 @@ public:
        void PreviousRow();
        void SelectIndex(int index);
 
-       void Add(const char *title, const T &value, const Sprite *icon = 0) { entries.push_back(Entry(title, value, icon)); }
+       int EntryCount() const { return entries.size(); }
+       T &ValueAt(int index) { return entries[index].value; }
+       const T &ValueAt(int index) const { return entries[index].value; }
+
+       void Add(const char *title, const T &value, bool enabled = true, const Sprite *icon = 0) { entries.push_back(Entry(title, value, enabled, icon)); }
+       void Disable(int index) { entries[index].enabled = false; }
+       void Enable(int index) { entries[index].enabled = true; }
        void Reserve(int n) { entries.reserve(n); }
 
        void Draw(SDL_Surface *dest, geometry::Point<int> position) const;
@@ -53,11 +63,12 @@ private:
 
 private:
        struct Entry {
-               Entry(const char *title, const T &value, const Sprite *icon = 0)
-               : title(title), icon(icon), value(value) { }
+               Entry(const char *title, const T &value, bool enabled = true, const Sprite *icon = 0)
+               : title(title), icon(icon), value(value), enabled(enabled) { }
                const char *title;
                const Sprite *icon;
                T value;
+               bool enabled;
        };
        const Font *font;
        std::vector<Entry> entries;