My Project
GUIBase.h
1 #pragma once
2 
3 #include <vector>
4 #include <string>
5 #include <deque>
6 #include "math/ParaPoint.h"
7 #include "util/ParaMemPool.h"
8 #include "GUIEvent.h"
9 #include "IObjectDrag.h"
10 #include "Type.h"
11 #include "IAttributeFields.h"
12 #include "GUIPosition.h"
13 #include "GUIState.h"
14 #include "PaintEngine/PaintDevice.h"
15 #include <stdint.h>
16 
17 namespace ParaEngine
18 {
19  using namespace std;
20 
21  class CBaseObject;
22  class CEventBinding;
23  class SimpleScript;
24  class CRenderTarget;
25 
26  typedef FixedSizedAllocator<CGUIBase*> DL_Allocator_CGUIBase_Ptr;
27  typedef std::deque<CGUIBase*, DL_Allocator_CGUIBase_Ptr> GUIBase_List_Type;
28 
29  class CGUIBase;
30  class CSceneObject;
31  class CGUISensor;
32  class CGUIResource;
33  class CGUIContainer;
34  struct GUITextureElement;
35  struct GUIFontElement;
36  struct TouchEvent;
37 
38  struct AssetEntity;
39 
54  class CGUIBase : public IAttributeFields, public IObjectDrag, public CPaintDevice
55  {
56  public:
58 
59  virtual const IType* GetType()const { return m_type; };
61  // implementation of IAttributeFields
62 
64  virtual int GetAttributeClassID(){ return ATTRIBUTE_CLASSID_CGUIBase; }
66  virtual const char* GetAttributeClassName(){ static const char name[] = "CGUIBase"; return name; }
68  virtual const char* GetAttributeClassDescription(){ static const char desc[] = ""; return desc; }
70  virtual int InstallFields(CAttributeClass* pClass, bool bOverride);
71 
75  virtual void* QueryObject(int nObjectType);
77  virtual IAttributeFields* GetChildAttributeObject(const std::string& sName);
79  virtual int GetChildAttributeObjectCount(int nColumnIndex = 0);
81  virtual int GetChildAttributeColumnCount();
82  virtual IAttributeFields* GetChildAttributeObject(int nRowIndex, int nColumnIndex = 0);
83 
84  ATTRIBUTE_METHOD1(CGUIBase, GetName_s, const char**) { *p1 = cls->GetName().c_str(); return S_OK; }
85  ATTRIBUTE_METHOD1(CGUIBase, SetName_s, const char*) { cls->SetName(p1); return S_OK; }
86 
87  ATTRIBUTE_METHOD1(CGUIBase, GetTextScale_s, float*) { *p1 = cls->GetTextScale(); return S_OK; }
88  ATTRIBUTE_METHOD1(CGUIBase, SetTextScale_s, float) { cls->SetTextScale(p1); return S_OK; }
89 
90  ATTRIBUTE_METHOD1(CGUIBase, GetUseTextShadow_s, bool*) { *p1 = cls->GetUseTextShadow(); return S_OK; }
91  ATTRIBUTE_METHOD1(CGUIBase, SetUseTextShadow_s, bool) { cls->SetUseTextShadow(p1); return S_OK; }
92 
93  ATTRIBUTE_METHOD1(CGUIBase, GetTextShadowQuality_s, int*) { *p1 = cls->GetTextShadowQuality(); return S_OK; }
94  ATTRIBUTE_METHOD1(CGUIBase, SetTextShadowQuality_s, int) { cls->SetTextShadowQuality(p1); return S_OK; }
95 
96  ATTRIBUTE_METHOD1(CGUIBase, GetTextShadowColor_s, int*) { *p1 = cls->GetTextShadowColor(); return S_OK; }
97  ATTRIBUTE_METHOD1(CGUIBase, SetTextShadowColor_s, int) { cls->SetTextShadowColor(p1); return S_OK; }
98 
99  ATTRIBUTE_METHOD1(CGUIBase, GetTextOffsetX_s, int*) { *p1 = cls->GetTextOffsetX(); return S_OK; }
100  ATTRIBUTE_METHOD1(CGUIBase, SetTextOffsetX_s, int) { cls->SetTextOffsetX(p1); return S_OK; }
101 
102  ATTRIBUTE_METHOD1(CGUIBase, GetTextOffsetY_s, int*) { *p1 = cls->GetTextOffsetY(); return S_OK; }
103  ATTRIBUTE_METHOD1(CGUIBase, SetTextOffsetY_s, int) { cls->SetTextOffsetY(p1); return S_OK; }
104 
105  ATTRIBUTE_METHOD1(CGUIBase, GetEnabled_s, bool*) { *p1 = cls->GetEnabled(); return S_OK; }
106  ATTRIBUTE_METHOD1(CGUIBase, SetEnabled_s, bool) { cls->SetEnabled(p1); return S_OK; }
107 
108  ATTRIBUTE_METHOD1(CGUIBase, GetAlwaysMouseOver_s, bool*) { *p1 = cls->GetAlwaysMouseOver(); return S_OK; }
109  ATTRIBUTE_METHOD1(CGUIBase, SetAlwaysMouseOver_s, bool) { cls->SetAlwaysMouseOver(p1); return S_OK; }
110 
111  ATTRIBUTE_METHOD1(CGUIBase, GetDepth_s, float*) { *p1 = cls->GetDepth(); return S_OK; }
112  ATTRIBUTE_METHOD1(CGUIBase, SetDepth_s, float) { cls->SetDepth(p1); return S_OK; }
113 
114  ATTRIBUTE_METHOD1(CGUIBase, GetLifeTime_s, int*) { *p1 = cls->GetLifeTime(); return S_OK; }
115  ATTRIBUTE_METHOD1(CGUIBase, SetLifeTime_s, int) { cls->SetLifeTime(p1); return S_OK; }
116 
117  ATTRIBUTE_METHOD1(CGUIBase, GetX_s, int*) { *p1 = cls->GetX(); return S_OK; }
118  ATTRIBUTE_METHOD1(CGUIBase, SetX_s, int) { cls->SetX(p1); return S_OK; }
119 
120  ATTRIBUTE_METHOD1(CGUIBase, GetY_s, int*) { *p1 = cls->GetY(); return S_OK; }
121  ATTRIBUTE_METHOD1(CGUIBase, SetY_s, int) { cls->SetY(p1); return S_OK; }
122 
123  ATTRIBUTE_METHOD1(CGUIBase, GetWidth_s, int*) { *p1 = cls->GetWidth(); return S_OK; }
124  ATTRIBUTE_METHOD1(CGUIBase, SetWidth_s, int) { cls->SetWidth(p1); return S_OK; }
125 
126  ATTRIBUTE_METHOD1(CGUIBase, GetHeight_s, int*) { *p1 = cls->GetHeight(); return S_OK; }
127  ATTRIBUTE_METHOD1(CGUIBase, SetHeight_s, int) { cls->SetHeight(p1); return S_OK; }
128 
129  ATTRIBUTE_METHOD1(CGUIBase, GetRotation_s, float*) { *p1 = cls->GetRotation(); return S_OK; }
130  ATTRIBUTE_METHOD1(CGUIBase, SetRotation_s, float) { cls->SetRotation(p1); return S_OK; }
131 
132  ATTRIBUTE_METHOD1(CGUIBase, GetScaling_s, Vector2*) { cls->GetScaling(p1); return S_OK; }
133  ATTRIBUTE_METHOD1(CGUIBase, SetScaling_s, Vector2) { cls->SetScaling(p1); return S_OK; }
134 
135  ATTRIBUTE_METHOD1(CGUIBase, GetTranslation_s, Vector2*) { cls->GetTranslation(p1); return S_OK; }
136  ATTRIBUTE_METHOD1(CGUIBase, SetTranslation_s, Vector2) { cls->SetTranslation(p1); return S_OK; }
137 
138  ATTRIBUTE_METHOD1(CGUIBase, GetRotOriginOffset_s, Vector2*) { cls->GetRotOriginOffset(p1); return S_OK; }
139  ATTRIBUTE_METHOD1(CGUIBase, SetRotOriginOffset_s, Vector2) { cls->SetRotOriginOffset(p1); return S_OK; }
140 
141  ATTRIBUTE_METHOD1(CGUIBase, GetColorMask_s, DWORD*) { *p1 = cls->GetColorMask(); return S_OK; }
142  ATTRIBUTE_METHOD1(CGUIBase, SetColorMask_s, DWORD) { cls->SetColorMask(p1); return S_OK; }
143 
144  ATTRIBUTE_METHOD1(CGUIBase, GetText_s, const char**) {
145  static std::string sStr;
146  sStr.clear();
147  cls->GetTextA(sStr);
148  *p1 = sStr.c_str(); return S_OK;
149  }
150  ATTRIBUTE_METHOD1(CGUIBase, SetText_s, const char*) { cls->SetTextA(p1); return S_OK; }
151 
152  ATTRIBUTE_METHOD1(CGUIBase, GetSpacing_s, int*) { *p1 = cls->GetSpacing(); return S_OK; }
153  ATTRIBUTE_METHOD1(CGUIBase, SetSpacing_s, int) { cls->SetSpacing(p1); return S_OK; }
154 
155  ATTRIBUTE_METHOD1(CGUIBase, GetPadding_s, int*) { *p1 = cls->GetPadding(); return S_OK; }
156  ATTRIBUTE_METHOD1(CGUIBase, SetPadding_s, int) { cls->SetPadding(p1); return S_OK; }
157 
158  ATTRIBUTE_METHOD1(CGUIBase, GetZOrder_s, int*) { *p1 = cls->GetZOrder(); return S_OK; }
159  ATTRIBUTE_METHOD1(CGUIBase, SetZOrder_s, int) { cls->SetZOrder(p1); return S_OK; }
160 
161  ATTRIBUTE_METHOD1(CGUIBase, GetCursor_s, const char**) { *p1 = cls->GetCursor().c_str(); return S_OK; }
162  ATTRIBUTE_METHOD1(CGUIBase, SetCursor_s, const char*) { cls->SetCursor(p1); return S_OK; }
163 
164  ATTRIBUTE_METHOD1(CGUIBase, GetIndex_s, int*) { *p1 = cls->GetIndex(); return S_OK; }
165 
166  ATTRIBUTE_METHOD1(CGUIBase, GetID_s, int*) { *p1 = cls->GetID(); return S_OK; }
167  ATTRIBUTE_METHOD1(CGUIBase, SetID_s, int) { cls->SetID(p1); return S_OK; }
168 
169  ATTRIBUTE_METHOD1(CGUIBase, GetVisible_s, bool*) { *p1 = cls->GetVisible(); return S_OK; }
170  ATTRIBUTE_METHOD1(CGUIBase, SetVisible_s, bool) { cls->SetVisible(p1); return S_OK; }
171 
172  ATTRIBUTE_METHOD1(CGUIBase, GetVisibleRecursive_s, bool*) { *p1 = cls->GetVisibleRecursive(); return S_OK; }
173 
174  ATTRIBUTE_METHOD1(CGUIBase, GetHighlightStyle_s, int*) { *p1 = cls->GetHighlightStyle(); return S_OK; }
175  ATTRIBUTE_METHOD1(CGUIBase, SetHighlightStyle_s, int) { cls->SetHighlightStyle(p1); return S_OK; }
176 
177  ATTRIBUTE_METHOD1(CGUIBase, GetAnimationStyle_s, int*) { *p1 = cls->GetAnimationStyle(); return S_OK; }
178  ATTRIBUTE_METHOD1(CGUIBase, SetAnimationStyle_s, int) { cls->SetAnimationStyle(p1); return S_OK; }
179 
180  ATTRIBUTE_METHOD1(CGUIBase, IsPressed_s, bool*) { *p1 = cls->IsPressed(); return S_OK; }
181 
182  ATTRIBUTE_METHOD1(CGUIBase, IsClickThrough_s, bool*) { *p1 = cls->IsClickThrough(); return S_OK; }
183  ATTRIBUTE_METHOD1(CGUIBase, SetClickThrough_s, bool) { cls->SetClickThrough(p1); return S_OK; }
184 
185  ATTRIBUTE_METHOD1(CGUIBase, CanHaveFocus_s, bool*) { *p1 = cls->CanHaveFocus(); return S_OK; }
186  ATTRIBUTE_METHOD1(CGUIBase, SetCanHaveFocus_s, bool) { cls->SetCanHaveFocus(p1); return S_OK; }
187 
188  ATTRIBUTE_METHOD1(CGUIBase, IsDirty_s, bool*) { *p1 = cls->IsDirty(); return S_OK; }
189  ATTRIBUTE_METHOD1(CGUIBase, SetDirty_s, bool) { cls->SetDirty(p1); return S_OK; }
190 
191  ATTRIBUTE_METHOD1(CGUIBase, IsOwnerDraw_s, bool*) { *p1 = cls->IsOwnerDraw(); return S_OK; }
192  ATTRIBUTE_METHOD1(CGUIBase, SetOwnerDraw_s, bool) { cls->SetOwnerDraw(p1); return S_OK; }
193 
194  ATTRIBUTE_METHOD1(CGUIBase, IsUVWrappingEnabled_s, bool*) { *p1 = cls->IsUVWrappingEnabled(); return S_OK; }
195  ATTRIBUTE_METHOD1(CGUIBase, EnableUVWrapping_s, bool) { cls->EnableUVWrapping(p1); return S_OK; }
196  ATTRIBUTE_METHOD1(CGUIBase, HasKeyFocus_s, bool*) { *p1 = cls->HasKeyFocus(); return S_OK; }
197 
198  ATTRIBUTE_METHOD1(CGUIBase, GetUsePointTextureFiltering_s, bool*) { *p1 = cls->GetUsePointTextureFiltering(); return S_OK; }
199  ATTRIBUTE_METHOD1(CGUIBase, SetUsePointTextureFiltering_s, bool) { cls->SetUsePointTextureFiltering(p1); return S_OK; }
200 
201  ATTRIBUTE_METHOD(CGUIBase, ApplyColorMask_s) { cls->ApplyColorMask(); return S_OK; }
202  ATTRIBUTE_METHOD(CGUIBase, ApplyAnim_s) { cls->ApplyAnim(); return S_OK; }
203 
204  ATTRIBUTE_METHOD1(CGUIBase, IsSelfPaintEnabled_s, bool*) { *p1 = cls->IsSelfPaintEnabled(); return S_OK; }
205  ATTRIBUTE_METHOD1(CGUIBase, EnableSelfPaint_s, bool) { cls->EnableSelfPaint(p1); return S_OK; }
206 
207  ATTRIBUTE_METHOD1(CGUIBase, IsAutoClearBackground_s, bool*) { *p1 = cls->IsAutoClearBackground(); return S_OK; }
208  ATTRIBUTE_METHOD1(CGUIBase, SetAutoClearBackground_s, bool) { cls->SetAutoClearBackground(p1); return S_OK; }
209 
210  ATTRIBUTE_METHOD1(CGUIBase, IsMouseCaptured_s, bool*) { *p1 = cls->IsMouseCaptured(); return S_OK; }
211  ATTRIBUTE_METHOD1(CGUIBase, SetMouseCaptured_s, bool) { (p1 ? cls->CaptureMouse() : cls->ReleaseMouseCapture()); return S_OK; }
212 
213  ATTRIBUTE_METHOD1(CGUIBase, IsInputMethodEnabled_s, bool*) { *p1 = cls->IsInputMethodEnabled(); return S_OK; }
214  ATTRIBUTE_METHOD1(CGUIBase, SetInputMethodEnabled_s, bool) { cls->SetInputMethodEnabled(p1); return S_OK; }
215 
216  ATTRIBUTE_METHOD1(CGUIBase, GetCompositionPoint_s, Vector2*) { auto pt = cls->GetCompositionPoint(); *p1 = Vector2((float)pt.x(), (float)pt.y()); return S_OK; }
217  ATTRIBUTE_METHOD1(CGUIBase, SetCompositionPoint_s, Vector2) { cls->SetCompositionPoint(QPoint((int)p1.x, (int)p1.y)); return S_OK; }
218 
219  ATTRIBUTE_METHOD1(CGUIBase, IsNonClientTestEnabled_s, bool*) { *p1 = cls->IsNonClientTestEnabled(); return S_OK; }
220  ATTRIBUTE_METHOD1(CGUIBase, EnableNonClientTest_s, bool) { cls->EnableNonClientTest(p1); return S_OK; }
221 
222  public:
223  virtual CPaintEngine * paintEngine() const;
224 
225  void DeleteThis();
226 
228  CGUIContainer* GetParent(){ return m_parent; }
230  CGUIContainer* GetPainterWindow();
232  inline bool IsPainterWindow(){
233  return IsSelfPaintEnabled();
234  }
235 
236  virtual int GetChildCount();
237 
240  virtual bool HasClickEvent();
241 
243  bool IsAncestorOf(CGUIBase * pChild);
244 
246  bool HasParent(CGUIContainer* pParent);
247 
249  void SetParent(CGUIContainer* parent){ m_parent = parent; }
250 
252  int GetIndex();
253 
255  bool GetEnabled(){ return m_bIsEnabled; }
256 
258  void SetEnabled(bool bEnabled){ m_bIsEnabled = bEnabled; }
259 
260  bool IsInputMethodEnabled() const;
261  void SetInputMethodEnabled(bool val);
262 
264  void SetNeedUpdate(bool bNeedUpdate = true) { m_bNeedUpdate = bNeedUpdate; }
268  bool IsNeedUpdate(bool bRecursive = false);
269 
273  void SetAlwaysMouseOver(bool bAlwaysMouseOver){ m_bAlwaysMouseOver = bAlwaysMouseOver; }
274 
278  bool GetAlwaysMouseOver(){ return m_bAlwaysMouseOver; }
279 
281  virtual GUIBase_List_Type* GetChildren(){ return NULL; };
282 
284  virtual bool IsPressed(){ return false; }
285 
286  //new
291  static void StaticInit();
292 
297  virtual void SetTextA(const char* szText){};
303  virtual void SetText(const char16_t* wszText){};
310  virtual int GetTextA(std::string& out);;
316  virtual const char16_t* GetText();
317 
321  virtual void Reset();
322  // -- Base object functions
324  // bool HasEvent(){return !m_objEvents.empty();}
328  bool HasEvent(int etype);
329 
333  void ClearAllEvent();
334 
339  void ClearEvent(int etype);
340 
344  void BeginDepthTest(GUIState* pState = NULL);
345  void EndDepthTest(GUIState* pState = NULL);
346 
353  virtual void GetAbsolutePosition(CGUIPosition* pOut, const CGUIPosition* pIn);
354 
359  virtual void SetDepth(float fDepth);
360 
363  virtual float GetDepth();
364 
365 
366  bool HasFocus() const;
367 
369  virtual bool HasKeyFocus();
370 
377  virtual bool MsgProc(MSG *event);
378 
382  virtual void SetLifeTime(int lifttime){ m_nLifeTimeCountDown = lifttime < 0 ? -1 : lifttime; }
383  virtual int GetLifeTime()const{ return m_nLifeTimeCountDown; }
384 
395  virtual bool ActivateScript(const string &code, int etype);
396 
408  virtual bool ActivateScript(const string &precode, const string &postcode, int etype);
409 
414  virtual void UpdateRects();
415 
418  void UpdateParentRect();
419 
426  virtual bool InvalidateRect(const RECT* lpRect);
427  RECT GetClippingRect(GUIState* pGUIState);
428 
430  virtual bool DoAutoSize();
431 
435  virtual void Begin(GUIState* pGUIState, float fElapsedTime);
439  virtual void End(GUIState* pGUIState, float fElapsedTime);
446  virtual HRESULT Render(GUIState* pGUIState, float fElapsedTime){ return S_OK; };
447 
449  virtual HRESULT DoRender(GUIState* pGUIState, float fElapsedTime);
450 
452  void Draw(GUIState* pGUIState = NULL, float fElapsedTime = 0.f);
453 
455  virtual void FillClippingRegion(GUIState* pGUIState);
456  virtual HRESULT DoSelfPaint(GUIState* pGUIState, float fElapsedTime);
460  virtual bool OnOwnerDraw(GUIState* pGUIState);
461 
462  //it may not be useful.
463  //virtual void Framemove( double dTimeDelta ){};
464 
466  //virtual AssetEntity* GetPrimaryAsset(){return NULL;};
467 
469  inline bool CanCaptureMouse() { return m_bCanCaptureMouse; };
470  void SetCanCaptureMouse(bool bCanCapture);
471 
472  //decide whether a control can have keyboard focus
473  virtual bool CanHaveFocus();
474  virtual void SetCanHaveFocus(bool bCanHaveFocus);
475 
476  //finds whether the given point is in the rectangle, the input rectangle should be in absolute position
477  virtual BOOL ContainsPoint(const RECT &pos, const POINT &pt)const;
478  virtual BOOL ContainsPoint(const POINT &pt)const;
485  virtual BOOL IsPointInControl(int x, int y);
486 
490  virtual void SetLocation(int x, int y);
491  virtual void SetSize(int width, int height);
492  virtual void SetWidth(int width);
493  virtual int GetWidth()const{ return m_position.GetWidth(); }
494  virtual void SetHeight(int height);
495  virtual int GetHeight()const{ return m_position.GetHeight(); }
496  virtual void SetPosition(int left, int top, int right, int bottom);
497  void SetX(int nX);
498  int GetX();
499  void SetY(int nY);
500  int GetY();
501 
504  virtual void Reposition(const char* alignment, int left, int top, int width, int height);
505 
508  virtual void SetRotation(float fRot);
509 
512  virtual float GetRotation();
513 
516  virtual void SetScaling(const Vector2& in);
517 
520  virtual void GetScaling(Vector2* pOut);
521 
524  virtual void SetTranslation(const Vector2& in);
525 
528  virtual void GetTranslation(Vector2* pOut);
529 
531  virtual void SetRotOriginOffset(const Vector2& in);
532 
534  virtual void GetRotOriginOffset(Vector2* pOut);
535 
537  virtual void SetColorMask(DWORD dwColor);
538 
540  virtual DWORD GetColorMask();
542  virtual void ApplyColorMask();
543 
548  virtual void ApplyAnim(const Vector2* pvOrigin = NULL, const float* pfRadian = NULL, const Vector2* pvScaling = NULL, const Vector2* pvTranslation = NULL, const DWORD* pdwColor = NULL);
549  virtual void ApplyAnimSelective(const Vector2* pvOrigin = NULL, const float* pfRadian = NULL, const Vector2* pvScaling = NULL, const Vector2* pvTranslation = NULL, const DWORD* pdwColor = NULL);
550 
552  virtual void SetSpacing(int nSpacing) { m_nSpacing = nSpacing; m_bNeedUpdate = true; }
553 
555  virtual int GetSpacing() { return m_nSpacing; }
556 
558  virtual void SetPadding(int nPadding) {}
559 
561  virtual int GetPadding() { return 0; }
562 
565  virtual void SetTextScale(float fScale);
568  virtual float GetTextScale();
569 
570  //set location/size/width/height/position without updating the parent's child rect
571  virtual void SetLocationI(int x, int y);
572  virtual void SetSizeI(int width, int height);
573  virtual void SetWidthI(int width);
574  virtual void SetHeightI(int height);
575  virtual void SetPositionI(int left, int top, int right, int bottom);
576  virtual void SetPositionI(const CGUIPosition& position);
577 
578  virtual CGUIPosition* GetPosition(){ return &m_position; }
579 
581  bool IsOwnerDraw() const { return m_bOwnerDraw; }
582  void SetOwnerDraw(bool val) { m_bOwnerDraw = val; }
583 
587  void SetReceiveDrag(bool bReceiveDrag){ m_bReceiveDrag = bReceiveDrag; };
588  bool GetReceiveDrag()const{ return m_bReceiveDrag; };
589 
591  void SetUseTextShadow(bool bUseTextShadow){ m_bUseTextShadow = bUseTextShadow; };
592  bool GetUseTextShadow() const{ return m_bUseTextShadow; };
593 
594  //valied value:0,4,8
595  void SetTextShadowQuality(uint8_t shadowQuality){ m_textShadowQuality = shadowQuality; }
596  uint8_t GetTextShadowQuality() const{ return m_textShadowQuality; };
597 
598  void SetTextShadowColor(uint32_t shadowColor){ m_textShadowColor = shadowColor; }
599  uint32_t GetTextShadowColor()const { return m_textShadowColor; }
600 
601  void SetTextOffsetX(int32_t x){ m_textOffsetX = x; }
602  int32_t GetTextOffsetX()const { return m_textOffsetX; }
603 
604  void SetTextOffsetY(int32_t y){ m_textOffsetY = y; }
605  int32_t GetTextOffsetY()const { return m_textOffsetY; }
610  virtual void BringToFront();
616  virtual void SendToBack();
617 
619  virtual int GetZOrder()const{ return m_nZOrder; };
620 
623  void SetZOrder(int nOrder);
624 
626  void SetZDepth(float fDepth);
627 
629  float GetZDepth();
630 
634  void SetHotkey(UINT nHotkey) { m_nHotkey = nHotkey; }
635  UINT GetHotkey() const{ return m_nHotkey; }
636 
640  void SetName(const char* szName);
641  const string & GetName()const{ return m_sIdentifer; };
642 
643  virtual const std::string& GetIdentifier();
644  virtual void SetIdentifier(const std::string& sID);
645 
649  void SetCursor(const char* szCursorFile, int nHotSpotX = -1, int nHotSpotY = -1);
650  const std::string& GetCursor(int* pnHotSpotX = 0, int* pnHotSpotY = 0) const;
651 
658  int GetID()const{ return m_nID; };
660  void SetID(int nID){ m_nID = nID; };
661 
666  virtual CGUIBase* GetChildByID(int nChildID){ return NULL; };
667 
672  virtual CGUIBase* GetChildByName(const string& name){ return NULL; };
673 
682  void AttachTo3D(const char* s3DObjectName);
683  void AttachTo3D(CBaseObject* p3DObject);
684 
685  enum EnumTexElementPredefined
686  {
687  TexElement_White = 0,
688  TexElement_Black,
689  TexElement_Tranparent,
690  TexElement_Last,
691  };
692  /*get predefined texture elements*/
693  static GUITextureElement* GetPredefinedTextureElement(EnumTexElementPredefined nID = TexElement_White);
694  static void ClearPredefinedTextureElement();
699  virtual void SetVisible(bool visible);
704  virtual bool GetVisible()const{ return m_bIsVisible; }
705 
707  virtual bool GetVisibleRecursive();
708 
709  virtual void SetHighlightStyle(int style){ m_eHighlight = style; }
710  virtual int GetHighlightStyle()const{ return m_eHighlight; }
714  virtual GUITextureElement* GetTextureElement(const char *texturename);
716  virtual GUIFontElement* GetFontElement(const char *fontname);
718  virtual GUIFontElement* GetFontElement(int nIndex);
719 
720  //if you want to erase an event script, use script=NULL;
721  void SetEventScript(int nEvent, const SimpleScript *script);
722  const SimpleScript* GetEventScript(int nEvent)const;
723 
728  virtual void UpdateScroll(int nXDelta, int nYDelta){};
729  /* only root uses these four functions
730  Most controls are designed to be device independent.
731  */
732  virtual HRESULT InitDeviceObjects(){ return 0; }; // device independent
733  virtual HRESULT RestoreDeviceObjects(){ m_bNeedUpdate = true; return 0; }; // device dependent
734  virtual HRESULT InvalidateDeviceObjects(){ return 0; };
735  virtual HRESULT DeleteDeviceObjects(){ return 0; };
736 
737  virtual string ToScript(int option = 0);
742  virtual void InitObject(const char * strObjectName, const char * alignment, int x, int y, int width, int height);
743 
744  //gain input focus of the current object
745  virtual void Focus();
746  virtual void LostFocus();
747  //some default on events
753  virtual bool OnFocusIn();
754 
760  virtual bool OnFocusOut();
766  virtual bool OnMouseEnter();
767 
773  virtual bool OnMouseLeave();
774 
781  virtual bool OnMouseWheel(int Delta, int X, int Y);
782 
789  virtual bool OnMouseMove(int MouseState, int X, int Y);
790 
797  virtual bool OnMouseHover(int MouseState, int X, int Y);
805  virtual bool OnMouseDown(int MouseState, int X, int Y);
816  virtual bool OnMouseUp(int MouseState, int X, int Y);
817 
819  virtual bool OnTouch(const TouchEvent& touch);
820 
825  virtual bool OnModify();
826 
828  virtual bool OnSize();
829 
833  virtual bool OnSelect();
834 
838  virtual bool OnChange(const char* code = NULL);
839 
840 
841  virtual bool OnKeyDown();
842 
843  virtual bool OnKeyUp();
844 
848  virtual bool OnFrameMove(float fDeltaTime);
849 
855  virtual bool OnClick(int MouseState, int X, int Y);
861  virtual bool OnDoubleClick(int MouseState, int X, int Y);
862 
863  virtual bool OnDragOver(int MouseState, int X, int Y);
864 
872  virtual bool OnActivate(int nState);
873 
874  virtual void MakeActivate(int nState);
875 
877  virtual bool OnDestroy();
878 
880  CGUIBase* GetWindow();
881 
892  virtual bool OnDragBegin(int MouseState, int X, int Y);
904  virtual bool OnDragEnd(int MouseState, int X, int Y);
905 
906  //inherited from IObjectDrag
907  virtual void BeginDrag(int nEvent, int x, int y, int z);
908  virtual void EndDrag(int nEvent, int x, int y, int z);
909 
910  virtual void SetCandrag(bool bCandrag){ m_bCandrag = bCandrag; };
911  virtual bool GetCandrag()const{ return m_bCandrag; };
912 
913  virtual BOOL IsOnObject(int x, int y, int z);
914 
917  virtual int GetAnimationStyle(){ return 0; };
920  virtual void SetAnimationStyle(int nStyle){};
921 
924  inline bool IsClickThrough(){ return m_bClickThrough; };
925  void SetClickThrough(bool bClickThrough);
926 
927 
929  virtual bool IsUVWrappingEnabled();
930 
932  virtual void EnableUVWrapping(bool bUVWrapping);
933 
935  virtual int OnHandleWinMsgChars(const std::wstring& sChars);
936 
937  void SendInputMethodEvent(const std::wstring& sChars);
938 
940  virtual QPoint GetCompositionPoint();
941  virtual void SetCompositionPoint(const QPoint& point);
942 
943  virtual bool IsNonClientTestEnabled();
944  virtual void EnableNonClientTest(bool val);
945 
947  bool GetUsePointTextureFiltering();
948  void SetUsePointTextureFiltering(bool bUse);
950  bool IsDirty() const;
952  bool IsDirtyRecursive();
953  void SetDirty(bool val);
954 
959  virtual bool IsScrollable();
960 
963  bool IsScrollableOrHasMouseWheelRecursive();
964 
968  CPaintDevice* GetForcedPaintDevice() const { return m_pForcedPaintDevice; }
969  void SetForcedPaintDevice(CPaintDevice* val) { m_pForcedPaintDevice = val; }
970 
974  virtual bool CanPaintOnDevice(CPaintDevice* val);
975 
980  void EnableSelfPaint(bool bEnable);
981  bool IsSelfPaintEnabled();
982 
984  bool IsAutoClearBackground() const;
985  void SetAutoClearBackground(bool val);
986 
988  CPainter* GetPainter(GUIState* pGUIState = NULL);
989 
990  protected:
995  HRESULT DrawElement(GUITextureElement* pElement, RECT *prcDest, RECT* prcWindow = NULL, GUIState* pGUIState = NULL);
996 
1001  HRESULT DrawText(const char16_t* strText, GUIFontElement* pElement, RECT* prcDest, RECT* prcWindow = NULL, bool bShadow = false, int nCount = -1, int shadowQuality = 0, Color shadowColor = 0, GUIState* pGUIState = NULL);
1002 
1004  HRESULT DrawRect(Color color, RECT *prcDest, RECT* prcWindow = NULL, GUIState* pGUIState = NULL);
1005 
1007  virtual CRenderTarget* CreateGetRenderTarget(bool bCreateIfNotExist = true);
1008 
1009  virtual bool IsMouseCaptured();
1010  virtual void CaptureMouse();
1011  virtual void ReleaseMouseCapture();
1012  public:
1013  CGUIBase(void);
1014  virtual ~CGUIBase(void);
1015 
1016  //The following four function inherited from the IObject interface.
1022  virtual int Release();
1023  virtual void Clone(IObject* pobj)const;
1024  virtual IObject* Clone()const;
1025  virtual bool Equals(const IObject *obj)const;
1026 
1027 
1028 
1029  static void InflateRect(RECT* lprc, int dx, int dy);
1030  static void OffsetRect(RECT* lprc, int dx, int dy);
1031  static BOOL UnionRect(RECT& lprcDst, const RECT& lprcSrc1, const RECT& lprcSrc2);
1032  static inline int RectWidth(const RECT &rc) { return ((rc).right - (rc).left); }
1033  static inline int RectHeight(const RECT &rc) { return ((rc).bottom - (rc).top); }
1034  static bool RectIntersect(const RECT &rect1, const RECT &rect2);
1035  static bool IntersectRect(RECT* lprcDst, const RECT &rect1, const RECT &rect2);
1036  static BOOL IsRectEmpty(const RECT& lprc);
1037  static void SetRectEmpty(RECT& rc);
1038  static BOOL PtInRect(const RECT& pos, const POINT &pt);
1039  static BOOL SetRect(RECT* pRc, int xLeft, int yTop, int xRight, int yBottom);
1040 
1044  virtual bool FetchIMEString();
1045 
1046  friend class CGUIContainer;
1047  friend class CGUIRoot;
1048 
1049  public:
1054  CGUIResource* m_objResource;
1055  protected:
1056 
1058  CGUIContainer* m_parent;
1059 
1061  UINT m_nHotkey;
1062 
1064  int m_nID;
1065 
1067  bool m_bCanCaptureMouse : 1;
1068 
1070  bool m_bCanHasFocus : 1;
1071 
1073  bool m_bHasFocus : 1;
1074 
1076  bool m_bMouseOver : 1;
1077 
1079  bool m_bReceiveDrag : 1;
1080 
1083  bool m_bClickThrough : 1;
1084 
1089  bool m_bIsEnabled : 1;
1091  bool m_bUseTextShadow : 1;
1093  bool m_bNeedUpdate : 1;
1095  bool m_bAlwaysMouseOver : 1;
1097  bool m_bIsVisible : 1;
1099  bool m_bIsUVWrappingEnabled : 1;
1101  bool m_bUsePointTextureFiltering : 1;
1102 
1104  bool m_bOwnerDraw : 1;
1106  bool m_bDirty : 1;
1108  bool m_bAutoClearBackground : 1;
1110  bool m_bInputMethodEnabled : 1;
1111 
1115  CPaintDevice* m_pForcedPaintDevice;
1116 
1117  uint8_t m_textShadowQuality;
1118  uint32_t m_textShadowColor;
1119  int32_t m_textOffsetX;
1120  int32_t m_textOffsetY;
1121 
1122  //the only event object
1123  CGUIEvent* m_event;
1124 
1126  std::string m_sIdentifer;
1128  std::string m_sCursorFile;
1130  int16 m_nCursorHotSpotX;
1132  int16 m_nCursorHotSpotY;
1133 
1135  CGUIPosition m_position;
1137  int m_nZOrder;
1138 
1143  int m_nLifeTimeCountDown;
1144 
1146  int m_eHighlight;
1148  float m_fRotation;
1150  Vector2 m_vRotOriginOffset;
1152  Vector2 m_vScaling;
1154  Vector2 m_vTranslation;
1156  DWORD m_dwColorMask;
1157 
1159  int m_nSpacing;
1160 
1162  float m_fForceZDepth;
1163 
1164  IType* m_type;
1165  };
1166 
1167  extern void DeleteGUIObject(CGUIBase * pObj);
1168 }
bool IsPainterWindow()
if control contains its own painting device.
Definition: GUIBase.h:232
IType is for type information and validating It contains type information of an object.
Definition: Type.h:75
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
virtual void SetText(const char16_t *wszText)
Set the text of this object The control internally store everything in Unicode.
Definition: GUIBase.h:303
Definition: combase.h:159
Definition: EventBinding.h:22
virtual int GetAttributeClassID()
attribute class ID should be identical, unless one knows how overriding rules work.
Definition: GUIBase.h:64
virtual const char * GetAttributeClassName()
a static string, describing the attribute class object&#39;s name
Definition: GUIBase.h:66
a render target scene object.
Definition: RenderTarget.h:16
different physics engine has different winding order.
Definition: EventBinding.h:32
void SetNeedUpdate(bool bNeedUpdate=true)
set need update
Definition: GUIBase.h:264
Definition: PEtypes.h:116
Place of the.
Definition: GUIEvent.h:43
virtual const char * GetAttributeClassDescription()
a static string, describing the attribute class object
Definition: GUIBase.h:68
Definition: ManagedDef.h:18
CGUIContainer * GetParent()
get the parent container
Definition: GUIBase.h:228
bool GetAlwaysMouseOver()
get whether make mouse over to true as long as it contains the mouse point, no matter it has mouse fo...
Definition: GUIBase.h:278
base object for all 2D GUI objects (1) 2D GUI object are not tested against view frustum, instead it is controlled by visibility tag automatically or through user input.
Definition: GUIBase.h:54
Definition: IObjectDrag.h:66
Standard 2-dimensional vector.
Definition: ParaVector2.h:16
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
virtual bool IsPressed()
whether it is pressed.
Definition: GUIBase.h:284
weak reference ptr use in a class like this: weak_ptr<CRefCounted> p; e.g.
Definition: PERef.h:105
touch event
Definition: EventClasses.h:118
Definition: EventBinding.h:42
m_objResource->m_objArtwork->DrawingRects[0]: client rectangle; m_objResource->m_objArtwork->DrawingR...
Definition: GUIContainer.h:19
base class for a surface to paint to.
Definition: Painter.h:38
a texture from a rectangular region of bitmap, and one additional texture color
Definition: GUIResource.h:12
void SetEnabled(bool bEnabled)
set whether the control is enabled or not
Definition: GUIBase.h:258
It&#39;s used as parameter to Render method of each GUI object.
Definition: GUIState.h:16
Each GUI control is associated with a CGUIResource object for rendering.
Definition: GUIResource.h:185
Definition: ParaPoint.h:5
virtual void SetTextA(const char *szText)
Set the text of this object.
Definition: GUIBase.h:297
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
The CPaintEngine class provides an abstract definition of how CPainter draws to a given device on a g...
Definition: PaintEngine.h:34
Definition: inftrees.h:24
a font name, format and font color
Definition: GUIResource.h:36
bool GetEnabled()
whether control is enabled.
Definition: GUIBase.h:255
void SetParent(CGUIContainer *parent)
set the parent container
Definition: GUIBase.h:249
Defines the base class of all scene elements:CBaseObject for Parallel World Engine.
Definition: BaseObject.h:230
base class for a surface to paint to.
Definition: PaintDevice.h:10
void SetAlwaysMouseOver(bool bAlwaysMouseOver)
set whether make mouse over to true as long as it contains the mouse point, no matter it has mouse fo...
Definition: GUIBase.h:273
position of the GUI object
Definition: GUIPosition.h:34
Definition: ParaColor.h:275
virtual void SetLifeTime(int lifttime)
Set/get how many frames the control will survive.
Definition: GUIBase.h:382
virtual GUIBase_List_Type * GetChildren()
get pointer to children list.
Definition: GUIBase.h:281
When rendering scene, root scene and the root GUI are rendered in sequence.
Definition: GUIRoot.h:48