00001 #ifndef GUI_BUTTON_HPP 00002 #define GUI_BUTTON_HPP 00003 00004 #include <utils.hpp> 00005 #include "gui_frame.hpp" 00006 00007 namespace gui 00008 { 00009 class texture; 00010 class font_string; 00011 00013 00024 class button : public frame 00025 { 00026 public : 00027 00028 enum state 00029 { 00030 STATE_UP, 00031 STATE_DOWN, 00032 STATE_DISABLED 00033 }; 00034 00036 explicit button(manager* pManager); 00037 00039 virtual ~button(); 00040 00042 00045 virtual std::string serialize(const std::string& sTab) const; 00046 00048 virtual void create_glue(); 00049 00051 00054 virtual bool can_use_script(const std::string& sScriptName) const; 00055 00057 00060 virtual void on(const std::string& sScriptName, event* pEvent = nullptr); 00061 00063 00065 virtual void on_event(const event& mEvent); 00066 00068 00070 virtual void copy_from(uiobject* pObj); 00071 00073 00075 virtual void set_text(const std::string& sText); 00076 00078 00080 const std::string& get_text() const; 00081 00083 00085 texture* get_normal_texture(); 00086 00088 00090 texture* get_pushed_texture(); 00091 00093 00095 texture* get_disabled_texture(); 00096 00098 00100 texture* get_highlight_texture(); 00101 00103 00105 font_string* get_normal_text(); 00106 00108 00110 font_string* get_highlight_text(); 00111 00113 00115 font_string* get_disabled_text(); 00116 00118 00120 font_string* get_CurrentFontString(); 00121 00123 00125 void set_normal_texture(texture* pTexture); 00126 00128 00130 void set_pushed_texture(texture* pTexture); 00131 00133 00135 void set_disabled_texture(texture* pTexture); 00136 00138 00140 void set_highlight_texture(texture* pTexture); 00141 00143 00145 void set_normal_text(font_string* pFont); 00146 00148 00150 void set_highlight_text(font_string* pFont); 00151 00153 00155 void set_disabled_text(font_string* pFont); 00156 00158 00160 virtual void disable(); 00161 00163 virtual void enable(); 00164 00166 00168 bool is_enabled() const; 00169 00171 00174 virtual void push(); 00175 00177 00180 virtual void release(); 00181 00183 00187 virtual void highlight(); 00188 00190 00194 virtual void unlight(); 00195 00197 00199 state get_button_state() const; 00200 00202 00205 void lock_highlight(); 00206 00208 void unlock_highlight(); 00209 00211 00213 virtual void set_pushed_text_offset(const std::array<int,2>& lOffset); 00214 00216 00218 const std::array<int,2>& get_pushed_text_offset() const; 00219 00221 00223 virtual void parse_block(xml::block* pBlock); 00224 00226 static void register_glue(utils::wptr<lua::state> pLua); 00227 00228 protected : 00229 00230 texture* create_normal_texture_(); 00231 texture* create_pushed_texture_(); 00232 texture* create_disabled_texture_(); 00233 texture* create_highlight_texture_(); 00234 font_string* create_normal_text_(); 00235 font_string* create_highlight_text_(); 00236 font_string* create_disabled_text_(); 00237 00238 state mState_; 00239 bool bHighlighted_; 00240 bool bLockHighlight_; 00241 00242 std::string sText_; 00243 00244 texture* pNormalTexture_; 00245 texture* pPushedTexture_; 00246 texture* pDisabledTexture_; 00247 texture* pHighlightTexture_; 00248 00249 font_string* pNormalText_; 00250 font_string* pHighlightText_; 00251 font_string* pDisabledText_; 00252 font_string* pCurrentFontString_; 00253 00254 std::array<int,2> lPushedTextOffset_; 00255 }; 00256 00260 class lua_button : public lua_frame 00261 { 00262 public : 00263 00264 explicit lua_button(lua_State* pLua); 00265 virtual ~lua_button() {} 00266 00267 // Glues 00268 int _click(lua_State*); 00269 int _disable(lua_State*); 00270 int _enable(lua_State*); 00271 int _get_button_state(lua_State*); 00272 int _get_disabled_font_object(lua_State*); 00273 int _get_disabled_text_color(lua_State*); 00274 int _get_disabled_texture(lua_State*); 00275 int _get_highlight_font_object(lua_State*); 00276 int _get_highlight_text_color(lua_State*); 00277 int _get_highlight_texture(lua_State*); 00278 int _get_normal_font_object(lua_State*); 00279 int _get_normal_texture(lua_State*); 00280 int _get_pushed_text_offset(lua_State*); 00281 int _get_pushed_texture(lua_State*); 00282 int _get_text(lua_State*); 00283 int _get_text_height(lua_State*); 00284 int _get_text_width(lua_State*); 00285 int _is_enabled(lua_State*); 00286 int _lock_highlight(lua_State*); 00287 int _set_button_state(lua_State*); 00288 int _set_disabled_font_object(lua_State*); 00289 int _set_disabled_text_color(lua_State*); 00290 int _set_disabled_texture(lua_State*); 00291 int _set_highlight_font_object(lua_State*); 00292 int _set_highlight_text_color(lua_State*); 00293 int _set_highlight_texture(lua_State*); 00294 int _set_normal_font_object(lua_State*); 00295 int _set_normal_text_color(lua_State*); 00296 int _set_normal_texture(lua_State*); 00297 int _set_pushed_text_offset(lua_State*); 00298 int _set_pushed_texture(lua_State*); 00299 int _set_text(lua_State*); 00300 00301 int _unlock_highlight(lua_State*); 00302 00303 static const char className[]; 00304 static const char* classList[]; 00305 static Lunar<lua_button>::RegType methods[]; 00306 00307 protected : 00308 00309 button* pButtonParent_; 00310 }; 00311 00314 } 00315 00316 #endif