Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef BUTTON_H_INCLUDED
00016 #define BUTTON_H_INCLUDED
00017
00018 #include "widget.hpp"
00019
00020 #include "../exceptions.hpp"
00021
00022 namespace gui {
00023
00024 class button : public widget
00025 {
00026 public:
00027 struct error : public game::error {
00028 error()
00029 : game::error("GUI1 button error")
00030 {}
00031 };
00032
00033 enum TYPE { TYPE_PRESS, TYPE_CHECK, TYPE_TURBO, TYPE_IMAGE };
00034
00035 enum SPACE_CONSUMPTION { DEFAULT_SPACE, MINIMUM_SPACE };
00036
00037 button(CVideo& video, const std::string& label, TYPE type=TYPE_PRESS,
00038 std::string button_image="", SPACE_CONSUMPTION spacing=DEFAULT_SPACE,
00039 const bool auto_join=true);
00040
00041
00042 virtual ~button();
00043 void set_check(bool check);
00044 void set_active(bool active);
00045 bool checked() const;
00046
00047 void set_label(const std::string& val);
00048
00049 bool pressed();
00050 bool hit(int x, int y) const;
00051 virtual void enable(bool new_val=true);
00052 void release();
00053
00054 protected:
00055 virtual void handle_event(const SDL_Event& event);
00056 virtual void mouse_motion(const SDL_MouseMotionEvent& event);
00057 virtual void mouse_down(const SDL_MouseButtonEvent& event);
00058 virtual void mouse_up(const SDL_MouseButtonEvent& event);
00059 virtual void draw_contents();
00060
00061 TYPE type_;
00062
00063 private:
00064
00065 void calculate_size();
00066
00067 std::string label_;
00068 surface image_, pressedImage_, activeImage_, pressedActiveImage_;
00069 SDL_Rect textRect_;
00070
00071 bool button_;
00072
00073 enum STATE { UNINIT, NORMAL, ACTIVE, PRESSED, PRESSED_ACTIVE };
00074 STATE state_;
00075
00076 bool pressed_;
00077
00078 SPACE_CONSUMPTION spacing_;
00079
00080 int base_height_, base_width_;
00081
00082 };
00083
00084 }
00085
00086 #endif