Manual_UI.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "../UI/Font.h"
  5. #include "../UI/ListView.h"
  6. #include "../UI/DropDownList.h"
  7. #include "../UI/FileSelector.h"
  8. #include "../UI/UI.h"
  9. namespace Urho3D
  10. {
  11. // bool Font::SaveXML(Serializer& dest, int pointSize, bool usedGlyphs = false, const String& indentation = "\t") | File: ../UI/Font.h
  12. template <class T> bool Font_SaveXML_File(File* file, int pointSize, bool usedGlyphs, const String& indentation, T* ptr)
  13. {
  14. return ptr->SaveXML(*file, pointSize, usedGlyphs, indentation);
  15. }
  16. // bool Font::SaveXML(Serializer& dest, int pointSize, bool usedGlyphs = false, const String& indentation = "\t") | File: ../UI/Font.h
  17. template <class T> bool Font_SaveXML_VectorBuffer(VectorBuffer& buffer, int pointSize, bool usedGlyphs, const String& indentation, T* ptr)
  18. {
  19. return ptr->SaveXML(buffer, pointSize, usedGlyphs, indentation);
  20. }
  21. // bool Font::SaveXML(Serializer& dest, int pointSize, bool usedGlyphs = false, const String& indentation = "\t") | File: ../UI/Font.h
  22. template <class T> bool Font_SaveXML_FileName(const String& fileName, int pointSize, bool usedGlyphs, const String& indentation, T* ptr)
  23. {
  24. if (fileName.Empty())
  25. return false;
  26. File file(ptr->GetContext(), fileName, FILE_WRITE);
  27. return ptr->SaveXML(file, pointSize, usedGlyphs, indentation);
  28. }
  29. #define REGISTER_MEMBERS_MANUAL_PART_Font() \
  30. /* bool Font::SaveXML(Serializer& dest, int pointSize, bool usedGlyphs = false, const String& indentation = "\t") | File: ../UI/Font.h */ \
  31. engine->RegisterObjectMethod(className, "bool SaveXML(File@+, int, bool usedGlyphs = false, const String&in indentation = \"\t\")", AS_FUNCTION_OBJLAST(Font_SaveXML_File<T>), AS_CALL_CDECL_OBJLAST); \
  32. engine->RegisterObjectMethod(className, "bool SaveXML(VectorBuffer&, int, bool usedGlyphs = false, const String&in indentation = \"\t\")", AS_FUNCTION_OBJLAST(Font_SaveXML_VectorBuffer<T>), AS_CALL_CDECL_OBJLAST); \
  33. engine->RegisterObjectMethod(className, "bool SaveXML(const String&in, int, bool usedGlyphs = false, const String&in indentation = \"\t\")", AS_FUNCTION_OBJLAST(Font_SaveXML_FileName<T>), AS_CALL_CDECL_OBJLAST);
  34. // ========================================================================================
  35. #define REGISTER_CLASS_MANUAL_PART_UIElement() \
  36. RegisterNamedObjectConstructor<UIElement>(engine, "UIElement");
  37. // bool UIElement::LoadXML(Deserializer& source) | File: ../UI/UIElement.h
  38. template <class T> bool UIElement_LoadXML_File(File* file, T* ptr)
  39. {
  40. return file && ptr->LoadXML(*file);
  41. }
  42. // bool UIElement::LoadXML(Deserializer& source) | File: ../UI/UIElement.h
  43. template <class T> bool UIElement_LoadXML_VectorBuffer(VectorBuffer& buffer, T* ptr)
  44. {
  45. return ptr->LoadXML(buffer);
  46. }
  47. // bool UIElement::LoadXML(const XMLElement& source) override | File: ../UI/UIElement.h
  48. template <class T> bool UIElement_LoadXML_XMLFile(XMLFile* file, XMLFile* styleFile, T* ptr)
  49. {
  50. if (file)
  51. {
  52. XMLElement rootElem = file->GetRoot("element");
  53. return rootElem && ptr->LoadXML(rootElem, styleFile);
  54. }
  55. else
  56. return false;
  57. }
  58. // virtual UIElement* UIElement::LoadChildXML(const XMLElement& childElem, XMLFile* styleFile) | File: ../UI/UIElement.h
  59. template <class T> UIElement* UIElement_LoadChildXML(XMLFile* file, XMLFile* styleFile, T* ptr)
  60. {
  61. if (!file)
  62. return nullptr;
  63. XMLElement rootElem = file->GetRoot("element");
  64. if (rootElem)
  65. return ptr->LoadChildXML(rootElem, styleFile);
  66. else
  67. return nullptr;
  68. }
  69. // bool UIElement::SaveXML(Serializer& dest, const String& indentation = "\t") const | File: ../UI/UIElement.h
  70. template <class T> bool UIElement_SaveXML_File(File* file, const String& indentation, T* ptr)
  71. {
  72. return file && ptr->SaveXML(*file, indentation);
  73. }
  74. // bool UIElement::SaveXML(Serializer& dest, const String& indentation = "\t") const | File: ../UI/UIElement.h
  75. template <class T> bool UIElement_SaveXML_VectorBuffer(VectorBuffer& buffer, const String& indentation, T* ptr)
  76. {
  77. return ptr->SaveXML(buffer, indentation);
  78. }
  79. // void UIElement::RemoveChildAtIndex(unsigned index) | File: ../UI/UIElement.h
  80. template <class T> void UIElement_RemoveChild(unsigned index, T* ptr)
  81. {
  82. ptr->RemoveChildAtIndex(index);
  83. }
  84. // bool UIElement::SetStyle(const String& styleName, XMLFile* file = nullptr) | File: ../UI/UIElement.h
  85. template <class T> void UIElement_SetStyle(const String& styleName, T* ptr)
  86. {
  87. if (styleName.Empty())
  88. ptr->SetStyleAuto();
  89. else
  90. ptr->SetStyle(styleName);
  91. }
  92. // unsigned UIElement::GetNumChildren(bool recursive = false) const | File: ../UI/UIElement.h
  93. template <class T> unsigned UIElement_GetNumChildren_NonRecursive(T* ptr)
  94. {
  95. return ptr->GetNumChildren(false);
  96. }
  97. // unsigned UIElement::GetNumChildren(bool recursive = false) const | File: ../UI/UIElement.h
  98. template <class T> unsigned UIElement_GetNumChildren_Recursive(T* ptr)
  99. {
  100. return ptr->GetNumChildren(true);
  101. }
  102. // void UIElement::SetParent(UIElement* parent, i32 index = ENDPOS) | File: ../UI/UIElement.h
  103. template <class T> void UIElement_SetParent(UIElement* parent, T* ptr)
  104. {
  105. ptr->SetParent(parent);
  106. }
  107. // XMLFile* UIElement::GetDefaultStyle(bool recursiveUp = true) const | File: ../UI/UIElement.h
  108. template <class T> XMLFile* UIElement_GetDefaultStyle(T* ptr)
  109. {
  110. return ptr->GetDefaultStyle();
  111. }
  112. // const VariantMap& UIElement::GetVars() const | File: ../UI/UIElement.h
  113. template <class T> VariantMap& UIElement_GetVars(T* ptr)
  114. {
  115. return const_cast<VariantMap&>(ptr->GetVars());
  116. }
  117. #define REGISTER_MEMBERS_MANUAL_PART_UIElement() \
  118. /* bool UIElement::LoadXML(Deserializer& source) | File: ../UI/UIElement.h */ \
  119. engine->RegisterObjectMethod(className, "bool LoadXML(File@+)", AS_FUNCTION_OBJLAST(UIElement_LoadXML_File<T>), AS_CALL_CDECL_OBJLAST); \
  120. engine->RegisterObjectMethod(className, "bool LoadXML(VectorBuffer&)", AS_FUNCTION_OBJLAST(UIElement_LoadXML_VectorBuffer<T>), AS_CALL_CDECL_OBJLAST); \
  121. \
  122. /* bool UIElement::LoadXML(const XMLElement& source) override | File: ../UI/UIElement.h */ \
  123. engine->RegisterObjectMethod(className, "bool LoadXML(XMLFile@+, XMLFile@+)", AS_FUNCTION_OBJLAST(UIElement_LoadXML_XMLFile<T>), AS_CALL_CDECL_OBJLAST); \
  124. \
  125. /* virtual UIElement* UIElement::LoadChildXML(const XMLElement& childElem, XMLFile* styleFile) | File: ../UI/UIElement.h */ \
  126. engine->RegisterObjectMethod(className, "UIElement@+ LoadChildXML(XMLFile@+, XMLFile@+)", AS_FUNCTION_OBJLAST(UIElement_LoadChildXML<T>), AS_CALL_CDECL_OBJLAST); \
  127. \
  128. /* bool UIElement::SaveXML(Serializer& dest, const String& indentation = "\t") const | File: ../UI/UIElement.h */ \
  129. engine->RegisterObjectMethod(className, "bool SaveXML(File@+, const String&in indentation = \"\t\")", AS_FUNCTION_OBJLAST(UIElement_SaveXML_File<T>), AS_CALL_CDECL_OBJLAST); \
  130. engine->RegisterObjectMethod(className, "bool SaveXML(VectorBuffer&, const String&in indentation = \"\t\")", AS_FUNCTION_OBJLAST(UIElement_SaveXML_VectorBuffer<T>), AS_CALL_CDECL_OBJLAST); \
  131. \
  132. /* void UIElement::RemoveChildAtIndex(unsigned index) | File: ../UI/UIElement.h */ \
  133. engine->RegisterObjectMethod(className, "void RemoveChild(uint)", AS_FUNCTION_OBJLAST(UIElement_RemoveChild<T>), AS_CALL_CDECL_OBJLAST); \
  134. \
  135. /* bool UIElement::SetStyle(const String& styleName, XMLFile* file = nullptr) | File: ../UI/UIElement.h */ \
  136. engine->RegisterObjectMethod(className, "void set_style(const String&in)", AS_FUNCTION_OBJLAST(UIElement_SetStyle<T>), AS_CALL_CDECL_OBJLAST); \
  137. \
  138. /* unsigned UIElement::GetNumChildren(bool recursive = false) const | File: ../UI/UIElement.h */ \
  139. engine->RegisterObjectMethod(className, "uint get_numChildren() const", AS_FUNCTION_OBJLAST(UIElement_GetNumChildren_NonRecursive<T>), AS_CALL_CDECL_OBJLAST); \
  140. engine->RegisterObjectMethod(className, "uint get_numAllChildren() const", AS_FUNCTION_OBJLAST(UIElement_GetNumChildren_Recursive<T>), AS_CALL_CDECL_OBJLAST); \
  141. \
  142. /* void UIElement::SetParent(UIElement* parent, i32 index = ENDPOS) | File: ../UI/UIElement.h */ \
  143. engine->RegisterObjectMethod(className, "void set_parent(UIElement@+)", AS_FUNCTION_OBJLAST(UIElement_SetParent<T>), AS_CALL_CDECL_OBJLAST); \
  144. \
  145. /* XMLFile* UIElement::GetDefaultStyle(bool recursiveUp = true) const | File: ../UI/UIElement.h */ \
  146. engine->RegisterObjectMethod(className, "XMLFile@+ get_defaultStyle() const", AS_FUNCTION_OBJLAST(UIElement_GetDefaultStyle<T>), AS_CALL_CDECL_OBJLAST); \
  147. \
  148. /* const VariantMap& UIElement::GetVars() const | File: ../UI/UIElement.h */ \
  149. engine->RegisterObjectMethod(className, "VariantMap& get_vars()", AS_FUNCTION_OBJLAST(UIElement_GetVars<T>), AS_CALL_CDECL_OBJLAST);
  150. // ========================================================================================
  151. // SharedPtr<UIElement> UI::LoadLayout(Deserializer& source, XMLFile* styleFile = nullptr) | File: ../UI/UI.h
  152. template <class T> UIElement* UI_LoadLayout_File(File* file, UI* ptr)
  153. {
  154. if (file)
  155. {
  156. SharedPtr<UIElement> root = ptr->LoadLayout(*file);
  157. if (root)
  158. root->AddRef();
  159. return root.Get();
  160. }
  161. else
  162. return nullptr;
  163. }
  164. // SharedPtr<UIElement> UI::LoadLayout(Deserializer& source, XMLFile* styleFile = nullptr) | File: ../UI/UI.h
  165. template <class T> UIElement* UI_LoadLayout_VectorBuffer(VectorBuffer& buffer, UI* ptr)
  166. {
  167. SharedPtr<UIElement> root = ptr->LoadLayout(buffer);
  168. if (root)
  169. root->AddRef();
  170. return root.Get();
  171. }
  172. // SharedPtr<UIElement> UI::LoadLayout(Deserializer& source, XMLFile* styleFile = nullptr) | File: ../UI/UI.h
  173. template <class T> UIElement* UI_LoadLayout_File_Style(File* file, XMLFile* styleFile, UI* ptr)
  174. {
  175. if (file)
  176. {
  177. SharedPtr<UIElement> root = ptr->LoadLayout(*file, styleFile);
  178. if (root)
  179. root->AddRef();
  180. return root.Get();
  181. }
  182. else
  183. return nullptr;
  184. }
  185. // SharedPtr<UIElement> UI::LoadLayout(Deserializer& source, XMLFile* styleFile = nullptr) | File: ../UI/UI.h
  186. template <class T> UIElement* UI_LoadLayout_VectorBuffer_Style(VectorBuffer& buffer, XMLFile* styleFile, UI* ptr)
  187. {
  188. SharedPtr<UIElement> root = ptr->LoadLayout(buffer, styleFile);
  189. if (root)
  190. root->AddRef();
  191. return root.Get();
  192. }
  193. // bool UI::SaveLayout(Serializer& dest, UIElement* element) | File: ../UI/UI.h
  194. template <class T> bool UI_SaveLayout_File(File* file, UIElement* element, UI* ptr)
  195. {
  196. return file && ptr->SaveLayout(*file, element);
  197. }
  198. // bool UI::SaveLayout(Serializer& dest, UIElement* element) | File: ../UI/UI.h
  199. template <class T> bool UI_SaveLayout_VectorBuffer(VectorBuffer& buffer, UIElement* element, UI* ptr)
  200. {
  201. return ptr->SaveLayout(buffer, element);
  202. }
  203. // const Vector<UIElement*> UI::GetDragElements() | File: ../UI/UI.h
  204. template <class T> CScriptArray* UI_GetDragElements(UI* ptr)
  205. {
  206. return VectorToHandleArray(ptr->GetDragElements(), "const Array<UIElement@>@");
  207. }
  208. // void UI::SetFocusElement(UIElement* element, bool byKey = false) | File: ../UI/UI.h
  209. template <class T> void UI_SetFocusElement(UIElement* element, UI* ptr)
  210. {
  211. ptr->SetFocusElement(element);
  212. }
  213. #define REGISTER_MEMBERS_MANUAL_PART_UI() \
  214. /* SharedPtr<UIElement> UI::LoadLayout(Deserializer& source, XMLFile* styleFile = nullptr) | File: ../UI/UI.h */ \
  215. engine->RegisterObjectMethod(className, "UIElement@ LoadLayout(File@+)", AS_FUNCTION_OBJLAST(UI_LoadLayout_File<T>), AS_CALL_CDECL_OBJLAST); \
  216. engine->RegisterObjectMethod(className, "UIElement@ LoadLayout(File@+, XMLFile@+)", AS_FUNCTION_OBJLAST(UI_LoadLayout_File_Style<T>), AS_CALL_CDECL_OBJLAST); \
  217. engine->RegisterObjectMethod(className, "UIElement@ LoadLayout(VectorBuffer&)", AS_FUNCTION_OBJLAST(UI_LoadLayout_VectorBuffer<T>), AS_CALL_CDECL_OBJLAST); \
  218. engine->RegisterObjectMethod(className, "UIElement@ LoadLayout(VectorBuffer&, XMLFile@+)", AS_FUNCTION_OBJLAST(UI_LoadLayout_VectorBuffer_Style<T>), AS_CALL_CDECL_OBJLAST); \
  219. \
  220. /* bool UI::SaveLayout(Serializer& dest, UIElement* element) | File: ../UI/UI.h */ \
  221. engine->RegisterObjectMethod(className, "bool SaveLayout(File@+, UIElement@+)", AS_FUNCTION_OBJLAST(UI_SaveLayout_File<T>), AS_CALL_CDECL_OBJLAST); \
  222. engine->RegisterObjectMethod(className, "bool SaveLayout(VectorBuffer&, UIElement@+)", AS_FUNCTION_OBJLAST(UI_SaveLayout_VectorBuffer<T>), AS_CALL_CDECL_OBJLAST); \
  223. \
  224. /* const Vector<UIElement*> UI::GetDragElements() | File: ../UI/UI.h */ \
  225. engine->RegisterObjectMethod(className, "const Array<UIElement@>@ GetDragElements()", AS_FUNCTION_OBJLAST(UI_GetDragElements<T>), AS_CALL_CDECL_OBJLAST); \
  226. \
  227. /* void UI::SetFocusElement(UIElement* element, bool byKey = false) | File: ../UI/UI.h */ \
  228. engine->RegisterObjectMethod(className, "void set_focusElement(UIElement@+)", AS_FUNCTION_OBJLAST(UI_SetFocusElement<T>), AS_CALL_CDECL_OBJLAST);
  229. // ========================================================================================
  230. #define REGISTER_CLASS_MANUAL_PART_BorderImage() \
  231. RegisterNamedObjectConstructor<BorderImage>(engine, "BorderImage");
  232. #define REGISTER_CLASS_MANUAL_PART_Button() \
  233. RegisterNamedObjectConstructor<Button>(engine, "Button");
  234. #define REGISTER_CLASS_MANUAL_PART_CheckBox() \
  235. RegisterNamedObjectConstructor<CheckBox>(engine, "CheckBox");
  236. #define REGISTER_CLASS_MANUAL_PART_Cursor() \
  237. RegisterNamedObjectConstructor<Cursor>(engine, "Cursor");
  238. #define REGISTER_CLASS_MANUAL_PART_Menu() \
  239. RegisterNamedObjectConstructor<Menu>(engine, "Menu");
  240. }