UI.cpp 41 KB

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