UIElement.pkg 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. bool LoadXML(Deserializer& source);
  55. bool SaveXML(Serializer& dest) const;
  56. bool FilterAttributes(XMLElement& dest) const;
  57. void SetName(const String& name);
  58. void SetName(const char* name);
  59. void SetPosition(const IntVector2& position);
  60. void SetPosition(int x, int y);
  61. void SetSize(const IntVector2& size);
  62. void SetSize(int width, int height);
  63. void SetWidth(int width);
  64. void SetHeight(int height);
  65. void SetMinSize(const IntVector2& minSize);
  66. void SetMinSize(int width, int height);
  67. void SetMinWidth(int width);
  68. void SetMinHeight(int height);
  69. void SetMaxSize(const IntVector2& maxSize);
  70. void SetMaxSize(int width, int height);
  71. void SetMaxWidth(int width);
  72. void SetMaxHeight(int height);
  73. void SetFixedSize(const IntVector2& size);
  74. void SetFixedSize(int width, int height);
  75. void SetFixedWidth(int width);
  76. void SetFixedHeight(int height);
  77. void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign);
  78. void SetHorizontalAlignment(HorizontalAlignment align);
  79. void SetVerticalAlignment(VerticalAlignment align);
  80. void SetClipBorder(const IntRect& rect);
  81. void SetColor(const Color& color);
  82. void SetColor(Corner corner, const Color& color);
  83. void SetPriority(int priority);
  84. void SetOpacity(float opacity);
  85. void SetBringToFront(bool enable);
  86. void SetBringToBack(bool enable);
  87. void SetClipChildren(bool enable);
  88. void SetSortChildren(bool enable);
  89. void SetUseDerivedOpacity(bool enable);
  90. void SetEnabled(bool enable);
  91. void SetFocus(bool enable);
  92. void SetSelected(bool enable);
  93. void SetVisible(bool enable);
  94. void SetFocusMode(FocusMode mode);
  95. void SetDragDropMode(unsigned mode);
  96. bool SetStyle(const String& styleName, XMLFile* file = 0);
  97. bool SetStyle(const char* styleName, XMLFile* file = 0);
  98. bool SetStyle(const XMLElement& element);
  99. bool SetStyleAuto(XMLFile* file = 0);
  100. void SetDefaultStyle(XMLFile* style);
  101. void SetLayout(LayoutMode mode, int spacing = 0, const IntRect& border = IntRect::ZERO);
  102. void SetLayoutMode(LayoutMode mode);
  103. void SetLayoutSpacing(int spacing);
  104. void SetLayoutBorder(const IntRect& border);
  105. void SetIndent(int indent);
  106. void SetIndentSpacing(int indentSpacing);
  107. void UpdateLayout();
  108. void DisableLayoutUpdate();
  109. void EnableLayoutUpdate();
  110. void BringToFront();
  111. // UIElement* CreateChild(ShortStringHash type, const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
  112. UIElement* CreateChild(const char* type, const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
  113. UIElement* CreateChild(const char* type, const char* name = 0, unsigned index = M_MAX_UNSIGNED);
  114. void AddChild(UIElement* element);
  115. void InsertChild(unsigned index, UIElement* element);
  116. void RemoveChild(UIElement* element, unsigned index = 0);
  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 SetInternal(bool enable);
  123. void SetTraversalMode(TraversalMode traversalMode);
  124. void SetElementEventSender(bool flag);
  125. // template <class T> T* CreateChild(const String& name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
  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. LayoutMode GetLayoutMode() const;
  165. int GetLayoutSpacing() const;
  166. const IntRect& GetLayoutBorder() const;
  167. unsigned GetNumChildren(bool recursive = false) const;
  168. UIElement* GetChild(unsigned index) const;
  169. UIElement* GetChild(const String& name, bool recursive = false) const;
  170. tolua_outside UIElement* UIElementGetChild @ GetChild(const char* name, bool recursive = false) const;
  171. UIElement* GetChild(const ShortStringHash& key, const Variant& value = Variant::EMPTY, bool recursive = false) const;
  172. tolua_outside UIElement* UIElementGetChild2 @ GetChild(const char* key, const Variant& value = Variant::EMPTY, bool recursive = false) const;
  173. UIElement* GetParent() const;
  174. UIElement* GetRoot() const;
  175. const Color& GetDerivedColor() const;
  176. IntVector2 ScreenToElement(const IntVector2& screenPosition);
  177. IntVector2 ElementToScreen(const IntVector2& position);
  178. bool IsInside(IntVector2 position, bool isScreen);
  179. bool IsInsideCombined(IntVector2 position, bool isScreen);
  180. IntRect GetCombinedScreenRect();
  181. void SortChildren();
  182. int GetLayoutMinSize() const;
  183. int GetIndent() const;
  184. int GetIndentSpacing() const;
  185. int GetIndentWidth() const;
  186. void SetChildOffset(const IntVector2& offset);
  187. void SetHovering(bool enable);
  188. const Color& GetColorAttr() const;
  189. TraversalMode GetTraversalMode() const;
  190. bool IsElementEventSender() const;
  191. UIElement* GetElementEventSender() const;
  192. tolua_readonly tolua_property__get_set IntVector2& screenPosition;
  193. tolua_property__get_set String& name;
  194. tolua_property__get_set IntVector2& position;
  195. tolua_property__get_set IntVector2 size;
  196. tolua_property__get_set int width;
  197. tolua_property__get_set int height;
  198. tolua_property__get_set IntVector2 minSize;
  199. tolua_property__get_set int minWidth;
  200. tolua_property__get_set int minHeight;
  201. tolua_property__get_set IntVector2 maxSize;
  202. tolua_property__get_set int maxWidth;
  203. tolua_property__get_set int maxHeight;
  204. tolua_readonly tolua_property__is_set bool fixedSize;
  205. tolua_readonly tolua_property__is_set bool fixedWidth;
  206. tolua_readonly tolua_property__is_set bool fixedHeight;
  207. tolua_property__get_set IntVector2& childOffset;
  208. tolua_property__get_set HorizontalAlignment horizontalAlignment;
  209. tolua_property__get_set VerticalAlignment verticalAlignment;
  210. tolua_property__get_set IntRect clipBorder;
  211. tolua_property__get_set Color& color; // Write only property.
  212. tolua_property__get_set int priority;
  213. tolua_property__get_set float opacity;
  214. tolua_readonly tolua_property__get_set float derivedOpacity;
  215. tolua_property__get_set bool bringToFront;
  216. tolua_property__get_set bool bringToBack;
  217. tolua_property__get_set bool clipChildren;
  218. tolua_property__get_set bool sortChildren;
  219. tolua_property__get_set bool useDerivedOpacity;
  220. tolua_property__has_set bool focus;
  221. tolua_property__is_set bool enabled;
  222. tolua_property__is_set bool selected;
  223. tolua_property__is_set bool visible;
  224. tolua_property__is_set bool hovering;
  225. tolua_property__is_set bool internal;
  226. tolua_readonly tolua_property__has_set bool colorGradient;
  227. tolua_property__get_set FocusMode focusMode;
  228. tolua_property__get_set unsigned dragDropMode;
  229. tolua_property__get_set String& style;
  230. tolua_property__get_set XMLFile* defaultStyle;
  231. tolua_property__get_set LayoutMode layoutMode;
  232. tolua_property__get_set int layoutSpacing;
  233. tolua_property__get_set IntRect& layoutBorder;
  234. tolua_readonly tolua_property__get_set unsigned numChildren;
  235. tolua_property__get_set UIElement* parent;
  236. tolua_readonly tolua_property__get_set UIElement* root;
  237. tolua_readonly tolua_property__get_set Color& derivedColor;
  238. tolua_readonly tolua_property__get_set IntRect combinedScreenRect;
  239. tolua_readonly tolua_property__get_set int layoutMinSize;
  240. tolua_property__get_set int indent;
  241. tolua_property__get_set int indentSpacing;
  242. tolua_readonly tolua_property__get_set int indentWidth;
  243. tolua_property__get_set Color& colorAttr;
  244. tolua_property__get_set TraversalMode traversalMode;
  245. tolua_property__is_set bool elementEventSender;
  246. };
  247. ${
  248. // Disable generated CreateChild function.
  249. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_CreateChild00
  250. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_CreateChild01
  251. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_CreateChild02
  252. static int tolua_UILuaAPI_UIElement_CreateChild00(lua_State* tolua_S)
  253. {
  254. #ifndef TOLUA_RELEASE
  255. tolua_Error tolua_err;
  256. if (
  257. !tolua_isusertype(tolua_S,1,"UIElement",0,&tolua_err) ||
  258. !tolua_isstring(tolua_S,2,0,&tolua_err) ||
  259. !tolua_isnoobj(tolua_S,3,&tolua_err)
  260. )
  261. goto tolua_lerror;
  262. else
  263. #endif
  264. {
  265. UIElement* self = (UIElement*) tolua_tousertype(tolua_S,1,0);
  266. const char* type = ((const char*) tolua_tostring(tolua_S,2,0));
  267. #ifndef TOLUA_RELEASE
  268. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateChild'", NULL);
  269. #endif
  270. {
  271. UIElement* tolua_ret = (UIElement*) self->CreateChild(type);
  272. tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
  273. }
  274. }
  275. return 1;
  276. #ifndef TOLUA_RELEASE
  277. tolua_lerror:
  278. tolua_error(tolua_S,"#ferror in function 'CreateChild'.",&tolua_err);
  279. return 0;
  280. #endif
  281. }
  282. static int tolua_UILuaAPI_UIElement_CreateChild01(lua_State* tolua_S)
  283. {
  284. tolua_Error tolua_err;
  285. if (
  286. !tolua_isusertype(tolua_S,1,"UIElement",0,&tolua_err) ||
  287. !tolua_isstring(tolua_S,2,0,&tolua_err) ||
  288. (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"const String",0,&tolua_err)) ||
  289. !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
  290. !tolua_isnoobj(tolua_S,5,&tolua_err)
  291. )
  292. goto tolua_lerror;
  293. else
  294. {
  295. UIElement* self = (UIElement*) tolua_tousertype(tolua_S,1,0);
  296. const char* type = ((const char*) tolua_tostring(tolua_S,2,0));
  297. const String* name = ((const String*) tolua_tousertype(tolua_S,3,0));
  298. unsigned index = ((unsigned) tolua_tonumber(tolua_S,4,M_MAX_UNSIGNED));
  299. #ifndef TOLUA_RELEASE
  300. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateChild'", NULL);
  301. #endif
  302. {
  303. UIElement* tolua_ret = (UIElement*) self->CreateChild(type,*name,index);
  304. tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
  305. }
  306. }
  307. return 1;
  308. tolua_lerror:
  309. return tolua_UILuaAPI_UIElement_CreateChild00(tolua_S);
  310. }
  311. static int tolua_UILuaAPI_UIElement_CreateChild02(lua_State* tolua_S)
  312. {
  313. tolua_Error tolua_err;
  314. if (
  315. !tolua_isusertype(tolua_S,1,"UIElement",0,&tolua_err) ||
  316. !tolua_isstring(tolua_S,2,0,&tolua_err) ||
  317. !tolua_isstring(tolua_S,3,1,&tolua_err) ||
  318. !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
  319. !tolua_isnoobj(tolua_S,5,&tolua_err)
  320. )
  321. goto tolua_lerror;
  322. else
  323. {
  324. UIElement* self = (UIElement*) tolua_tousertype(tolua_S,1,0);
  325. const char* type = ((const char*) tolua_tostring(tolua_S,2,0));
  326. const char* name = ((const char*) tolua_tostring(tolua_S,3,0));
  327. unsigned index = ((unsigned) tolua_tonumber(tolua_S,4,M_MAX_UNSIGNED));
  328. #ifndef TOLUA_RELEASE
  329. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CreateChild'", NULL);
  330. #endif
  331. {
  332. UIElement* tolua_ret = (UIElement*) self->CreateChild(type,name,index);
  333. tolua_pushusertype(tolua_S,(void*)tolua_ret,type);
  334. }
  335. }
  336. return 1;
  337. tolua_lerror:
  338. return tolua_UILuaAPI_UIElement_CreateChild01(tolua_S);
  339. }
  340. static UIElement* UIElementGetChild(const UIElement* element, const char* name, bool recursive = false)
  341. {
  342. return element->GetChild(String(name), recursive);
  343. }
  344. static UIElement* UIElementGetChild2(const UIElement* element, const char* key, const Variant& value = Variant::EMPTY, bool recursive = false)
  345. {
  346. return element->GetChild(ShortStringHash(key), value, recursive);
  347. }
  348. #define GetStyle GetAppliedStyle
  349. #define TOLUA_DISABLE_tolua_get_UIElement_color_ref
  350. #define tolua_get_UIElement_color_ref NULL
  351. $}