The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
frame.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2016 by Jeremy Rosen <[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  * Frame for unit's animation sequence.
18  */
19 
20 #ifndef UNIT_FRAME_H_INCLUDED
21 #define UNIT_FRAME_H_INCLUDED
22 
23 #include "halo.hpp"
24 #include "image.hpp"
25 
26 class config;
27 
29  public:
30  progressive_string(const std::string& data = "",int duration = 0);
31  int duration() const;
32  const std::string & get_current_element(int time) const;
33  bool does_not_change() const { return data_.size() <= 1; }
34  std::string get_original() const { return input_; }
35  private:
36  std::vector<std::pair<std::string,int> > data_;
38 };
39 
41  public:
42  progressive_image(const std::string& data = "",int duration = 0);
43  int duration() const;
44  const image::locator & get_current_element(int time) const;
45  bool does_not_change() const { return data_.size() <= 1; }
46  std::string get_original() const { return input_; }
47  private:
48  std::vector<std::pair<image::locator,int> > data_;
50 };
51 
52 template <class T>
54 {
55  std::vector<std::pair<std::pair<T, T>, int> > data_;
57 public:
58  progressive_(const std::string& data = "", int duration = 0);
59  int duration() const;
60  const T get_current_element(int time,T default_val=0) const;
61  bool does_not_change() const;
62  std::string get_original() const { return input_; }
63 };
64 
67 
69 bool tristate_to_bool(tristate tri, bool def);
70 /** All parameters from a frame at a given instant */
72  public:
74 
75  int duration;
80  int halo_x;
81  int halo_y;
85  Uint32 text_color;
86  Uint32 blend_with;
87  double blend_ratio;
89  double offset;
90  double submerge;
91  int x;
92  int y;
99 } ;
100 /**
101  * easily build frame parameters with the serialized constructors
102  */
105  public:
106  frame_builder();
107  frame_builder(const config& cfg,const std::string &frame_string = "");
108  /** allow easy chained modifications will raised assert if used after initialization */
109  frame_builder & duration(const int duration);
110  frame_builder & image(const std::string& image ,const std::string & image_mod="");
111  frame_builder & image_diagonal(const std::string& image_diagonal,const std::string & image_mod="");
113  frame_builder & text(const std::string& text,const Uint32 text_color);
114  frame_builder & halo(const std::string &halo, const std::string &halo_x, const std::string& halo_y,const std::string& halo_mod);
115  frame_builder & blend(const std::string& blend_ratio,const Uint32 blend_color);
119  frame_builder & x(const std::string& x);
120  frame_builder & y(const std::string& y);
123  frame_builder & auto_vflip(const bool auto_vflip);
124  frame_builder & auto_hflip(const bool auto_hflip);
127  /** getters for the different parameters */
128  private:
140  Uint32 text_color_;
141  Uint32 blend_with_;
154 };
155 /**
156  * keep most parameters in a separate class to simplify handling of large
157  * number of parameters handling is common for frame level and animation level
158  */
160  public:
161  frame_parsed_parameters(const frame_builder& builder=frame_builder(),int override_duration = 0);
162  /** allow easy chained modifications will raised assert if used after initialization */
163  void override( int duration
164  , const std::string& highlight = ""
165  , const std::string& blend_ratio =""
166  , Uint32 blend_color = 0
167  , const std::string& offset = ""
168  , const std::string& layer = ""
169  , const std::string& modifiers = "");
170  /** getters for the different parameters */
171  const frame_parameters parameters(int current_time) const ;
172 
173  int duration() const{ return duration_;}
174  bool does_not_change() const;
175  bool need_update() const;
176  std::vector<std::string> debug_strings() const; //contents of frame in strings
177  private:
188  Uint32 text_color_;
189  Uint32 blend_with_;
202 };
203 /** Describe a unit's animation sequence. */
204 class unit_frame {
205  public:
206  // Constructors
207  unit_frame(const frame_builder& builder=frame_builder()):builder_(builder){}
208  void redraw(const int frame_time,bool on_start_time,bool in_scope_of_frame,const map_location & src,const map_location & dst,halo::handle & halo_id, halo::manager & halo_man, const frame_parameters & animation_val,const frame_parameters & engine_val)const;
209  const frame_parameters merge_parameters(int current_time,const frame_parameters & animation_val,const frame_parameters & engine_val=frame_parameters()) const;
210  const frame_parameters parameters(int current_time) const {return builder_.parameters(current_time);}
212 
213  int duration() const { return builder_.duration();}
214  bool does_not_change() const{ return builder_.does_not_change();}
215  bool need_update() const{ return builder_.need_update();}
216  std::set<map_location> get_overlaped_hex(const int frame_time,const map_location & src,const map_location & dst,const frame_parameters & animation_val,const frame_parameters & engine_val) const;
217  std::vector<std::string> debug_strings() const { return builder_.debug_strings();} //contents of frame in strings
218  private:
220 
221 };
222 
223 #endif
double highlight_ratio
Definition: frame.hpp:88
double blend_ratio
Definition: frame.hpp:87
bool does_not_change() const
Definition: frame.hpp:33
Describe a unit's animation sequence.
Definition: frame.hpp:204
tristate auto_vflip_
Definition: frame.hpp:150
int duration() const
Definition: frame.cpp:185
std::string image_
Definition: frame.hpp:131
std::string sound
Definition: frame.hpp:83
frame_builder & y(const std::string &y)
Definition: frame.cpp:411
std::vector< std::pair< std::string, int > > data_
Definition: frame.hpp:36
progressive_int halo_x_
Definition: frame.hpp:183
progressive_double blend_ratio_
Definition: frame.hpp:190
frame_parsed_parameters(const frame_builder &builder=frame_builder(), int override_duration=0)
Definition: frame.cpp:450
image::locator image
Definition: frame.hpp:76
std::string image_mod_
Definition: frame.hpp:181
keep most parameters in a separate class to simplify handling of large number of parameters handling ...
Definition: frame.hpp:159
progressive_image(const std::string &data="", int duration=0)
Definition: frame.cpp:64
std::string blend_ratio_
Definition: frame.hpp:142
std::string sound_
Definition: frame.hpp:186
bool does_not_change() const
Definition: frame.hpp:45
Uint32 text_color
Definition: frame.hpp:85
std::string directional_y_
Definition: frame.hpp:149
std::vector< std::string > debug_strings() const
Definition: frame.cpp:593
std::string text_
Definition: frame.hpp:139
frame_builder & drawing_layer(const std::string &drawing_layer)
Definition: frame.cpp:444
frame_builder & image_diagonal(const std::string &image_diagonal, const std::string &image_mod="")
Definition: frame.cpp:355
std::vector< std::pair< std::pair< T, T >, int > > data_
Definition: frame.hpp:55
tristate
Definition: frame.hpp:68
std::vector< std::string > debug_strings() const
Definition: frame.hpp:217
tristate auto_hflip_
Definition: frame.hpp:151
std::string drawing_layer_
Definition: frame.hpp:153
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
Audio output for sound and music.
Definition: sound.cpp:43
std::string halo_mod_
Definition: frame.hpp:137
double submerge
Definition: frame.hpp:90
GLenum src
Definition: glew.h:2392
image::locator image_diagonal
Definition: frame.hpp:77
std::string get_original() const
Definition: frame.hpp:62
All parameters from a frame at a given instant.
Definition: frame.hpp:71
unit_frame(const frame_builder &builder=frame_builder())
Definition: frame.hpp:207
frame_builder & directional_x(const std::string &directional_x)
Definition: frame.cpp:416
bool need_update() const
Definition: frame.cpp:495
std::string halo_y_
Definition: frame.hpp:136
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
tristate auto_vflip
Definition: frame.hpp:95
frame_builder & blend(const std::string &blend_ratio, const Uint32 blend_color)
Definition: frame.cpp:385
frame_builder & image(const std::string &image, const std::string &image_mod="")
Definition: frame.cpp:349
std::string input_
Definition: frame.hpp:56
int duration() const
Definition: frame.cpp:54
const frame_parameters parameters(int current_time) const
getters for the different parameters
Definition: frame.cpp:516
std::string halo_
Definition: frame.hpp:134
frame_builder & submerge(const std::string &submerge)
Definition: frame.cpp:401
frame_parsed_parameters builder_
Definition: frame.hpp:219
double offset
Definition: frame.hpp:89
const frame_parameters merge_parameters(int current_time, const frame_parameters &animation_val, const frame_parameters &engine_val=frame_parameters()) const
Definition: frame.cpp:857
GLintptr offset
Definition: glew.h:1650
bool does_not_change() const
Definition: frame.hpp:214
frame_builder & auto_hflip(const bool auto_hflip)
Definition: frame.cpp:432
tristate primary_frame_
Definition: frame.hpp:200
std::set< map_location > get_overlaped_hex(const int frame_time, const map_location &src, const map_location &dst, const frame_parameters &animation_val, const frame_parameters &engine_val) const
Definition: frame.cpp:751
bool tristate_to_bool(tristate tri, bool def)
Definition: frame.cpp:207
frame_builder & sound(const std::string &sound)
Definition: frame.cpp:361
std::string get_original() const
Definition: frame.hpp:34
bool does_not_change() const
Definition: frame.cpp:197
GLenum GLenum GLuint GLint GLint layer
Definition: glew.h:3455
progressive_image image_diagonal_
Definition: frame.hpp:180
std::string highlight_ratio_
Definition: frame.hpp:143
tristate auto_hflip
Definition: frame.hpp:96
GLenum GLenum dst
Definition: glew.h:2392
std::string halo_mod
Definition: frame.hpp:82
progressive_int x_
Definition: frame.hpp:194
std::string text_
Definition: frame.hpp:187
progressive_(const std::string &data="", int duration=0)
Definition: frame.cpp:136
std::string input_
Definition: frame.hpp:49
int duration() const
Definition: frame.hpp:173
frame_builder & auto_vflip(const bool auto_vflip)
Definition: frame.cpp:426
progressive_image image_
Definition: frame.hpp:179
progressive_double highlight_ratio_
Definition: frame.hpp:191
std::string y_
Definition: frame.hpp:147
progressive_int halo_y_
Definition: frame.hpp:184
std::string text
Definition: frame.hpp:84
int drawing_layer
Definition: frame.hpp:98
const frame_parameters end_parameters() const
Definition: frame.hpp:211
std::vector< std::pair< image::locator, int > > data_
Definition: frame.hpp:48
std::string directional_x_
Definition: frame.hpp:148
progressive_int drawing_layer_
Definition: frame.hpp:201
progressive_int directional_x_
Definition: frame.hpp:196
Encapsulates the map of the game.
Definition: location.hpp:38
std::string get_original() const
Definition: frame.hpp:46
const T get_current_element(int time, T default_val=0) const
Definition: frame.cpp:158
frame_builder & text(const std::string &text, const Uint32 text_color)
Definition: frame.cpp:366
const image::locator & get_current_element(int time) const
Definition: frame.cpp:105
Uint32 text_color_
Definition: frame.hpp:140
std::string image_mod
Definition: frame.hpp:78
int directional_y
Definition: frame.hpp:94
Uint32 blend_with_
Definition: frame.hpp:141
int duration_
Definition: frame.hpp:130
progressive_< int > progressive_int
Definition: frame.hpp:65
frame_builder & offset(const std::string &offset)
Definition: frame.cpp:396
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
frame_builder & x(const std::string &x)
Definition: frame.cpp:406
int duration() const
Definition: frame.hpp:213
std::string offset_
Definition: frame.hpp:144
bool does_not_change() const
Definition: frame.cpp:478
frame_builder & primary_frame(const bool primary_frame)
Definition: frame.cpp:438
frame_builder & directional_y(const std::string &directional_y)
Definition: frame.cpp:421
tristate primary_frame_
Definition: frame.hpp:152
progressive_double submerge_
Definition: frame.hpp:193
std::string input_
Definition: frame.hpp:37
std::string halo
Definition: frame.hpp:79
int duration() const
Definition: frame.cpp:93
Definition: display.hpp:43
progressive_int directional_y_
Definition: frame.hpp:197
tristate primary_frame
Definition: frame.hpp:97
Uint32 blend_with
Definition: frame.hpp:86
const frame_parameters parameters(int current_time) const
Definition: frame.hpp:210
this module manages the cache of images.
Definition: image.cpp:75
progressive_< double > progressive_double
Definition: frame.hpp:66
std::string halo_mod_
Definition: frame.hpp:185
std::string image_diagonal_
Definition: frame.hpp:132
frame_builder & duration(const int duration)
allow easy chained modifications will raised assert if used after initialization
Definition: frame.cpp:380
Definition: frame.hpp:68
progressive_double offset_
Definition: frame.hpp:192
frame_builder & highlight(const std::string &highlight)
Definition: frame.cpp:391
std::string halo_x_
Definition: frame.hpp:135
std::string x_
Definition: frame.hpp:146
progressive_string halo_
Definition: frame.hpp:182
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
progressive_int y_
Definition: frame.hpp:195
std::string image_mod_
Definition: frame.hpp:133
const std::string & get_current_element(int time) const
Definition: frame.cpp:121
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool need_update() const
Definition: frame.hpp:215
void redraw(const int frame_time, bool on_start_time, bool in_scope_of_frame, const map_location &src, const map_location &dst, halo::handle &halo_id, halo::manager &halo_man, const frame_parameters &animation_val, const frame_parameters &engine_val) const
Definition: frame.cpp:630
frame_builder & halo(const std::string &halo, const std::string &halo_x, const std::string &halo_y, const std::string &halo_mod)
Definition: frame.cpp:372
progressive_string(const std::string &data="", int duration=0)
Definition: frame.cpp:25
std::string submerge_
Definition: frame.hpp:145
std::string sound_
Definition: frame.hpp:138
int directional_x
Definition: frame.hpp:93