The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
wml_message.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2016 by Mark de Wever <[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 GUI_DIALOGS_WML_MESSAGE_HPP_INCLUDED
16 #define GUI_DIALOGS_WML_MESSAGE_HPP_INCLUDED
17 
18 #include "gui/dialogs/dialog.hpp"
19 
20 namespace gui2
21 {
22 
23 /**
24  * Helper class for message options
25  */
27 public:
29  : label_(label)
31  , image_(image)
32  {}
33  std::string label() const {return label_;};
35  std::string image() const {return image_;};
36 private:
38 };
39 
40 /**
41  * Base class for the wml generated messages.
42  *
43  * We have a separate sub class for left and right images.
44  */
45 class twml_message_ : public tdialog
46 {
47 public:
48  twml_message_(const std::string& title,
49  const std::string& message,
50  const std::string& portrait,
51  const bool mirror)
52  : title_(title)
53  , image_("")
54  , message_(message)
55  , portrait_(portrait)
56  , mirror_(mirror)
57  , has_input_(false)
58  , input_caption_("")
59  , input_text_(nullptr)
61  , option_list_()
62  , chosen_option_(nullptr)
63  {
64  }
65 
66  /**
67  * Sets the input text variables.
68  *
69  * @param caption The caption for the label.
70  * @param [in,out] text The initial text, after showing the final
71  * text.
72  * @param maximum_length The maximum length of the text.
73  */
74  void set_input(const std::string& caption,
75  std::string* text,
76  const unsigned maximum_length);
77  /**
78  * Sets the option list
79  *
80  * @param option_list The list of options to display.
81  * @param [in,out] chosen_option Pointer to the index of the initially
82  * selected option; after showing, the
83  * chosen option.
84  */
85  void set_option_list(const std::vector<twml_message_option>& option_list,
86  int* chosen_option);
87 
88 private:
89  /** The title for the dialog. */
91 
92  /**
93  * The image which is shown in the dialog.
94  *
95  * This image can be an icon or portrait or any other image.
96  */
98 
99  /** The message to show to the user. */
101  /** Filename of the portrait. */
103 
104  /** Mirror the portrait? */
105  bool mirror_;
106 
107  /** Do we need to show an input box? */
109 
110  /** The caption to show for the input text. */
112 
113  /** The text input. */
115 
116  /** The maximum length of the input text. */
118 
119  /** The list of options the user can choose. */
120  std::vector<twml_message_option> option_list_;
121 
122  /** The chosen option. */
124 
125  /** Inherited from tdialog. */
126  void pre_show(twindow& window);
127 
128  /** Inherited from tdialog. */
129  void post_show(twindow& window);
130 };
131 
132 /** Shows a dialog with the portrait on the left side. */
134 {
135 public:
137  const std::string& message,
138  const std::string& portrait,
139  const bool mirror)
140  : twml_message_(title, message, portrait, mirror)
141  {
142  }
143 
144 private:
145  /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
146  virtual const std::string& window_id() const;
147 };
148 
149 /** Shows a dialog with the portrait on the right side. */
151 {
152 public:
154  const std::string& message,
155  const std::string& portrait,
156  const bool mirror)
157  : twml_message_(title, message, portrait, mirror)
158  {
159  }
160 
161 private:
162  /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
163  virtual const std::string& window_id() const;
164 };
165 
166 
167 /**
168  * Helper function to show a portrait.
169  *
170  * @param left_side If true the portrait is shown on the left,
171  * on the right side otherwise.
172  * @param video The display variable.
173  * @param title The title of the dialog.
174  * @param message The message to show.
175  * @param portrait Filename of the portrait.
176  * @param mirror Does the portrait need to be mirrored?
177  *
178  * @param has_input Do we need to show the input box.
179  * @param input_caption The caption for the optional input text
180  * box. If this value != "" there is an input
181  * and the input text parameter is mandatory.
182  * @param input_text Pointer to the initial text value will be
183  * set to the result.
184  * @param maximum_length The maximum length of the text.
185  *
186  * @param option_list A list of options to select in the dialog.
187  * @param chosen_option Pointer to the initially chosen option.
188  * Will be set to the chosen option when the
189  * dialog closes.
190  */
191 int show_wml_message(const bool left_side,
192  CVideo& video,
193  const std::string& title,
194  const std::string& message,
195  const std::string& portrait,
196  const bool mirror,
197  const bool has_input,
198  const std::string& input_caption,
199  std::string* input_text,
200  const unsigned maximum_length,
201  const std::vector<twml_message_option>& option_list,
202  int* chosen_option);
203 
204 
205 } // namespace gui2
206 
207 #endif
void post_show(twindow &window)
Inherited from tdialog.
twml_message_option(std::string label, std::string description="", std::string image="")
Definition: wml_message.hpp:28
virtual const std::string & window_id() const
Inherited from tdialog, implemented by REGISTER_DIALOG.
std::string label() const
Definition: wml_message.hpp:33
virtual const std::string & window_id() const
Inherited from tdialog, implemented by REGISTER_DIALOG.
Definition: video.hpp:58
std::string image_
The image which is shown in the dialog.
Definition: wml_message.hpp:97
twml_message_left(const std::string &title, const std::string &message, const std::string &portrait, const bool mirror)
bool has_input_
Do we need to show an input box?
std::string description() const
Definition: wml_message.hpp:34
std::string portrait_
Filename of the portrait.
twml_message_right(const std::string &title, const std::string &message, const std::string &portrait, const bool mirror)
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
int * chosen_option_
The chosen option.
Base class for the wml generated messages.
Definition: wml_message.hpp:45
Abstract base class for all dialogs.
Definition: dialog.hpp:121
std::vector< twml_message_option > option_list_
The list of options the user can choose.
Helper class for message options.
Definition: wml_message.hpp:26
void set_input(const std::string &caption, std::string *text, const unsigned maximum_length)
Sets the input text variables.
Definition: wml_message.cpp:34
unsigned input_maximum_length_
The maximum length of the input text.
int show_wml_message(const bool left_side, CVideo &video, const std::string &title, const std::string &message, const std::string &portrait, const bool mirror, const bool has_input, const std::string &input_caption, std::string *input_text, const unsigned maximum_length, const std::vector< twml_message_option > &option_list, int *chosen_option)
Helper function to show a portrait.
Shows a dialog with the portrait on the left side.
Shows a dialog with the portrait on the right side.
std::string * input_text_
The text input.
bool mirror_
Mirror the portrait?
twml_message_(const std::string &title, const std::string &message, const std::string &portrait, const bool mirror)
Definition: wml_message.hpp:48
std::string input_caption_
The caption to show for the input text.
this module manages the cache of images.
Definition: image.cpp:75
std::string title_
The title for the dialog.
Definition: wml_message.hpp:90
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
std::string message_
The message to show to the user.
void set_option_list(const std::vector< twml_message_option > &option_list, int *chosen_option)
Sets the option list.
Definition: wml_message.cpp:46
void pre_show(twindow &window)
Inherited from tdialog.
Definition: wml_message.cpp:62
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::string image() const
Definition: wml_message.hpp:35