The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
widget.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef WIDGET_HPP_INCLUDED
16 #define WIDGET_HPP_INCLUDED
17 
18 #include "events.hpp"
19 #include "sdl/utils.hpp"
20 
21 class CVideo;
22 
23 namespace gui {
24 
26 {
27 public:
28  SDL_Rect const &location() const;
29  virtual void set_location(SDL_Rect const &rect);
30  void set_location(int x, int y);
31  void set_width(int w);
32  void set_height(int h);
33  void set_measurements(int w, int h);
34 
35  int width() const;
36  int height() const;
37 
38  //focus() may gain the focus if the currently focused handler doesn't require this event
39  bool focus(const SDL_Event* event);
40  void set_focus(bool focus);
41 
42  virtual void hide(bool value = true);
43  bool hidden() const;
44  virtual void enable(bool new_val = true);
45  bool enabled() const;
46 
47  void set_clip_rect(const SDL_Rect& rect);
48 
49  //Function to set the widget to draw in 'volatile' mode.
50  //When in 'volatile' mode, instead of using the normal
51  //save-background-redraw-when-dirty procedure, redrawing is done
52  //every frame, and then after every frame the area under the widget
53  //is restored to the state it was in before the frame. This is useful
54  //for drawing widgets with alpha components in volatile settings where
55  //the background may change at any time.
56  //(e.g. for putting widgets on top of the game map)
57  void set_volatile(bool val=true);
58 
59  void set_dirty(bool dirty=true);
60  bool dirty() const;
61  const std::string& id() const;
62  void set_id(const std::string& id);
63 
64  void set_help_string(const std::string& str);
65  void set_tooltip_string(const std::string& str);
66 
67  virtual void process_help_string(int mousex, int mousey);
68  virtual void process_tooltip_string(int mousex, int mousey);
69 
70 protected:
71  widget(widget const &o);
72  widget(CVideo& video, const bool auto_join=true);
73  virtual ~widget();
74 
75  // During each relocation, this function should be called to register
76  // the rectangles the widget needs to refresh automatically
77  void bg_register(SDL_Rect const &rect);
78  void bg_restore() const;
79  void bg_restore(SDL_Rect const &rect) const;
80  void bg_update();
81  void bg_cancel();
82 
83  CVideo& video() const { return *video_; }
84 
85  virtual void draw();
86  virtual void draw_contents() {}
87  virtual void update_location(SDL_Rect const &rect);
88 
89  const SDL_Rect* clip_rect() const;
90  virtual sdl_handler_vector member_handlers() { return sdl_handler::handler_members(); }
91 
92  virtual void handle_event(SDL_Event const &);
93  virtual void handle_window_event(SDL_Event const &event);
94  bool focus_; // Should user input be ignored?
95 
96  bool mouse_locked() const;
97 
98  void aquire_mouse_lock();
99  void free_mouse_lock();
100 private:
101  void volatile_draw();
102  void volatile_undraw();
103 
104  void hide_override(bool value = true);
105 
107  std::vector< surface_restorer > restorer_;
108  SDL_Rect rect_;
109  mutable bool needs_restore_; // Have we drawn ourselves, so that if moved, we need to restore the background?
110 
113  bool enabled_;
114  bool clip_;
115  SDL_Rect clip_rect_;
116 
117  bool volatile_;
118 
123 
125  static bool mouse_lock_;
126 
127  friend class scrollpane;
128  friend class dialog;
129 };
130 
131 }
132 
133 #endif
void bg_cancel()
Definition: widget.cpp:77
virtual void draw_contents()
Definition: widget.hpp:86
bool hidden_override_
Definition: widget.hpp:112
void aquire_mouse_lock()
Definition: widget.cpp:56
bool enabled() const
Definition: widget.cpp:212
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:163
virtual void enable(bool new_val=true)
Definition: widget.cpp:204
void bg_update()
Definition: widget.cpp:244
virtual void update_location(SDL_Rect const &rect)
Definition: widget.cpp:99
Definition: video.hpp:58
void set_clip_rect(const SDL_Rect &rect)
Definition: widget.cpp:191
void bg_register(SDL_Rect const &rect)
Definition: widget.cpp:109
CVideo & video() const
Definition: widget.hpp:83
General purpose widgets.
void set_width(int w)
Definition: widget.cpp:119
GLuint const GLfloat * val
Definition: glew.h:2614
void set_focus(bool focus)
Definition: widget.cpp:149
virtual sdl_handler_vector member_handlers()
Definition: widget.hpp:90
SDL_Rect rect_
Definition: widget.hpp:108
Scrollpane.
Definition: scrollpane.hpp:30
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
static bool mouse_lock_
Definition: widget.hpp:125
void set_measurements(int w, int h)
Definition: widget.cpp:129
virtual void process_help_string(int mousex, int mousey)
Definition: widget.cpp:324
bool hidden() const
Definition: widget.cpp:198
void set_dirty(bool dirty=true)
Definition: widget.cpp:217
std::vector< surface_restorer > restorer_
Definition: widget.hpp:107
virtual void process_tooltip_string(int mousex, int mousey)
Definition: widget.cpp:337
const SDL_Rect * clip_rect() const
Definition: widget.cpp:104
bool focus(const SDL_Event *event)
Definition: widget.cpp:157
virtual void handle_window_event(SDL_Event const &event)
Definition: widget.cpp:352
virtual void hide(bool value=true)
Definition: widget.cpp:162
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
GLsizei const GLfloat * value
Definition: glew.h:1817
CVideo * video_
Definition: widget.hpp:106
bool dirty() const
Definition: widget.cpp:227
void volatile_undraw()
Definition: widget.cpp:307
void free_mouse_lock()
Definition: widget.cpp:63
void volatile_draw()
Definition: widget.cpp:298
bool mouse_lock_local_
Definition: widget.hpp:124
enum gui::widget::@27 state_
void set_help_string(const std::string &str)
Definition: widget.cpp:314
std::string id_
Definition: widget.hpp:122
bool focus_
Definition: widget.hpp:94
std::string help_text_
Definition: widget.hpp:119
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
virtual void draw()
Definition: widget.cpp:283
bool needs_restore_
Definition: widget.hpp:109
bool enabled_
Definition: widget.hpp:113
void set_tooltip_string(const std::string &str)
Definition: widget.cpp:319
bool volatile_
Definition: widget.hpp:117
SDL_Rect clip_rect_
Definition: widget.hpp:115
void set_id(const std::string &id)
Definition: widget.cpp:237
void bg_restore() const
Definition: widget.cpp:251
bool clip_
Definition: widget.hpp:114
cl_event event
Definition: glew.h:3070
void set_volatile(bool val=true)
Definition: widget.cpp:276
bool mouse_locked() const
Definition: widget.cpp:72
virtual void set_location(SDL_Rect const &rect)
Definition: widget.cpp:85
virtual void handle_event(SDL_Event const &)
Definition: widget.cpp:345
int help_string_
Definition: widget.hpp:121
int width() const
Definition: widget.cpp:134
SDL_Rect const & location() const
Definition: widget.cpp:144
widget(widget const &o)
Definition: widget.cpp:35
virtual ~widget()
Definition: widget.cpp:50
void set_height(int h)
Definition: widget.cpp:124
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void hide_override(bool value=true)
Definition: widget.cpp:177
const std::string & id() const
Definition: widget.cpp:232
std::string tooltip_text_
Definition: widget.hpp:120
int height() const
Definition: widget.cpp:139