My Project
ParaScriptingGUI.h
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2004 - 2007 ParaEngine Tech Studio, All Rights Reserved.
3 // Date: 2005.4
4 // Description: API for GUI objects
5 //-----------------------------------------------------------------------------
6 #pragma once
7 #include "ParaScriptingCommon.h"
8 #include "ParaScriptingGlobal.h"
9 #include "2dengine/GUIBase.h"
10 #if defined (USE_FLASH_MANAGER) && defined(USE_DIRECTX_RENDERER)
11 #include "ParaScriptingFlashPlayer.h"
12 #endif
13 #ifdef USE_DIRECTX_RENDERER
14 #include "ParaScriptingBrowserManager.h"
15 #include "ParaScriptingHTMLBrowser.h"
16 #endif
17 #include "ParaScriptingPainter.h"
18 #include "ParaScriptingGraphics.h"
19 
20 namespace ParaScripting
21 {
22  using namespace std;
23  using namespace luabind;
24  using namespace ParaEngine;
25 
104  class PE_CORE_DECL ParaUIObject
105  {
106  public:
107  CGUIBase::WeakPtr_type m_pObj;
108 
109  ParaUIObject();
110  ParaUIObject(CGUIBase * obj);
111 
116  bool IsValid() const;
122  void AddChild(ParaUIObject pChild);
123 
125  ParaAttributeObject GetAttributeObject();
127  void GetAttributeObject_(ParaAttributeObject& output);
128 
133  void AddTextItem(const char*text);
137  void AttachToRoot();
138 
139  void SetName(const char *szName);
143  string GetName()const;
144 
146  ParaUIObject GetChild(const char *name);
147 
149  ParaUIObject GetChildAt(int index);
150 
152  int GetChildCount();
153 
160  int GetID() const;
161 
163  void SetID(int nID);
164 
169  ParaUIObject GetChildByID(int nChildID);
170 
175  ParaUIObject GetChildByName(const char* name);
176 
177 
182  void SetEnabled(bool bEnabled);
183  bool GetEnabled() const;
184 
186  void SetUseTextShadow(bool bUseTextShadow);
187  bool GetUseTextShadow() const;
188 
191  void SetTextScale(float fScale);
194  float GetTextScale();
195 
196  void SetHighlightStyle(const char* style);
197  const char* GetHighlightStyle()const;
198 
200  string GetColor()const;
201 
205  void SetColor(const char *strColor);
206 
208  void SetZDepth(float fDepth);
209 
211  float GetZDepth();
212 
217  void SetAutoSize(bool bAutosize);
218  bool GetAutoSize() const;
219 
221  void GetTextLineSize(int* width, int* height);
222 
227  void SetVisible(bool bVisible);
228  bool GetVisible() const;
229 
230 
231  bool GetScrollable() const;
232 
233  string GetType() const;
237  //ParaUIResource GetResource();
238 
239  void SetReceiveDrag(bool bReceiveDrag);
240  bool GetReceiveDrag()const;
241 
242  ParaUIObject GetParent()const;
243  void SetParent(ParaUIObject parent);
244 
247  object GetField(const char* sFieldname, const object& output);
248 
252  void SetField(const char* sFieldname, const object& input);
253 
256  void CallField(const char* sFieldname);
257 
263  void SetDefault(bool bDefaultButton);
264 
270  void SetLifeTime(int nSeconds);
276  int GetLifeTime()const;
277 
281  string GetText() const;
290  void SetText3(const char * strText, const char * strColor, const char * strFontAssetName);
291  void SetText1(const object& strText);
292  void SetText(const char* strText);
293 
300  void SetTextAutoTranslate(const char* strText, const char* sConverter);
301 
312  void SetPasswordChar(string PasswordChar);
314  string GetPasswordChar() const;
315 
319  void SetTopLevel(bool value);
331  void SetBGImage1(const object& szBackground);
332  void SetBGImageStr(const char * szBackground);
333  void SetBGImage5(const char * TextFilename,int left,int top,int width,int height);
334  void SetBGImage(ParaAssetObject pTextureEntity);
335  void SetBGImageAndRect(ParaAssetObject pTextureEntity,int left,int top,int width,int height);
336  // internally used
337  void SetBGImage_(TextureEntity* pTextureEntity,RECT *rect);
338  // internally used
339  void SetBGImage2(const char * TextFilename,RECT *rect);
340 
341  string GetBGImage()const;
342 
343  void SetBtnImage2(const char * TextFilename, RECT *rect);
344  void SetBtnImage1(const object& szButton);
345  string GetBtnImage()const;
346 
353  void SetNineElementBG(const char * TextFilename, int left, int top, int toRight, int toBottom);
354 
360  int GetFirstVisibleCharIndex();
361 
365  int GetCaretPosition();
366 
371  void SetCaretPosition(int nCharacterPos);
372 
376  int GetTextSize();
377 
379  void GetPriorWordPos( int nCP, int PriorIn, int &Prior );
380 
382  void GetNextWordPos( int nCP, int NextIn, int &Next);
383 
385  void CPtoXY( int nCP, bool bTrail, int XIn, int YIn, int &X, int &Y);
386 
388  void XYtoCP( int nX, int nY, int CPIn,int nTrailIn, int & CP,int &nTrail);
389 
394  void SetPageSize(int pagesize);
395 
397  void SetStep(int nDelta);
398 
400  int GetStep();
401 
407  void SetTrackRange(int nBegin,int nEnd);
408 
409  void GetTrackRange(int &nBegin, int &nEnd);
410 
420  int GetAnimationStyle() const;
421 
431  void SetAnimationStyle(int nStyle);
432 
437  void SetScrollable(bool bScrollable);
438 
448  void GetAbsPosition(float &x,float &y,float& width, float& height, float &z)const;
449 
450 
454  void SetPosition(const char * pos);
455 
457  string GetPosition()const;
458 
461  void Reposition(const char* alignment, int left,int top, int width, int height);
462 
463 
468  int GetValue()const;
469  void SetValue(int value);
479  void OnClick(const object& strScriptName);
480  string GetOnClick()const;
481 
486  void OnSize(const object& strScriptName);
487  string GetOnSize()const;
488 
492  void OnDestroy(const object& strScriptName);
493  string GetOnDestroy()const;
494 
503  void OnActivate(const object& strScriptName);
504  string GetOnActivate()const;
505 
514  void OnDoubleClick(const object& strScriptName);
515  string GetOnDoubleClick()const;
524  void OnKeyDown(const object& strScriptName);
525  string GetOnKeyDown()const;
526 
527  void OnKeyUp(const object& strScriptName);
528  string GetOnKeyUp()const;
529 
530  void OnDragBegin(const object& strScriptName);
531  string GetOnDragBegin()const;
532 
533  void OnDragEnd(const object& strScriptName);
534  string GetOnDragEnd()const;
535 
536  void OnDragOver(const object& strScriptName);
537  string GetOnDragOver()const;
538  void OnMouseMove(const object& strScriptName);
539  string GetOnMouseMove()const;
540  void OnMouseHover(const object& strScriptName);
541  string GetOnMouseHover()const;
542  void OnMouseEnter(const object& strScriptName);
543  string GetOnMouseEnter()const;
544  void OnMouseLeave(const object& strScriptName);
545  string GetOnMouseLeave()const;
546  void OnMouseDown(const object& strScriptName);
547  string GetOnMouseDown()const;
548  void OnMouseUp(const object& strScriptName);
549  string GetOnMouseUp()const;
550  void OnMouseWheel(const object& strScriptName);
551  string GetOnMouseWheel()const;
552  void OnFrameMove(const object& strScriptName);
553  string GetOnFrameMove()const;
554  void OnTouch(const object& strScriptName);
555  string GetOnTouch()const;
556  void OnDraw(const object& strScriptName);
557  string GetOnDraw()const;
558  void OnInputMethod(const object& strScriptName);
559  string GetOnInputMethod()const;
560 
564  void SetCursor(const object& szCursorFile);
565  std::string GetCursor() const;
568  void SetCursorEx(const char* szCursorFile, int nHotSpotX, int nHotSpotY);
569 
572  void OnChange(const object& strScriptName);
573  string GetOnChange()const;
574  void OnSelect(const object& strScriptName);
575  string GetOnSelect()const;
576  void OnModify(const object& strScriptName);
577  string GetOnModify()const;
578  void SetCanDrag(bool bCanDrag);
579  bool GetCanDrag() const;
580 
581  void SetFontString(const char* font);
582  void SetFontString1(const object& font);
583  void SetFontString3(const char *fontname,DWORD fontsize,bool isbold);
584 
585 
586  string ToScript()const;
587  string GetFontString()const;
588  //make this object get keyboard focus, if it can get keyboard focus
589  void Focus();
590  //make this object lost keyboard focus, if it has focus
591  void LostFocus();
592  bool GetReadOnly()const;
593  void SetReadOnly(bool readonly);
594  int GetX()const;
595  int GetY()const;
596  float GetDepth()const;
597  void SetDepth(float depth);
598  void SetX(int x);
599  void SetY(int y);
600  void SetWidth(int width);
601  void SetHeight(int height);
602  int Width()const;
603  int Height()const;
604  void SetSize(int width, int height);
605 
608  void SetRotation(float fRot);
609 
612  float GetRotation() const;
613 
615  void SetRotOriginOffset(float x, float y);
616 
618  void GetRotOriginOffset(float *x, float * y) const;
619 
622  void SetScaling(float x, float y);
623 
626  void GetScaling(float *x, float * y) const;
627 
628  void SetScalingX(float x);
629  float GetScalingX() const;
630  void SetScalingY(float y);
631  float GetScalingY() const;
632 
635  void SetTranslation(float x, float y);
636 
639  void GetTranslation(float *x, float * y) const;
640 
641  void SetTranslationX(float x);
642  float GetTranslationX() const;
643  void SetTranslationY(float y);
644  float GetTranslationY() const;
645 
647  void SetColorMask(const char *strColor);
648  string GetColorMask()const;
649 
652  void ApplyAnim();
653 
654 
656  void SetSpacing( int nSpacing );
657 
659  int GetSpacing() const;
660 
661  //for scrollbar and short-cut for container
662  int GetScrollbarWidth()const;
663  void SetScrollbarWidth(int width);
664 
665  //for scrollbar
666  bool GetFixedThumb()const;
667  void SetFixedThumb(bool bFixed);
668 
669  int GetThumbSize()const;
670  void SetThumbSize(int size);
671 
672  void SetBindingObj(ParaUIObject obj);//set linked object of a scrollbar
673 
674  void SetFastRender(bool fastrender);
675  bool GetFastRender()const;
676 
677  bool GetWordbreak()const;
678  void SetWordbreak(bool wordbreak);
679 
680  int GetItemHeight()const;
681  void SetItemHeight(int itemheight);
682 
683  bool GetMultipleSelect()const;
684  void SetMultipleSelect(bool multiple);
694  void AttachTo3D(const ParaObject obj);
703  void AttachTo3D_(const char* s3DObjectName);
704 
705  string GetToolTip()const;
706  void SetToolTip(const object& tooltip);
707 
708  void RemoveAll();
709 
710  void RemoveItem(int index);
711 
712  void SetPopUp(int popup);
713  int GetPopUp()const;
714 
715 
716  ParaUIFont CreateFont(const char *name,const char *fontname);
717  ParaUITexture CreateTexture(const char *name,const char *texturename);
720  ParaUIFont GetFont(const char *name);
722  ParaUIFont GetFont_(int nIndex);
723 
725  void DoAutoSize();
726 
737  ParaUITexture GetTexture(const object& name);
738 
739 
741  void BringToFront();
742 
744  void BringToBack();
745 
747  int GetZOrder()const;
748 
751  void SetZOrder(int nOrder);
752 
753  bool IsModified()const;
764  void SetActiveLayer(const char *layer);
765 
770  bool HasLayer(const char *layer);
771 
782  void SetCurrentState(const char *statename);
783 
793  void CloneState(const char* statename);
794  void ActivateScript(const char* scripttype);
795 
800  void InvalidateRect();
801 
805  void UpdateRect();
806 
807  protected:
808  string GenGetImage(int index)const;
809  string GenGetFont(int index)const;
810  private:
811  void GetEventScript(DWORD type, string& out)const;
812  void SetEventScript(DWORD type, const char * strScriptName);
813 
814  };
826  class PE_CORE_DECL ParaUI
827  {
828  public:
833  static void PlaySound(const char * strSoundAssetName, bool bLoop);
834 
840  static void StopSound(const char * strSoundAssetName);
841 
847  static void Destroy(const char * strObjectName);
853  static void Destroy1(int nID);
854 
856  static void DestroyUIObject(ParaUIObject& obj);
857 
861  static void PostDestroy(const char * strObjectName);
862 
870  static ParaUIObject GetUIObject_any(const object& NameOrID);
871  static ParaUIObject GetUIObject(const char* Name);
872 
878  static ParaUIObject GetUIObjectAtPoint(int x,int y);
879 
886  static void GetMousePosition(float &x,float &y);
887 
888  static void SetMousePosition(float x,float y);
889 
890  /* check if a given key is currently in pressed state. Please note that there may be time delays since the scripting interface is called at regularly interval.
891  * e.g. ParaUI.IsKeyPressed(DIK_SCANCODE.DIK_LCONTROL) or ParaUI.IsKeyPressed(DIK_SCANCODE.DIK_LSHIFT) or ParaUI.IsKeyPressed(DIK_SCANCODE.DIK_LMENU)
892  * @param nDikScanCode: DirectInput keyboard scan codes.
893  */
894  static bool IsKeyPressed(int nDikScanCode);
895 
896  /* check if a given mouse button is currently in pressed state.
897  * @param nButton: 0 is left, 1 is right, 2 is middle.
898  this is just traditional mouse key mapping.
899  enum MOUSE_KEY_STD{
900  LEFT_BUTTON = 0,
901  RIGHT_BUTTON = 1,
902  MIDDLE_BUTTON = 2
903  };
904  */
905  static bool IsMousePressed(int nButton);
906 
945  static ParaUIObject CreateUIObject(const char* strType, const char * strObjectName,const char * alignment, int x, int y, int width, int height);
946 
950  static ParaUIObject GetTopLevelControl();
951 
952 
960  static ParaUIObject GetDefaultObject(const char *strType);
962  static void SetCursorFont(const char *fontname,const char * strColor,DWORD transparency);
964  static void SetCursorTexture(const char *texturename, const char * strColor,DWORD transparency );
966  static void SetCursorText(const char *strText);
974  static void SetCursorFromFile(const char *szCursor, int XHotSpot, int YHotSpot);
976  static void SetCursorFromFile_(const char *szCursor);
977  /*
978  * get the current cursor file name.
979  * @return: the cursor file is returned.
980  */
981  static const char* GetCursorFile();
982 
984  static void SetUseSystemCursor(bool bUseSystem);
985 
987  static bool GetUseSystemCursor();
988 
990  static string ToScript();
991 
997  static bool SaveLayout(const char *filename);
998 
1003  static void SetDesignTime(bool bDesign);
1004 
1009  static void ShowCursor(bool bShow);
1010 
1015  static void LockMouse(bool bLock);
1016 
1020  static bool IsMouseLocked();
1021 
1023  static void ResetUI();
1024 
1030  static void SetIMEOpenStatus(bool bOpen);
1031 
1033  static bool GetIMEOpenStatus();
1034 
1035 
1041  static void SetUIScale(float fScalingX, float fScalingY);
1042 
1049  static void SetMinimumScreenSize(int nWidth, int nHeight, bool bAutoUIScaling);
1050 
1051 
1056  static void AddDragReceiver(const char* sName);
1057 
1058 
1063  static void SetToolTipBehavior(const char* behavior);
1064 
1072  static bool SetHighlightParam(const char* szEffectName, const char* szParamName, const char* szParamValue);
1073 
1074 #ifdef USE_DIRECTX_RENDERER
1075 #ifdef USE_FLASH_MANAGER
1076 
1079  static ParaFlashPlayer GetFlashPlayer(const char* sFileName);
1080 
1084  static ParaFlashPlayer CreateFlashPlayer(const char* sFileName);
1085 
1089  static ParaFlashPlayer GetFlashPlayer1(int nIndex);
1090 #endif
1091 #endif
1092  };
1093 }
Which DXT Compression to Use? Obviously, there are some trade-offs between the different formats whic...
Definition: TextureEntity.h:29
ParaUI namespace contains a list of HAPI functions to create user interface controls, such as windows, buttons, as well as event triggers.
Definition: ParaScriptingGUI.h:826
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: ManagedDef.h:18
ParaObject class: it is used to control game scene objects from scripts.
Definition: ParaScriptingScene.h:56
a GUI texture object
Definition: ParaScriptingGraphics.h:22
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
weak reference ptr use in a class like this: weak_ptr<CRefCounted> p; e.g.
Definition: PERef.h:105
Definition: PEtypes.h:507
Definition: enum_maker.hpp:46
it represents an attribute object associated with an object.
Definition: ParaScriptingGlobal.h:458
a GUI font object
Definition: ParaScriptingGraphics.h:50
for luabind, The main drawback of this approach is that the compilation time will increase for the fi...
Definition: luaSQLite.cpp:1971
it represents a GUI object.
Definition: ParaScriptingGUI.h:104
it represents an asset entity.
Definition: ParaScriptingCommon.h:85