X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbutton.h;h=a6850fe9402c293c8d068e6e0b885767b947d11d;hb=b322b763e4782f0519434fed6dbee60686eeb1a4;hp=5e306a05ee201b089c571e73a31431b82f13c500;hpb=e59a8e5e758978341d5410f09b705c4e969dc9a0;p=supertux.git diff --git a/src/button.h b/src/button.h index 5e306a05e..a6850fe94 100644 --- a/src/button.h +++ b/src/button.h @@ -13,52 +13,62 @@ #ifndef SUPERTUX_BUTTON_H #define SUPERTUX_BUTTON_H +#include #include "texture.h" -enum { +enum ButtonState { + BUTTON_NONE = -1, BUTTON_CLICKED, BUTTON_PRESSED, BUTTON_HOVER }; -typedef struct button_type +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; texture_type icon; texture_type* bkgd; - char *info; + std::string info; SDLKey shortcut; - int x; - int y; - int w; - int h; - int show_info; - int state; + SDL_Rect rect; + bool show_info; + ButtonState state; int tag; - } -button_type; - -void button_load(button_type* pbutton,char* icon_file, char* info, SDLKey shortcut, int x, int y); -button_type* button_create(char* icon_file, char* info, SDLKey shortcut, int x, int y); -void button_change_icon(button_type* pbutton,char* icon_file); -void button_draw(button_type* pbutton); -void button_free(button_type* pbutton); -void button_event(button_type* pbutton, SDL_Event* event); -int button_get_state(button_type* pbutton); + }; -typedef struct button_panel_type +class ButtonPanel { - int num_items; - int hidden; - int x,y; - int w,h; - button_type* item; - } -button_panel_type; + 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; } -void button_panel_init(button_panel_type* pbutton_panel, int x, int y, int w, int h); -void button_panel_free(button_panel_type* pbutton_panel); -void button_panel_draw(button_panel_type* pbutton_panel); -void button_panel_additem(button_panel_type* pbutton_panel, button_type* pbutton, int tag); -button_type* button_panel_event(button_panel_type* pbutton_panel, SDL_Event* event); + private: + int bw, bh; + bool hidden; + SDL_Rect rect; + std::vector item; + }; #endif /*SUPERTUX_BUTTON_H*/