FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
visual.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 #ifndef FIFE_VIEW_VISUAL_H
23 #define FIFE_VIEW_VISUAL_H
24 
25 // Standard C++ library includes
26 
27 // 3rd party library includes
28 
29 // FIFE includes
30 // These includes are split up in two parts, separated by one empty line
31 // First block: files included from the FIFE root src directory
32 // Second block: files included from the same folder
34 #include "util/math/angles.h"
35 #include "util/structures/rect.h"
36 #include "video/animation.h"
37 #include "video/color.h"
38 
39 
40 namespace FIFE {
41  class Object;
42  class Instance;
43  class Action;
44  class Image;
45 
46  class OverlayColors {
47  public:
50  OverlayColors();
51  OverlayColors(ImagePtr image);
52  OverlayColors(AnimationPtr animation);
53 
57 
58  void setColorOverlayImage(ImagePtr image);
60  void setColorOverlayAnimation(AnimationPtr animation);
62  void changeColor(const Color& source, const Color& target);
63  const std::map<Color, Color>& getColors();
64  void resetColors();
65 
66  private:
67  std::map<Color, Color> m_colorMap;
70  };
71 
77  class Visual2DGfx: public IVisual {
78  public:
81  virtual ~Visual2DGfx();
82 
83  protected:
86  Visual2DGfx();
87  };
88 
91  class ObjectVisual: public Visual2DGfx {
92  public:
95  static ObjectVisual* create(Object* object);
96 
99  virtual ~ObjectVisual();
100 
110  void addStaticImage(uint32_t angle, int32_t image_index);
111 
115  int32_t getStaticImageIndexByAngle(int32_t angle);
116 
119  void addStaticColorOverlay(uint32_t angle, const OverlayColors& colors);
120 
124  OverlayColors* getStaticColorOverlay(int32_t angle);
125 
128  void removeStaticColorOverlay(int32_t angle);
129 
133  int32_t getClosestMatchingAngle(int32_t angle);
134 
137  void getStaticImageAngles(std::vector<int32_t>& angles);
138 
141  bool isColorOverlay() { return !m_colorOverlayMap.empty(); }
142 
143  private:
146  ObjectVisual();
147 
149 
150  typedef std::map<uint32_t, OverlayColors> AngleColorOverlayMap;
151  AngleColorOverlayMap m_colorOverlayMap;
153  };
154 
155 
158  class InstanceVisual: public Visual2DGfx {
159  public:
162  static InstanceVisual* create(Instance* instance);
163 
166  virtual ~InstanceVisual();
167 
171  void setTransparency(uint8_t transparency);
172 
176  uint8_t getTransparency();
177 
181  void setVisible(bool visible);
182 
186  bool isVisible();
187 
193  void setStackPosition(int32_t stackposition);
194 
198  int32_t getStackPosition();
199 
200  private:
203  InstanceVisual();
205  bool m_visible;
208  };
209 
212  class ActionVisual: public Visual2DGfx {
213  public:
216  static ActionVisual* create(Action* action);
217 
220  virtual ~ActionVisual();
221 
224  void addAnimation(uint32_t angle, AnimationPtr animationptr);
225 
229  AnimationPtr getAnimationByAngle(int32_t angle);
230 
233  void addAnimationOverlay(uint32_t angle, int32_t order, AnimationPtr animationptr);
234 
238  std::map<int32_t, AnimationPtr> getAnimationOverlay(int32_t angle);
239 
242  void removeAnimationOverlay(uint32_t angle, int32_t order);
243 
247  void addColorOverlay(uint32_t angle, const OverlayColors& colors);
248 
252  OverlayColors* getColorOverlay(int32_t angle);
253 
256  void removeColorOverlay(int32_t angle);
257 
261  void addColorOverlay(uint32_t angle, int32_t order, const OverlayColors& colors);
262 
266  OverlayColors* getColorOverlay(int32_t angle, int32_t order);
267 
270  void removeColorOverlay(int32_t angle, int32_t order);
271 
274  void getActionImageAngles(std::vector<int32_t>& angles);
275 
280  void convertToOverlays(bool color);
281 
284  bool isAnimationOverlay() { return !m_animationOverlayMap.empty(); }
285 
288  bool isColorOverlay() { return !m_colorOverlayMap.empty() || !m_colorAnimationOverlayMap.empty(); }
289 
290  private:
293  ActionVisual();
294 
295  // animations associated with this action
296  typedef std::map<uint32_t, AnimationPtr> AngleAnimationMap;
297  AngleAnimationMap m_animation_map;
298 
299  typedef std::map<uint32_t, std::map<int32_t, AnimationPtr> > AngleAnimationOverlayMap;
300  AngleAnimationOverlayMap m_animationOverlayMap;
301 
302  typedef std::map<uint32_t, OverlayColors> AngleColorOverlayMap;
303  AngleColorOverlayMap m_colorOverlayMap;
304 
305  typedef std::map<uint32_t, std::map<int32_t, OverlayColors> > AngleColorAnimationOverlayMap;
306  AngleColorAnimationOverlayMap m_colorAnimationOverlayMap;
307  //need this map to use the getIndexByAngle() function in angles.h
309  };
310 
311 }
312 #endif
void setColorOverlayAnimation(AnimationPtr animation)
Definition: visual.cpp:68
ImagePtr m_image
Definition: visual.h:68
AngleAnimationMap m_animation_map
Definition: visual.h:297
AngleColorAnimationOverlayMap m_colorAnimationOverlayMap
Definition: visual.h:306
std::map< Color, Color > m_colorMap
Definition: visual.h:67
Object class.
Definition: object.h:51
Instance visual contains data that is needed to visualize the instance on screen. ...
Definition: visual.h:158
Action visual contains data that is needed to visualize different actions on screen.
Definition: visual.h:212
std::map< uint32_t, std::map< int32_t, AnimationPtr > > AngleAnimationOverlayMap
Definition: visual.h:299
type_angle2id m_angle2img
Definition: visual.h:148
type_angle2id m_map
Definition: visual.h:152
AngleColorOverlayMap m_colorOverlayMap
Definition: visual.h:151
int32_t m_stackposition
Definition: visual.h:206
unsigned char uint8_t
Definition: core.h:38
AngleColorOverlayMap m_colorOverlayMap
Definition: visual.h:303
void changeColor(const Color &source, const Color &target)
Definition: visual.cpp:76
AngleAnimationOverlayMap m_animationOverlayMap
Definition: visual.h:300
void setColorOverlayImage(ImagePtr image)
Definition: visual.cpp:60
std::map< uint32_t, OverlayColors > AngleColorOverlayMap
Definition: visual.h:302
std::map< uint32_t, std::map< int32_t, OverlayColors > > AngleColorAnimationOverlayMap
Definition: visual.h:305
type_angle2id m_map
Definition: visual.h:308
const std::map< Color, Color > & getColors()
Definition: visual.cpp:84
bool isColorOverlay()
Indicates if there exists a color overlay.
Definition: visual.h:141
Instance * m_instance
Definition: visual.h:207
ImagePtr getColorOverlayImage()
Definition: visual.cpp:64
uint8_t m_transparency
Definition: visual.h:204
std::map< uint32_t, OverlayColors > AngleColorOverlayMap
Definition: visual.h:150
Object visual contains data that is needed for visualizing objects.
Definition: visual.h:91
AnimationPtr m_animation
Definition: visual.h:69
std::map< uint32_t, AnimationPtr > AngleAnimationMap
Definition: visual.h:296
std::map< uint32_t, int32_t > type_angle2id
Definition: angles.h:37
AnimationPtr getColorOverlayAnimation()
Definition: visual.cpp:72
OverlayColors()
Constructors.
Definition: visual.cpp:46
unsigned int uint32_t
Definition: core.h:40
void resetColors()
Definition: visual.cpp:88
~OverlayColors()
Destructor.
Definition: visual.cpp:57
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:94
bool isAnimationOverlay()
Returns true if it exists a animation overlay, otherwise false.
Definition: visual.h:284
bool isColorOverlay()
Returns true if it exists a color overlay, otherwise false.
Definition: visual.h:288
Base class for all 2 dimensional visual classes Visual classes are extensions to visualize the stuff ...
Definition: visual.h:77