UI.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "CheckBox.h"
  24. #include "Context.h"
  25. #include "CoreEvents.h"
  26. #include "Cursor.h"
  27. #include "DropDownList.h"
  28. #include "FileSelector.h"
  29. #include "Font.h"
  30. #include "Graphics.h"
  31. #include "GraphicsEvents.h"
  32. #include "Input.h"
  33. #include "InputEvents.h"
  34. #include "LineEdit.h"
  35. #include "ListView.h"
  36. #include "Log.h"
  37. #include "Matrix3x4.h"
  38. #include "Profiler.h"
  39. #include "Renderer.h"
  40. #include "ScrollBar.h"
  41. #include "Shader.h"
  42. #include "ShaderVariation.h"
  43. #include "Slider.h"
  44. #include "Sort.h"
  45. #include "Sprite.h"
  46. #include "Text.h"
  47. #include "Text3D.h"
  48. #include "Texture2D.h"
  49. #include "UI.h"
  50. #include "UIEvents.h"
  51. #include "VertexBuffer.h"
  52. #include "Window.h"
  53. #include "DebugNew.h"
  54. namespace Urho3D
  55. {
  56. ShortStringHash VAR_ORIGIN("Origin");
  57. const ShortStringHash VAR_ORIGINAL_PARENT("OriginalParent");
  58. const ShortStringHash VAR_ORIGINAL_CHILD_INDEX("OriginalChildIndex");
  59. const ShortStringHash VAR_PARENT_CHANGED("ParentChanged");
  60. const ShortStringHash VAR_NO_AUTO_REMOVE("NoAutoRemove");
  61. const char* UI_CATEGORY = "UI";
  62. OBJECTTYPESTATIC(UI);
  63. UI::UI(Context* context) :
  64. Object(context),
  65. rootElement_(new UIElement(context)),
  66. rootModalElement_(new UIElement(context)),
  67. mouseButtons_(0),
  68. qualifiers_(0),
  69. initialized_(false),
  70. #ifdef WIN32
  71. nonFocusedMouseWheel_(false), // Default MS Windows behaviour
  72. #else
  73. nonFocusedMouseWheel_(true), // Default Mac OS X and Linux behaviour
  74. #endif
  75. nonModalBatchSize_(0)
  76. {
  77. rootElement_->SetTraversalMode(TM_DEPTH_FIRST);
  78. rootModalElement_->SetTraversalMode(TM_DEPTH_FIRST);
  79. SubscribeToEvent(E_SCREENMODE, HANDLER(UI, HandleScreenMode));
  80. SubscribeToEvent(E_MOUSEBUTTONDOWN, HANDLER(UI, HandleMouseButtonDown));
  81. SubscribeToEvent(E_MOUSEBUTTONUP, HANDLER(UI, HandleMouseButtonUp));
  82. SubscribeToEvent(E_MOUSEMOVE, HANDLER(UI, HandleMouseMove));
  83. SubscribeToEvent(E_MOUSEWHEEL, HANDLER(UI, HandleMouseWheel));
  84. SubscribeToEvent(E_TOUCHBEGIN, HANDLER(UI, HandleTouchBegin));
  85. SubscribeToEvent(E_TOUCHEND, HANDLER(UI, HandleTouchEnd));
  86. SubscribeToEvent(E_TOUCHMOVE, HANDLER(UI, HandleTouchMove));
  87. SubscribeToEvent(E_KEYDOWN, HANDLER(UI, HandleKeyDown));
  88. SubscribeToEvent(E_CHAR, HANDLER(UI, HandleChar));
  89. // Delay SubscribeToEvent(E_POSTUPDATE, HANDLER(UI, HandlePostUpdate)) and
  90. // SubscribeToEvent(E_RENDERUPDATE, HANDLER(UI, HandleRenderUpdate)) until UI is initialized
  91. // Try to initialize right now, but skip if screen mode is not yet set
  92. Initialize();
  93. }
  94. UI::~UI()
  95. {
  96. }
  97. void UI::SetCursor(Cursor* cursor)
  98. {
  99. // Remove old cursor (if any) and set new
  100. if (cursor_)
  101. {
  102. rootElement_->RemoveChild(cursor_);
  103. cursor_.Reset();
  104. }
  105. if (cursor)
  106. {
  107. rootElement_->AddChild(cursor);
  108. cursor_ = cursor;
  109. IntVector2 pos = cursor_->GetPosition();
  110. const IntVector2& rootSize = rootElement_->GetSize();
  111. pos.x_ = Clamp(pos.x_, 0, rootSize.x_ - 1);
  112. pos.y_ = Clamp(pos.y_, 0, rootSize.y_ - 1);
  113. cursor_->SetPosition(pos);
  114. }
  115. }
  116. void UI::SetFocusElement(UIElement* element)
  117. {
  118. using namespace FocusChanged;
  119. VariantMap eventData;
  120. eventData[P_CLICKEDELEMENT] = (void*)element;
  121. if (element)
  122. {
  123. // Return if already has focus
  124. if (focusElement_ == element)
  125. return;
  126. // Only allow child elements of the modal element to receive focus
  127. if (HasModalElement())
  128. {
  129. UIElement* topLevel = element->GetParent();
  130. while (topLevel && topLevel->GetParent() != rootElement_)
  131. topLevel = topLevel->GetParent();
  132. if (topLevel) // If parented to non-modal root then ignore
  133. return;
  134. }
  135. // Search for an element in the hierarchy that can alter focus. If none found, exit
  136. element = GetFocusableElement(element);
  137. if (!element)
  138. return;
  139. }
  140. // Remove focus from the old element
  141. if (focusElement_)
  142. {
  143. UIElement* oldFocusElement = focusElement_;
  144. focusElement_.Reset();
  145. VariantMap focusEventData;
  146. focusEventData[Defocused::P_ELEMENT] = oldFocusElement;
  147. oldFocusElement->SendEvent(E_DEFOCUSED, focusEventData);
  148. }
  149. // Then set focus to the new
  150. if (element && element->GetFocusMode() >= FM_FOCUSABLE)
  151. {
  152. focusElement_ = element;
  153. VariantMap focusEventData;
  154. focusEventData[Focused::P_ELEMENT] = element;
  155. element->SendEvent(E_FOCUSED, focusEventData);
  156. }
  157. eventData[P_ELEMENT] = (void*)element;
  158. SendEvent(E_FOCUSCHANGED, eventData);
  159. }
  160. bool UI::SetModalElement(UIElement* modalElement, bool enable)
  161. {
  162. if (!modalElement)
  163. return false;
  164. // Currently only allow modal window
  165. if (modalElement->GetType() != Window::GetTypeStatic())
  166. return false;
  167. assert(rootModalElement_);
  168. const Vector<SharedPtr<UIElement> >& children = rootModalElement_->GetChildren();
  169. if (enable)
  170. {
  171. // Make sure it is not already the child of the root modal element
  172. for (unsigned i = 0; i < children.Size(); ++i)
  173. {
  174. if (children[i] == modalElement)
  175. return false;
  176. }
  177. // Adopt modal root as parent
  178. UIElement* oriParent = modalElement->GetParent();
  179. modalElement->SetVar(VAR_ORIGINAL_PARENT, oriParent);
  180. modalElement->SetVar(VAR_ORIGINAL_CHILD_INDEX, oriParent ? oriParent->FindChild(modalElement) : M_MAX_UNSIGNED);
  181. modalElement->SetParent(rootModalElement_);
  182. // If it is a popup element, bring along its top-level parent
  183. UIElement* originElement = static_cast<UIElement*>(modalElement->GetVar(VAR_ORIGIN).GetPtr());
  184. if (originElement)
  185. {
  186. UIElement* element = originElement;
  187. while (element && element->GetParent() != rootElement_)
  188. element = element->GetParent();
  189. if (element)
  190. {
  191. originElement->SetVar(VAR_PARENT_CHANGED, element);
  192. oriParent = element->GetParent();
  193. element->SetVar(VAR_ORIGINAL_PARENT, oriParent);
  194. element->SetVar(VAR_ORIGINAL_CHILD_INDEX, oriParent ? oriParent->FindChild(element) : M_MAX_UNSIGNED);
  195. element->SetParent(rootModalElement_);
  196. }
  197. }
  198. return true;
  199. }
  200. else
  201. {
  202. // Only the modal element can disable itself
  203. for (unsigned i = 0; i < children.Size(); ++i)
  204. {
  205. if (children[i] == modalElement)
  206. {
  207. // Revert back to original parent
  208. modalElement->SetParent(static_cast<UIElement*>(modalElement->GetVar(VAR_ORIGINAL_PARENT).GetPtr()), modalElement->GetVar(VAR_ORIGINAL_CHILD_INDEX).GetUInt());
  209. VariantMap& vars = const_cast<VariantMap&>(modalElement->GetVars());
  210. vars.Erase(VAR_ORIGINAL_PARENT);
  211. vars.Erase(VAR_ORIGINAL_CHILD_INDEX);
  212. // If it is a popup element, revert back its top-level parent to its original parent
  213. UIElement* originElement = static_cast<UIElement*>(modalElement->GetVar(VAR_ORIGIN).GetPtr());
  214. if (originElement)
  215. {
  216. UIElement* element = static_cast<UIElement*>(originElement->GetVar(VAR_PARENT_CHANGED).GetPtr());
  217. if (element)
  218. {
  219. const_cast<VariantMap&>(originElement->GetVars()).Erase(VAR_PARENT_CHANGED);
  220. element->SetParent(static_cast<UIElement*>(element->GetVar(VAR_ORIGINAL_PARENT).GetPtr()), element->GetVar(VAR_ORIGINAL_CHILD_INDEX).GetUInt());
  221. vars = const_cast<VariantMap&>(element->GetVars());
  222. vars.Erase(VAR_ORIGINAL_PARENT);
  223. vars.Erase(VAR_ORIGINAL_CHILD_INDEX);
  224. }
  225. }
  226. return true;
  227. }
  228. }
  229. return false;
  230. }
  231. }
  232. void UI::Clear()
  233. {
  234. rootElement_->RemoveAllChildren();
  235. rootModalElement_->RemoveAllChildren();
  236. if (cursor_)
  237. rootElement_->AddChild(cursor_);
  238. }
  239. void UI::Update(float timeStep)
  240. {
  241. assert(rootElement_ && rootModalElement_);
  242. PROFILE(UpdateUI);
  243. IntVector2 cursorPos;
  244. bool cursorVisible;
  245. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  246. if (cursorVisible)
  247. {
  248. WeakPtr<UIElement> element(GetElementAt(cursorPos));
  249. bool dragSource = dragElement_ && (dragElement_->GetDragDropMode() & DD_SOURCE) != 0;
  250. bool dragTarget = element && (element->GetDragDropMode() & DD_TARGET) != 0;
  251. bool dragDropTest = dragSource && dragTarget && element != dragElement_;
  252. // Hover effect
  253. // If a drag is going on, transmit hover only to the element being dragged, unless it's a drop target
  254. if (element && element->IsEnabled())
  255. {
  256. if (!dragElement_ || dragElement_ == element || dragDropTest)
  257. element->OnHover(element->ScreenToElement(cursorPos), cursorPos, mouseButtons_, qualifiers_, cursor_);
  258. }
  259. else
  260. SetCursorShape(CS_NORMAL);
  261. // Drag and drop test
  262. if (dragDropTest)
  263. {
  264. bool accept = element->OnDragDropTest(dragElement_);
  265. if (accept)
  266. {
  267. using namespace DragDropTest;
  268. VariantMap eventData;
  269. eventData[P_SOURCE] = (void*)dragElement_.Get();
  270. eventData[P_TARGET] = (void*)element.Get();
  271. eventData[P_ACCEPT] = accept;
  272. SendEvent(E_DRAGDROPTEST, eventData);
  273. accept = eventData[P_ACCEPT].GetBool();
  274. }
  275. SetCursorShape(accept ? CS_ACCEPTDROP : CS_REJECTDROP);
  276. }
  277. else if (dragSource)
  278. SetCursorShape(dragElement_ == element ? CS_ACCEPTDROP : CS_REJECTDROP);
  279. }
  280. // Touch hover
  281. Input* input = GetSubsystem<Input>();
  282. if (input)
  283. {
  284. unsigned numTouches = input->GetNumTouches();
  285. for (unsigned i = 0; i < numTouches; ++i)
  286. {
  287. TouchState* touch = input->GetTouch(i);
  288. UIElement* element = GetElementAt(touch->position_);
  289. if (element && element->IsEnabled())
  290. element->OnHover(element->ScreenToElement(touch->position_), touch->position_, MOUSEB_LEFT, 0, 0);
  291. }
  292. }
  293. Update(timeStep, rootElement_);
  294. Update(timeStep, rootModalElement_);
  295. }
  296. void UI::RenderUpdate()
  297. {
  298. assert(rootElement_ && rootModalElement_ && graphics_);
  299. PROFILE(GetUIBatches);
  300. // If the OS cursor is visible, do not render the UI's own cursor
  301. bool osCursorVisible = GetSubsystem<Input>()->IsMouseVisible();
  302. bool uiCursorVisible = false;
  303. if (osCursorVisible && cursor_)
  304. {
  305. uiCursorVisible = cursor_->IsVisible();
  306. cursor_->SetTempVisible(false);
  307. }
  308. // Get rendering batches from the non-modal UI elements
  309. batches_.Clear();
  310. vertexData_.Clear();
  311. const IntVector2& rootSize = rootElement_->GetSize();
  312. IntRect currentScissor = IntRect(0, 0, rootSize.x_, rootSize.y_);
  313. GetBatches(rootElement_, currentScissor);
  314. // Save the batch size of the non-modal batches for later use
  315. nonModalBatchSize_ = batches_.Size();
  316. // Get rendering batches from the modal UI elements
  317. GetBatches(rootModalElement_, currentScissor);
  318. // Restore UI cursor visibility state
  319. if (osCursorVisible && cursor_)
  320. cursor_->SetTempVisible(uiCursorVisible);
  321. }
  322. void UI::Render()
  323. {
  324. PROFILE(RenderUI);
  325. // Render non-modal batches
  326. Render(batches_, vertexData_, 0, nonModalBatchSize_);
  327. // Render debug draw
  328. Render(debugDrawBatches_, debugDrawVertexData_, 0, debugDrawBatches_.Size());
  329. // Render modal batches
  330. Render(batches_, vertexData_, nonModalBatchSize_, batches_.Size());
  331. // Clear the debug draw batches and data
  332. debugDrawBatches_.Clear();
  333. debugDrawVertexData_.Clear();
  334. }
  335. void UI::DebugDraw(UIElement* element)
  336. {
  337. if (element)
  338. {
  339. const IntVector2& rootSize = rootElement_->GetSize();
  340. element->GetDebugDrawBatches(debugDrawBatches_, debugDrawVertexData_, IntRect(0, 0, rootSize.x_, rootSize.y_));
  341. }
  342. }
  343. SharedPtr<UIElement> UI::LoadLayout(Deserializer& source, XMLFile* styleFile)
  344. {
  345. SharedPtr<XMLFile> xml(new XMLFile(context_));
  346. if (!xml->Load(source))
  347. return SharedPtr<UIElement>();
  348. else
  349. return LoadLayout(xml, styleFile);
  350. }
  351. SharedPtr<UIElement> UI::LoadLayout(XMLFile* file, XMLFile* styleFile)
  352. {
  353. PROFILE(LoadUILayout);
  354. SharedPtr<UIElement> root;
  355. if (!file)
  356. {
  357. LOGERROR("Null UI layout XML file");
  358. return root;
  359. }
  360. LOGDEBUG("Loading UI layout " + file->GetName());
  361. XMLElement rootElem = file->GetRoot("element");
  362. if (!rootElem)
  363. {
  364. LOGERROR("No root UI element in " + file->GetName());
  365. return root;
  366. }
  367. String typeName = rootElem.GetAttribute("type");
  368. if (typeName.Empty())
  369. typeName = "UIElement";
  370. root = DynamicCast<UIElement>(context_->CreateObject(typeName));
  371. if (!root)
  372. {
  373. LOGERROR("Could not create unknown UI element " + typeName);
  374. return root;
  375. }
  376. // Use default style file of the root element if it has one
  377. if (!styleFile)
  378. styleFile = rootElement_->GetDefaultStyle(false);
  379. // Set it as default for later use by children elements
  380. if (styleFile)
  381. root->SetDefaultStyle(styleFile);
  382. root->LoadXML(rootElem, styleFile);
  383. return root;
  384. }
  385. bool UI::SaveLayout(Serializer& dest, UIElement* element)
  386. {
  387. PROFILE(SaveUILayout);
  388. return element && element->SaveXML(dest);
  389. }
  390. void UI::SetClipBoardText(const String& text)
  391. {
  392. clipBoard_ = text;
  393. }
  394. void UI::SetNonFocusedMouseWheel(bool nonFocusedMouseWheel)
  395. {
  396. nonFocusedMouseWheel_ = nonFocusedMouseWheel;
  397. }
  398. UIElement* UI::GetElementAt(const IntVector2& position, bool enabledOnly)
  399. {
  400. UIElement* result = 0;
  401. GetElementAt(result, HasModalElement() ? rootModalElement_ : rootElement_, position, enabledOnly);
  402. return result;
  403. }
  404. UIElement* UI::GetElementAt(int x, int y, bool enabledOnly)
  405. {
  406. return GetElementAt(IntVector2(x, y), enabledOnly);
  407. }
  408. UIElement* UI::GetFrontElement() const
  409. {
  410. const Vector<SharedPtr<UIElement> >& rootChildren = rootElement_->GetChildren();
  411. int maxPriority = M_MIN_INT;
  412. UIElement* front = 0;
  413. for (unsigned i = 0; i < rootChildren.Size(); ++i)
  414. {
  415. // Do not take into account input-disabled elements, hidden elements or those that are always in the front
  416. if (!rootChildren[i]->IsEnabled() || !rootChildren[i]->IsVisible() || !rootChildren[i]->GetBringToBack())
  417. continue;
  418. int priority = rootChildren[i]->GetPriority();
  419. if (priority > maxPriority)
  420. {
  421. maxPriority = priority;
  422. front = rootChildren[i];
  423. }
  424. }
  425. return front;
  426. }
  427. IntVector2 UI::GetCursorPosition() const
  428. {
  429. return cursor_ ? cursor_->GetPosition() : GetSubsystem<Input>()->GetMousePosition();
  430. }
  431. bool UI::HasModalElement() const
  432. {
  433. return rootModalElement_->GetNumChildren() > 0;
  434. }
  435. void UI::Initialize()
  436. {
  437. Graphics* graphics = GetSubsystem<Graphics>();
  438. Renderer* renderer = GetSubsystem<Renderer>();
  439. if (!graphics || !graphics->IsInitialized() || !renderer)
  440. return;
  441. PROFILE(InitUI);
  442. graphics_ = graphics;
  443. rootElement_->SetSize(graphics->GetWidth(), graphics->GetHeight());
  444. rootModalElement_->SetSize(rootElement_->GetSize());
  445. noTextureVS_ = renderer->GetVertexShader("Basic_VCol");
  446. diffTextureVS_ = renderer->GetVertexShader("Basic_DiffVCol");
  447. noTexturePS_ = renderer->GetPixelShader("Basic_VCol");
  448. diffTexturePS_ = renderer->GetPixelShader("Basic_DiffVCol");
  449. diffMaskTexturePS_ = renderer->GetPixelShader("Basic_DiffAlphaMaskVCol");
  450. alphaTexturePS_ = renderer->GetPixelShader("Basic_AlphaVCol");
  451. vertexBuffer_ = new VertexBuffer(context_);
  452. initialized_ = true;
  453. SubscribeToEvent(E_POSTUPDATE, HANDLER(UI, HandlePostUpdate));
  454. SubscribeToEvent(E_RENDERUPDATE, HANDLER(UI, HandleRenderUpdate));
  455. LOGINFO("Initialized user interface");
  456. }
  457. void UI::Update(float timeStep, UIElement* element)
  458. {
  459. element->Update(timeStep);
  460. const Vector<SharedPtr<UIElement> >& children = element->GetChildren();
  461. for (Vector<SharedPtr<UIElement> >::ConstIterator i = children.Begin(); i != children.End(); ++i)
  462. Update(timeStep, *i);
  463. }
  464. void UI::Render(const PODVector<UIBatch>& batches, const PODVector<float>& vertexData, unsigned batchStart, unsigned batchSize)
  465. {
  466. // Engine does not render when window is closed or device is lost
  467. assert(graphics_ && graphics_->IsInitialized() && !graphics_->IsDeviceLost());
  468. if (vertexData.Empty())
  469. return;
  470. // Update quad geometry into the vertex buffer
  471. unsigned numVertices = vertexData.Size() / UI_VERTEX_SIZE;
  472. // Resize the vertex buffer if too small or much too large
  473. if (vertexBuffer_->GetVertexCount() < numVertices || vertexBuffer_->GetVertexCount() > numVertices * 2)
  474. vertexBuffer_->SetSize(numVertices, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1, true);
  475. vertexBuffer_->SetData(&vertexData[0]);
  476. Vector2 invScreenSize(1.0f / (float)graphics_->GetWidth(), 1.0f / (float)graphics_->GetHeight());
  477. Vector2 scale(2.0f * invScreenSize.x_, -2.0f * invScreenSize.y_);
  478. Vector2 offset(-1.0f, 1.0f);
  479. Matrix4 projection(Matrix4::IDENTITY);
  480. projection.m00_ = scale.x_;
  481. projection.m03_ = offset.x_;
  482. projection.m11_ = scale.y_;
  483. projection.m13_ = offset.y_;
  484. projection.m22_ = 1.0f;
  485. projection.m23_ = 0.0f;
  486. projection.m33_ = 1.0f;
  487. graphics_->ClearParameterSources();
  488. graphics_->SetCullMode(CULL_CCW);
  489. graphics_->SetDepthTest(CMP_ALWAYS);
  490. graphics_->SetDepthWrite(false);
  491. graphics_->SetStencilTest(false);
  492. graphics_->ResetRenderTargets();
  493. ShaderVariation* ps = 0;
  494. ShaderVariation* vs = 0;
  495. unsigned alphaFormat = Graphics::GetAlphaFormat();
  496. for (unsigned i = batchStart; i < batchSize; ++i)
  497. {
  498. const UIBatch& batch = batches[i];
  499. if (batch.vertexStart_ == batch.vertexEnd_)
  500. continue;
  501. if (!batch.texture_)
  502. {
  503. ps = noTexturePS_;
  504. vs = noTextureVS_;
  505. }
  506. else
  507. {
  508. // If texture contains only an alpha channel, use alpha shader (for fonts)
  509. vs = diffTextureVS_;
  510. if (batch.texture_->GetFormat() == alphaFormat)
  511. ps = alphaTexturePS_;
  512. else if (batch.blendMode_ != BLEND_ALPHA && batch.blendMode_ != BLEND_ADDALPHA && batch.blendMode_ != BLEND_PREMULALPHA)
  513. ps = diffMaskTexturePS_;
  514. else
  515. ps = diffTexturePS_;
  516. }
  517. graphics_->SetShaders(vs, ps);
  518. if (graphics_->NeedParameterUpdate(SP_OBJECTTRANSFORM, this))
  519. graphics_->SetShaderParameter(VSP_MODEL, Matrix3x4::IDENTITY);
  520. if (graphics_->NeedParameterUpdate(SP_CAMERA, this))
  521. graphics_->SetShaderParameter(VSP_VIEWPROJ, projection);
  522. if (graphics_->NeedParameterUpdate(SP_MATERIAL, this))
  523. graphics_->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
  524. graphics_->SetBlendMode(batch.blendMode_);
  525. graphics_->SetScissorTest(true, batch.scissor_);
  526. graphics_->SetTexture(0, batch.texture_);
  527. graphics_->SetVertexBuffer(vertexBuffer_);
  528. graphics_->Draw(TRIANGLE_LIST, batch.vertexStart_ / UI_VERTEX_SIZE, (batch.vertexEnd_ - batch.vertexStart_) /
  529. UI_VERTEX_SIZE);
  530. }
  531. }
  532. void UI::GetBatches(UIElement* element, IntRect currentScissor)
  533. {
  534. // Set clipping scissor for child elements. No need to draw if zero size
  535. element->AdjustScissor(currentScissor);
  536. if (currentScissor.left_ == currentScissor.right_ || currentScissor.top_ == currentScissor.bottom_)
  537. return;
  538. element->SortChildren();
  539. const Vector<SharedPtr<UIElement> >& children = element->GetChildren();
  540. if (children.Empty())
  541. return;
  542. // For non-root elements draw all children of same priority before recursing into their children: assumption is that they have
  543. // same renderstate
  544. Vector<SharedPtr<UIElement> >::ConstIterator i = children.Begin();
  545. if (element->GetTraversalMode() == TM_BREADTH_FIRST)
  546. {
  547. Vector<SharedPtr<UIElement> >::ConstIterator j = i;
  548. while (i != children.End())
  549. {
  550. int currentPriority = (*i)->GetPriority();
  551. while (j != children.End() && (*j)->GetPriority() == currentPriority)
  552. {
  553. if ((*j)->IsWithinScissor(currentScissor))
  554. (*j)->GetBatches(batches_, vertexData_, currentScissor);
  555. ++j;
  556. }
  557. // Now recurse into the children
  558. while (i != j)
  559. {
  560. if ((*i)->IsVisible())
  561. GetBatches(*i, currentScissor);
  562. ++i;
  563. }
  564. }
  565. }
  566. // On the root level draw each element and its children immediately after to avoid artifacts
  567. else
  568. {
  569. while (i != children.End())
  570. {
  571. if ((*i)->IsWithinScissor(currentScissor))
  572. (*i)->GetBatches(batches_, vertexData_, currentScissor);
  573. if ((*i)->IsVisible())
  574. GetBatches(*i, currentScissor);
  575. ++i;
  576. }
  577. }
  578. }
  579. void UI::GetElementAt(UIElement*& result, UIElement* current, const IntVector2& position, bool enabledOnly)
  580. {
  581. if (!current)
  582. return;
  583. current->SortChildren();
  584. const Vector<SharedPtr<UIElement> >& children = current->GetChildren();
  585. LayoutMode parentLayoutMode = current->GetLayoutMode();
  586. for (unsigned i = 0; i < children.Size(); ++i)
  587. {
  588. UIElement* element = children[i];
  589. bool hasChildren = element->GetNumChildren() > 0;
  590. if (element != cursor_.Get() && element->IsVisible())
  591. {
  592. if (element->IsInside(position, true))
  593. {
  594. // Store the current result, then recurse into its children. Because children
  595. // are sorted from lowest to highest priority, the topmost match should remain
  596. if (element->IsEnabled() || !enabledOnly)
  597. result = element;
  598. if (hasChildren)
  599. GetElementAt(result, element, position, enabledOnly);
  600. // Layout optimization: if the element has no children, can break out after the first match
  601. else if (parentLayoutMode != LM_FREE)
  602. break;
  603. }
  604. else
  605. {
  606. if (hasChildren)
  607. {
  608. if (element->IsInsideCombined(position, true))
  609. GetElementAt(result, element, position, enabledOnly);
  610. }
  611. // Layout optimization: if position is much beyond the visible screen, check how many elements we can skip,
  612. // or if we already passed all visible elements
  613. else if (parentLayoutMode != LM_FREE)
  614. {
  615. if (!i)
  616. {
  617. int screenPos = (parentLayoutMode == LM_HORIZONTAL) ? element->GetScreenPosition().x_ :
  618. element->GetScreenPosition().y_;
  619. int layoutMinSize = current->GetLayoutMinSize();
  620. if (screenPos < 0 && layoutMinSize > 0)
  621. {
  622. unsigned toSkip = -screenPos / layoutMinSize;
  623. if (toSkip > 0)
  624. i += (toSkip - 1);
  625. }
  626. }
  627. else if (parentLayoutMode == LM_HORIZONTAL)
  628. {
  629. if (element->GetScreenPosition().x_ >= rootElement_->GetSize().x_)
  630. break;
  631. }
  632. else if (parentLayoutMode == LM_VERTICAL)
  633. {
  634. if (element->GetScreenPosition().y_ >= rootElement_->GetSize().y_)
  635. break;
  636. }
  637. }
  638. }
  639. }
  640. }
  641. }
  642. UIElement* UI::GetFocusableElement(UIElement* element)
  643. {
  644. while (element)
  645. {
  646. if (element->GetFocusMode() != FM_NOTFOCUSABLE)
  647. break;
  648. element = element->GetParent();
  649. }
  650. return element;
  651. }
  652. void UI::GetCursorPositionAndVisible(IntVector2& pos, bool& visible)
  653. {
  654. if (cursor_)
  655. {
  656. pos = cursor_->GetPosition();
  657. visible = cursor_->IsVisible();
  658. }
  659. else
  660. {
  661. Input* input = GetSubsystem<Input>();
  662. pos = input->GetMousePosition();
  663. visible = input->IsMouseVisible();
  664. }
  665. }
  666. void UI::SetCursorShape(CursorShape shape)
  667. {
  668. if (cursor_)
  669. cursor_->SetShape(shape);
  670. }
  671. void UI::HandleScreenMode(StringHash eventType, VariantMap& eventData)
  672. {
  673. using namespace ScreenMode;
  674. if (!initialized_)
  675. Initialize();
  676. else
  677. {
  678. rootElement_->SetSize(eventData[P_WIDTH].GetInt(), eventData[P_HEIGHT].GetInt());
  679. rootModalElement_->SetSize(rootElement_->GetSize());
  680. }
  681. }
  682. void UI::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
  683. {
  684. mouseButtons_ = eventData[MouseButtonDown::P_BUTTONS].GetInt();
  685. qualifiers_ = eventData[MouseButtonDown::P_QUALIFIERS].GetInt();
  686. IntVector2 cursorPos;
  687. bool cursorVisible;
  688. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  689. if (cursorVisible)
  690. {
  691. int button = eventData[MouseButtonDown::P_BUTTON].GetInt();
  692. WeakPtr<UIElement> element(GetElementAt(cursorPos));
  693. if (element)
  694. {
  695. // Handle focusing & bringing to front
  696. if (button == MOUSEB_LEFT)
  697. {
  698. SetFocusElement(element);
  699. element->BringToFront();
  700. }
  701. // Handle click
  702. element->OnClick(element->ScreenToElement(cursorPos), cursorPos, mouseButtons_, qualifiers_, cursor_);
  703. // Handle start of drag. OnClick() may have caused destruction of the element, so check the pointer again
  704. if (element && !dragElement_ && mouseButtons_ == MOUSEB_LEFT)
  705. {
  706. dragElement_ = element;
  707. element->OnDragBegin(element->ScreenToElement(cursorPos), cursorPos, mouseButtons_, qualifiers_, cursor_);
  708. }
  709. }
  710. else
  711. {
  712. // If clicked over no element, or a disabled element, lose focus
  713. SetFocusElement(0);
  714. }
  715. using namespace UIMouseClick;
  716. VariantMap eventData;
  717. eventData[UIMouseClick::P_ELEMENT] = (void*)element.Get();
  718. eventData[UIMouseClick::P_X] = cursorPos.x_;
  719. eventData[UIMouseClick::P_Y] = cursorPos.y_;
  720. eventData[UIMouseClick::P_BUTTON] = button;
  721. eventData[UIMouseClick::P_BUTTONS] = mouseButtons_;
  722. eventData[UIMouseClick::P_QUALIFIERS] = qualifiers_;
  723. SendEvent(E_UIMOUSECLICK, eventData);
  724. }
  725. }
  726. void UI::HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
  727. {
  728. using namespace MouseButtonUp;
  729. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  730. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  731. IntVector2 cursorPos;
  732. bool cursorVisible;
  733. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  734. if (cursorVisible || dragElement_)
  735. {
  736. if (dragElement_ && !mouseButtons_)
  737. {
  738. if (dragElement_->IsEnabled() && dragElement_->IsVisible())
  739. {
  740. dragElement_->OnDragEnd(dragElement_->ScreenToElement(cursorPos), cursorPos, cursor_);
  741. // Drag and drop finish
  742. bool dragSource = dragElement_ && (dragElement_->GetDragDropMode() & DD_SOURCE) != 0;
  743. if (dragSource)
  744. {
  745. WeakPtr<UIElement> target(GetElementAt(cursorPos));
  746. bool dragTarget = target && (target->GetDragDropMode() & DD_TARGET) != 0;
  747. bool dragDropFinish = dragSource && dragTarget && target != dragElement_;
  748. if (dragDropFinish)
  749. {
  750. bool accept = target->OnDragDropFinish(dragElement_);
  751. // OnDragDropFinish() may have caused destruction of the elements, so check the pointers again
  752. if (accept && dragElement_ && target)
  753. {
  754. using namespace DragDropFinish;
  755. VariantMap eventData;
  756. eventData[P_SOURCE] = (void*)dragElement_.Get();
  757. eventData[P_TARGET] = (void*)target.Get();
  758. eventData[P_ACCEPT] = accept;
  759. SendEvent(E_DRAGDROPFINISH, eventData);
  760. }
  761. }
  762. }
  763. }
  764. dragElement_.Reset();
  765. }
  766. }
  767. }
  768. void UI::HandleMouseMove(StringHash eventType, VariantMap& eventData)
  769. {
  770. using namespace MouseMove;
  771. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  772. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  773. Input* input = GetSubsystem<Input>();
  774. const IntVector2& rootSize = rootElement_->GetSize();
  775. if (cursor_)
  776. {
  777. if (!input->IsMouseVisible())
  778. {
  779. // Relative mouse motion: move cursor only when visible
  780. if (cursor_->IsVisible())
  781. {
  782. IntVector2 pos = cursor_->GetPosition();
  783. pos.x_ += eventData[P_DX].GetInt();
  784. pos.y_ += eventData[P_DY].GetInt();
  785. pos.x_ = Clamp(pos.x_, 0, rootSize.x_ - 1);
  786. pos.y_ = Clamp(pos.y_, 0, rootSize.y_ - 1);
  787. cursor_->SetPosition(pos);
  788. }
  789. }
  790. else
  791. {
  792. // Absolute mouse motion: move always
  793. cursor_->SetPosition(IntVector2(eventData[P_X].GetInt(), eventData[P_Y].GetInt()));
  794. }
  795. }
  796. IntVector2 cursorPos;
  797. bool cursorVisible;
  798. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  799. if (cursorVisible && dragElement_ && mouseButtons_)
  800. {
  801. if (dragElement_->IsEnabled() && dragElement_->IsVisible())
  802. dragElement_->OnDragMove(dragElement_->ScreenToElement(cursorPos), cursorPos, mouseButtons_, qualifiers_, cursor_);
  803. else
  804. {
  805. dragElement_->OnDragEnd(dragElement_->ScreenToElement(cursorPos), cursorPos, cursor_);
  806. dragElement_.Reset();
  807. }
  808. }
  809. }
  810. void UI::HandleMouseWheel(StringHash eventType, VariantMap& eventData)
  811. {
  812. using namespace MouseWheel;
  813. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  814. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  815. int delta = eventData[P_WHEEL].GetInt();
  816. IntVector2 cursorPos;
  817. bool cursorVisible;
  818. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  819. UIElement* element;
  820. if (!nonFocusedMouseWheel_&& (element = focusElement_))
  821. element->OnWheel(delta, mouseButtons_, qualifiers_);
  822. else
  823. {
  824. // If no element has actual focus or in non-focused mode, get the element at cursor
  825. if (cursorVisible)
  826. {
  827. element = GetElementAt(cursorPos);
  828. if (nonFocusedMouseWheel_)
  829. {
  830. // Going up the hierarchy chain to find element that could handle mouse wheel
  831. while (element)
  832. {
  833. if (element->GetType() == ListView::GetTypeStatic() ||
  834. element->GetType() == ScrollView::GetTypeStatic())
  835. break;
  836. element = element->GetParent();
  837. }
  838. }
  839. else
  840. // If the element itself is not focusable, search for a focusable parent,
  841. // although the focusable element may not actually handle mouse wheel
  842. element = GetFocusableElement(element);
  843. if (element && (nonFocusedMouseWheel_ || element->GetFocusMode() >= FM_FOCUSABLE))
  844. element->OnWheel(delta, mouseButtons_, qualifiers_);
  845. }
  846. }
  847. }
  848. void UI::HandleTouchBegin(StringHash eventType, VariantMap& eventData)
  849. {
  850. using namespace TouchBegin;
  851. IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
  852. WeakPtr<UIElement> element(GetElementAt(pos));
  853. if (element)
  854. {
  855. // Handle focusing & bringing to front
  856. SetFocusElement(element);
  857. element->BringToFront();
  858. // Handle click
  859. element->OnClick(element->ScreenToElement(pos), pos, MOUSEB_LEFT, 0, 0);
  860. // Handle start of drag. OnClick() may have caused destruction of the element, so check the pointer again
  861. if (element && !dragElement_ )
  862. {
  863. dragElement_ = element;
  864. element->OnDragBegin(element->ScreenToElement(pos), pos, MOUSEB_LEFT, 0, 0);
  865. }
  866. }
  867. else
  868. {
  869. // If clicked over no element, or a disabled element, lose focus
  870. SetFocusElement(0);
  871. }
  872. using namespace UIMouseClick;
  873. VariantMap clickEventData;
  874. clickEventData[UIMouseClick::P_ELEMENT] = (void*)element.Get();
  875. clickEventData[UIMouseClick::P_X] = pos.x_;
  876. clickEventData[UIMouseClick::P_Y] = pos.y_;
  877. clickEventData[UIMouseClick::P_BUTTON] = MOUSEB_LEFT;
  878. clickEventData[UIMouseClick::P_BUTTONS] = MOUSEB_LEFT;
  879. clickEventData[UIMouseClick::P_QUALIFIERS] = 0;
  880. SendEvent(E_UIMOUSECLICK, clickEventData);
  881. }
  882. void UI::HandleTouchEnd(StringHash eventType, VariantMap& eventData)
  883. {
  884. using namespace TouchEnd;
  885. IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
  886. // Transmit hover end to the position where the finger was lifted
  887. UIElement* element = GetElementAt(pos);
  888. if (element && element->IsEnabled())
  889. element->OnHover(element->ScreenToElement(pos), pos, 0, 0, 0);
  890. if (dragElement_)
  891. {
  892. if (dragElement_->IsEnabled() && dragElement_->IsVisible())
  893. {
  894. dragElement_->OnDragEnd(dragElement_->ScreenToElement(pos), pos, cursor_);
  895. // Drag and drop finish
  896. bool dragSource = dragElement_ && (dragElement_->GetDragDropMode() & DD_SOURCE) != 0;
  897. if (dragSource)
  898. {
  899. WeakPtr<UIElement> target(GetElementAt(pos));
  900. bool dragTarget = target && (target->GetDragDropMode() & DD_TARGET) != 0;
  901. bool dragDropFinish = dragSource && dragTarget && target != dragElement_;
  902. if (dragDropFinish)
  903. {
  904. bool accept = target->OnDragDropFinish(dragElement_);
  905. // OnDragDropFinish() may have caused destruction of the elements, so check the pointers again
  906. if (accept && dragElement_ && target)
  907. {
  908. using namespace DragDropFinish;
  909. VariantMap eventData;
  910. eventData[P_SOURCE] = (void*)dragElement_.Get();
  911. eventData[P_TARGET] = (void*)target.Get();
  912. eventData[P_ACCEPT] = accept;
  913. SendEvent(E_DRAGDROPFINISH, eventData);
  914. }
  915. }
  916. }
  917. }
  918. dragElement_.Reset();
  919. }
  920. }
  921. void UI::HandleTouchMove(StringHash eventType, VariantMap& eventData)
  922. {
  923. using namespace TouchMove;
  924. IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
  925. if (dragElement_)
  926. {
  927. if (dragElement_->IsEnabled() && dragElement_->IsVisible())
  928. dragElement_->OnDragMove(dragElement_->ScreenToElement(pos), pos, MOUSEB_LEFT, 0, 0);
  929. else
  930. {
  931. dragElement_->OnDragEnd(dragElement_->ScreenToElement(pos), pos, 0);
  932. dragElement_.Reset();
  933. }
  934. }
  935. }
  936. void UI::HandleKeyDown(StringHash eventType, VariantMap& eventData)
  937. {
  938. using namespace KeyDown;
  939. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  940. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  941. int key = eventData[P_KEY].GetInt();
  942. // Dismiss modal element if any when ESC key is pressed
  943. if (key == KEY_ESC && HasModalElement())
  944. {
  945. UIElement* element = rootModalElement_->GetChild(rootModalElement_->GetNumChildren() - 1);
  946. if (element->GetVars().Contains(VAR_ORIGIN))
  947. // If it is a popup, dismiss by defocusing it
  948. SetFocusElement(0);
  949. else
  950. {
  951. // If it is a modal window, by resetting its modal flag and auto-remove it
  952. Window* window = dynamic_cast<Window*>(element);
  953. if (window)
  954. {
  955. window->SetModal(false);
  956. if (window->GetVars().Contains(VAR_NO_AUTO_REMOVE))
  957. const_cast<VariantMap&>(window->GetVars()).Erase(VAR_NO_AUTO_REMOVE);
  958. else
  959. window->Remove();
  960. }
  961. }
  962. return;
  963. }
  964. UIElement* element = focusElement_;
  965. if (element)
  966. {
  967. // Switch focus between focusable elements in the same top level window
  968. if (key == KEY_TAB)
  969. {
  970. UIElement* topLevel = element->GetParent();
  971. while (topLevel && topLevel->GetParent() != rootElement_ && topLevel->GetParent() != rootModalElement_)
  972. topLevel = topLevel->GetParent();
  973. if (topLevel)
  974. {
  975. topLevel->GetChildren(tempElements_, true);
  976. for (PODVector<UIElement*>::Iterator i = tempElements_.Begin(); i != tempElements_.End();)
  977. {
  978. if ((*i)->GetFocusMode() < FM_FOCUSABLE)
  979. i = tempElements_.Erase(i);
  980. else
  981. ++i;
  982. }
  983. for (unsigned i = 0; i < tempElements_.Size(); ++i)
  984. {
  985. if (tempElements_[i] == element)
  986. {
  987. UIElement* next = tempElements_[(i + 1) % tempElements_.Size()];
  988. SetFocusElement(next);
  989. return;
  990. }
  991. }
  992. }
  993. }
  994. // Defocus the element
  995. else if (key == KEY_ESC && element->GetFocusMode() == FM_FOCUSABLE_DEFOCUSABLE)
  996. element->SetFocus(false);
  997. // If none of the special keys, pass the key to the focused element
  998. else
  999. element->OnKey(key, mouseButtons_, qualifiers_);
  1000. }
  1001. }
  1002. void UI::HandleChar(StringHash eventType, VariantMap& eventData)
  1003. {
  1004. using namespace Char;
  1005. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  1006. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  1007. UIElement* element = focusElement_;
  1008. if (element)
  1009. element->OnChar(eventData[P_CHAR].GetInt(), mouseButtons_, qualifiers_);
  1010. }
  1011. void UI::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
  1012. {
  1013. using namespace PostUpdate;
  1014. Update(eventData[P_TIMESTEP].GetFloat());
  1015. }
  1016. void UI::HandleRenderUpdate(StringHash eventType, VariantMap& eventData)
  1017. {
  1018. RenderUpdate();
  1019. }
  1020. void RegisterUILibrary(Context* context)
  1021. {
  1022. Font::RegisterObject(context);
  1023. UIElement::RegisterObject(context);
  1024. BorderImage::RegisterObject(context);
  1025. Sprite::RegisterObject(context);
  1026. Button::RegisterObject(context);
  1027. CheckBox::RegisterObject(context);
  1028. Cursor::RegisterObject(context);
  1029. Text::RegisterObject(context);
  1030. Text3D::RegisterObject(context);
  1031. Window::RegisterObject(context);
  1032. LineEdit::RegisterObject(context);
  1033. Slider::RegisterObject(context);
  1034. ScrollBar::RegisterObject(context);
  1035. ScrollView::RegisterObject(context);
  1036. ListView::RegisterObject(context);
  1037. Menu::RegisterObject(context);
  1038. DropDownList::RegisterObject(context);
  1039. FileSelector::RegisterObject(context);
  1040. }
  1041. }