UIElement.pkg 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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 SetPosition(const IntVector2& position);
  59. void SetPosition(int x, int y);
  60. void SetSize(const IntVector2& size);
  61. void SetSize(int width, int height);
  62. void SetWidth(int width);
  63. void SetHeight(int height);
  64. void SetMinSize(const IntVector2& minSize);
  65. void SetMinSize(int width, int height);
  66. void SetMinWidth(int width);
  67. void SetMinHeight(int height);
  68. void SetMaxSize(const IntVector2& maxSize);
  69. void SetMaxSize(int width, int height);
  70. void SetMaxWidth(int width);
  71. void SetMaxHeight(int height);
  72. void SetFixedSize(const IntVector2& size);
  73. void SetFixedSize(int width, int height);
  74. void SetFixedWidth(int width);
  75. void SetFixedHeight(int height);
  76. void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign);
  77. void SetHorizontalAlignment(HorizontalAlignment align);
  78. void SetVerticalAlignment(VerticalAlignment align);
  79. void SetClipBorder(const IntRect& rect);
  80. void SetColor(const Color& color);
  81. void SetColor(Corner corner, const Color& color);
  82. void SetPriority(int priority);
  83. void SetOpacity(float opacity);
  84. void SetBringToFront(bool enable);
  85. void SetBringToBack(bool enable);
  86. void SetClipChildren(bool enable);
  87. void SetSortChildren(bool enable);
  88. void SetUseDerivedOpacity(bool enable);
  89. void SetEnabled(bool enable);
  90. void SetEditable(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 XMLElement& element);
  98. bool SetStyleAuto(XMLFile* file = 0);
  99. void SetDefaultStyle(XMLFile* style);
  100. void SetLayout(LayoutMode mode, int spacing = 0, const IntRect& border = IntRect::ZERO);
  101. void SetLayoutMode(LayoutMode mode);
  102. void SetLayoutSpacing(int spacing);
  103. void SetLayoutBorder(const IntRect& border);
  104. void SetIndent(int indent);
  105. void SetIndentSpacing(int indentSpacing);
  106. void UpdateLayout();
  107. void DisableLayoutUpdate();
  108. void EnableLayoutUpdate();
  109. void BringToFront();
  110. UIElement* CreateChild(const String type, const String name = String::EMPTY, unsigned index = M_MAX_UNSIGNED);
  111. void AddChild(UIElement* element);
  112. void InsertChild(unsigned index, UIElement* element);
  113. void RemoveChild(UIElement* element, unsigned index = 0);
  114. void RemoveChildAtIndex @ RemoveChild(unsigned index);
  115. void RemoveAllChildren();
  116. void Remove();
  117. unsigned FindChild(UIElement* element) const;
  118. void SetParent(UIElement* parent, unsigned index = M_MAX_UNSIGNED);
  119. void SetVar(ShortStringHash key, const Variant& value);
  120. void SetInternal(bool enable);
  121. void SetTraversalMode(TraversalMode traversalMode);
  122. void SetElementEventSender(bool flag);
  123. const String GetName() const;
  124. const IntVector2& GetPosition() const;
  125. const IntVector2& GetSize() const;
  126. int GetWidth() const;
  127. int GetHeight() const;
  128. const IntVector2& GetMinSize() const;
  129. int GetMinWidth() const;
  130. int GetMinHeight() const;
  131. const IntVector2& GetMaxSize() const;
  132. int GetMaxWidth() const;
  133. int GetMaxHeight() const;
  134. bool IsFixedSize() const;
  135. bool IsFixedWidth() const;
  136. bool IsFixedHeight() const;
  137. const IntVector2& GetChildOffset() const;
  138. HorizontalAlignment GetHorizontalAlignment() const;
  139. VerticalAlignment GetVerticalAlignment() const;
  140. const IntRect& GetClipBorder() const;
  141. const Color& GetColor(Corner corner) const;
  142. int GetPriority() const;
  143. float GetOpacity() const;
  144. float GetDerivedOpacity() const;
  145. bool GetBringToFront() const;
  146. bool GetBringToBack() const;
  147. bool GetClipChildren() const;
  148. bool GetSortChildren() const;
  149. bool GetUseDerivedOpacity() const;
  150. bool HasFocus() const;
  151. bool IsEnabled() const;
  152. bool IsEditable() const;
  153. bool IsSelected() const;
  154. bool IsVisible() const;
  155. bool IsHovering() const;
  156. bool IsInternal() const;
  157. bool HasColorGradient() const;
  158. FocusMode GetFocusMode() const;
  159. unsigned GetDragDropMode() const;
  160. const String GetAppliedStyle() const;
  161. XMLFile* GetDefaultStyle(bool recursiveUp = true) const;
  162. LayoutMode GetLayoutMode() const;
  163. int GetLayoutSpacing() const;
  164. const IntRect& GetLayoutBorder() const;
  165. unsigned GetNumChildren(bool recursive = false) const;
  166. UIElement* GetChild(unsigned index) const;
  167. UIElement* GetChild(const String name, bool recursive = false) const;
  168. UIElement* GetParent() const;
  169. UIElement* GetRoot() const;
  170. const Color& GetDerivedColor() const;
  171. const Variant& GetVar(ShortStringHash key) const;
  172. const VariantMap& GetVars() const;
  173. IntVector2 ScreenToElement(const IntVector2& screenPosition);
  174. IntVector2 ElementToScreen(const IntVector2& position);
  175. bool IsInside(IntVector2 position, bool isScreen);
  176. bool IsInsideCombined(IntVector2 position, bool isScreen);
  177. IntRect GetCombinedScreenRect();
  178. void SortChildren();
  179. int GetLayoutMinSize() const;
  180. int GetIndent() const;
  181. int GetIndentSpacing() const;
  182. int GetIndentWidth() const;
  183. void SetChildOffset(const IntVector2& offset);
  184. void SetHovering(bool enable);
  185. const Color& GetColorAttr() const;
  186. TraversalMode GetTraversalMode() const;
  187. bool IsElementEventSender() const;
  188. UIElement* GetElementEventSender() const;
  189. tolua_readonly tolua_property__get_set IntVector2& screenPosition;
  190. tolua_property__get_set String& name;
  191. tolua_property__get_set IntVector2& position;
  192. tolua_property__get_set IntVector2 size;
  193. tolua_property__get_set int width;
  194. tolua_property__get_set int height;
  195. tolua_property__get_set IntVector2 minSize;
  196. tolua_property__get_set int minWidth;
  197. tolua_property__get_set int minHeight;
  198. tolua_property__get_set IntVector2 maxSize;
  199. tolua_property__get_set int maxWidth;
  200. tolua_property__get_set int maxHeight;
  201. tolua_readonly tolua_property__is_set bool fixedSize;
  202. tolua_readonly tolua_property__is_set bool fixedWidth;
  203. tolua_readonly tolua_property__is_set bool fixedHeight;
  204. tolua_property__get_set IntVector2& childOffset;
  205. tolua_property__get_set HorizontalAlignment horizontalAlignment;
  206. tolua_property__get_set VerticalAlignment verticalAlignment;
  207. tolua_property__get_set IntRect clipBorder;
  208. tolua_property__get_set Color& color; // Write only property.
  209. tolua_property__get_set int priority;
  210. tolua_property__get_set float opacity;
  211. tolua_readonly tolua_property__get_set float derivedOpacity;
  212. tolua_property__get_set bool bringToFront;
  213. tolua_property__get_set bool bringToBack;
  214. tolua_property__get_set bool clipChildren;
  215. tolua_property__get_set bool sortChildren;
  216. tolua_property__get_set bool useDerivedOpacity;
  217. tolua_property__has_set bool focus;
  218. tolua_property__is_set bool enabled;
  219. tolua_property__is_set bool editable;
  220. tolua_property__is_set bool selected;
  221. tolua_property__is_set bool visible;
  222. tolua_property__is_set bool hovering;
  223. tolua_property__is_set bool internal;
  224. tolua_readonly tolua_property__has_set bool colorGradient;
  225. tolua_property__get_set FocusMode focusMode;
  226. tolua_property__get_set unsigned dragDropMode;
  227. tolua_property__get_set String& style;
  228. tolua_property__get_set XMLFile* defaultStyle;
  229. tolua_property__get_set LayoutMode layoutMode;
  230. tolua_property__get_set int layoutSpacing;
  231. tolua_property__get_set IntRect& layoutBorder;
  232. tolua_readonly tolua_property__get_set unsigned numChildren;
  233. tolua_property__get_set UIElement* parent;
  234. tolua_readonly tolua_property__get_set UIElement* root;
  235. tolua_readonly tolua_property__get_set Color& derivedColor;
  236. tolua_readonly tolua_property__get_set IntRect combinedScreenRect;
  237. tolua_readonly tolua_property__get_set int layoutMinSize;
  238. tolua_property__get_set int indent;
  239. tolua_property__get_set int indentSpacing;
  240. tolua_readonly tolua_property__get_set int indentWidth;
  241. tolua_property__get_set Color& colorAttr;
  242. tolua_property__get_set TraversalMode traversalMode;
  243. tolua_property__is_set bool elementEventSender;
  244. };
  245. ${
  246. // Disable generated CreateChild function.
  247. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_CreateChild00
  248. static int tolua_UILuaAPI_UIElement_CreateChild00(lua_State* tolua_S)
  249. {
  250. #ifndef TOLUA_RELEASE
  251. tolua_Error tolua_err;
  252. if (
  253. !tolua_isusertype(tolua_S,1,"UIElement",0,&tolua_err) ||
  254. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  255. !tolua_isurho3dstring(tolua_S,3,1,&tolua_err) ||
  256. !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
  257. !tolua_isnoobj(tolua_S,5,&tolua_err)
  258. )
  259. goto tolua_lerror;
  260. else
  261. #endif
  262. {
  263. UIElement* self = (UIElement*) tolua_tousertype(tolua_S,1,0);
  264. const String type = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  265. const String name = ((const String) tolua_tourho3dstring(tolua_S,3,String::EMPTY));
  266. unsigned index = ((unsigned) tolua_tonumber(tolua_S,4,M_MAX_UNSIGNED));
  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,name,index);
  272. tolua_pushusertype(tolua_S,(void*)tolua_ret,type.CString());
  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. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_GetChild00
  283. static int tolua_UILuaAPI_UIElement_GetChild00(lua_State* tolua_S)
  284. {
  285. #ifndef TOLUA_RELEASE
  286. tolua_Error tolua_err;
  287. if (
  288. !tolua_isusertype(tolua_S,1,"const UIElement",0,&tolua_err) ||
  289. !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
  290. !tolua_isnoobj(tolua_S,3,&tolua_err)
  291. )
  292. goto tolua_lerror;
  293. else
  294. #endif
  295. {
  296. const UIElement* self = (const UIElement*) tolua_tousertype(tolua_S,1,0);
  297. unsigned index = ((unsigned) tolua_tonumber(tolua_S,2,0));
  298. #ifndef TOLUA_RELEASE
  299. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetChild'", NULL);
  300. #endif
  301. {
  302. UIElement* tolua_ret = (UIElement*) self->GetChild(index);
  303. if (tolua_ret)
  304. tolua_pushusertype(tolua_S,(void*)tolua_ret,tolua_ret->GetTypeName().CString());
  305. else
  306. lua_pushnil(tolua_S);
  307. }
  308. }
  309. return 1;
  310. #ifndef TOLUA_RELEASE
  311. tolua_lerror:
  312. tolua_error(tolua_S,"#ferror in function 'GetChild'.",&tolua_err);
  313. return 0;
  314. #endif
  315. }
  316. #define TOLUA_DISABLE_tolua_UILuaAPI_UIElement_GetChild01
  317. static int tolua_UILuaAPI_UIElement_GetChild01(lua_State* tolua_S)
  318. {
  319. tolua_Error tolua_err;
  320. if (
  321. !tolua_isusertype(tolua_S,1,"const UIElement",0,&tolua_err) ||
  322. !tolua_isurho3dstring(tolua_S,2,0,&tolua_err) ||
  323. !tolua_isboolean(tolua_S,3,1,&tolua_err) ||
  324. !tolua_isnoobj(tolua_S,4,&tolua_err)
  325. )
  326. goto tolua_lerror;
  327. else
  328. {
  329. const UIElement* self = (const UIElement*) tolua_tousertype(tolua_S,1,0);
  330. const String name = ((const String) tolua_tourho3dstring(tolua_S,2,0));
  331. bool recursive = ((bool) tolua_toboolean(tolua_S,3,false));
  332. #ifndef TOLUA_RELEASE
  333. if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GetChild'", NULL);
  334. #endif
  335. {
  336. UIElement* tolua_ret = (UIElement*) self->GetChild(name,recursive);
  337. if (tolua_ret)
  338. tolua_pushusertype(tolua_S,(void*)tolua_ret,tolua_ret->GetTypeName().CString());
  339. else
  340. lua_pushnil(tolua_S);
  341. }
  342. }
  343. return 1;
  344. tolua_lerror:
  345. return tolua_UILuaAPI_UIElement_GetChild00(tolua_S);
  346. }
  347. #define GetStyle GetAppliedStyle
  348. #define TOLUA_DISABLE_tolua_get_UIElement_color_ref
  349. #define tolua_get_UIElement_color_ref NULL
  350. $}