00001 /* $Id: widget.hpp 23842 2008-02-16 08:47:16Z mordante $ */ 00002 /* 00003 Copyright (C) 2003 - 2008 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 version 2 00008 or at your option any later version. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details. 00013 */ 00014 00015 #ifndef WIDGET_HPP_INCLUDED 00016 #define WIDGET_HPP_INCLUDED 00017 00018 #include "../events.hpp" 00019 #include "../sdl_utils.hpp" 00020 00021 #include "SDL.h" 00022 00023 #include <string> 00024 #include <vector> 00025 00026 class CVideo; 00027 00028 namespace gui { 00029 00030 class widget : public events::handler 00031 { 00032 public: 00033 SDL_Rect const &location() const; 00034 virtual void set_location(SDL_Rect const &rect); 00035 void set_location(int x, int y); 00036 void set_width(unsigned w); 00037 void set_height(unsigned h); 00038 void set_measurements(unsigned w, unsigned h); 00039 00040 unsigned width() const; 00041 unsigned height() const; 00042 00043 //focus() may gain the focus if the currently focused handler doesn't require this event 00044 bool focus(const SDL_Event* event); 00045 void set_focus(bool focus); 00046 00047 virtual void hide(bool value = true); 00048 bool hidden() const; 00049 virtual void enable(bool new_val = true); 00050 bool enabled() const; 00051 00052 void set_clip_rect(const SDL_Rect& rect); 00053 00054 //Function to set the widget to draw in 'volatile' mode. 00055 //When in 'volatile' mode, instead of using the normal 00056 //save-background-redraw-when-dirty procedure, redrawing is done 00057 //every frame, and then after every frame the area under the widget 00058 //is restored to the state it was in before the frame. This is useful 00059 //for drawing widgets with alpha components in volatile settings where 00060 //the background may change at any time. 00061 //(e.g. for putting widgets on top of the game map) 00062 void set_volatile(bool val=true); 00063 00064 void set_dirty(bool dirty=true); 00065 bool dirty() const; 00066 const std::string& id() const; 00067 void set_id(const std::string& id); 00068 00069 void set_help_string(const std::string& str); 00070 00071 virtual void process_help_string(int mousex, int mousey); 00072 00073 protected: 00074 widget(widget const &o); 00075 widget(CVideo& video, const bool auto_join=true); 00076 virtual ~widget(); 00077 00078 // During each relocation, this function should be called to register 00079 // the rectangles the widget needs to refresh automatically 00080 void bg_register(SDL_Rect const &rect); 00081 void bg_restore() const; 00082 void bg_restore(SDL_Rect const &rect) const; 00083 void bg_update(); 00084 void bg_cancel(); 00085 00086 CVideo& video() const { return *video_; }; 00087 00088 virtual void draw(); 00089 virtual void draw_contents() {}; 00090 virtual void update_location(SDL_Rect const &rect); 00091 00092 const SDL_Rect* clip_rect() const; 00093 virtual handler_vector member_handlers() { return handler::handler_members(); } 00094 00095 virtual void handle_event(SDL_Event const &/*event*/) {} 00096 bool focus_; // Should user input be ignored? 00097 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 friend class scrollpane; 00122 friend class dialog; 00123 }; 00124 00125 } 00126 00127 #endif
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |