UIElement.pkg 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. void SetName(const String& name);
  55. void SetPosition(const IntVector2& position);
  56. void SetPosition(int x, int y);
  57. void SetSize(const IntVector2& size);
  58. void SetSize(int width, int height);
  59. void SetWidth(int width);
  60. void SetHeight(int height);
  61. void SetMinSize(const IntVector2& minSize);
  62. void SetMinSize(int width, int height);
  63. void SetMinWidth(int width);
  64. void SetMinHeight(int height);
  65. void SetMaxSize(const IntVector2& maxSize);
  66. void SetMaxSize(int width, int height);
  67. void SetMaxWidth(int width);
  68. void SetMaxHeight(int height);
  69. void SetFixedSize(const IntVector2& size);
  70. void SetFixedSize(int width, int height);
  71. void SetFixedWidth(int width);
  72. void SetFixedHeight(int height);
  73. void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign);
  74. void SetHorizontalAlignment(HorizontalAlignment align);
  75. void SetVerticalAlignment(VerticalAlignment align);
  76. void SetClipBorder(const IntRect& rect);
  77. void SetColor(const Color& color);
  78. void SetColor(Corner corner, const Color& color);
  79. void SetPriority(int priority);
  80. void SetOpacity(float opacity);
  81. void SetBringToFront(bool enable);
  82. void SetBringToBack(bool enable);
  83. void SetClipChildren(bool enable);
  84. void SetSortChildren(bool enable);
  85. void SetUseDerivedOpacity(bool enable);
  86. void SetEnabled(bool enable);
  87. void SetFocus(bool enable);
  88. void SetSelected(bool enable);
  89. void SetVisible(bool enable);
  90. void SetFocusMode(FocusMode mode);
  91. void SetDragDropMode(unsigned mode);
  92. bool SetStyle(const String& styleName, XMLFile* file = 0);
  93. bool SetStyle(const String& styleName);
  94. bool SetStyle(const XMLElement& element);
  95. bool SetStyleAuto(XMLFile* file = 0);
  96. bool SetStyleAuto();
  97. void SetDefaultStyle(XMLFile* style);
  98. void SetLayout(LayoutMode mode, int spacing = 0, const IntRect& border = IntRect::ZERO);
  99. void SetLayout(LayoutMode mode, int spacing = 0);
  100. void SetLayout(LayoutMode mode);
  101. void SetLayoutMode(LayoutMode mode);
  102. void SetLayoutSpacing(int spacing);
  103. void SetLayoutBorder(const IntRect& border);
  104. void SetIndent(int indent);
  105. void SetIndentSpacing(int indentSpacing);
  106. void UpdateLayout();
  107. void DisableLayoutUpdate();
  108. void EnableLayoutUpdate();
  109. void BringToFront();
  110. UIElement* CreateChild(ShortStringHash type, const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
  111. UIElement* CreateChild(ShortStringHash type, const String& name = String::EMPTY);
  112. UIElement* CreateChild(ShortStringHash type);
  113. void AddChild(UIElement* element);
  114. void InsertChild(unsigned index, UIElement* element);
  115. void RemoveChild(UIElement* element, unsigned index = 0);
  116. void RemoveChild(UIElement* element);
  117. void RemoveChildAtIndex @ RemoveChild(unsigned index);
  118. void RemoveAllChildren();
  119. void Remove();
  120. unsigned FindChild(UIElement* element) const;
  121. void SetParent(UIElement* parent, unsigned index = M_MAX_UNSIGNED);
  122. void SetParent(UIElement* parent);
  123. void SetInternal(bool enable);
  124. void SetTraversalMode(TraversalMode traversalMode);
  125. void SetElementEventSender(bool flag);
  126. const String& GetName() const;
  127. const IntVector2& GetPosition() const;
  128. const IntVector2& GetSize() const;
  129. int GetWidth() const;
  130. int GetHeight() const;
  131. const IntVector2& GetMinSize() const;
  132. int GetMinWidth() const;
  133. int GetMinHeight() const;
  134. const IntVector2& GetMaxSize() const;
  135. int GetMaxWidth() const;
  136. int GetMaxHeight() const;
  137. bool IsFixedSize() const;
  138. bool IsFixedWidth() const;
  139. bool IsFixedHeight() const;
  140. const IntVector2& GetChildOffset() const;
  141. HorizontalAlignment GetHorizontalAlignment() const;
  142. VerticalAlignment GetVerticalAlignment() const;
  143. const IntRect& GetClipBorder() const;
  144. const Color& GetColor(Corner corner) const;
  145. int GetPriority() const;
  146. float GetOpacity() const;
  147. float GetDerivedOpacity() const;
  148. bool GetBringToFront() const;
  149. bool GetBringToBack() const;
  150. bool GetClipChildren() const;
  151. bool GetSortChildren() const;
  152. bool GetUseDerivedOpacity() const;
  153. bool HasFocus() const;
  154. bool IsEnabled() const;
  155. bool IsSelected() const;
  156. bool IsVisible() const;
  157. bool IsHovering() const;
  158. bool IsInternal() const;
  159. bool HasColorGradient() const;
  160. FocusMode GetFocusMode() const;
  161. unsigned GetDragDropMode() const;
  162. const String& GetAppliedStyle() const;
  163. XMLFile* GetDefaultStyle(bool recursiveUp = true) const;
  164. XMLFile* GetDefaultStyle() const;
  165. LayoutMode GetLayoutMode() const;
  166. int GetLayoutSpacing() const;
  167. const IntRect& GetLayoutBorder() const;
  168. unsigned GetNumChildren(bool recursive = false) const;
  169. unsigned GetNumChildren() const;
  170. UIElement* GetChild(unsigned index) const;
  171. UIElement* GetChild(const String& name, bool recursive = false) const;
  172. UIElement* GetChild(const String& name) const;
  173. tolua_outside UIElement* UIElementGetChild @ GetChild(const char* name, bool recursive = false) const;
  174. tolua_outside UIElement* UIElementGetChild @ GetChild(const char* name) const;
  175. UIElement* GetChild(const ShortStringHash& key, const Variant& value = Variant::EMPTY, bool recursive = false) const;
  176. UIElement* GetChild(const ShortStringHash& key, const Variant& value = Variant::EMPTY) const;
  177. UIElement* GetChild(const ShortStringHash& key) const;
  178. UIElement* GetParent() const;
  179. UIElement* GetRoot() const;
  180. const Color& GetDerivedColor() const;
  181. IntVector2 ScreenToElement(const IntVector2& screenPosition);
  182. IntVector2 ElementToScreen(const IntVector2& position);
  183. bool IsInside(IntVector2 position, bool isScreen);
  184. bool IsInsideCombined(IntVector2 position, bool isScreen);
  185. IntRect GetCombinedScreenRect();
  186. void SortChildren();
  187. int GetLayoutMinSize() const;
  188. int GetIndent() const;
  189. int GetIndentSpacing() const;
  190. int GetIndentWidth() const;
  191. void SetChildOffset(const IntVector2& offset);
  192. void SetHovering(bool enable);
  193. TraversalMode GetTraversalMode() const;
  194. bool IsElementEventSender() const;
  195. UIElement* GetElementEventSender() const;
  196. tolua_property__get_set String& style;
  197. tolua_property__get_set String& name;
  198. tolua_property__get_set IntVector2& position;
  199. tolua_property__get_set IntVector2 size;
  200. tolua_property__get_set int width;
  201. tolua_property__get_set int height;
  202. tolua_property__get_set IntVector2 minSize;
  203. tolua_property__get_set int minWidth;
  204. tolua_property__get_set int minHeight;
  205. tolua_property__get_set IntVector2 maxSize;
  206. tolua_property__get_set int maxWidth;
  207. tolua_property__get_set int maxHeight;
  208. tolua_readonly tolua_property__is_set bool fixedSize;
  209. tolua_readonly tolua_property__is_set bool fixedWidth;
  210. tolua_readonly tolua_property__is_set bool fixedHeight;
  211. tolua_property__get_set HorizontalAlignment horizontalAlignment;
  212. tolua_property__get_set VerticalAlignment verticalAlignment;
  213. tolua_property__get_set IntRect clipBorder;
  214. tolua_property__get_set int priority;
  215. tolua_property__get_set float opacity;
  216. tolua_property__get_set bool bringToFront;
  217. tolua_property__get_set bool bringToBack;
  218. tolua_property__get_set bool clipChildren;
  219. tolua_property__get_set bool sortChildren;
  220. tolua_property__get_set bool useDerivedOpacity;
  221. tolua_property__is_set bool enabled;
  222. tolua_property__has_set bool focus;
  223. tolua_property__is_set bool selected;
  224. tolua_property__is_set bool visible;
  225. tolua_property__is_set bool hovering;
  226. tolua_property__is_set bool internal;
  227. tolua_readonly tolua_property__has_set bool colorGradient;
  228. tolua_property__get_set FocusMode focusMode;
  229. tolua_property__get_set unsigned dragDropMode;
  230. tolua_property__get_set TraversalMode traversalMode;
  231. tolua_property__get_set XMLFile* defaultStyle;
  232. tolua_property__get_set LayoutMode layoutMode;
  233. tolua_property__get_set int layoutSpacing;
  234. tolua_property__get_set IntRect& layoutBorder;
  235. tolua_property__get_set int indent;
  236. tolua_property__get_set int indentSpacing;
  237. tolua_readonly tolua_property__get_set int indentWidth;
  238. tolua_property__get_set IntVector2& childOffset;
  239. tolua_property__is_set bool elementEventSender;
  240. tolua_readonly tolua_property__get_set unsigned numChildren;
  241. tolua_property__get_set UIElement* parent;
  242. tolua_readonly tolua_property__get_set UIElement* root;
  243. tolua_readonly tolua_property__get_set IntVector2& screenPosition;
  244. tolua_readonly tolua_property__get_set IntRect combinedScreenRect;
  245. tolua_readonly tolua_property__get_set float derivedOpacity;
  246. };
  247. ${
  248. UIElement* UIElementGetChild(const UIElement* uiElement, const char* name, bool recursive = false)
  249. {
  250. return uiElement->GetChild(String(name), recursive);
  251. }
  252. #define GetStyle GetAppliedStyle
  253. $}