UI.cpp 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  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. if (styleFile)
  376. // Set it as default for later use by children elements
  377. root->SetDefaultStyle(styleFile);
  378. else
  379. // Use default style file of the root element if it has one
  380. styleFile = rootElement_->GetDefaultStyle(false);
  381. root->LoadXML(rootElem, styleFile);
  382. return root;
  383. }
  384. bool UI::SaveLayout(Serializer& dest, UIElement* element)
  385. {
  386. PROFILE(SaveUILayout);
  387. if (element)
  388. return element->SaveXML(dest);
  389. else
  390. return false;
  391. }
  392. void UI::SetClipBoardText(const String& text)
  393. {
  394. clipBoard_ = text;
  395. }
  396. void UI::SetNonFocusedMouseWheel(bool nonFocusedMouseWheel)
  397. {
  398. nonFocusedMouseWheel_ = nonFocusedMouseWheel;
  399. }
  400. UIElement* UI::GetElementAt(const IntVector2& position, bool enabledOnly)
  401. {
  402. UIElement* result = 0;
  403. GetElementAt(result, HasModalElement() ? rootModalElement_ : rootElement_, position, enabledOnly);
  404. return result;
  405. }
  406. UIElement* UI::GetElementAt(int x, int y, bool enabledOnly)
  407. {
  408. return GetElementAt(IntVector2(x, y), enabledOnly);
  409. }
  410. UIElement* UI::GetFrontElement() const
  411. {
  412. const Vector<SharedPtr<UIElement> >& rootChildren = rootElement_->GetChildren();
  413. int maxPriority = M_MIN_INT;
  414. UIElement* front = 0;
  415. for (unsigned i = 0; i < rootChildren.Size(); ++i)
  416. {
  417. // Do not take into account input-disabled elements, hidden elements or those that are always in the front
  418. if (!rootChildren[i]->IsEnabled() || !rootChildren[i]->IsVisible() || !rootChildren[i]->GetBringToBack())
  419. continue;
  420. int priority = rootChildren[i]->GetPriority();
  421. if (priority > maxPriority)
  422. {
  423. maxPriority = priority;
  424. front = rootChildren[i];
  425. }
  426. }
  427. return front;
  428. }
  429. IntVector2 UI::GetCursorPosition() const
  430. {
  431. return cursor_ ? cursor_->GetPosition() : GetSubsystem<Input>()->GetMousePosition();
  432. }
  433. bool UI::HasModalElement() const
  434. {
  435. return rootModalElement_->GetNumChildren() > 0;
  436. }
  437. void UI::Initialize()
  438. {
  439. Graphics* graphics = GetSubsystem<Graphics>();
  440. Renderer* renderer = GetSubsystem<Renderer>();
  441. if (!graphics || !graphics->IsInitialized() || !renderer)
  442. return;
  443. PROFILE(InitUI);
  444. graphics_ = graphics;
  445. rootElement_->SetSize(graphics->GetWidth(), graphics->GetHeight());
  446. rootModalElement_->SetSize(rootElement_->GetSize());
  447. noTextureVS_ = renderer->GetVertexShader("Basic_VCol");
  448. diffTextureVS_ = renderer->GetVertexShader("Basic_DiffVCol");
  449. noTexturePS_ = renderer->GetPixelShader("Basic_VCol");
  450. diffTexturePS_ = renderer->GetPixelShader("Basic_DiffVCol");
  451. diffMaskTexturePS_ = renderer->GetPixelShader("Basic_DiffAlphaMaskVCol");
  452. alphaTexturePS_ = renderer->GetPixelShader("Basic_AlphaVCol");
  453. vertexBuffer_ = new VertexBuffer(context_);
  454. initialized_ = true;
  455. SubscribeToEvent(E_POSTUPDATE, HANDLER(UI, HandlePostUpdate));
  456. SubscribeToEvent(E_RENDERUPDATE, HANDLER(UI, HandleRenderUpdate));
  457. LOGINFO("Initialized user interface");
  458. }
  459. void UI::Update(float timeStep, UIElement* element)
  460. {
  461. element->Update(timeStep);
  462. const Vector<SharedPtr<UIElement> >& children = element->GetChildren();
  463. for (Vector<SharedPtr<UIElement> >::ConstIterator i = children.Begin(); i != children.End(); ++i)
  464. Update(timeStep, *i);
  465. }
  466. void UI::Render(const PODVector<UIBatch>& batches, const PODVector<float>& vertexData, unsigned batchStart, unsigned batchSize)
  467. {
  468. // Engine does not render when window is closed or device is lost
  469. assert(graphics_ && graphics_->IsInitialized() && !graphics_->IsDeviceLost());
  470. if (vertexData.Empty())
  471. return;
  472. // Update quad geometry into the vertex buffer
  473. unsigned numVertices = vertexData.Size() / UI_VERTEX_SIZE;
  474. // Resize the vertex buffer if too small or much too large
  475. if (vertexBuffer_->GetVertexCount() < numVertices || vertexBuffer_->GetVertexCount() > numVertices * 2)
  476. vertexBuffer_->SetSize(numVertices, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1, true);
  477. vertexBuffer_->SetData(&vertexData[0]);
  478. Vector2 invScreenSize(1.0f / (float)graphics_->GetWidth(), 1.0f / (float)graphics_->GetHeight());
  479. Vector2 scale(2.0f * invScreenSize.x_, -2.0f * invScreenSize.y_);
  480. Vector2 offset(-1.0f, 1.0f);
  481. Matrix4 projection(Matrix4::IDENTITY);
  482. projection.m00_ = scale.x_;
  483. projection.m03_ = offset.x_;
  484. projection.m11_ = scale.y_;
  485. projection.m13_ = offset.y_;
  486. projection.m22_ = 1.0f;
  487. projection.m23_ = 0.0f;
  488. projection.m33_ = 1.0f;
  489. graphics_->ClearParameterSources();
  490. graphics_->SetCullMode(CULL_CCW);
  491. graphics_->SetDepthTest(CMP_ALWAYS);
  492. graphics_->SetDepthWrite(false);
  493. graphics_->SetStencilTest(false);
  494. graphics_->ResetRenderTargets();
  495. ShaderVariation* ps = 0;
  496. ShaderVariation* vs = 0;
  497. unsigned alphaFormat = Graphics::GetAlphaFormat();
  498. for (unsigned i = batchStart; i < batchSize; ++i)
  499. {
  500. const UIBatch& batch = batches[i];
  501. if (batch.vertexStart_ == batch.vertexEnd_)
  502. continue;
  503. if (!batch.texture_)
  504. {
  505. ps = noTexturePS_;
  506. vs = noTextureVS_;
  507. }
  508. else
  509. {
  510. // If texture contains only an alpha channel, use alpha shader (for fonts)
  511. vs = diffTextureVS_;
  512. if (batch.texture_->GetFormat() == alphaFormat)
  513. ps = alphaTexturePS_;
  514. else if (batch.blendMode_ != BLEND_ALPHA && batch.blendMode_ != BLEND_ADDALPHA && batch.blendMode_ != BLEND_PREMULALPHA)
  515. ps = diffMaskTexturePS_;
  516. else
  517. ps = diffTexturePS_;
  518. }
  519. graphics_->SetShaders(vs, ps);
  520. if (graphics_->NeedParameterUpdate(SP_OBJECTTRANSFORM, this))
  521. graphics_->SetShaderParameter(VSP_MODEL, Matrix3x4::IDENTITY);
  522. if (graphics_->NeedParameterUpdate(SP_CAMERA, this))
  523. graphics_->SetShaderParameter(VSP_VIEWPROJ, projection);
  524. if (graphics_->NeedParameterUpdate(SP_MATERIAL, this))
  525. graphics_->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
  526. graphics_->SetBlendMode(batch.blendMode_);
  527. graphics_->SetScissorTest(true, batch.scissor_);
  528. graphics_->SetTexture(0, batch.texture_);
  529. graphics_->SetVertexBuffer(vertexBuffer_);
  530. graphics_->Draw(TRIANGLE_LIST, batch.vertexStart_ / UI_VERTEX_SIZE, (batch.vertexEnd_ - batch.vertexStart_) /
  531. UI_VERTEX_SIZE);
  532. }
  533. }
  534. void UI::GetBatches(UIElement* element, IntRect currentScissor)
  535. {
  536. // Set clipping scissor for child elements. No need to draw if zero size
  537. element->AdjustScissor(currentScissor);
  538. if (currentScissor.left_ == currentScissor.right_ || currentScissor.top_ == currentScissor.bottom_)
  539. return;
  540. element->SortChildren();
  541. const Vector<SharedPtr<UIElement> >& children = element->GetChildren();
  542. if (children.Empty())
  543. return;
  544. // For non-root elements draw all children of same priority before recursing into their children: assumption is that they have
  545. // same renderstate
  546. Vector<SharedPtr<UIElement> >::ConstIterator i = children.Begin();
  547. if (element->GetTraversalMode() == TM_BREADTH_FIRST)
  548. {
  549. Vector<SharedPtr<UIElement> >::ConstIterator j = i;
  550. while (i != children.End())
  551. {
  552. int currentPriority = (*i)->GetPriority();
  553. while (j != children.End() && (*j)->GetPriority() == currentPriority)
  554. {
  555. if ((*j)->IsWithinScissor(currentScissor))
  556. (*j)->GetBatches(batches_, vertexData_, currentScissor);
  557. ++j;
  558. }
  559. // Now recurse into the children
  560. while (i != j)
  561. {
  562. if ((*i)->IsVisible())
  563. GetBatches(*i, currentScissor);
  564. ++i;
  565. }
  566. }
  567. }
  568. // On the root level draw each element and its children immediately after to avoid artifacts
  569. else
  570. {
  571. while (i != children.End())
  572. {
  573. if ((*i)->IsWithinScissor(currentScissor))
  574. (*i)->GetBatches(batches_, vertexData_, currentScissor);
  575. if ((*i)->IsVisible())
  576. GetBatches(*i, currentScissor);
  577. ++i;
  578. }
  579. }
  580. }
  581. void UI::GetElementAt(UIElement*& result, UIElement* current, const IntVector2& position, bool enabledOnly)
  582. {
  583. if (!current)
  584. return;
  585. current->SortChildren();
  586. const Vector<SharedPtr<UIElement> >& children = current->GetChildren();
  587. LayoutMode parentLayoutMode = current->GetLayoutMode();
  588. for (unsigned i = 0; i < children.Size(); ++i)
  589. {
  590. UIElement* element = children[i];
  591. bool hasChildren = element->GetNumChildren() > 0;
  592. if (element != cursor_.Get() && element->IsVisible())
  593. {
  594. if (element->IsInside(position, true))
  595. {
  596. // Store the current result, then recurse into its children. Because children
  597. // are sorted from lowest to highest priority, the topmost match should remain
  598. if (element->IsEnabled() || !enabledOnly)
  599. result = element;
  600. if (hasChildren)
  601. GetElementAt(result, element, position, enabledOnly);
  602. // Layout optimization: if the element has no children, can break out after the first match
  603. else if (parentLayoutMode != LM_FREE)
  604. break;
  605. }
  606. else
  607. {
  608. if (hasChildren)
  609. {
  610. if (element->IsInsideCombined(position, true))
  611. GetElementAt(result, element, position, enabledOnly);
  612. }
  613. // Layout optimization: if position is much beyond the visible screen, check how many elements we can skip,
  614. // or if we already passed all visible elements
  615. else if (parentLayoutMode != LM_FREE)
  616. {
  617. if (!i)
  618. {
  619. int screenPos = (parentLayoutMode == LM_HORIZONTAL) ? element->GetScreenPosition().x_ :
  620. element->GetScreenPosition().y_;
  621. int layoutMinSize = current->GetLayoutMinSize();
  622. if (screenPos < 0 && layoutMinSize > 0)
  623. {
  624. unsigned toSkip = -screenPos / layoutMinSize;
  625. if (toSkip > 0)
  626. i += (toSkip - 1);
  627. }
  628. }
  629. else if (parentLayoutMode == LM_HORIZONTAL)
  630. {
  631. if (element->GetScreenPosition().x_ >= rootElement_->GetSize().x_)
  632. break;
  633. }
  634. else if (parentLayoutMode == LM_VERTICAL)
  635. {
  636. if (element->GetScreenPosition().y_ >= rootElement_->GetSize().y_)
  637. break;
  638. }
  639. }
  640. }
  641. }
  642. }
  643. }
  644. UIElement* UI::GetFocusableElement(UIElement* element)
  645. {
  646. while (element)
  647. {
  648. if (element->GetFocusMode() != FM_NOTFOCUSABLE)
  649. break;
  650. element = element->GetParent();
  651. }
  652. return element;
  653. }
  654. void UI::GetCursorPositionAndVisible(IntVector2& pos, bool& visible)
  655. {
  656. if (cursor_)
  657. {
  658. pos = cursor_->GetPosition();
  659. visible = cursor_->IsVisible();
  660. }
  661. else
  662. {
  663. Input* input = GetSubsystem<Input>();
  664. pos = input->GetMousePosition();
  665. visible = input->IsMouseVisible();
  666. }
  667. }
  668. void UI::SetCursorShape(CursorShape shape)
  669. {
  670. if (cursor_)
  671. cursor_->SetShape(shape);
  672. }
  673. void UI::HandleScreenMode(StringHash eventType, VariantMap& eventData)
  674. {
  675. using namespace ScreenMode;
  676. if (!initialized_)
  677. Initialize();
  678. else
  679. {
  680. rootElement_->SetSize(eventData[P_WIDTH].GetInt(), eventData[P_HEIGHT].GetInt());
  681. rootModalElement_->SetSize(rootElement_->GetSize());
  682. }
  683. }
  684. void UI::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
  685. {
  686. mouseButtons_ = eventData[MouseButtonDown::P_BUTTONS].GetInt();
  687. qualifiers_ = eventData[MouseButtonDown::P_QUALIFIERS].GetInt();
  688. IntVector2 cursorPos;
  689. bool cursorVisible;
  690. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  691. if (cursorVisible)
  692. {
  693. int button = eventData[MouseButtonDown::P_BUTTON].GetInt();
  694. WeakPtr<UIElement> element(GetElementAt(cursorPos));
  695. if (element)
  696. {
  697. // Handle focusing & bringing to front
  698. if (button == MOUSEB_LEFT)
  699. {
  700. SetFocusElement(element);
  701. element->BringToFront();
  702. }
  703. // Handle click
  704. element->OnClick(element->ScreenToElement(cursorPos), cursorPos, mouseButtons_, qualifiers_, cursor_);
  705. // Handle start of drag. OnClick() may have caused destruction of the element, so check the pointer again
  706. if (element && !dragElement_ && mouseButtons_ == MOUSEB_LEFT)
  707. {
  708. dragElement_ = element;
  709. element->OnDragBegin(element->ScreenToElement(cursorPos), cursorPos, mouseButtons_, qualifiers_, cursor_);
  710. }
  711. }
  712. else
  713. {
  714. // If clicked over no element, or a disabled element, lose focus
  715. SetFocusElement(0);
  716. }
  717. using namespace UIMouseClick;
  718. VariantMap eventData;
  719. eventData[UIMouseClick::P_ELEMENT] = (void*)element.Get();
  720. eventData[UIMouseClick::P_X] = cursorPos.x_;
  721. eventData[UIMouseClick::P_Y] = cursorPos.y_;
  722. eventData[UIMouseClick::P_BUTTON] = button;
  723. eventData[UIMouseClick::P_BUTTONS] = mouseButtons_;
  724. eventData[UIMouseClick::P_QUALIFIERS] = qualifiers_;
  725. SendEvent(E_UIMOUSECLICK, eventData);
  726. }
  727. }
  728. void UI::HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
  729. {
  730. using namespace MouseButtonUp;
  731. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  732. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  733. IntVector2 cursorPos;
  734. bool cursorVisible;
  735. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  736. if (cursorVisible || dragElement_)
  737. {
  738. if (dragElement_ && !mouseButtons_)
  739. {
  740. if (dragElement_->IsEnabled() && dragElement_->IsVisible())
  741. {
  742. dragElement_->OnDragEnd(dragElement_->ScreenToElement(cursorPos), cursorPos, cursor_);
  743. // Drag and drop finish
  744. bool dragSource = dragElement_ && (dragElement_->GetDragDropMode() & DD_SOURCE) != 0;
  745. if (dragSource)
  746. {
  747. WeakPtr<UIElement> target(GetElementAt(cursorPos));
  748. bool dragTarget = target && (target->GetDragDropMode() & DD_TARGET) != 0;
  749. bool dragDropFinish = dragSource && dragTarget && target != dragElement_;
  750. if (dragDropFinish)
  751. {
  752. bool accept = target->OnDragDropFinish(dragElement_);
  753. // OnDragDropFinish() may have caused destruction of the elements, so check the pointers again
  754. if (accept && dragElement_ && target)
  755. {
  756. using namespace DragDropFinish;
  757. VariantMap eventData;
  758. eventData[P_SOURCE] = (void*)dragElement_.Get();
  759. eventData[P_TARGET] = (void*)target.Get();
  760. eventData[P_ACCEPT] = accept;
  761. SendEvent(E_DRAGDROPFINISH, eventData);
  762. }
  763. }
  764. }
  765. }
  766. dragElement_.Reset();
  767. }
  768. }
  769. }
  770. void UI::HandleMouseMove(StringHash eventType, VariantMap& eventData)
  771. {
  772. using namespace MouseMove;
  773. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  774. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  775. Input* input = GetSubsystem<Input>();
  776. const IntVector2& rootSize = rootElement_->GetSize();
  777. if (cursor_)
  778. {
  779. if (!input->IsMouseVisible())
  780. {
  781. // Relative mouse motion: move cursor only when visible
  782. if (cursor_->IsVisible())
  783. {
  784. IntVector2 pos = cursor_->GetPosition();
  785. pos.x_ += eventData[P_DX].GetInt();
  786. pos.y_ += eventData[P_DY].GetInt();
  787. pos.x_ = Clamp(pos.x_, 0, rootSize.x_ - 1);
  788. pos.y_ = Clamp(pos.y_, 0, rootSize.y_ - 1);
  789. cursor_->SetPosition(pos);
  790. }
  791. }
  792. else
  793. {
  794. // Absolute mouse motion: move always
  795. cursor_->SetPosition(IntVector2(eventData[P_X].GetInt(), eventData[P_Y].GetInt()));
  796. }
  797. }
  798. IntVector2 cursorPos;
  799. bool cursorVisible;
  800. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  801. if (cursorVisible && dragElement_ && mouseButtons_)
  802. {
  803. if (dragElement_->IsEnabled() && dragElement_->IsVisible())
  804. dragElement_->OnDragMove(dragElement_->ScreenToElement(cursorPos), cursorPos, mouseButtons_, qualifiers_, cursor_);
  805. else
  806. {
  807. dragElement_->OnDragEnd(dragElement_->ScreenToElement(cursorPos), cursorPos, cursor_);
  808. dragElement_.Reset();
  809. }
  810. }
  811. }
  812. void UI::HandleMouseWheel(StringHash eventType, VariantMap& eventData)
  813. {
  814. using namespace MouseWheel;
  815. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  816. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  817. int delta = eventData[P_WHEEL].GetInt();
  818. IntVector2 cursorPos;
  819. bool cursorVisible;
  820. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  821. UIElement* element;
  822. if (!nonFocusedMouseWheel_&& (element = focusElement_))
  823. element->OnWheel(delta, mouseButtons_, qualifiers_);
  824. else
  825. {
  826. // If no element has actual focus or in non-focused mode, get the element at cursor
  827. if (cursorVisible)
  828. {
  829. element = GetElementAt(cursorPos);
  830. if (nonFocusedMouseWheel_)
  831. {
  832. // Going up the hierarchy chain to find element that could handle mouse wheel
  833. while (element)
  834. {
  835. if (element->GetType() == ListView::GetTypeStatic() ||
  836. element->GetType() == ScrollView::GetTypeStatic())
  837. break;
  838. element = element->GetParent();
  839. }
  840. }
  841. else
  842. // If the element itself is not focusable, search for a focusable parent,
  843. // although the focusable element may not actually handle mouse wheel
  844. element = GetFocusableElement(element);
  845. if (element && (nonFocusedMouseWheel_ || element->GetFocusMode() >= FM_FOCUSABLE))
  846. element->OnWheel(delta, mouseButtons_, qualifiers_);
  847. }
  848. }
  849. }
  850. void UI::HandleTouchBegin(StringHash eventType, VariantMap& eventData)
  851. {
  852. using namespace TouchBegin;
  853. IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
  854. WeakPtr<UIElement> element(GetElementAt(pos));
  855. if (element)
  856. {
  857. // Handle focusing & bringing to front
  858. SetFocusElement(element);
  859. element->BringToFront();
  860. // Handle click
  861. element->OnClick(element->ScreenToElement(pos), pos, MOUSEB_LEFT, 0, 0);
  862. // Handle start of drag. OnClick() may have caused destruction of the element, so check the pointer again
  863. if (element && !dragElement_ )
  864. {
  865. dragElement_ = element;
  866. element->OnDragBegin(element->ScreenToElement(pos), pos, MOUSEB_LEFT, 0, 0);
  867. }
  868. }
  869. else
  870. {
  871. // If clicked over no element, or a disabled element, lose focus
  872. SetFocusElement(0);
  873. }
  874. using namespace UIMouseClick;
  875. VariantMap clickEventData;
  876. clickEventData[UIMouseClick::P_ELEMENT] = (void*)element.Get();
  877. clickEventData[UIMouseClick::P_X] = pos.x_;
  878. clickEventData[UIMouseClick::P_Y] = pos.y_;
  879. clickEventData[UIMouseClick::P_BUTTON] = MOUSEB_LEFT;
  880. clickEventData[UIMouseClick::P_BUTTONS] = MOUSEB_LEFT;
  881. clickEventData[UIMouseClick::P_QUALIFIERS] = 0;
  882. SendEvent(E_UIMOUSECLICK, clickEventData);
  883. }
  884. void UI::HandleTouchEnd(StringHash eventType, VariantMap& eventData)
  885. {
  886. using namespace TouchEnd;
  887. IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
  888. // Transmit hover end to the position where the finger was lifted
  889. UIElement* element = GetElementAt(pos);
  890. if (element && element->IsEnabled())
  891. element->OnHover(element->ScreenToElement(pos), pos, 0, 0, 0);
  892. if (dragElement_)
  893. {
  894. if (dragElement_->IsEnabled() && dragElement_->IsVisible())
  895. {
  896. dragElement_->OnDragEnd(dragElement_->ScreenToElement(pos), pos, cursor_);
  897. // Drag and drop finish
  898. bool dragSource = dragElement_ && (dragElement_->GetDragDropMode() & DD_SOURCE) != 0;
  899. if (dragSource)
  900. {
  901. WeakPtr<UIElement> target(GetElementAt(pos));
  902. bool dragTarget = target && (target->GetDragDropMode() & DD_TARGET) != 0;
  903. bool dragDropFinish = dragSource && dragTarget && target != dragElement_;
  904. if (dragDropFinish)
  905. {
  906. bool accept = target->OnDragDropFinish(dragElement_);
  907. // OnDragDropFinish() may have caused destruction of the elements, so check the pointers again
  908. if (accept && dragElement_ && target)
  909. {
  910. using namespace DragDropFinish;
  911. VariantMap eventData;
  912. eventData[P_SOURCE] = (void*)dragElement_.Get();
  913. eventData[P_TARGET] = (void*)target.Get();
  914. eventData[P_ACCEPT] = accept;
  915. SendEvent(E_DRAGDROPFINISH, eventData);
  916. }
  917. }
  918. }
  919. }
  920. dragElement_.Reset();
  921. }
  922. }
  923. void UI::HandleTouchMove(StringHash eventType, VariantMap& eventData)
  924. {
  925. using namespace TouchMove;
  926. IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
  927. if (dragElement_)
  928. {
  929. if (dragElement_->IsEnabled() && dragElement_->IsVisible())
  930. dragElement_->OnDragMove(dragElement_->ScreenToElement(pos), pos, MOUSEB_LEFT, 0, 0);
  931. else
  932. {
  933. dragElement_->OnDragEnd(dragElement_->ScreenToElement(pos), pos, 0);
  934. dragElement_.Reset();
  935. }
  936. }
  937. }
  938. void UI::HandleKeyDown(StringHash eventType, VariantMap& eventData)
  939. {
  940. using namespace KeyDown;
  941. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  942. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  943. int key = eventData[P_KEY].GetInt();
  944. // Dismiss modal element if any when ESC key is pressed
  945. if (key == KEY_ESC && HasModalElement())
  946. {
  947. UIElement* element = rootModalElement_->GetChild(rootModalElement_->GetNumChildren() - 1);
  948. if (element->GetVars().Contains(VAR_ORIGIN))
  949. // If it is a popup, dismiss by defocusing it
  950. SetFocusElement(0);
  951. else
  952. {
  953. // If it is a modal window, by resetting its modal flag and auto-remove it
  954. Window* window = dynamic_cast<Window*>(element);
  955. if (window)
  956. {
  957. window->SetModal(false);
  958. if (window->GetVars().Contains(VAR_NO_AUTO_REMOVE))
  959. const_cast<VariantMap&>(window->GetVars()).Erase(VAR_NO_AUTO_REMOVE);
  960. else
  961. window->Remove();
  962. }
  963. }
  964. return;
  965. }
  966. UIElement* element = focusElement_;
  967. if (element)
  968. {
  969. // Switch focus between focusable elements in the same top level window
  970. if (key == KEY_TAB)
  971. {
  972. UIElement* topLevel = element->GetParent();
  973. while (topLevel && topLevel->GetParent() != rootElement_ && topLevel->GetParent() != rootModalElement_)
  974. topLevel = topLevel->GetParent();
  975. if (topLevel)
  976. {
  977. topLevel->GetChildren(tempElements_, true);
  978. for (PODVector<UIElement*>::Iterator i = tempElements_.Begin(); i != tempElements_.End();)
  979. {
  980. if ((*i)->GetFocusMode() < FM_FOCUSABLE)
  981. i = tempElements_.Erase(i);
  982. else
  983. ++i;
  984. }
  985. for (unsigned i = 0; i < tempElements_.Size(); ++i)
  986. {
  987. if (tempElements_[i] == element)
  988. {
  989. UIElement* next = tempElements_[(i + 1) % tempElements_.Size()];
  990. SetFocusElement(next);
  991. return;
  992. }
  993. }
  994. }
  995. }
  996. // Defocus the element
  997. else if (key == KEY_ESC && element->GetFocusMode() == FM_FOCUSABLE_DEFOCUSABLE)
  998. element->SetFocus(false);
  999. // If none of the special keys, pass the key to the focused element
  1000. else
  1001. element->OnKey(key, mouseButtons_, qualifiers_);
  1002. }
  1003. }
  1004. void UI::HandleChar(StringHash eventType, VariantMap& eventData)
  1005. {
  1006. using namespace Char;
  1007. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  1008. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  1009. UIElement* element = focusElement_;
  1010. if (element)
  1011. element->OnChar(eventData[P_CHAR].GetInt(), mouseButtons_, qualifiers_);
  1012. }
  1013. void UI::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
  1014. {
  1015. using namespace PostUpdate;
  1016. Update(eventData[P_TIMESTEP].GetFloat());
  1017. }
  1018. void UI::HandleRenderUpdate(StringHash eventType, VariantMap& eventData)
  1019. {
  1020. RenderUpdate();
  1021. }
  1022. void RegisterUILibrary(Context* context)
  1023. {
  1024. Font::RegisterObject(context);
  1025. UIElement::RegisterObject(context);
  1026. BorderImage::RegisterObject(context);
  1027. Sprite::RegisterObject(context);
  1028. Button::RegisterObject(context);
  1029. CheckBox::RegisterObject(context);
  1030. Cursor::RegisterObject(context);
  1031. Text::RegisterObject(context);
  1032. Text3D::RegisterObject(context);
  1033. Window::RegisterObject(context);
  1034. LineEdit::RegisterObject(context);
  1035. Slider::RegisterObject(context);
  1036. ScrollBar::RegisterObject(context);
  1037. ScrollView::RegisterObject(context);
  1038. ListView::RegisterObject(context);
  1039. Menu::RegisterObject(context);
  1040. DropDownList::RegisterObject(context);
  1041. FileSelector::RegisterObject(context);
  1042. }
  1043. }