The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
part.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Ignacio R. Morelle <[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 /**
16  * @file
17  * Storyscreen parts and floating images representation.
18  */
19 
20 #ifndef STORYSCREEN_PART_HPP_INCLUDED
21 #define STORYSCREEN_PART_HPP_INCLUDED
22 
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 #include "sdl/utils.hpp"
28 #include "sdl/image.hpp"
29 
30 class config;
31 class vconfig;
32 class display;
33 
34 namespace storyscreen {
35 
36 /**
37  * Represents and contains information about image labels used
38  * in story screen parts.
39  */
41 {
42 public:
43  struct render_input
44  {
45  SDL_Rect rect; /**< Corrected rectangle for rendering surf. */
46 #ifdef SDL_GPU
47  sdl::timage image;
48 #else
49  surface image; /**< Surface, scaled if required. */
50 #endif
51  };
52 
53  /**
54  * WML-based constructor.
55  * @param cfg Object corresponding to a [image] block's contents from
56  * a [part] node.
57  */
58  floating_image(const config& cfg);
59 
60  /**
61  * Copy constructor.
62  */
63  floating_image(const floating_image& fi);
64 
66  assign(fi);
67  return *this;
68  }
69 
70  /**
71  * Returns the referential X coordinate of the image.
72  * The actual (corrected) value is determined at render time - see get_render_input().
73  */
74  int ref_x() const {
75  return x_;
76  }
77 
78  /**
79  * Returns the referential Y coordinate of the image.
80  * The actual (corrected) value is determined at render time - see get_render_input().
81  */
82  int ref_y() const {
83  return y_;
84  }
85 
86  /**
87  * Whether the image should be automatically scaled as much as
88  * the storyscreen background is.
89  */
90  bool autoscale() const { return autoscaled_; }
91 
92  /**
93  * Whether the image coordinates specify the location of its
94  * center (true) or top-left corner (false).
95  */
96  bool centered() const { return centered_; }
97 
98  /**
99  * Delay before displaying, in milliseconds.
100  */
101  int display_delay() const { return delay_; }
102 
103  /**
104  * Gets a render_input object for use by the rendering code after applying
105  * any geometric transformations required.
106  */
107  render_input get_render_input(double xscale, double yscale, SDL_Rect& dst_rect) const;
108 
109 private:
111  int x_, y_; // referential (non corrected) x,y
112  int delay_;
114  bool centered_;
115 
116  /** Copy constructor and operator=() implementation details. */
117  void assign(const floating_image& fi);
118 };
119 
121 {
122 public:
123  /**
124  * Constructor.
125  */
127 
128  /**
129  * Constructor. Initializes a background_layer object from a
130  * [background_layer] WML node.
131  */
132  background_layer(const config& cfg);
133 
134  /**
135  * Whether the layer should be scaled horizontally.
136  */
137  bool scale_horizontally() const {
138  return scale_horizontally_;
139  }
140 
141  /**
142  * Sets whether the layer should be scaled horizontally.
143  */
146  }
147 
148  /**
149  * Whether the layer should be scaled vertically.
150  */
151  bool scale_vertically() const {
152  return scale_vertically_;
153  }
154 
155  /**
156  * Sets whether the layer should be scaled vertically.
157  */
158  void set_scale_vertically(bool b) {
160  }
161 
162  /**
163  * Whether the layer should be tiled horizontally.
164  */
165  bool tile_horizontally() const {
166  return tile_horizontally_;
167  }
168 
169  /**
170  * Sets whether the layer should be tiled horizontally.
171  */
174  }
175 
176  /**
177  * Whether the layer should be tiled vertically.
178  */
179  bool tile_vertically() const {
180  return tile_vertically_;
181  }
182 
183  /**
184  * Sets whether the layer should be tiled vertically.
185  */
186  void set_tile_vertically(bool b) {
188  }
189 
190  /**
191  * Whether the aspect ratio should be preserved while scaling.
192  */
193  bool keep_aspect_ratio() const {
194  return keep_aspect_ratio_;
195  }
196 
197  /**
198  * Sets whether the aspect ratio should be preserved.
199  */
202  }
203 
204  /**
205  * Whether is this layer the base layer.
206  */
207  bool is_base_layer() const {
208  return is_base_layer_;
209  }
210 
211  /**
212  * Sets whether is this layer a base layer.
213  */
214  void set_base_layer(bool b) {
215  is_base_layer_ = b;
216  }
217 
218  /**
219  * The path to the file to load the image from.
220  */
221  const std::string& file() const {
222  return image_file_;
223  }
224 
225  /**
226  * Sets the path to the image file.
227  */
228  void set_file(const std::string& str) {
229  image_file_ = str;
230  }
231 private:
239 };
240 
241 /**
242  * Represents and contains information about a single storyscreen part.
243  */
244 class part
245 {
246 public:
247  /**
248  * Currently used to indicate where the text block should be placed.
249  * Note that it will always take as much space as it is
250  * possible horizontally.
251  */
253  BLOCK_TOP, /**< Top of the screen. */
254  BLOCK_MIDDLE, /**< Center of the screen. */
255  BLOCK_BOTTOM /**< Bottom of the screen. This is the default. */
256  };
257  /**
258  * Currently used to indicate where the page title should be placed.
259  * It always takes as little space (horizontally) as possible,
260  * and it is always placed at the top of the screen.
261  */
263  TEXT_LEFT, /**< Top-left corner. */
264  TEXT_CENTERED, /**< Center on the topmost edge of the screen. */
265  TEXT_RIGHT /**< Top-right corner. */
266  };
267  /**
268  * Used to signal user actions.
269  */
270  enum RESULT {
271  NEXT, /**< Jump to next story part. */
272  SKIP, /**< Skip all story parts for this set. */
273  QUIT /**< Quit game and go back to main menu. */
274  };
275 
276  /**
277  * Constructs a storyscreen part from a managed WML node.
278  * @param part_cfg Node object which should correspond to a [part] block's contents.
279  */
280  part(const vconfig &part_cfg);
281 
282  /** Whether the story screen title should be displayed or not. */
283  bool show_title() const {
284  return show_title_;
285  }
286 
287  /** Retrieves the story text itself. */
288  const std::string& text() const {
289  return text_;
290  }
291 
292  /** Changes the story text. */
293  void set_text(const std::string& text) {
294  text_ = text;
295  }
296 
297  /** Retrieves the story screen title. */
298  const std::string& title() const {
299  return text_title_;
300  }
301 
302  /** Changes the story screen title. */
303  void set_title(const std::string& title) {
304  text_title_ = title;
305  }
306 
307  /** Retrieves the background music. */
308  const std::string& music() const {
309  return music_;
310  }
311 
312  /** Retrieves a one-time-only sound effect. */
313  const std::string& sound() const {
314  return sound_;
315  }
316 
317  /** Retrieves the area of the screen on which the story text is displayed. */
319  return text_block_loc_;
320  }
321 
322  /** Retrieves the alignment of the title text against the screen. */
324  return title_alignment_;
325  }
326 
327  /** Retrieve any associated floating images for this story screen. */
328  const std::vector<floating_image>& get_floating_images() const {
329  return floating_images_;
330  }
331 
332  /** Retrieve background layers for this story screen. */
333  const std::vector<background_layer>& get_background_layers() const {
334  return background_layers_;
335  }
336 
337 private:
338  /** Takes care of initializing and branching properties. */
339  void resolve_wml(const vconfig &cfg);
340 
343 
349 
352 
353  std::vector<background_layer> background_layers_;
354  std::vector<floating_image> floating_images_;
355 };
356 
357 } // end namespace storyscreen
358 
359 
360 #endif /* ! STORYSCREEN_PART_HPP_INCLUDED */
std::string music_
Definition: part.hpp:350
void set_keep_aspect_ratio(bool b)
Sets whether the aspect ratio should be preserved.
Definition: part.hpp:200
Skip all story parts for this set.
Definition: part.hpp:272
Center of the screen.
Definition: part.hpp:254
bool tile_vertically() const
Whether the layer should be tiled vertically.
Definition: part.hpp:179
int ref_y() const
Returns the referential Y coordinate of the image.
Definition: part.hpp:82
bool keep_aspect_ratio() const
Whether the aspect ratio should be preserved while scaling.
Definition: part.hpp:193
SDL_Rect rect
Corrected rectangle for rendering surf.
Definition: part.hpp:45
BLOCK_LOCATION story_text_location() const
Retrieves the area of the screen on which the story text is displayed.
Definition: part.hpp:318
void set_title(const std::string &title)
Changes the story screen title.
Definition: part.hpp:303
floating_image & operator=(const floating_image &fi)
Definition: part.hpp:65
bool scale_vertically() const
Whether the layer should be scaled vertically.
Definition: part.hpp:151
Center on the topmost edge of the screen.
Definition: part.hpp:264
const std::string & title() const
Retrieves the story screen title.
Definition: part.hpp:298
std::string text_
Definition: part.hpp:345
const std::vector< background_layer > & get_background_layers() const
Retrieve background layers for this story screen.
Definition: part.hpp:333
bool scale_horizontally() const
Whether the layer should be scaled horizontally.
Definition: part.hpp:137
static TEXT_ALIGNMENT string_title_align(const std::string &s)
Definition: part.cpp:201
Bottom of the screen.
Definition: part.hpp:255
render_input get_render_input(double xscale, double yscale, SDL_Rect &dst_rect) const
Gets a render_input object for use by the rendering code after applying any geometric transformations...
Definition: part.cpp:69
void set_tile_vertically(bool b)
Sets whether the layer should be tiled vertically.
Definition: part.hpp:186
Top-left corner.
Definition: part.hpp:263
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
const std::string & file() const
The path to the file to load the image from.
Definition: part.hpp:221
BLOCK_LOCATION text_block_loc_
Definition: part.hpp:347
void set_file(const std::string &str)
Sets the path to the image file.
Definition: part.hpp:228
RESULT
Used to signal user actions.
Definition: part.hpp:270
const std::string & music() const
Retrieves the background music.
Definition: part.hpp:308
Represents and contains information about image labels used in story screen parts.
Definition: part.hpp:40
void set_tile_horizontally(bool b)
Sets whether the layer should be tiled horizontally.
Definition: part.hpp:172
background_layer()
Constructor.
Definition: part.cpp:122
const std::string & text() const
Retrieves the story text itself.
Definition: part.hpp:288
TEXT_ALIGNMENT title_alignment_
Definition: part.hpp:348
bool centered() const
Whether the image coordinates specify the location of its center (true) or top-left corner (false)...
Definition: part.hpp:96
std::vector< background_layer > background_layers_
Definition: part.hpp:353
Represents and contains information about a single storyscreen part.
Definition: part.hpp:244
std::vector< floating_image > floating_images_
Definition: part.hpp:354
std::string sound_
Definition: part.hpp:351
void resolve_wml(const vconfig &cfg)
Takes care of initializing and branching properties.
Definition: part.cpp:214
static BLOCK_LOCATION string_tblock_loc(const std::string &s)
Definition: part.cpp:188
std::string text_title_
Definition: part.hpp:346
bool is_base_layer() const
Whether is this layer the base layer.
Definition: part.hpp:207
const std::string & sound() const
Retrieves a one-time-only sound effect.
Definition: part.hpp:313
Top of the screen.
Definition: part.hpp:253
void assign(const floating_image &fi)
Copy constructor and operator=() implementation details.
Definition: part.cpp:60
Contains a wrapper class for the GPU_Image class.
int ref_x() const
Returns the referential X coordinate of the image.
Definition: part.hpp:74
bool show_title_
Definition: part.hpp:344
int display_delay() const
Delay before displaying, in milliseconds.
Definition: part.hpp:101
Quit game and go back to main menu.
Definition: part.hpp:273
bool show_title() const
Whether the story screen title should be displayed or not.
Definition: part.hpp:283
void set_base_layer(bool b)
Sets whether is this layer a base layer.
Definition: part.hpp:214
floating_image(const config &cfg)
WML-based constructor.
Definition: part.cpp:50
Top-right corner.
Definition: part.hpp:265
part(const vconfig &part_cfg)
Constructs a storyscreen part from a managed WML node.
Definition: part.cpp:174
A variable-expanding proxy for the config class.
Definition: variable.hpp:36
TEXT_ALIGNMENT title_text_alignment() const
Retrieves the alignment of the title text against the screen.
Definition: part.hpp:323
void set_text(const std::string &text)
Changes the story text.
Definition: part.hpp:293
void set_scale_horizontally(bool b)
Sets whether the layer should be scaled horizontally.
Definition: part.hpp:144
surface image
Surface, scaled if required.
Definition: part.hpp:49
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
Jump to next story part.
Definition: part.hpp:271
TEXT_ALIGNMENT
Currently used to indicate where the page title should be placed.
Definition: part.hpp:262
GLdouble s
Definition: glew.h:1358
void set_scale_vertically(bool b)
Sets whether the layer should be scaled vertically.
Definition: part.hpp:158
bool tile_horizontally() const
Whether the layer should be tiled horizontally.
Definition: part.hpp:165
const std::vector< floating_image > & get_floating_images() const
Retrieve any associated floating images for this story screen.
Definition: part.hpp:328
GLsizei const GLcharARB ** string
Definition: glew.h:4503
BLOCK_LOCATION
Currently used to indicate where the text block should be placed.
Definition: part.hpp:252
bool autoscale() const
Whether the image should be automatically scaled as much as the storyscreen background is...
Definition: part.hpp:90