Pyrogenesis  trunk
CGUISprite.h
Go to the documentation of this file.
1 /* Copyright (C) 2015 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19 A GUI Sprite
20 
21 --Overview--
22 
23  A GUI Sprite, which is actually a collage of several
24  sprites.
25 
26 --Usage--
27 
28  Used internally and declared in XML files, read documentations
29  on how.
30 
31 --More info--
32 
33  Check GUI.h
34 
35 */
36 
37 #ifndef INCLUDED_CGUISPRITE
38 #define INCLUDED_CGUISPRITE
39 
40 #include "GUIbase.h"
41 
43 
45 {
50 };
51 
52 /**
53  * A CGUISprite is actually a collage of several <b>real</b>
54  * sprites, this struct represents is such real sprite.
55  */
56 struct SGUIImage
57 {
59 public:
61  m_FixedHAspectRatio(0.f), m_RoundCoordinates(true), m_WrapMode(GL_REPEAT),
62  m_Effects(NULL), m_Border(false), m_DeltaZ(0.f)
63  {
64  }
65 
67  {
68  delete m_Effects;
69  }
70 
71  // Filename of the texture
73 
74  // Image placement (relative to object)
76 
77  // Texture placement (relative to image placement)
79 
80  // Because OpenGL wants textures in squares with a power of 2 (64x64, 256x256)
81  // it's sometimes tedious to adjust this. So this value simulates which area
82  // is the real texture
84 
85  // For textures that contain a collection of icons (e.g. unit portraits), this
86  // will be set to the size of one icon. An object's cell-id will determine
87  // which part of the texture is used.
88  // Equal to CSize(0,0) for non-celled textures.
90 
91  /**
92  * If non-zero, then the image's width will be adjusted when rendering so that
93  * the width:height ratio equals this value.
94  */
96 
97  /**
98  * If true, the image's coordinates will be rounded to integer pixels when
99  * rendering, to avoid blurry filtering.
100  */
102 
103  /**
104  * Texture wrapping mode (GL_REPEAT, GL_CLAMP_TO_EDGE, etc)
105  */
106  GLint m_WrapMode;
107 
108  // Visual effects (e.g. color modulation)
110 
111  // Color
114 
115  // 0 or 1 pixel border is the only option
116  bool m_Border;
117 
118  /**
119  * Z value modification of the image.
120  * Inputted in XML as x-level, although it just an easier and safer
121  * way of declaring delta-z.
122  */
123  float m_DeltaZ;
124 };
125 
126 /**
127  * The GUI sprite, is actually several real sprites (images)
128  * like a collage. View the section <sprites> in the GUI
129  * TDD for more information.
130  *
131  * Drawing routine is located in CGUI
132  *
133  * @see CGUI#DrawSprite
134  */
136 {
138 public:
140  virtual ~CGUISprite();
141 
142  /**
143  * Adds an image to the sprite collage.
144  *
145  * @param image Adds this image to the sprite collage.
146  */
147  void AddImage(SGUIImage*);
148 
149  /// List of images
150  std::vector<SGUIImage*> m_Images;
151 };
152 
153 #include "GUIRenderer.h"
154 
155 // An instance of a sprite, usually stored in IGUIObjects - basically a string
156 // giving the sprite's name, but with some extra data to cache rendering
157 // calculations between draw calls.
159 {
160 public:
162  CGUISpriteInstance(const CStr& SpriteName);
163  CGUISpriteInstance(const CGUISpriteInstance& Sprite);
164  CGUISpriteInstance& operator=(const CStr& SpriteName);
165  void Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*>& Sprites, float Z) const;
166  void Invalidate();
167  bool IsEmpty() const;
168  const CStr& GetName() { return m_SpriteName; }
169 
170 private:
172 
173  // Stored drawing calls, for more efficient rendering
175  // Relevant details of previously rendered sprite; the cache is invalidated
176  // whenever any of these values changes.
178  mutable int m_CachedCellID;
179 };
180 
181 #endif // INCLUDED_CGUISPRITE
#define NONCOPYABLE(className)
Indicates that a class is noncopyable (usually due to const or reference members, or because the clas...
Definition: code_annotation.h:217
CRect m_CachedSize
Definition: CGUISprite.h:177
CColor m_AddColor
Definition: CGUISprite.h:47
Made to represent a screen size, should in philosophy be made of unsigned ints, but for the sake of c...
Definition: Shapes.h:207
Definition: CGUISprite.h:44
float m_FixedHAspectRatio
If non-zero, then the image&#39;s width will be adjusted when rendering so that the width:height ratio eq...
Definition: CGUISprite.h:95
Definition: Shapes.h:36
bool m_Border
Definition: CGUISprite.h:116
int m_CachedCellID
Definition: CGUISprite.h:178
bool m_RoundCoordinates
If true, the image&#39;s coordinates will be rounded to integer pixels when rendering, to avoid blurry filtering.
Definition: CGUISprite.h:101
SGUIImage()
Definition: CGUISprite.h:60
float m_DeltaZ
Z value modification of the image.
Definition: CGUISprite.h:123
Definition: path.h:77
Definition: GUIRenderer.h:67
CColor m_BackColor
Definition: CGUISprite.h:112
CClientArea m_Size
Definition: CGUISprite.h:75
SGUIImageEffects * m_Effects
Definition: CGUISprite.h:109
CRect m_TexturePlacementInFile
Definition: CGUISprite.h:83
SGUIImageEffects()
Definition: CGUISprite.h:46
VfsPath m_TextureName
Definition: CGUISprite.h:72
A CGUISprite is actually a collage of several real sprites, this struct represents is such real sprit...
Definition: CGUISprite.h:56
The GUI sprite, is actually several real sprites (images) like a collage.
Definition: CGUISprite.h:135
CStr m_SpriteName
Definition: CGUISprite.h:171
CColor m_BorderColor
Definition: CGUISprite.h:113
Definition: Decompose.h:22
std::vector< SGUIImage * > m_Images
List of images.
Definition: CGUISprite.h:150
void Draw(DrawCalls &Calls, float Z)
Definition: GUIRenderer.cpp:345
CGUISprite()
Definition: CGUISprite.h:139
Definition: CGUISprite.h:158
~SGUIImage()
Definition: CGUISprite.h:66
const CStr & GetName()
Definition: CGUISprite.h:168
CSize m_CellSize
Definition: CGUISprite.h:89
CClientArea m_TextureSize
Definition: CGUISprite.h:78
GLint m_WrapMode
Texture wrapping mode (GL_REPEAT, GL_CLAMP_TO_EDGE, etc)
Definition: CGUISprite.h:106
bool m_Greyscale
Definition: CGUISprite.h:49
CColor m_SolidColor
Definition: CGUISprite.h:48
Rectangle class used for screen rectangles.
Definition: Shapes.h:73
GUIRenderer::DrawCalls m_DrawCallCache
Definition: CGUISprite.h:174
Client Area is a rectangle relative to a parent rectangle.
Definition: GUIbase.h:164