The Battle for Wesnoth  1.19.5+dev
frame.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2024
3  by Jeremy Rosen <jeremy.rosen@enst-bretagne.fr>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Frame for unit's animation sequence.
19  */
20 
21 #pragma once
22 
23 #include "units/frame_private.hpp"
24 
25 #include "color.hpp"
26 #include "drawing_layer.hpp"
27 #include "halo.hpp"
28 #include "picture.hpp"
29 #include "utils/optional_fwd.hpp"
30 
31 #include <boost/logic/tribool.hpp>
32 
33 class config;
34 
35 constexpr int get_abs_frame_layer(drawing_layer layer)
36 {
37  return int(layer) - int(drawing_layer::unit_first);
38 }
39 
40 /** All parameters from a frame at a given instant */
42 {
43  int duration = 0;
44 
47 
48  std::string image_mod;
49  std::string halo;
50 
51  int halo_x = 0;
52  int halo_y = 0;
53 
54  std::string halo_mod;
55  std::string sound;
56  std::string text;
57 
58  utils::optional<color_t> text_color;
59  utils::optional<color_t> blend_with;
60 
61  double blend_ratio = 0.0;
62  double highlight_ratio = 1.0;
63  double offset = 0.0;
64  double submerge = 0.0;
65 
66  int x = 0;
67  int y = 0;
68  int directional_x = 0;
69  int directional_y = 0;
70 
71  boost::tribool auto_vflip = boost::logic::indeterminate;
72  boost::tribool auto_hflip = boost::logic::indeterminate;
73  boost::tribool primary_frame = boost::logic::indeterminate;
74 
76 };
77 
78 /**
79  * Easily build frame parameters with the serialized constructors
80  */
82 {
83 public:
84  frame_builder();
85  frame_builder(const config& cfg, const std::string& frame_string = "");
86 
87  /** Allow easy chained modifications. Will raised assert if used after initialization */
88  frame_builder& duration(const int duration);
89  frame_builder& image(const std::string& image, const std::string& image_mod = "");
90  frame_builder& image_diagonal(const std::string& image_diagonal, const std::string& image_mod = "");
91  frame_builder& sound(const std::string& sound);
92  frame_builder& text(const std::string& text, const color_t text_color);
93  frame_builder& halo(const std::string& halo, const std::string& halo_x, const std::string& halo_y, const std::string& halo_mod);
94  frame_builder& blend(const std::string& blend_ratio, const color_t blend_color);
95  frame_builder& highlight(const std::string& highlight);
96  frame_builder& offset(const std::string& offset);
97  frame_builder& submerge(const std::string& submerge);
98  frame_builder& x(const std::string& x);
99  frame_builder& y(const std::string& y);
100  frame_builder& directional_x(const std::string& directional_x);
101  frame_builder& directional_y(const std::string& directional_y);
102  frame_builder& auto_vflip(const bool auto_vflip);
103  frame_builder& auto_hflip(const bool auto_hflip);
105  frame_builder& drawing_layer(const std::string& drawing_layer);
106 
107 private:
109 
111 
112  std::string image_;
113  std::string image_diagonal_;
114  std::string image_mod_;
115  std::string halo_;
116  std::string halo_x_;
117  std::string halo_y_;
118  std::string halo_mod_;
119  std::string sound_;
120  std::string text_;
121 
122  utils::optional<color_t> text_color_;
123  utils::optional<color_t> blend_with_;
124 
125  std::string blend_ratio_;
126  std::string highlight_ratio_;
127  std::string offset_;
128  std::string submerge_;
129  std::string x_;
130  std::string y_;
131  std::string directional_x_;
132  std::string directional_y_;
133 
134  boost::tribool auto_vflip_;
135  boost::tribool auto_hflip_;
136  boost::tribool primary_frame_;
137 
138  std::string drawing_layer_;
139 };
140 
141 /**
142  * Keep most parameters in a separate class to simplify the handling of the large
143  * number of parameters between the frame level and animation level.
144  */
146 {
147 public:
148  frame_parsed_parameters(const frame_builder& builder = frame_builder(), int override_duration = 0);
149 
150  void override(int duration,
151  const std::string& highlight = "",
152  const std::string& blend_ratio = "",
153  color_t blend_color = {0,0,0},
154  const std::string& offset = "",
155  const std::string& layer = "",
156  const std::string& modifiers = "");
157 
158  /** Getters for the different parameters */
159  frame_parameters parameters(int current_time) const;
160 
161  int duration() const{ return duration_;}
162  bool does_not_change() const;
163  bool need_update() const;
164 
165  /** Contents of frame in strings */
166  std::vector<std::string> debug_strings() const;
167 
168 private:
170 
173 
174  std::string image_mod_;
175 
179 
180  std::string halo_mod_;
181  std::string sound_;
182  std::string text_;
183 
184  utils::optional<color_t> text_color_;
185  utils::optional<color_t> blend_with_;
186 
195 
196  boost::tribool auto_vflip_;
197  boost::tribool auto_hflip_;
198  boost::tribool primary_frame_;
199 
201 };
202 
203 /** Describes a unit's animation sequence. */
205 {
206 public:
207  // Constructors
208  unit_frame(const frame_builder& builder = frame_builder()) : builder_(builder) {}
209 
210  void redraw(const int frame_time, bool on_start_time, bool in_scope_of_frame, const map_location& src, const map_location& dst,
211  halo::handle& halo_id, halo::manager& halo_man, const frame_parameters& animation_val, const frame_parameters& engine_val) const;
212 
213  frame_parameters merge_parameters(int current_time, const frame_parameters& animation_val,
214  const frame_parameters& engine_val = frame_parameters()) const;
215 
216  frame_parameters parameters(int current_time) const
217  {
218  return builder_.parameters(current_time);
219  }
220 
222  {
223  return builder_.parameters(duration());
224  }
225 
226  int duration() const
227  {
228  return builder_.duration();
229  }
230 
231  bool does_not_change() const
232  {
233  return builder_.does_not_change();
234  }
235 
236  bool need_update() const
237  {
238  return builder_.need_update();
239  }
240 
241  std::vector<std::string> debug_strings() const
242  {
243  // Contents of frame in strings
244  return builder_.debug_strings();
245  }
246 
247  std::set<map_location> get_overlaped_hex(const int frame_time, const map_location& src, const map_location& dst,
248  const frame_parameters& animation_val, const frame_parameters& engine_val) const;
249 
250 private:
252 };
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
Easily build frame parameters with the serialized constructors.
Definition: frame.hpp:82
std::string offset_
Definition: frame.hpp:127
std::string halo_y_
Definition: frame.hpp:117
std::string image_mod_
Definition: frame.hpp:114
utils::optional< color_t > blend_with_
Definition: frame.hpp:123
std::string halo_mod_
Definition: frame.hpp:118
std::string image_diagonal_
Definition: frame.hpp:113
frame_builder()
Definition: frame.cpp:27
boost::tribool auto_vflip_
Definition: frame.hpp:134
boost::tribool primary_frame_
Definition: frame.hpp:136
frame_builder & duration(const int duration)
Allow easy chained modifications.
Definition: frame.cpp:144
frame_builder & auto_hflip(const bool auto_hflip)
Definition: frame.cpp:205
std::string halo_
Definition: frame.hpp:115
frame_builder & highlight(const std::string &highlight)
Definition: frame.cpp:157
std::string sound_
Definition: frame.hpp:119
frame_builder & image_diagonal(const std::string &image_diagonal, const std::string &image_mod="")
Definition: frame.cpp:115
frame_builder & directional_x(const std::string &directional_x)
Definition: frame.cpp:187
frame_builder & submerge(const std::string &submerge)
Definition: frame.cpp:169
std::string image_
Definition: frame.hpp:112
std::string submerge_
Definition: frame.hpp:128
int duration_
Definition: frame.hpp:110
frame_builder & y(const std::string &y)
Definition: frame.cpp:181
frame_builder & primary_frame(const bool primary_frame)
Definition: frame.cpp:211
frame_builder & auto_vflip(const bool auto_vflip)
Definition: frame.cpp:199
std::string y_
Definition: frame.hpp:130
std::string highlight_ratio_
Definition: frame.hpp:126
boost::tribool auto_hflip_
Definition: frame.hpp:135
std::string blend_ratio_
Definition: frame.hpp:125
std::string text_
Definition: frame.hpp:120
std::string drawing_layer_
Definition: frame.hpp:138
frame_builder & drawing_layer(const std::string &drawing_layer)
Definition: frame.cpp:217
std::string directional_x_
Definition: frame.hpp:131
std::string directional_y_
Definition: frame.hpp:132
std::string halo_x_
Definition: frame.hpp:116
frame_builder & text(const std::string &text, const color_t text_color)
Definition: frame.cpp:128
frame_builder & blend(const std::string &blend_ratio, const color_t blend_color)
Definition: frame.cpp:150
frame_builder & x(const std::string &x)
Definition: frame.cpp:175
utils::optional< color_t > text_color_
Definition: frame.hpp:122
frame_builder & offset(const std::string &offset)
Definition: frame.cpp:163
frame_builder & directional_y(const std::string &directional_y)
Definition: frame.cpp:193
frame_builder & image(const std::string &image, const std::string &image_mod="")
Definition: frame.cpp:108
frame_builder & sound(const std::string &sound)
Definition: frame.cpp:122
std::string x_
Definition: frame.hpp:129
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:135
Keep most parameters in a separate class to simplify the handling of the large number of parameters b...
Definition: frame.hpp:146
std::string text_
Definition: frame.hpp:182
progressive_int directional_x_
Definition: frame.hpp:193
progressive_int halo_y_
Definition: frame.hpp:178
boost::tribool auto_hflip_
Definition: frame.hpp:197
progressive_image image_
Definition: frame.hpp:171
boost::tribool primary_frame_
Definition: frame.hpp:198
bool need_update() const
Definition: frame.cpp:269
progressive_double blend_ratio_
Definition: frame.hpp:187
progressive_double highlight_ratio_
Definition: frame.hpp:188
progressive_double offset_
Definition: frame.hpp:189
boost::tribool auto_vflip_
Definition: frame.hpp:196
progressive_string halo_
Definition: frame.hpp:176
utils::optional< color_t > blend_with_
Definition: frame.hpp:185
progressive_int x_
Definition: frame.hpp:191
int duration() const
Definition: frame.hpp:161
std::string sound_
Definition: frame.hpp:181
progressive_double submerge_
Definition: frame.hpp:190
std::string halo_mod_
Definition: frame.hpp:180
std::string image_mod_
Definition: frame.hpp:174
progressive_int halo_x_
Definition: frame.hpp:177
progressive_int y_
Definition: frame.hpp:192
progressive_int drawing_layer_
Definition: frame.hpp:200
utils::optional< color_t > text_color_
Definition: frame.hpp:184
frame_parameters parameters(int current_time) const
Getters for the different parameters.
Definition: frame.cpp:274
std::vector< std::string > debug_strings() const
Contents of frame in strings.
Definition: frame.cpp:385
progressive_int directional_y_
Definition: frame.hpp:194
progressive_image image_diagonal_
Definition: frame.hpp:172
bool does_not_change() const
Definition: frame.cpp:250
frame_parsed_parameters(const frame_builder &builder=frame_builder(), int override_duration=0)
Definition: frame.cpp:223
Generic locator abstracting the location of an image.
Definition: picture.hpp:59
Describes a unit's animation sequence.
Definition: frame.hpp:205
bool need_update() const
Definition: frame.hpp:236
frame_parameters merge_parameters(int current_time, const frame_parameters &animation_val, const frame_parameters &engine_val=frame_parameters()) const
This function merges the value provided by:
Definition: frame.cpp:914
int duration() const
Definition: frame.hpp:226
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:627
bool does_not_change() const
Definition: frame.hpp:231
std::vector< std::string > debug_strings() const
Definition: frame.hpp:241
frame_parameters parameters(int current_time) const
Definition: frame.hpp: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
Definition: frame.cpp:793
frame_parameters end_parameters() const
Definition: frame.hpp:221
unit_frame(const frame_builder &builder=frame_builder())
Definition: frame.hpp:208
frame_parsed_parameters builder_
Definition: frame.hpp:251
drawing_layer
@ unit_default
Default layer for drawing units.
@ unit_first
Reserve layers to be selected for wml.
constexpr int get_abs_frame_layer(drawing_layer layer)
Definition: frame.hpp:35
Definition: halo.cpp:39
std::shared_ptr< halo_record > handle
Definition: halo.hpp:31
Functions to load and save images from/to disk.
Audio output for sound and music.
Definition: sound.cpp:40
rect dst
Location on the final composed sheet.
rect src
Non-transparent portion of the surface to compose.
The basic class for representing 8-bit RGB or RGBA colour values.
Definition: color.hpp:59
All parameters from a frame at a given instant.
Definition: frame.hpp:42
std::string halo
Definition: frame.hpp:49
utils::optional< color_t > blend_with
Definition: frame.hpp:59
double highlight_ratio
Definition: frame.hpp:62
std::string text
Definition: frame.hpp:56
boost::tribool auto_hflip
Definition: frame.hpp:72
int directional_x
Definition: frame.hpp:68
double offset
Definition: frame.hpp:63
std::string sound
Definition: frame.hpp:55
std::string image_mod
Definition: frame.hpp:48
double submerge
Definition: frame.hpp:64
image::locator image_diagonal
Definition: frame.hpp:46
boost::tribool primary_frame
Definition: frame.hpp:73
int directional_y
Definition: frame.hpp:69
image::locator image
Definition: frame.hpp:45
utils::optional< color_t > text_color
Definition: frame.hpp:58
double blend_ratio
Definition: frame.hpp:61
std::string halo_mod
Definition: frame.hpp:54
boost::tribool auto_vflip
Definition: frame.hpp:71
Encapsulates the map of the game.
Definition: location.hpp:45