UIElement.pkg 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. $#include "IO/File.h"
  2. $#include "UI/UIElement.h"
  3. enum HorizontalAlignment
  4. {
  5. HA_LEFT = 0,
  6. HA_CENTER,
  7. HA_RIGHT,
  8. HA_CUSTOM
  9. };
  10. enum VerticalAlignment
  11. {
  12. VA_TOP = 0,
  13. VA_CENTER,
  14. VA_BOTTOM,
  15. VA_CUSTOM
  16. };
  17. enum Corner
  18. {
  19. C_TOPLEFT = 0,
  20. C_TOPRIGHT,
  21. C_BOTTOMLEFT,
  22. C_BOTTOMRIGHT,
  23. MAX_UIELEMENT_CORNERS
  24. };
  25. enum Orientation
  26. {
  27. O_HORIZONTAL = 0,
  28. O_VERTICAL
  29. };
  30. enum FocusMode
  31. {
  32. FM_NOTFOCUSABLE = 0,
  33. FM_RESETFOCUS,
  34. FM_FOCUSABLE,
  35. FM_FOCUSABLE_DEFOCUSABLE
  36. };
  37. enum LayoutMode
  38. {
  39. LM_FREE = 0,
  40. LM_HORIZONTAL,
  41. LM_VERTICAL
  42. };
  43. enum TraversalMode
  44. {
  45. TM_BREADTH_FIRST = 0,
  46. TM_DEPTH_FIRST
  47. };
  48. static const unsigned DD_DISABLED;
  49. static const unsigned DD_SOURCE;
  50. static const unsigned DD_TARGET;
  51. static const unsigned DD_SOURCE_AND_TARGET;
  52. class UIElement : public Animatable
  53. {
  54. UIElement();
  55. virtual ~UIElement();
  56. virtual const IntVector2& GetScreenPosition() const;
  57. bool LoadXML(Deserializer& source);
  58. bool SaveXML(Serializer& dest, const String indentation = "\t") const;
  59. tolua_outside bool UIElementLoadXML @ LoadXML(const String fileName);
  60. tolua_outside bool UIElementSaveXML @ SaveXML(const String fileName, const String indentation = "\t") const;
  61. bool FilterAttributes(XMLElement& dest) const;
  62. void SetName(const String name);
  63. void SetPosition(const IntVector2& position);
  64. void SetPosition(int x, int y);
  65. void SetSize(const IntVector2& size);
  66. void SetSize(int width, int height);
  67. void SetWidth(int width);
  68. void SetHeight(int height);
  69. void SetMinSize(const IntVector2& minSize);
  70. void SetMinSize(int width, int height);
  71. void SetMinWidth(int width);
  72. void SetMinHeight(int height);
  73. void SetMaxSize(const IntVector2& maxSize);
  74. void SetMaxSize(int width, int height);
  75. void SetMaxWidth(int width);
  76. void SetMaxHeight(int height);
  77. void SetFixedSize(const IntVector2& size);
  78. void SetFixedSize(int width, int height);
  79. void SetFixedWidth(int width);
  80. void SetFixedHeight(int height);
  81. void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign);
  82. void SetHorizontalAlignment(HorizontalAlignment align);
  83. void SetVerticalAlignment(VerticalAlignment align);
  84. void SetEnableAnchor(bool enable);
  85. void SetMinAnchor(const Vector2& anchor);
  86. void SetMinAnchor(float x, float y);
  87. void SetMaxAnchor(const Vector2& anchor);
  88. void SetMaxAnchor(float x, float y);
  89. void SetMinOffset(const IntVector2& offset);
  90. void SetMaxOffset(const IntVector2& offset);
  91. void SetPivot(const Vector2& pivot);
  92. void SetPivot(float x, float y);
  93. void SetClipBorder(const IntRect& rect);
  94. void SetColor(const Color& color);
  95. void SetColor(Corner corner, const Color& color);
  96. void SetPriority(int priority);
  97. void SetOpacity(float opacity);
  98. void SetBringToFront(bool enable);
  99. void SetBringToBack(bool enable);
  100. void SetClipChildren(bool enable);
  101. void SetSortChildren(bool enable);
  102. void SetUseDerivedOpacity(bool enable);
  103. void SetEnabled(bool enable);
  104. void SetDeepEnabled(bool enable);
  105. void ResetDeepEnabled();
  106. void SetEnabledRecursive(bool enable);
  107. void SetEditable(bool enable);
  108. void SetFocus(bool enable);
  109. void SetSelected(bool enable);
  110. void SetVisible(bool enable);
  111. void SetFocusMode(FocusMode mode);
  112. void SetDragDropMode(unsigned mode);
  113. bool SetStyle(const String styleName, XMLFile* file = 0);
  114. bool SetStyle(const XMLElement& element);
  115. bool SetStyleAuto(XMLFile* file = 0);
  116. void SetDefaultStyle(XMLFile* style);
  117. void SetLayout(LayoutMode mode, int spacing = 0, const IntRect& border = IntRect::ZERO);
  118. void SetLayoutMode(LayoutMode mode);
  119. void SetLayoutSpacing(int spacing);
  120. void SetLayoutBorder(const IntRect& border);
  121. void SetLayoutFlexScale(const Vector2& scale);
  122. void SetIndent(int indent);
  123. void SetIndentSpacing(int indentSpacing);
  124. void UpdateLayout();
  125. void DisableLayoutUpdate();
  126. void EnableLayoutUpdate();
  127. void BringToFront();
  128. UIElement* CreateChild(const String type, const String name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
  129. void AddChild(UIElement* element);
  130. void InsertChild(unsigned index, UIElement* element);
  131. void RemoveChild(UIElement* element, unsigned index = 0);
  132. void RemoveChildAtIndex(unsigned index);
  133. void RemoveAllChildren();
  134. void Remove();
  135. unsigned FindChild(UIElement* element) const;
  136. void SetParent(UIElement* parent, unsigned index = M_MAX_UNSIGNED);
  137. void SetVar(StringHash key, const Variant& value);
  138. void SetInternal(bool enable);
  139. void SetTraversalMode(TraversalMode traversalMode);
  140. void SetElementEventSender(bool flag);
  141. void AddTag(const String tag);
  142. void AddTags(const String tags, char separator);
  143. bool RemoveTag(const String tag);
  144. void RemoveAllTags();
  145. const String GetName() const;
  146. const IntVector2& GetPosition() const;
  147. const IntVector2& GetSize() const;
  148. int GetWidth() const;
  149. int GetHeight() const;
  150. const IntVector2& GetMinSize() const;
  151. int GetMinWidth() const;
  152. int GetMinHeight() const;
  153. const IntVector2& GetMaxSize() const;
  154. int GetMaxWidth() const;
  155. int GetMaxHeight() const;
  156. bool IsFixedSize() const;
  157. bool IsFixedWidth() const;
  158. bool IsFixedHeight() const;
  159. const IntVector2& GetChildOffset() const;
  160. HorizontalAlignment GetHorizontalAlignment() const;
  161. VerticalAlignment GetVerticalAlignment() const;
  162. bool GetEnableAnchor() const;
  163. const Vector2& GetMinAnchor() const;
  164. const Vector2& GetMaxAnchor() const;
  165. const IntVector2& GetMinOffset() const;
  166. const IntVector2& GetMaxOffset() const;
  167. const Vector2& GetPivot() const;
  168. const IntRect& GetClipBorder() const;
  169. const Color& GetColor(Corner corner) const;
  170. int GetPriority() const;
  171. float GetOpacity() const;
  172. float GetDerivedOpacity() const;
  173. bool GetBringToFront() const;
  174. bool GetBringToBack() const;
  175. bool GetClipChildren() const;
  176. bool GetSortChildren() const;
  177. bool GetUseDerivedOpacity() const;
  178. bool HasFocus() const;
  179. bool IsEnabled() const;
  180. bool IsEnabledSelf() const;
  181. bool IsEditable() const;
  182. bool IsSelected() const;
  183. bool IsVisible() const;
  184. bool IsVisibleEffective() const;
  185. bool IsHovering() const;
  186. bool IsInternal() const;
  187. bool HasColorGradient() const;
  188. FocusMode GetFocusMode() const;
  189. unsigned GetDragDropMode() const;
  190. const String GetAppliedStyle() const;
  191. XMLFile* GetDefaultStyle(bool recursiveUp = true) const;
  192. LayoutMode GetLayoutMode() const;
  193. int GetLayoutSpacing() const;
  194. const IntRect& GetLayoutBorder() const;
  195. const Vector2& GetLayoutFlexScale() const;
  196. unsigned GetNumChildren(bool recursive = false) const;
  197. int GetDragButtonCombo() const;
  198. unsigned GetDragButtonCount() const;
  199. UIElement* GetChild(const String name, bool recursive = false) const;
  200. UIElement* GetChild(unsigned index) const;
  201. UIElement* GetParent() const;
  202. UIElement* GetRoot() const;
  203. const Color& GetDerivedColor() const;
  204. const Variant& GetVar(StringHash key) const;
  205. const VariantMap& GetVars() const;
  206. bool HasTag(const String tag) const;
  207. const StringVector& GetTags() const;
  208. // void GetChildrenWithTag(PODVector<UIElement*>& dest, const String& tag, bool recursive = false) const;
  209. tolua_outside const PODVector<UIElement*>& UIElementGetChildrenWithTag @ GetChildrenWithTag(const String& tag, bool recursive = false) const;
  210. IntVector2 ScreenToElement(const IntVector2& screenPosition);
  211. IntVector2 ElementToScreen(const IntVector2& position);
  212. bool IsInside(IntVector2 position, bool isScreen);
  213. bool IsInsideCombined(IntVector2 position, bool isScreen);
  214. IntRect GetCombinedScreenRect();
  215. void SortChildren();
  216. int GetIndent() const;
  217. int GetIndentSpacing() const;
  218. int GetIndentWidth() const;
  219. void SetChildOffset(const IntVector2& offset);
  220. void SetHovering(bool enable);
  221. const Color& GetColorAttr @ GetColor() const;
  222. TraversalMode GetTraversalMode() const;
  223. bool IsElementEventSender() const;
  224. UIElement* GetElementEventSender() const;
  225. tolua_readonly tolua_property__get_set IntVector2& screenPosition;
  226. tolua_property__get_set String name;
  227. tolua_property__get_set IntVector2& position;
  228. tolua_property__get_set IntVector2 size;
  229. tolua_property__get_set int width;
  230. tolua_property__get_set int height;
  231. tolua_property__get_set IntVector2 minSize;
  232. tolua_property__get_set int minWidth;
  233. tolua_property__get_set int minHeight;
  234. tolua_property__get_set IntVector2 maxSize;
  235. tolua_property__get_set int maxWidth;
  236. tolua_property__get_set int maxHeight;
  237. tolua_readonly tolua_property__is_set bool fixedSize;
  238. tolua_readonly tolua_property__is_set bool fixedWidth;
  239. tolua_readonly tolua_property__is_set bool fixedHeight;
  240. tolua_property__get_set IntVector2& childOffset;
  241. tolua_property__get_set HorizontalAlignment horizontalAlignment;
  242. tolua_property__get_set VerticalAlignment verticalAlignment;
  243. tolua_property__get_set bool enableAnchor;
  244. tolua_property__get_set IntVector2& minOffset;
  245. tolua_property__get_set IntVector2& maxOffset;
  246. tolua_property__get_set Vector2& minAnchor;
  247. tolua_property__get_set Vector2& maxAnchor;
  248. tolua_property__get_set Vector2& pivot;
  249. tolua_property__get_set IntRect clipBorder;
  250. tolua_property__get_set Color& colorAttr @ color;
  251. tolua_property__get_set int priority;
  252. tolua_property__get_set float opacity;
  253. tolua_readonly tolua_property__get_set float derivedOpacity;
  254. tolua_property__get_set bool bringToFront;
  255. tolua_property__get_set bool bringToBack;
  256. tolua_property__get_set bool clipChildren;
  257. tolua_property__get_set bool sortChildren;
  258. tolua_property__get_set bool useDerivedOpacity;
  259. tolua_property__has_set bool focus;
  260. tolua_property__is_set bool enabled;
  261. tolua_readonly tolua_property__is_set bool enabledSelf;
  262. tolua_property__is_set bool editable;
  263. tolua_property__is_set bool selected;
  264. tolua_property__is_set bool visible;
  265. tolua_readonly tolua_property__is_set bool visibleEffective;
  266. tolua_property__is_set bool hovering;
  267. tolua_property__is_set bool internal;
  268. tolua_readonly tolua_property__has_set bool colorGradient;
  269. tolua_property__get_set FocusMode focusMode;
  270. tolua_property__get_set unsigned dragDropMode;
  271. tolua_property__get_set String style;
  272. tolua_property__get_set XMLFile* defaultStyle;
  273. tolua_property__get_set LayoutMode layoutMode;
  274. tolua_property__get_set int layoutSpacing;
  275. tolua_property__get_set IntRect& layoutBorder;
  276. tolua_property__get_set Vector2& layoutFlexScale;
  277. tolua_readonly tolua_property__get_set unsigned numChildren;
  278. tolua_property__get_set UIElement* parent;
  279. tolua_readonly tolua_property__get_set UIElement* root;
  280. tolua_readonly tolua_property__get_set Color& derivedColor;
  281. tolua_readonly tolua_property__get_set IntRect combinedScreenRect;
  282. tolua_property__get_set int indent;
  283. tolua_property__get_set int indentSpacing;
  284. tolua_readonly tolua_property__get_set int indentWidth;
  285. tolua_property__get_set TraversalMode traversalMode;
  286. tolua_property__is_set bool elementEventSender;
  287. };
  288. ${
  289. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_new00
  290. static int tolua_UILuaAPI_UIElement_new00(lua_State* tolua_S)
  291. {
  292. return ToluaNewObject<UIElement>(tolua_S);
  293. }
  294. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_new00_local
  295. static int tolua_UILuaAPI_UIElement_new00_local(lua_State* tolua_S)
  296. {
  297. return ToluaNewObjectGC<UIElement>(tolua_S);
  298. }
  299. static bool UIElementLoadXML(UIElement* element, const String& fileName)
  300. {
  301. if (!element)
  302. return false;
  303. File file(element->GetContext());
  304. if (!file.Open(fileName, FILE_READ))
  305. return false;
  306. return element->LoadXML(file);
  307. }
  308. static bool UIElementSaveXML(const UIElement* element, const String& fileName, const String& indentation)
  309. {
  310. if (!element)
  311. return false;
  312. File file(element->GetContext());
  313. if (!file.Open(fileName, FILE_WRITE))
  314. return false;
  315. return element->SaveXML(file, indentation);
  316. }
  317. static const PODVector<UIElement*>& UIElementGetChildrenWithTag(const UIElement* element, const String& tag, bool recursive = false)
  318. {
  319. static PODVector<UIElement*> dest;
  320. element->GetChildrenWithTag(dest, tag, recursive);
  321. return dest;
  322. }
  323. #define GetStyle GetAppliedStyle
  324. #define SetColorAttr SetColor
  325. $}