My Project
GUIResource.h
1 #pragma once
2 
3 #include "TextureEntity.h"
4 #include "MiscEntity.h"
5 #include "GUIScript.h"
6 
7 namespace ParaEngine
8 {
13  public:
14  RECT rcTexture; // Bounding rect of this element on the composite texture
15  LinearColor TextureColor;
16  string ToScript(int index,int option=0);
17  string name;
18  void SetElement( TextureEntity* pTexture, const RECT* prcTexture=NULL, Color defaultTextureColor=0xffffffff );
19  TextureEntity* GetTexture() {return pTexture.get();}
20 
23  void Cleanup();
24 
26  void GetRect(RECT* pOut);
27  protected:
28 
29  // constructible and assignable shared pointer
30  asset_ptr<TextureEntity> pTexture;
31  };
32 
36  struct GUIFontElement {
37  public:
38  DWORD dwTextFormat; // The format argument to DrawText
39  LinearColor FontColor;
40  string ToScript(int index,int option=0);
41  string name;
43  FontColor=0xff000000;
44  dwTextFormat=0;
45  name="";
46  }
47  ~GUIFontElement();
48  void Cleanup();
49 
78  void SetElement( SpriteFontEntity* pFont, Color defaultFontColor=0xff000000, DWORD dwTextFormat=0 );
79 
80  SpriteFontEntity* GetFont() {return pFont.get();}
81 
82  protected:
83  // constructible and assignable shared pointer
84  asset_ptr<SpriteFontEntity> pFont;
85  };
86 
87 
93  private:
94  vector<GUIFontElement> m_fonts;
95  vector<GUITextureElement> m_textures;
96  public:
97  map<string,DWORD> fontmap;
98  map<string,DWORD> texturemap;
99  size_t TextureSize(){return m_textures.size();}
100  size_t FontSize(){return m_fonts.size();}
105  GUIFontElement* AddElement(const GUIFontElement *pElement,const char* name=NULL);
106  GUITextureElement * AddElement(const GUITextureElement *pElement,const char* name=NULL);
107 
108 
110  GUITextureElement * SetElement(const GUITextureElement *pElement, int nIndex);
111 
113  GUIFontElement * SetElement(const GUIFontElement *pElement, int nIndex);
114 
115  GUIFontElement* GetFontElement(const string &name);
116  GUIFontElement* GetFontElement(int index);;
117  GUITextureElement* GetTextureElement(const string &name);
118  GUITextureElement* GetTextureElement(int index);
119  void init();
120  void Clone(GUIStateElement* output);
121  };
122 
131  struct GUILAYER {
132  public:
133  //-------------------------------------
134  // 9 Element assignment:
135  // 0 - text area
136  // 1 - top left border
137  // 2 - top border
138  // 3 - top right border
139  // 4 - left border
140  // 5 - right border
141  // 6 - lower left border
142  // 7 - lower border
143  // 8 - lower right border
144  enum GUILAYER_TYPE{
145  ONE_ELEMENT,NINE_ELEMENT };
146  GUIStateElement eDisabled;
147  GUIStateElement eNormal;
148  GUIStateElement ePressed;
149  GUIStateElement eHighlight;
150  GUIStateElement* eCurrent;
151  vector<RECT> DrawingRects;// actual drawing rectangles of all elements, set using UpdateRects;
152  bool bIsEnabled;//if the layer is enabled.
153  int m_objType;
154 
155  void init(){
156  eNormal.init();ePressed.init();eHighlight.init();
157  eCurrent=&eNormal;
158  }
159  GUITextureElement * AddElement(const GUITextureElement* pElement,const char* name=NULL);
160  void AddElement(const GUIFontElement* pElement,const char* name=NULL);
161 
162  void SetElement( GUITextureElement* pElement,int index=0);
163 
164  void SetElement( GUIFontElement* pElement,int index=0);
165 
166  void Clone(GUILAYER* output);
167  string ToScript(int option=0);
168  };
169 
170  enum GUIResourceState
171  {
172  GUIResourceState_Normal,
173  GUIResourceState_Pressed,
174  GUIResourceState_Highlight,
175  GUIResourceState_Disabled,
176  };
185  class CGUIResource:public IObject
186  {
187  public:
188  enum GUI_RESOURCE_TYPE{
189  NONE=0, BUTTON, CONTAINER, TEXT, EDITBOX, IMEEDITBOX, SCROLLBAR
190  };
191  enum GUI_RESOURCE_LAYER_ENUM{
192  LAYER_ARTWORK=0,LAYER_OVERLAY, LAYER_BACKGROUND,
193  };
194 
195  CGUIResource();
196  ~CGUIResource();
197 
198  //this is the to do list of the scripts in this resource object.
199  //CGUIScript m_objScripts;
200 
213  void SetActiveLayer(const char *layer);
214 
220  void SetActiveLayer(GUI_RESOURCE_LAYER_ENUM nLayerID = LAYER_ARTWORK);
221 
223  GUI_RESOURCE_LAYER_ENUM GetActiveLayer();
224 
229  bool HasLayer(const char *layer);
230 
235  bool HasLayer(GUI_RESOURCE_LAYER_ENUM nLayerID = LAYER_ARTWORK);
236 
244  GUI_RESOURCE_LAYER_ENUM GetLayerIDByName(const char* layer=NULL);
245 
247  void SetLayerType(int etype);
248 
253  void SetFont(const char *fontname,int index=0);
254  void SetFontColor(DWORD color, int index=0);
255  void SetFontFormat(DWORD dwFormat, int index=0);
256  void SetFontTransparency(DWORD transparency,int index=0);
257 
258  void SetTexture(const char *fontname,int index=0);
259  void SetTextureColor(DWORD color, int index=0);
260  void SetTextureTransparency(DWORD transparency,int index=0);
261 
263  //updates all rectangles to screen coordinate with reference to the new control position
264  //@param rcWindow: The control's rectangle.
265  //*/
266  //void UpdateRects(RECT rcWindow);
267 
268  virtual void Clone(IObject *pobj)const;
269  virtual IObject *Clone()const;
270  virtual int Release();
271  virtual bool Equals(const IObject *obj)const;
272  void SetDrawingRects(RECT *rcDest,int index=0);
273 
274  RECT GetDrawingRects(int index=0)const;
275 
276  GUIFontElement* GetFontElement(int index=0);
277  GUITextureElement* GetTextureElement(int index=0);
278  GUIFontElement* GetFontElement(const char *fontname);
279  GUITextureElement* GetTextureElement(const char* texturename);
280  void SetElement( GUITextureElement* pElement,int index=0);
281  void SetElement( GUIFontElement* pElement,int index=0);
282  void CloneState(const char * statename);
283  int GetLayerType();
284 
285  void AddElement(const GUIFontElement* pElement,const char* name=NULL);
286  GUITextureElement * AddElement(const GUITextureElement* pElement,const char* name=NULL);
299  void SetCurrentState(const char* statename=NULL);
300  void SetCurrentState(GUIResourceState state);
301  GUIResourceState GetCurrentState() {return m_CurrentState;};
302  size_t TextureSize(){return m_pActiveLayer->eCurrent->TextureSize();}
303  size_t FontSize(){return m_pActiveLayer->eCurrent->FontSize();}
304 
305  void Clear();
306  string ToScript(int option=0);
307  //the resource type
308  int m_objType;
309  protected:
310  //we design a three layers, it fits for most cases
311  GUILAYER* m_objBackground;
312  GUILAYER* m_objArtwork;
313  GUILAYER* m_objOverlay;
314  GUILAYER* m_pActiveLayer;
315 
316  GUIResourceState m_CurrentState;
317  };
318 }
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
void GetRect(RECT *pOut)
get bounding rect of this element on the composite texture
Definition: GUIResource.cpp:49
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: ManagedDef.h:18
A GUI layer contains four drawable GUIStateElement, which are "normal", "highlight", "pressed", and "disabled".
Definition: GUIResource.h:131
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
a texture from a rectangular region of bitmap, and one additional texture color
Definition: GUIResource.h:12
Each GUI control is associated with a CGUIResource object for rendering.
Definition: GUIResource.h:185
a font name, format and font color
Definition: GUIResource.h:36
A drawable element containing several textures and fonts, which can be retrieved by name or index...
Definition: GUIResource.h:92
A linear, 32-bit/component floating point RGBA color.
Definition: ParaColor.h:12
Definition: ParaColor.h:275
Definition: SpriteFontEntity.h:26