UI.cpp 41 KB

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