UI.cpp 42 KB

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