- fixed problem with last_menu not being able to handle menues deeper than two submenues
[supertux.git] / src / button.h
index 12925fa..69af7f3 100644 (file)
@@ -1,7 +1,7 @@
 //
 // C Interface: button
 //
-// Description: 
+// Description:
 //
 //
 // Author: Tobias Glaesser <tobi.web@gmx.de>, (C) 2004
 #ifndef SUPERTUX_BUTTON_H
 #define SUPERTUX_BUTTON_H
 
+#include <vector>
 #include "texture.h"
 
-typedef struct button_type
-  {
-    texture_type icon;
-    char *info;
-    char *text;
-    int x;
-    int y;
-    int w;
-    int h;
-    int state;
-  } button_type;
-  
-void button_load(button_type* pbutton,char* icon_file, char* text, char* info, int x, int y);
-void button_draw(button_type* pbutton);
-void button_free(button_type* pbutton);
-int button_pressed(button_type* pbutton, int x, int y);
-
-enum {
-  BN_PRESSED
+enum ButtonState {
+  BUTTON_NONE = -1,
+  BUTTON_CLICKED,
+  BUTTON_PRESSED,
+  BUTTON_HOVER
 };
 
+class ButtonPanel;
+
+class Button
+  {
+    friend class ButtonPanel;
+
+  public:
+    Button(std::string icon_file, std::string info, SDLKey shortcut, int x, int y, int mw = -1, int h = -1);
+    ~Button();
+    void event(SDL_Event& event);
+    void draw();
+    int get_state();
+    void change_icon(std::string icon_file, int mw, int mh);
+    int get_tag()
+    {
+      return tag;
+    }
+
+  private:
+    static Timer popup_timer;
+    Surface* icon;
+    Surface* bkgd;
+    std::string info;
+    SDLKey shortcut;
+    SDL_Rect rect;
+    bool show_info;
+    ButtonState state;
+    int tag;
+  };
+
+class ButtonPanel
+  {
+  public:
+    ButtonPanel(int x, int y, int w, int h);
+    ~ButtonPanel();
+    void draw();
+    Button* event(SDL_Event &event);
+    void additem(Button* pbutton, int tag);
+    Button* button_panel_event(SDL_Event& event);
+    void set_button_size(int w, int h) { bw = w; bh = h; }
+
+  private:
+    int bw, bh;
+    bool hidden;
+    SDL_Rect rect;
+    std::vector<Button*> item;
+  };
+
 #endif /*SUPERTUX_BUTTON_H*/