The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
show_dialog.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 SHOW_DIALOG_HPP_INCLUDED
16 #define SHOW_DIALOG_HPP_INCLUDED
17 
18 class config;
19 class display;
20 
21 #include "cursor.hpp"
22 #include "floating_label.hpp"
23 #include "font.hpp"
24 #include "tooltips.hpp"
25 #include "video.hpp"
26 #include "widgets/menu.hpp"
27 
28 namespace gui
29 {
30 
31 extern const int ButtonHPadding;
32 extern const int ButtonVPadding;
38  ESCAPE_DIALOG=-3, //special return used by WML event dialogs
41  /* results (0..N) reserved for standard button indices */
42 };
43 
44 bool in_dialog();
45 
49 
50 private:
51  bool reset_to;
52 };
53 
55 public:
59  };
60  class style {
61  public:
62  style(std::string const& p, int br) : panel(p), blur_radius(br) {}
65  };
66 
67  //Static members
68  static const int title_border_w, title_border_h;
69  static const style default_style;
70  static const style message_style;
71  static const style preview_style;
72  static const style titlescreen_style;
73 
74  dialog_frame(CVideo &video, const std::string& title="",
75  const style& dialog_style=default_style,
76  bool auto_restore=true, std::vector<button*>* buttons=nullptr,
77  button* help_button=nullptr);
78  ~dialog_frame();
79 
80  dimension_measurements layout(int x, int y, int w, int h);
81  dimension_measurements layout(SDL_Rect const& frame_area);
82  void set_layout(dimension_measurements &new_dim) { dim_ = new_dim; }
84 
85  int top_padding() const;
86  int bottom_padding() const;
87 
88  void draw();
89 
90  //called by draw
91  void draw_border();
92  void draw_background();
93 
94  //also called by layout with null param
95  SDL_Rect draw_title(CVideo *video);
96 
97  void set_dirty(bool dirty = true);
98 
99  virtual void handle_event(const SDL_Event&);
100  void handle_window_event(const SDL_Event& event);
101 
102 private:
103  void clear_background();
104 
108  std::vector<button*>* buttons_;
113 #ifdef SDL_GPU
115 #else
117 #endif
119  bool dirty_;
120 };
121 
122 //frame_measurements draw_dialog_frame(int x, int y, int w, int h, CVideo &video, const std::string* dialog_style=nullptr, surface_restorer* restorer=nullptr);
123 
124 //SDL_Rect draw_dialog_background(int x, int y, int w, int h, CVideo &video, const std::string& dialog_style);
125 
126 //given the location of a dialog, will draw its title.
127 //Returns the area the title takes up
128 //SDL_Rect draw_dialog_title(int x, int y, CVideo* disp, const std::string& text, label** label_widget);
129 
130 //function to draw a dialog on the screen. x,y,w,h give the dimensions of the client area
131 //of the dialog. 'title' is the title of the dialog. The title will be displayed at the
132 //top of the dialog above the client area. 'dialog_style' if present gives the style of
133 //the dialog to use.
134 //'buttons' contains pointers to standard dialog buttons such as 'ok' and 'cancel' that
135 //will appear on the dialog. If present, they will be located at the bottom of the dialog,
136 //below the client area.
137 //if 'restorer' is present, it will be set to a restorer that will reset the screen area
138 //to its original state after the dialog is drawn.
139 //void draw_dialog(int x, int y, int w, int h, CVideo &video, const std::string& title,
140  // const std::string* dialog_style=nullptr, std::vector<button*>* buttons=nullptr,
141  // surface_restorer* restorer=nullptr, button* help_button=nullptr, label** label_widget);
142 //void draw_dialog(frame_measurements &fm, CVideo &video, const std::string& title,
143  // const std::string* dialog_style=nullptr, std::vector<button*>* buttons=nullptr,
144  // surface_restorer* restorer=nullptr, button* help_button=nullptr, label** label_widget);
145 
147 {
148 public:
150 
152 
153  virtual RESULT button_pressed(int menu_selection) = 0;
154 };
155 
157 {
158  dialog_button_info(dialog_button_action* handler, const std::string& label) : handler(handler), label(label)
159  {}
160 
163 };
164 
166 
167 struct check_item {
168  check_item(const std::string& label, bool checked) : label(label), checked(checked) {}
170  bool checked;
171 };
172 
173 //an interface for a 'preview pane'. A preview pane is shown beside a dialog created
174 //by 'show_dialog' and shows information about the selection.
175 class preview_pane : public widget {
176 public:
177  preview_pane(CVideo &video) : widget(video, false) {}
179 
180  virtual bool show_above() const { return false; }
181  virtual bool left_side() const = 0;
182  virtual void set_selection(int index) = 0;
184 };
185 
186 //if a menu is given, then returns -1 if the dialog was canceled, and the
187 //index of the selection otherwise. If no menu is given, returns the index
188 //of the button that was pressed
189 int show_dialog(CVideo& video, surface image,
190  const std::string& caption, const std::string& message,
192  const std::vector<std::string>* menu_items=nullptr,
193  const std::vector<preview_pane*>* preview_panes=nullptr,
194  const std::string& text_widget_label="",
195  std::string* text_widget_text=nullptr,
196  const int text_widget_max_chars = 256,
197  std::vector<check_item>* options=nullptr,
198  int xloc=-1,
199  int yloc=-1,
200  const dialog_frame::style* dialog_style=nullptr,
201  std::vector<dialog_button_info>* buttons=nullptr,
202  const menu::sorter* sorter=nullptr,
203  menu::style* menu_style=nullptr
204  );
205 
206 void check_quit(CVideo &video);
207 
208 }
209 
210 #endif
static const style preview_style
Definition: show_dialog.hpp:71
void check_quit(CVideo &video)
std::vector< events::sdl_handler * > sdl_handler_vector
Definition: events.hpp:163
dialog_button_action * handler
static const style default_style
Definition: show_dialog.hpp:69
void set_dirty(bool dirty=true)
dialog_button_info(dialog_button_action *handler, const std::string &label)
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
Definition: video.hpp:58
bool in_dialog()
Definition: show_dialog.cpp:57
CVideo & video() const
Definition: widget.hpp:83
General purpose widgets.
std::vector< button * > * buttons_
style(std::string const &p, int br)
Definition: show_dialog.hpp:62
surface_restorer * restorer_
virtual bool show_above() const
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
virtual ~preview_pane()
-file util.hpp
const style & dialog_style_
void clear_tooltips()
Definition: tooltips.cpp:125
const int ButtonHPadding
Definition: show_dialog.cpp:43
dimension_measurements layout(int x, int y, int w, int h)
check_item(const std::string &label, bool checked)
SDL_Rect draw_title(CVideo *video)
int top_padding() const
const config & options()
int bottom_padding() const
friend class style
Definition: menu.hpp:114
virtual sdl_handler_vector handler_members()
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
virtual void handle_event(const SDL_Event &)
virtual bool left_side() const =0
int show_dialog(CVideo &video, surface image, const std::string &caption, const std::string &message, DIALOG_TYPE type, const std::vector< std::string > *menu_items, const std::vector< preview_pane * > *preview_panes, const std::string &text_widget_label, std::string *text_widget_text, const int text_widget_max_chars, std::vector< check_item > *options, int xloc, int yloc, const dialog_frame::style *dialog_style, std::vector< dialog_button_info > *action_buttons, const menu::sorter *sorter, menu::style *menu_style)
GLfloat GLfloat p
Definition: glew.h:12766
virtual RESULT button_pressed(int menu_selection)=0
std::string title_
static const int title_border_w
Definition: show_dialog.hpp:68
static const style titlescreen_style
Definition: show_dialog.hpp:72
virtual void set_selection(int index)=0
GLuint index
Definition: glew.h:1782
structure which will hide all current floating labels, and cause floating labels instantiated after i...
dimension_measurements dim_
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
virtual std::vector< sdl_handler * > handler_members()
Definition: events.hpp:89
DIALOG_RESULT
Definition: show_dialog.hpp:33
void handle_window_event(const SDL_Event &event)
void set_layout(dimension_measurements &new_dim)
Definition: show_dialog.hpp:82
cl_event event
Definition: glew.h:3070
dimension_measurements get_layout() const
Definition: show_dialog.hpp:83
this module manages the cache of images.
Definition: image.cpp:75
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
static const int title_border_h
Definition: show_dialog.hpp:68
SDL_Rect const & location() const
Definition: widget.cpp:144
const int ButtonVPadding
Definition: show_dialog.cpp:44
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
dialog_frame(CVideo &video, const std::string &title="", const style &dialog_style=default_style, bool auto_restore=true, std::vector< button * > *buttons=nullptr, button *help_button=nullptr)
Definition: show_dialog.cpp:82
GLsizei const GLcharARB ** string
Definition: glew.h:4503
static const style message_style
Definition: show_dialog.hpp:70
preview_pane(CVideo &video)
std::string label