Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CGUISprite.h
Go to the documentation of this file.
1 /* Copyright (C) 2011 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 //--------------------------------------------------------
41 // Includes / Compiler directives
42 //--------------------------------------------------------
43 #include "GUIbase.h"
44 
45 #include "ps/Overlay.h"
47 
48 //--------------------------------------------------------
49 // Macros
50 //--------------------------------------------------------
51 
52 //--------------------------------------------------------
53 // Types
54 //--------------------------------------------------------
55 
56 //--------------------------------------------------------
57 // Error declarations
58 //--------------------------------------------------------
59 
60 //--------------------------------------------------------
61 // Declarations
62 //--------------------------------------------------------
63 
64 
66 {
70 };
71 
72 
73 /**
74  * A CGUISprite is actually a collage of several <b>real</b>
75  * sprites, this struct represents is such real sprite.
76  */
77 struct SGUIImage
78 {
80  m_FixedHAspectRatio(0.f), m_RoundCoordinates(true), m_WrapMode(GL_REPEAT),
81  m_Effects(NULL), m_Border(false), m_DeltaZ(0.f)
82  {
83  }
84 
85  // Filename of the texture
87 
88  // Image placement (relative to object)
90 
91  // Texture placement (relative to image placement)
93 
94  // Because OpenGL wants textures in squares with a power of 2 (64x64, 256x256)
95  // it's sometimes tedious to adjust this. So this value simulates which area
96  // is the real texture
98 
99  // For textures that contain a collection of icons (e.g. unit portraits), this
100  // will be set to the size of one icon. An object's cell-id will determine
101  // which part of the texture is used.
102  // Equal to CSize(0,0) for non-celled textures.
104 
105  /**
106  * If non-zero, then the image's width will be adjusted when rendering so that
107  * the width:height ratio equals this value.
108  */
110 
111  /**
112  * If true, the image's coordinates will be rounded to integer pixels when
113  * rendering, to avoid blurry filtering.
114  */
116 
117  /**
118  * Texture wrapping mode (GL_REPEAT, GL_CLAMP_TO_EDGE, etc)
119  */
120  GLint m_WrapMode;
121 
122  // Visual effects (e.g. colour modulation)
124 
125  // Color
128 
129  // 0 or 1 pixel border is the only option
130  bool m_Border;
131 
132  /**
133  * Z value modification of the image.
134  * Inputted in XML as x-level, although it just an easier and safer
135  * way of declaring delta-z.
136  */
137  float m_DeltaZ;
138 };
139 
140 
141 /**
142  * The GUI sprite, is actually several real sprites (images)
143  * like a collage. View the section <sprites> in the GUI
144  * TDD for more information.
145  *
146  * Drawing routine is located in CGUI
147  *
148  * @see CGUI#DrawSprite
149  */
151 {
152 public:
154  virtual ~CGUISprite() {}
155 
156  /**
157  * Adds an image to the sprite collage.
158  *
159  * @param image Adds this image to the sprite collage.
160  */
161  void AddImage(const SGUIImage &image) { m_Images.push_back(image); }
162 
163  /// List of images
164  std::vector<SGUIImage> m_Images;
165 };
166 
167 #include "GUIRenderer.h"
168 
169 // An instance of a sprite, usually stored in IGUIObjects - basically a string
170 // giving the sprite's name, but with some extra data to cache rendering
171 // calculations between draw calls.
173 {
174 public:
176  CGUISpriteInstance(const CStr& SpriteName);
177  CGUISpriteInstance(const CGUISpriteInstance &Sprite);
178  CGUISpriteInstance &operator=(const CStr& SpriteName);
179  void Draw(CRect Size, int CellID, std::map<CStr, CGUISprite> &Sprites, float Z) const;
180  void Invalidate();
181  bool IsEmpty() const;
182  const CStr& GetName() { return m_SpriteName; }
183 
184 private:
186 
187  // Stored drawing calls, for more efficient rendering
189  // Relevant details of previously rendered sprite; the cache is invalidated
190  // whenever any of these values changes.
192  mutable int m_CachedCellID;
193 };
194 
195 #endif
CColor m_AddColor
Definition: CGUISprite.h:68
Made to represent a screen size, should in philosophy be made of unsigned ints, but for the sake of c...
Definition: Overlay.h:205
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:109
Definition: Overlay.h:34
bool m_Border
Definition: CGUISprite.h:130
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:115
float m_DeltaZ
Z value modification of the image.
Definition: CGUISprite.h:137
Definition: path.h:75
std::vector< SGUIImage > m_Images
List of images.
Definition: CGUISprite.h:164
CColor m_BackColor
Definition: CGUISprite.h:126
CClientArea m_Size
Definition: CGUISprite.h:89
void AddImage(const SGUIImage &image)
Adds an image to the sprite collage.
Definition: CGUISprite.h:161
SGUIImageEffects * m_Effects
Definition: CGUISprite.h:123
CRect m_TexturePlacementInFile
Definition: CGUISprite.h:97
VfsPath m_TextureName
Definition: CGUISprite.h:86
A CGUISprite is actually a collage of several real sprites, this struct represents is such real sprit...
Definition: CGUISprite.h:77
The GUI sprite, is actually several real sprites (images) like a collage.
Definition: CGUISprite.h:150
bool IsEmpty() const
Definition: CGUISprite.cpp:38
virtual ~CGUISprite()
Definition: CGUISprite.h:154
CColor m_BorderColor
Definition: CGUISprite.h:127
Definition: Decompose.h:22
CGUISpriteInstance & operator=(const CStr &SpriteName)
Definition: CGUISprite.cpp:62
const CStr & GetName()
Definition: CGUISprite.h:182
void Draw(CRect Size, int CellID, std::map< CStr, CGUISprite > &Sprites, float Z) const
Definition: CGUISprite.cpp:21
CSize m_CellSize
Definition: CGUISprite.h:103
CClientArea m_TextureSize
Definition: CGUISprite.h:92
GLint m_WrapMode
Texture wrapping mode (GL_REPEAT, GL_CLAMP_TO_EDGE, etc)
Definition: CGUISprite.h:120
Rectangle class used for screen rectangles.
Definition: Overlay.h:71
GUIRenderer::DrawCalls m_DrawCallCache
Definition: CGUISprite.h:188
Client Area is a rectangle relative to a parent rectangle.
Definition: GUIbase.h:179