UIElement.pkg 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 SetIndent(int indent);
  111. void SetIndentSpacing(int indentSpacing);
  112. void UpdateLayout();
  113. void DisableLayoutUpdate();
  114. void EnableLayoutUpdate();
  115. void BringToFront();
  116. UIElement* CreateChild(const String type, const String name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
  117. void AddChild(UIElement* element);
  118. void InsertChild(unsigned index, UIElement* element);
  119. void RemoveChild(UIElement* element, unsigned index = 0);
  120. void RemoveChildAtIndex(unsigned index);
  121. void RemoveAllChildren();
  122. void Remove();
  123. unsigned FindChild(UIElement* element) const;
  124. void SetParent(UIElement* parent, unsigned index = M_MAX_UNSIGNED);
  125. void SetVar(StringHash key, const Variant& value);
  126. void SetInternal(bool enable);
  127. void SetTraversalMode(TraversalMode traversalMode);
  128. void SetElementEventSender(bool flag);
  129. const String GetName() const;
  130. const IntVector2& GetPosition() const;
  131. const IntVector2& GetSize() const;
  132. int GetWidth() const;
  133. int GetHeight() const;
  134. const IntVector2& GetMinSize() const;
  135. int GetMinWidth() const;
  136. int GetMinHeight() const;
  137. const IntVector2& GetMaxSize() const;
  138. int GetMaxWidth() const;
  139. int GetMaxHeight() const;
  140. bool IsFixedSize() const;
  141. bool IsFixedWidth() const;
  142. bool IsFixedHeight() const;
  143. const IntVector2& GetChildOffset() const;
  144. HorizontalAlignment GetHorizontalAlignment() const;
  145. VerticalAlignment GetVerticalAlignment() const;
  146. const IntRect& GetClipBorder() const;
  147. const Color& GetColor(Corner corner) const;
  148. int GetPriority() const;
  149. float GetOpacity() const;
  150. float GetDerivedOpacity() const;
  151. bool GetBringToFront() const;
  152. bool GetBringToBack() const;
  153. bool GetClipChildren() const;
  154. bool GetSortChildren() const;
  155. bool GetUseDerivedOpacity() const;
  156. bool HasFocus() const;
  157. bool IsEnabled() const;
  158. bool IsEnabledSelf() const;
  159. bool IsEditable() const;
  160. bool IsSelected() const;
  161. bool IsVisible() const;
  162. bool IsHovering() const;
  163. bool IsInternal() const;
  164. bool HasColorGradient() const;
  165. FocusMode GetFocusMode() const;
  166. unsigned GetDragDropMode() const;
  167. const String GetAppliedStyle() const;
  168. XMLFile* GetDefaultStyle(bool recursiveUp = true) const;
  169. LayoutMode GetLayoutMode() const;
  170. int GetLayoutSpacing() const;
  171. const IntRect& GetLayoutBorder() const;
  172. unsigned GetNumChildren(bool recursive = false) const;
  173. UIElement* GetChild(const String name, bool recursive = false) const;
  174. UIElement* GetChild(unsigned index) const;
  175. UIElement* GetParent() const;
  176. UIElement* GetRoot() const;
  177. const Color& GetDerivedColor() const;
  178. const Variant& GetVar(StringHash key) const;
  179. const VariantMap& GetVars() const;
  180. IntVector2 ScreenToElement(const IntVector2& screenPosition);
  181. IntVector2 ElementToScreen(const IntVector2& position);
  182. bool IsInside(IntVector2 position, bool isScreen);
  183. bool IsInsideCombined(IntVector2 position, bool isScreen);
  184. IntRect GetCombinedScreenRect();
  185. void SortChildren();
  186. int GetLayoutMinSize() const;
  187. int GetIndent() const;
  188. int GetIndentSpacing() const;
  189. int GetIndentWidth() const;
  190. void SetChildOffset(const IntVector2& offset);
  191. void SetHovering(bool enable);
  192. const Color& GetColorAttr @ GetColor() const;
  193. TraversalMode GetTraversalMode() const;
  194. bool IsElementEventSender() const;
  195. UIElement* GetElementEventSender() const;
  196. tolua_readonly tolua_property__get_set IntVector2& screenPosition;
  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 IntVector2& childOffset;
  212. tolua_property__get_set HorizontalAlignment horizontalAlignment;
  213. tolua_property__get_set VerticalAlignment verticalAlignment;
  214. tolua_property__get_set IntRect clipBorder;
  215. tolua_property__get_set Color& colorAttr @ color;
  216. tolua_property__get_set int priority;
  217. tolua_property__get_set float opacity;
  218. tolua_readonly tolua_property__get_set float derivedOpacity;
  219. tolua_property__get_set bool bringToFront;
  220. tolua_property__get_set bool bringToBack;
  221. tolua_property__get_set bool clipChildren;
  222. tolua_property__get_set bool sortChildren;
  223. tolua_property__get_set bool useDerivedOpacity;
  224. tolua_property__has_set bool focus;
  225. tolua_property__is_set bool enabled;
  226. tolua_readonly tolua_property__is_set bool enabledSelf;
  227. tolua_property__is_set bool editable;
  228. tolua_property__is_set bool selected;
  229. tolua_property__is_set bool visible;
  230. tolua_property__is_set bool hovering;
  231. tolua_property__is_set bool internal;
  232. tolua_readonly tolua_property__has_set bool colorGradient;
  233. tolua_property__get_set FocusMode focusMode;
  234. tolua_property__get_set unsigned dragDropMode;
  235. tolua_property__get_set String style;
  236. tolua_property__get_set XMLFile* defaultStyle;
  237. tolua_property__get_set LayoutMode layoutMode;
  238. tolua_property__get_set int layoutSpacing;
  239. tolua_property__get_set IntRect& layoutBorder;
  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 Color& derivedColor;
  244. tolua_readonly tolua_property__get_set IntRect combinedScreenRect;
  245. tolua_readonly tolua_property__get_set int layoutMinSize;
  246. tolua_property__get_set int indent;
  247. tolua_property__get_set int indentSpacing;
  248. tolua_readonly tolua_property__get_set int indentWidth;
  249. tolua_property__get_set TraversalMode traversalMode;
  250. tolua_property__is_set bool elementEventSender;
  251. };
  252. ${
  253. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_new00
  254. static int tolua_UILuaAPI_UIElement_new00(lua_State* tolua_S)
  255. {
  256. return ToluaNewObject<UIElement>(tolua_S);
  257. }
  258. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_new00_local
  259. static int tolua_UILuaAPI_UIElement_new00_local(lua_State* tolua_S)
  260. {
  261. return ToluaNewObjectGC<UIElement>(tolua_S);
  262. }
  263. static bool UIElementLoadXML(UIElement* element, const String& fileName)
  264. {
  265. if (!element)
  266. return false;
  267. File file(element->GetContext());
  268. if (!file.Open(fileName, FILE_READ))
  269. return false;
  270. return element->LoadXML(file);
  271. }
  272. static bool UIElementSaveXML(const UIElement* element, const String& fileName)
  273. {
  274. if (!element)
  275. return false;
  276. File file(element->GetContext());
  277. if (!file.Open(fileName, FILE_WRITE))
  278. return false;
  279. return element->SaveXML(file);
  280. }
  281. #define GetStyle GetAppliedStyle
  282. #define SetColorAttr SetColor
  283. $}