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