00001 #ifndef GSGL_FRAMEWORK_WIDGET_H
00002 #define GSGL_FRAMEWORK_WIDGET_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "framework/framework.hpp"
00038 #include "scenegraph/event_map.hpp"
00039 #include "data/stack.hpp"
00040 #include "platform/platform.hpp"
00041 #include "platform/color.hpp"
00042 #include "platform/texture.hpp"
00043
00044
00045 union SDL_Event;
00046
00047 namespace gsgl
00048 {
00049
00050 namespace framework
00051 {
00052
00053 class FRAMEWORK_API widget
00054 : public framework_object
00055 {
00056 gsgl::flags_t flags;
00057
00058 widget *parent, *next_tab, *prev_tab;
00059 data::simple_stack<widget *> children;
00060
00061 int x, y, w, h;
00062 platform::color foreground, background;
00063 platform::texture *tex;
00064
00065 public:
00066 enum widget_flags
00067 {
00068 NO_FLAGS = 0,
00069 WIDGET_INVISIBLE = (1 << 0),
00070 WIDGET_INACTIVE = (1 << 1),
00071 WIDGET_CAN_FOCUS = (1 << 2),
00072 };
00073
00074
00075 widget(widget *parent, const int x, const int y, const int w, const int h,
00076 const platform::color & foreground, const platform::color & background);
00077 virtual ~widget();
00078
00079
00080
00081 gsgl::flags_t & get_flags() { return flags; }
00082 void set_flags(const gsgl::flags_t f, bool flag_on);
00083
00084 widget * & get_next_tab() { return next_tab; }
00085 widget * & get_prev_tab() { return prev_tab; }
00086
00087 widget * get_parent() { return parent; }
00088 data::simple_stack<widget *> & get_children() { return children; }
00089
00090 int & get_x() { return x; }
00091 int & get_y() { return y; }
00092 int & get_w() { return w; }
00093 int & get_h() { return h; }
00094
00095 platform::color & get_foreground() { return foreground; }
00096 platform::color & get_background() { return background; }
00097 platform::texture * & get_texture() { return tex; }
00098
00099
00100 void add_child(widget *);
00101 void remove_child(widget *);
00102
00103 virtual void draw();
00104 virtual bool handle_event(const SDL_Event &);
00105
00106
00107
00108
00109 typedef bool (*event_handler)(widget *this_widget, const SDL_Event &);
00110
00111
00112
00113
00114 event_handler & get_event_handler() { return handler; }
00115
00116
00117
00118
00119
00120
00121
00122 void get_abs(int & x, int & y);
00123
00124
00125 void get_local(int & x, int & y);
00126
00127
00128 bool button_down_here(int button);
00129
00130
00131 void draw_line(int x0, int y0, int x1, int y1);
00132
00133
00134 void draw_box(int x, int y, int w, int h);
00135
00136
00137
00138 private:
00139 event_handler handler;
00140 };
00141
00142
00143 }
00144
00145 }
00146
00147 #endif