UIElement.pkg 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. $#include "File.h"
  2. $#include "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;
  57. tolua_outside bool UIElementLoadXML @ LoadXML(const String fileName);
  58. tolua_outside bool UIElementSaveXML @ SaveXML(const String fileName) 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. const String GetName() const;
  131. const IntVector2& GetPosition() const;
  132. const IntVector2& GetSize() const;
  133. int GetWidth() const;
  134. int GetHeight() const;
  135. const IntVector2& GetMinSize() const;
  136. int GetMinWidth() const;
  137. int GetMinHeight() const;
  138. const IntVector2& GetMaxSize() const;
  139. int GetMaxWidth() const;
  140. int GetMaxHeight() const;
  141. bool IsFixedSize() const;
  142. bool IsFixedWidth() const;
  143. bool IsFixedHeight() const;
  144. const IntVector2& GetChildOffset() const;
  145. HorizontalAlignment GetHorizontalAlignment() const;
  146. VerticalAlignment GetVerticalAlignment() const;
  147. const IntRect& GetClipBorder() const;
  148. const Color& GetColor(Corner corner) const;
  149. int GetPriority() const;
  150. float GetOpacity() const;
  151. float GetDerivedOpacity() const;
  152. bool GetBringToFront() const;
  153. bool GetBringToBack() const;
  154. bool GetClipChildren() const;
  155. bool GetSortChildren() const;
  156. bool GetUseDerivedOpacity() const;
  157. bool HasFocus() const;
  158. bool IsEnabled() const;
  159. bool IsEnabledSelf() const;
  160. bool IsEditable() const;
  161. bool IsSelected() const;
  162. bool IsVisible() const;
  163. bool IsHovering() const;
  164. bool IsInternal() const;
  165. bool HasColorGradient() const;
  166. FocusMode GetFocusMode() const;
  167. unsigned GetDragDropMode() const;
  168. const String GetAppliedStyle() const;
  169. XMLFile* GetDefaultStyle(bool recursiveUp = true) const;
  170. LayoutMode GetLayoutMode() const;
  171. int GetLayoutSpacing() const;
  172. const IntRect& GetLayoutBorder() const;
  173. const Vector2& GetLayoutFlexScale() const;
  174. unsigned GetNumChildren(bool recursive = false) const;
  175. int GetDragButtonCombo() const;
  176. unsigned GetDragButtonCount() const;
  177. UIElement* GetChild(const String name, bool recursive = false) const;
  178. UIElement* GetChild(unsigned index) const;
  179. UIElement* GetParent() const;
  180. UIElement* GetRoot() const;
  181. const Color& GetDerivedColor() const;
  182. const Variant& GetVar(StringHash key) const;
  183. const VariantMap& GetVars() const;
  184. IntVector2 ScreenToElement(const IntVector2& screenPosition);
  185. IntVector2 ElementToScreen(const IntVector2& position);
  186. bool IsInside(IntVector2 position, bool isScreen);
  187. bool IsInsideCombined(IntVector2 position, bool isScreen);
  188. IntRect GetCombinedScreenRect();
  189. void SortChildren();
  190. int GetIndent() const;
  191. int GetIndentSpacing() const;
  192. int GetIndentWidth() const;
  193. void SetChildOffset(const IntVector2& offset);
  194. void SetHovering(bool enable);
  195. const Color& GetColorAttr @ GetColor() const;
  196. TraversalMode GetTraversalMode() const;
  197. bool IsElementEventSender() const;
  198. UIElement* GetElementEventSender() const;
  199. tolua_readonly tolua_property__get_set IntVector2& screenPosition;
  200. tolua_property__get_set String name;
  201. tolua_property__get_set IntVector2& position;
  202. tolua_property__get_set IntVector2 size;
  203. tolua_property__get_set int width;
  204. tolua_property__get_set int height;
  205. tolua_property__get_set IntVector2 minSize;
  206. tolua_property__get_set int minWidth;
  207. tolua_property__get_set int minHeight;
  208. tolua_property__get_set IntVector2 maxSize;
  209. tolua_property__get_set int maxWidth;
  210. tolua_property__get_set int maxHeight;
  211. tolua_readonly tolua_property__is_set bool fixedSize;
  212. tolua_readonly tolua_property__is_set bool fixedWidth;
  213. tolua_readonly tolua_property__is_set bool fixedHeight;
  214. tolua_property__get_set IntVector2& childOffset;
  215. tolua_property__get_set HorizontalAlignment horizontalAlignment;
  216. tolua_property__get_set VerticalAlignment verticalAlignment;
  217. tolua_property__get_set IntRect clipBorder;
  218. tolua_property__get_set Color& colorAttr @ color;
  219. tolua_property__get_set int priority;
  220. tolua_property__get_set float opacity;
  221. tolua_readonly tolua_property__get_set float derivedOpacity;
  222. tolua_property__get_set bool bringToFront;
  223. tolua_property__get_set bool bringToBack;
  224. tolua_property__get_set bool clipChildren;
  225. tolua_property__get_set bool sortChildren;
  226. tolua_property__get_set bool useDerivedOpacity;
  227. tolua_property__has_set bool focus;
  228. tolua_property__is_set bool enabled;
  229. tolua_readonly tolua_property__is_set bool enabledSelf;
  230. tolua_property__is_set bool editable;
  231. tolua_property__is_set bool selected;
  232. tolua_property__is_set bool visible;
  233. tolua_property__is_set bool hovering;
  234. tolua_property__is_set bool internal;
  235. tolua_readonly tolua_property__has_set bool colorGradient;
  236. tolua_property__get_set FocusMode focusMode;
  237. tolua_property__get_set unsigned dragDropMode;
  238. tolua_property__get_set String style;
  239. tolua_property__get_set XMLFile* defaultStyle;
  240. tolua_property__get_set LayoutMode layoutMode;
  241. tolua_property__get_set int layoutSpacing;
  242. tolua_property__get_set IntRect& layoutBorder;
  243. tolua_property__get_set Vector2& layoutFlexScale;
  244. tolua_readonly tolua_property__get_set unsigned numChildren;
  245. tolua_property__get_set UIElement* parent;
  246. tolua_readonly tolua_property__get_set UIElement* root;
  247. tolua_readonly tolua_property__get_set Color& derivedColor;
  248. tolua_readonly tolua_property__get_set IntRect combinedScreenRect;
  249. tolua_property__get_set int indent;
  250. tolua_property__get_set int indentSpacing;
  251. tolua_readonly tolua_property__get_set int indentWidth;
  252. tolua_property__get_set TraversalMode traversalMode;
  253. tolua_property__is_set bool elementEventSender;
  254. };
  255. ${
  256. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_new00
  257. static int tolua_UILuaAPI_UIElement_new00(lua_State* tolua_S)
  258. {
  259. return ToluaNewObject<UIElement>(tolua_S);
  260. }
  261. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_new00_local
  262. static int tolua_UILuaAPI_UIElement_new00_local(lua_State* tolua_S)
  263. {
  264. return ToluaNewObjectGC<UIElement>(tolua_S);
  265. }
  266. static bool UIElementLoadXML(UIElement* element, const String& fileName)
  267. {
  268. if (!element)
  269. return false;
  270. File file(element->GetContext());
  271. if (!file.Open(fileName, FILE_READ))
  272. return false;
  273. return element->LoadXML(file);
  274. }
  275. static bool UIElementSaveXML(const UIElement* element, const String& fileName)
  276. {
  277. if (!element)
  278. return false;
  279. File file(element->GetContext());
  280. if (!file.Open(fileName, FILE_WRITE))
  281. return false;
  282. return element->SaveXML(file);
  283. }
  284. #define GetStyle GetAppliedStyle
  285. #define SetColorAttr SetColor
  286. $}