00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef HEADER_CONSTRUO_GUI_BUTTONS_HXX
00021 #define HEADER_CONSTRUO_GUI_BUTTONS_HXX
00022
00023 #include "colors.hxx"
00024 #include "gui_component.hxx"
00025
00027 class GUIButton : public GUIComponent
00028 {
00029 protected:
00030 std::string title;
00031
00032 bool mouse_over;
00033 bool pressed;
00034
00035 public:
00036 GUIButton (const std::string& title, int x_pos_, int y_pos_, int width_, int height_);
00037
00038 void draw_border_hover(GraphicContext*);
00039 void draw_border_pressed(GraphicContext*);
00040 void draw_border_normal(GraphicContext*);
00041
00042 void on_mouse_enter ();
00043 void on_mouse_leave ();
00044
00045 void on_primary_button_press (int x, int y);
00046 void on_primary_button_release (int x, int y);
00047
00048 void draw (GraphicContext*);
00049
00050 virtual void draw_content (GraphicContext*);
00051 virtual void on_click ();
00052 };
00053
00054 class GUIRunButton : public GUIButton
00055 {
00056 public:
00057 GUIRunButton ();
00058 void draw_content (GraphicContext*);
00059 void on_click();
00060 };
00061
00062 class GUISlowMoButton : public GUIButton
00063 {
00064 public:
00065 GUISlowMoButton ();
00066 void draw_content (GraphicContext*);
00067 void on_click();
00068 };
00069
00070 class GUIZoomInButton : public GUIButton
00071 {
00072 public:
00073 GUIZoomInButton ();
00074 void on_click();
00075 };
00076
00077 class GUIZoomOutButton : public GUIButton
00078 {
00079 public:
00080 GUIZoomOutButton ();
00081 void on_click();
00082 };
00083
00084
00085 class GUIQuitButton : public GUIButton
00086 {
00087 public:
00088 GUIQuitButton ();
00089 void on_click();
00090 };
00091
00092 class GUILoadButton : public GUIButton
00093 {
00094 public:
00095 GUILoadButton ();
00096 void on_click();
00097 };
00098
00099 inline bool always_false()
00100 {
00101 return false;
00102 }
00103
00104 class GUIGenericButton : public GUIButton
00105 {
00106 private:
00107 typedef void (*Func)();
00108 typedef bool (*HighlightFunc)();
00109 Func func;
00110 HighlightFunc hfunc;
00111 public:
00112 GUIGenericButton (const std::string& title, int x, int y, int width, int height,
00113 Func f, HighlightFunc h = always_false)
00114 : GUIButton (title, x, y, width, height),
00115 func (f),
00116 hfunc(h)
00117 {
00118 }
00119
00120 void on_click ()
00121 {
00122 func ();
00123 }
00124
00125 void draw_content (GraphicContext* gc)
00126 {
00127 if (hfunc())
00128 gc->draw_fill_rect (x_pos, y_pos,
00129 x_pos + width, y_pos + height, Colors::button_bg_active);
00130
00131 GUIButton::draw_content (gc);
00132 }
00133 };
00134
00135 #endif
00136
00137