00001 /* $Id: widget.hpp 52533 2012-01-07 02:35:17Z shadowmaster $ */ 00002 /* 00003 Copyright (C) 2003 - 2012 by David White <dave@whitevine.net> 00004 Part of the Battle for Wesnoth Project http://www.wesnoth.org/ 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY. 00012 00013 See the COPYING file for more details. 00014 */ 00015 00016 #ifndef WIDGET_HPP_INCLUDED 00017 #define WIDGET_HPP_INCLUDED 00018 00019 #include "../events.hpp" 00020 #include "../sdl_utils.hpp" 00021 00022 class CVideo; 00023 00024 namespace gui { 00025 00026 class widget : public events::handler 00027 { 00028 public: 00029 SDL_Rect const &location() const; 00030 virtual void set_location(SDL_Rect const &rect); 00031 void set_location(int x, int y); 00032 void set_width(unsigned w); 00033 void set_height(unsigned h); 00034 void set_measurements(unsigned w, unsigned h); 00035 00036 unsigned width() const; 00037 unsigned height() const; 00038 00039 //focus() may gain the focus if the currently focused handler doesn't require this event 00040 bool focus(const SDL_Event* event); 00041 void set_focus(bool focus); 00042 00043 virtual void hide(bool value = true); 00044 bool hidden() const; 00045 virtual void enable(bool new_val = true); 00046 bool enabled() const; 00047 00048 void set_clip_rect(const SDL_Rect& rect); 00049 00050 //Function to set the widget to draw in 'volatile' mode. 00051 //When in 'volatile' mode, instead of using the normal 00052 //save-background-redraw-when-dirty procedure, redrawing is done 00053 //every frame, and then after every frame the area under the widget 00054 //is restored to the state it was in before the frame. This is useful 00055 //for drawing widgets with alpha components in volatile settings where 00056 //the background may change at any time. 00057 //(e.g. for putting widgets on top of the game map) 00058 void set_volatile(bool val=true); 00059 00060 void set_dirty(bool dirty=true); 00061 bool dirty() const; 00062 const std::string& id() const; 00063 void set_id(const std::string& id); 00064 00065 void set_help_string(const std::string& str); 00066 00067 virtual void process_help_string(int mousex, int mousey); 00068 00069 protected: 00070 widget(widget const &o); 00071 widget(CVideo& video, const bool auto_join=true); 00072 virtual ~widget(); 00073 00074 // During each relocation, this function should be called to register 00075 // the rectangles the widget needs to refresh automatically 00076 void bg_register(SDL_Rect const &rect); 00077 void bg_restore() const; 00078 void bg_restore(SDL_Rect const &rect) const; 00079 void bg_update(); 00080 void bg_cancel(); 00081 00082 CVideo& video() const { return *video_; }; 00083 00084 virtual void draw(); 00085 virtual void draw_contents() {}; 00086 virtual void update_location(SDL_Rect const &rect); 00087 00088 const SDL_Rect* clip_rect() const; 00089 virtual handler_vector member_handlers() { return handler::handler_members(); } 00090 00091 virtual void handle_event(SDL_Event const &/*event*/) {} 00092 bool focus_; // Should user input be ignored? 00093 00094 bool mouse_locked() const; 00095 00096 void aquire_mouse_lock(); 00097 void free_mouse_lock(); 00098 private: 00099 void volatile_draw(); 00100 void volatile_undraw(); 00101 00102 void hide_override(bool value = true); 00103 00104 CVideo* video_; 00105 std::vector< surface_restorer > restorer_; 00106 SDL_Rect rect_; 00107 mutable bool needs_restore_; // Have we drawn ourselves, so that if moved, we need to restore the background? 00108 00109 enum { UNINIT, HIDDEN, DIRTY, DRAWN } state_; 00110 bool hidden_override_; 00111 bool enabled_; 00112 bool clip_; 00113 SDL_Rect clip_rect_; 00114 00115 bool volatile_; 00116 00117 std::string help_text_; 00118 int help_string_; 00119 std::string id_; 00120 00121 bool mouse_lock_local_; 00122 static bool mouse_lock_; 00123 00124 friend class scrollpane; 00125 friend class dialog; 00126 }; 00127 00128 } 00129 00130 #endif
| Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:00 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |