UI.cpp 41 KB

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