UIElement.pkg 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. $#include "UIElement.h"
  2. enum HorizontalAlignment
  3. {
  4. HA_LEFT = 0,
  5. HA_CENTER,
  6. HA_RIGHT
  7. };
  8. enum VerticalAlignment
  9. {
  10. VA_TOP = 0,
  11. VA_CENTER,
  12. VA_BOTTOM
  13. };
  14. enum Corner
  15. {
  16. C_TOPLEFT = 0,
  17. C_TOPRIGHT,
  18. C_BOTTOMLEFT,
  19. C_BOTTOMRIGHT,
  20. MAX_UIELEMENT_CORNERS
  21. };
  22. enum Orientation
  23. {
  24. O_HORIZONTAL = 0,
  25. O_VERTICAL
  26. };
  27. enum FocusMode
  28. {
  29. FM_NOTFOCUSABLE = 0,
  30. FM_RESETFOCUS,
  31. FM_FOCUSABLE,
  32. FM_FOCUSABLE_DEFOCUSABLE
  33. };
  34. enum LayoutMode
  35. {
  36. LM_FREE = 0,
  37. LM_HORIZONTAL,
  38. LM_VERTICAL
  39. };
  40. enum TraversalMode
  41. {
  42. TM_BREADTH_FIRST = 0,
  43. TM_DEPTH_FIRST
  44. };
  45. static const unsigned DD_DISABLED;
  46. static const unsigned DD_SOURCE;
  47. static const unsigned DD_TARGET;
  48. static const unsigned DD_SOURCE_AND_TARGET;
  49. class UIElement : public Serializable
  50. {
  51. UIElement(Context* context);
  52. virtual ~UIElement();
  53. virtual const IntVector2& GetScreenPosition() const;
  54. bool LoadXML(Deserializer& source);
  55. bool SaveXML(Serializer& dest) const;
  56. bool FilterAttributes(XMLElement& dest) const;
  57. void SetName(const String& name);
  58. void SetName(const char* name);
  59. void SetPosition(const IntVector2& position);
  60. void SetPosition(int x, int y);
  61. void SetSize(const IntVector2& size);
  62. void SetSize(int width, int height);
  63. void SetWidth(int width);
  64. void SetHeight(int height);
  65. void SetMinSize(const IntVector2& minSize);
  66. void SetMinSize(int width, int height);
  67. void SetMinWidth(int width);
  68. void SetMinHeight(int height);
  69. void SetMaxSize(const IntVector2& maxSize);
  70. void SetMaxSize(int width, int height);
  71. void SetMaxWidth(int width);
  72. void SetMaxHeight(int height);
  73. void SetFixedSize(const IntVector2& size);
  74. void SetFixedSize(int width, int height);
  75. void SetFixedWidth(int width);
  76. void SetFixedHeight(int height);
  77. void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign);
  78. void SetHorizontalAlignment(HorizontalAlignment align);
  79. void SetVerticalAlignment(VerticalAlignment align);
  80. void SetClipBorder(const IntRect& rect);
  81. void SetColor(const Color& color);
  82. void SetColor(Corner corner, const Color& color);
  83. void SetPriority(int priority);
  84. void SetOpacity(float opacity);
  85. void SetBringToFront(bool enable);
  86. void SetBringToBack(bool enable);
  87. void SetClipChildren(bool enable);
  88. void SetSortChildren(bool enable);
  89. void SetUseDerivedOpacity(bool enable);
  90. void SetEnabled(bool enable);
  91. void SetFocus(bool enable);
  92. void SetSelected(bool enable);
  93. void SetVisible(bool enable);
  94. void SetFocusMode(FocusMode mode);
  95. void SetDragDropMode(unsigned mode);
  96. bool SetStyle(const String& styleName, XMLFile* file = 0);
  97. bool SetStyle(const char* styleName, XMLFile* file = 0);
  98. bool SetStyle(const XMLElement& element);
  99. bool SetStyleAuto(XMLFile* file = 0);
  100. void SetDefaultStyle(XMLFile* style);
  101. void SetLayout(LayoutMode mode, int spacing = 0, const IntRect& border = IntRect::ZERO);
  102. void SetLayoutMode(LayoutMode mode);
  103. void SetLayoutSpacing(int spacing);
  104. void SetLayoutBorder(const IntRect& border);
  105. void SetIndent(int indent);
  106. void SetIndentSpacing(int indentSpacing);
  107. void UpdateLayout();
  108. void DisableLayoutUpdate();
  109. void EnableLayoutUpdate();
  110. void BringToFront();
  111. // UIElement* CreateChild(ShortStringHash type, const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
  112. // UIElement* CreateChild(const char* type, const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  113. void AddChild(UIElement* element);
  114. void InsertChild(unsigned index, UIElement* element);
  115. void RemoveChild(UIElement* element, unsigned index = 0);
  116. void RemoveChildAtIndex @ RemoveChild(unsigned index);
  117. void RemoveAllChildren();
  118. void Remove();
  119. unsigned FindChild(UIElement* element) const;
  120. void SetParent(UIElement* parent, unsigned index = M_MAX_UNSIGNED);
  121. void SetInternal(bool enable);
  122. void SetTraversalMode(TraversalMode traversalMode);
  123. void SetElementEventSender(bool flag);
  124. // template <class T> T* CreateChild(const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
  125. BorderImage* CreateChild<BorderImage> @ CreateBorderImage(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  126. Button* CreateChild<Button> @ CreateButton(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  127. CheckBox* CreateChild<CheckBox> @ CreateCheckBox(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  128. Cursor* CreateChild<Cursor> @ CreateCursor(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  129. DropDownList* CreateChild<DropDownList> @ CreateDropDownList(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  130. LineEdit* CreateChild<LineEdit> @ CreateLineEdit(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  131. ListView* CreateChild<ListView> @ CreateListView(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  132. Menu* CreateChild<Menu> @ CreateMenu(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  133. ScrollBar* CreateChild<ScrollBar> @ CreateScrollBar(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  134. ScrollView* CreateChild<ScrollView> @ CreateScrollView(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  135. Slider* CreateChild<Slider> @ CreateSlider(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  136. Sprite* CreateChild<Sprite> @ CreateSprite(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  137. Text* CreateChild<Text> @ CreateText(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  138. UIElement* CreateChild<UIElement> @ CreateUIElement(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  139. Window* CreateChild<Window> @ CreateWindow(const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  140. const String& GetName() const;
  141. const IntVector2& GetPosition() const;
  142. const IntVector2& GetSize() const;
  143. int GetWidth() const;
  144. int GetHeight() const;
  145. const IntVector2& GetMinSize() const;
  146. int GetMinWidth() const;
  147. int GetMinHeight() const;
  148. const IntVector2& GetMaxSize() const;
  149. int GetMaxWidth() const;
  150. int GetMaxHeight() const;
  151. bool IsFixedSize() const;
  152. bool IsFixedWidth() const;
  153. bool IsFixedHeight() const;
  154. const IntVector2& GetChildOffset() const;
  155. HorizontalAlignment GetHorizontalAlignment() const;
  156. VerticalAlignment GetVerticalAlignment() const;
  157. const IntRect& GetClipBorder() const;
  158. const Color& GetColor(Corner corner) const;
  159. int GetPriority() const;
  160. float GetOpacity() const;
  161. float GetDerivedOpacity() const;
  162. bool GetBringToFront() const;
  163. bool GetBringToBack() const;
  164. bool GetClipChildren() const;
  165. bool GetSortChildren() const;
  166. bool GetUseDerivedOpacity() const;
  167. bool HasFocus() const;
  168. bool IsEnabled() const;
  169. bool IsSelected() const;
  170. bool IsVisible() const;
  171. bool IsHovering() const;
  172. bool IsInternal() const;
  173. bool HasColorGradient() const;
  174. FocusMode GetFocusMode() const;
  175. unsigned GetDragDropMode() const;
  176. const String& GetAppliedStyle() const;
  177. XMLFile* GetDefaultStyle(bool recursiveUp = true) const;
  178. LayoutMode GetLayoutMode() const;
  179. int GetLayoutSpacing() const;
  180. const IntRect& GetLayoutBorder() const;
  181. unsigned GetNumChildren(bool recursive = false) const;
  182. UIElement* GetChild(unsigned index) const;
  183. UIElement* GetChild(const String& name, bool recursive = false) const;
  184. tolua_outside UIElement* UIElementGetChild @ GetChild(const char* name, bool recursive = false) const;
  185. UIElement* GetChild(const ShortStringHash& key, const Variant& value = Variant::EMPTY, bool recursive = false) const;
  186. tolua_outside UIElement* UIElementGetChild2 @ GetChild(const char* key, const Variant& value = Variant::EMPTY, bool recursive = false) const;
  187. UIElement* GetParent() const;
  188. UIElement* GetRoot() const;
  189. const Color& GetDerivedColor() const;
  190. IntVector2 ScreenToElement(const IntVector2& screenPosition);
  191. IntVector2 ElementToScreen(const IntVector2& position);
  192. bool IsInside(IntVector2 position, bool isScreen);
  193. bool IsInsideCombined(IntVector2 position, bool isScreen);
  194. IntRect GetCombinedScreenRect();
  195. void SortChildren();
  196. int GetLayoutMinSize() const;
  197. int GetIndent() const;
  198. int GetIndentSpacing() const;
  199. int GetIndentWidth() const;
  200. void SetChildOffset(const IntVector2& offset);
  201. void SetHovering(bool enable);
  202. const Color& GetColorAttr() const;
  203. TraversalMode GetTraversalMode() const;
  204. bool IsElementEventSender() const;
  205. UIElement* GetElementEventSender() const;
  206. tolua_readonly tolua_property__get_set IntVector2& screenPosition;
  207. tolua_property__get_set String& name;
  208. tolua_property__get_set IntVector2& position;
  209. tolua_property__get_set IntVector2 size;
  210. tolua_property__get_set int width;
  211. tolua_property__get_set int height;
  212. tolua_property__get_set IntVector2 minSize;
  213. tolua_property__get_set int minWidth;
  214. tolua_property__get_set int minHeight;
  215. tolua_property__get_set IntVector2 maxSize;
  216. tolua_property__get_set int maxWidth;
  217. tolua_property__get_set int maxHeight;
  218. tolua_readonly tolua_property__is_set bool fixedSize;
  219. tolua_readonly tolua_property__is_set bool fixedWidth;
  220. tolua_readonly tolua_property__is_set bool fixedHeight;
  221. tolua_property__get_set IntVector2& childOffset;
  222. tolua_property__get_set HorizontalAlignment horizontalAlignment;
  223. tolua_property__get_set VerticalAlignment verticalAlignment;
  224. tolua_property__get_set IntRect clipBorder;
  225. tolua_property__get_set Color& color; // Write only property.
  226. tolua_property__get_set int priority;
  227. tolua_property__get_set float opacity;
  228. tolua_readonly tolua_property__get_set float derivedOpacity;
  229. tolua_property__get_set bool bringToFront;
  230. tolua_property__get_set bool bringToBack;
  231. tolua_property__get_set bool clipChildren;
  232. tolua_property__get_set bool sortChildren;
  233. tolua_property__get_set bool useDerivedOpacity;
  234. tolua_property__has_set bool focus;
  235. tolua_property__is_set bool enabled;
  236. tolua_property__is_set bool selected;
  237. tolua_property__is_set bool visible;
  238. tolua_property__is_set bool hovering;
  239. tolua_property__is_set bool internal;
  240. tolua_readonly tolua_property__has_set bool colorGradient;
  241. tolua_property__get_set FocusMode focusMode;
  242. tolua_property__get_set unsigned dragDropMode;
  243. tolua_property__get_set String& style;
  244. tolua_property__get_set XMLFile* defaultStyle;
  245. tolua_property__get_set LayoutMode layoutMode;
  246. tolua_property__get_set int layoutSpacing;
  247. tolua_property__get_set IntRect& layoutBorder;
  248. tolua_readonly tolua_property__get_set unsigned numChildren;
  249. tolua_property__get_set UIElement* parent;
  250. tolua_readonly tolua_property__get_set UIElement* root;
  251. tolua_readonly tolua_property__get_set Color& derivedColor;
  252. tolua_readonly tolua_property__get_set IntRect combinedScreenRect;
  253. tolua_readonly tolua_property__get_set int layoutMinSize;
  254. tolua_property__get_set int indent;
  255. tolua_property__get_set int indentSpacing;
  256. tolua_readonly tolua_property__get_set int indentWidth;
  257. tolua_property__get_set Color& colorAttr;
  258. tolua_property__get_set TraversalMode traversalMode;
  259. tolua_property__is_set bool elementEventSender;
  260. };
  261. ${
  262. static UIElement* UIElementGetChild(const UIElement* element, const char* name, bool recursive = false)
  263. {
  264. return element->GetChild(String(name), recursive);
  265. }
  266. static UIElement* UIElementGetChild2(const UIElement* element, const char* key, const Variant& value = Variant::EMPTY, bool recursive = false)
  267. {
  268. return element->GetChild(ShortStringHash(key), value, recursive);
  269. }
  270. #define GetStyle GetAppliedStyle
  271. #define TOLUA_DISABLE_tolua_get_UIElement_color_ref
  272. #define tolua_get_UIElement_color_ref NULL
  273. $}