UIElement.pkg 12 KB

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