UI.cpp 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784
  1. //
  2. // Copyright (c) 2008-2015 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 "../UI/CheckBox.h"
  23. #include "../Core/Context.h"
  24. #include "../Core/CoreEvents.h"
  25. #include "../UI/Cursor.h"
  26. #include "../UI/DropDownList.h"
  27. #include "../UI/FileSelector.h"
  28. #include "../UI/Font.h"
  29. #include "../Graphics/Graphics.h"
  30. #include "../Graphics/GraphicsEvents.h"
  31. #include "../Input/Input.h"
  32. #include "../Input/InputEvents.h"
  33. #include "../UI/LineEdit.h"
  34. #include "../UI/ListView.h"
  35. #include "../IO/Log.h"
  36. #include "../Math/Matrix3x4.h"
  37. #include "../UI/MessageBox.h"
  38. #include "../Core/Profiler.h"
  39. #include "../Resource/ResourceCache.h"
  40. #include "../UI/ScrollBar.h"
  41. #include "../Graphics/Shader.h"
  42. #include "../Graphics/ShaderVariation.h"
  43. #include "../UI/Slider.h"
  44. #include "../Container/Sort.h"
  45. #include "../UI/Sprite.h"
  46. #include "../UI/Text.h"
  47. #include "../UI/Text3D.h"
  48. #include "../Graphics/Texture2D.h"
  49. #include "../UI/ToolTip.h"
  50. #include "../UI/UI.h"
  51. #include "../UI/UIEvents.h"
  52. #include "../Graphics/VertexBuffer.h"
  53. #include "../UI/Window.h"
  54. #include "../UI/View3D.h"
  55. #include <SDL/SDL.h>
  56. #include "../DebugNew.h"
  57. #define TOUCHID_MASK(id) (1 << id)
  58. namespace Urho3D
  59. {
  60. StringHash VAR_ORIGIN("Origin");
  61. const StringHash VAR_ORIGINAL_PARENT("OriginalParent");
  62. const StringHash VAR_ORIGINAL_CHILD_INDEX("OriginalChildIndex");
  63. const StringHash VAR_PARENT_CHANGED("ParentChanged");
  64. const float DEFAULT_DOUBLECLICK_INTERVAL = 0.5f;
  65. const float DEFAULT_DRAGBEGIN_INTERVAL = 0.5f;
  66. const float DEFAULT_TOOLTIP_DELAY = 0.5f;
  67. const int DEFAULT_DRAGBEGIN_DISTANCE = 5;
  68. const int DEFAULT_FONT_TEXTURE_MAX_SIZE = 2048;
  69. const char* UI_CATEGORY = "UI";
  70. UI::UI(Context* context) :
  71. Object(context),
  72. rootElement_(new UIElement(context)),
  73. rootModalElement_(new UIElement(context)),
  74. doubleClickInterval_(DEFAULT_DOUBLECLICK_INTERVAL),
  75. dragBeginInterval_(DEFAULT_DRAGBEGIN_INTERVAL),
  76. defaultToolTipDelay_(DEFAULT_TOOLTIP_DELAY),
  77. dragBeginDistance_(DEFAULT_DRAGBEGIN_DISTANCE),
  78. mouseButtons_(0),
  79. lastMouseButtons_(0),
  80. qualifiers_(0),
  81. maxFontTextureSize_(DEFAULT_FONT_TEXTURE_MAX_SIZE),
  82. initialized_(false),
  83. usingTouchInput_(false),
  84. #ifdef WIN32
  85. nonFocusedMouseWheel_(false), // Default MS Windows behaviour
  86. #else
  87. nonFocusedMouseWheel_(true), // Default Mac OS X and Linux behaviour
  88. #endif
  89. useSystemClipboard_(false),
  90. #if defined(ANDROID) || defined(IOS)
  91. useScreenKeyboard_(true),
  92. #else
  93. useScreenKeyboard_(false),
  94. #endif
  95. useMutableGlyphs_(false),
  96. forceAutoHint_(false),
  97. uiRendered_(false),
  98. nonModalBatchSize_(0),
  99. dragElementsCount_(0),
  100. dragConfirmedCount_(0)
  101. {
  102. rootElement_->SetTraversalMode(TM_DEPTH_FIRST);
  103. rootModalElement_->SetTraversalMode(TM_DEPTH_FIRST);
  104. // Register UI library object factories
  105. RegisterUILibrary(context_);
  106. SubscribeToEvent(E_SCREENMODE, HANDLER(UI, HandleScreenMode));
  107. SubscribeToEvent(E_MOUSEBUTTONDOWN, HANDLER(UI, HandleMouseButtonDown));
  108. SubscribeToEvent(E_MOUSEBUTTONUP, HANDLER(UI, HandleMouseButtonUp));
  109. SubscribeToEvent(E_MOUSEMOVE, HANDLER(UI, HandleMouseMove));
  110. SubscribeToEvent(E_MOUSEWHEEL, HANDLER(UI, HandleMouseWheel));
  111. SubscribeToEvent(E_TOUCHBEGIN, HANDLER(UI, HandleTouchBegin));
  112. SubscribeToEvent(E_TOUCHEND, HANDLER(UI, HandleTouchEnd));
  113. SubscribeToEvent(E_TOUCHMOVE, HANDLER(UI, HandleTouchMove));
  114. SubscribeToEvent(E_KEYDOWN, HANDLER(UI, HandleKeyDown));
  115. SubscribeToEvent(E_TEXTINPUT, HANDLER(UI, HandleTextInput));
  116. SubscribeToEvent(E_DROPFILE, HANDLER(UI, HandleDropFile));
  117. // Try to initialize right now, but skip if screen mode is not yet set
  118. Initialize();
  119. }
  120. UI::~UI()
  121. {
  122. }
  123. void UI::SetCursor(Cursor* cursor)
  124. {
  125. // Remove old cursor (if any) and set new
  126. if (cursor_)
  127. {
  128. rootElement_->RemoveChild(cursor_);
  129. cursor_.Reset();
  130. }
  131. if (cursor)
  132. {
  133. rootElement_->AddChild(cursor);
  134. cursor_ = cursor;
  135. IntVector2 pos = cursor_->GetPosition();
  136. const IntVector2& rootSize = rootElement_->GetSize();
  137. pos.x_ = Clamp(pos.x_, 0, rootSize.x_ - 1);
  138. pos.y_ = Clamp(pos.y_, 0, rootSize.y_ - 1);
  139. cursor_->SetPosition(pos);
  140. }
  141. }
  142. void UI::SetFocusElement(UIElement* element, bool byKey)
  143. {
  144. using namespace FocusChanged;
  145. UIElement* originalElement = element;
  146. if (element)
  147. {
  148. // Return if already has focus
  149. if (focusElement_ == element)
  150. return;
  151. // Only allow child elements of the modal element to receive focus
  152. if (HasModalElement())
  153. {
  154. UIElement* topLevel = element->GetParent();
  155. while (topLevel && topLevel->GetParent() != rootElement_)
  156. topLevel = topLevel->GetParent();
  157. if (topLevel) // If parented to non-modal root then ignore
  158. return;
  159. }
  160. // Search for an element in the hierarchy that can alter focus. If none found, exit
  161. element = GetFocusableElement(element);
  162. if (!element)
  163. return;
  164. }
  165. // Remove focus from the old element
  166. if (focusElement_)
  167. {
  168. UIElement* oldFocusElement = focusElement_;
  169. focusElement_.Reset();
  170. VariantMap& focusEventData = GetEventDataMap();
  171. focusEventData[Defocused::P_ELEMENT] = oldFocusElement;
  172. oldFocusElement->SendEvent(E_DEFOCUSED, focusEventData);
  173. }
  174. // Then set focus to the new
  175. if (element && element->GetFocusMode() >= FM_FOCUSABLE)
  176. {
  177. focusElement_ = element;
  178. VariantMap& focusEventData = GetEventDataMap();
  179. focusEventData[Focused::P_ELEMENT] = element;
  180. focusEventData[Focused::P_BYKEY] = byKey;
  181. element->SendEvent(E_FOCUSED, focusEventData);
  182. }
  183. VariantMap& eventData = GetEventDataMap();
  184. eventData[P_CLICKEDELEMENT] = originalElement;
  185. eventData[P_ELEMENT] = element;
  186. SendEvent(E_FOCUSCHANGED, eventData);
  187. }
  188. bool UI::SetModalElement(UIElement* modalElement, bool enable)
  189. {
  190. if (!modalElement)
  191. return false;
  192. // Currently only allow modal window
  193. if (modalElement->GetType() != Window::GetTypeStatic())
  194. return false;
  195. assert(rootModalElement_);
  196. UIElement* currParent = modalElement->GetParent();
  197. if (enable)
  198. {
  199. // Make sure it is not already the child of the root modal element
  200. if (currParent == rootModalElement_)
  201. return false;
  202. // Adopt modal root as parent
  203. modalElement->SetVar(VAR_ORIGINAL_PARENT, currParent);
  204. modalElement->SetVar(VAR_ORIGINAL_CHILD_INDEX, currParent ? currParent->FindChild(modalElement) : M_MAX_UNSIGNED);
  205. modalElement->SetParent(rootModalElement_);
  206. // If it is a popup element, bring along its top-level parent
  207. UIElement* originElement = static_cast<UIElement*>(modalElement->GetVar(VAR_ORIGIN).GetPtr());
  208. if (originElement)
  209. {
  210. UIElement* element = originElement;
  211. while (element && element->GetParent() != rootElement_)
  212. element = element->GetParent();
  213. if (element)
  214. {
  215. originElement->SetVar(VAR_PARENT_CHANGED, element);
  216. UIElement* oriParent = element->GetParent();
  217. element->SetVar(VAR_ORIGINAL_PARENT, oriParent);
  218. element->SetVar(VAR_ORIGINAL_CHILD_INDEX, oriParent ? oriParent->FindChild(element) : M_MAX_UNSIGNED);
  219. element->SetParent(rootModalElement_);
  220. }
  221. }
  222. return true;
  223. }
  224. else
  225. {
  226. // Only the modal element can disable itself
  227. if (currParent != rootModalElement_)
  228. return false;
  229. // Revert back to original parent
  230. modalElement->SetParent(static_cast<UIElement*>(modalElement->GetVar(VAR_ORIGINAL_PARENT).GetPtr()),
  231. modalElement->GetVar(VAR_ORIGINAL_CHILD_INDEX).GetUInt());
  232. VariantMap& vars = const_cast<VariantMap&>(modalElement->GetVars());
  233. vars.Erase(VAR_ORIGINAL_PARENT);
  234. vars.Erase(VAR_ORIGINAL_CHILD_INDEX);
  235. // If it is a popup element, revert back its top-level parent
  236. UIElement* originElement = static_cast<UIElement*>(modalElement->GetVar(VAR_ORIGIN).GetPtr());
  237. if (originElement)
  238. {
  239. UIElement* element = static_cast<UIElement*>(originElement->GetVar(VAR_PARENT_CHANGED).GetPtr());
  240. if (element)
  241. {
  242. const_cast<VariantMap&>(originElement->GetVars()).Erase(VAR_PARENT_CHANGED);
  243. element->SetParent(static_cast<UIElement*>(element->GetVar(VAR_ORIGINAL_PARENT).GetPtr()),
  244. element->GetVar(VAR_ORIGINAL_CHILD_INDEX).GetUInt());
  245. vars = const_cast<VariantMap&>(element->GetVars());
  246. vars.Erase(VAR_ORIGINAL_PARENT);
  247. vars.Erase(VAR_ORIGINAL_CHILD_INDEX);
  248. }
  249. }
  250. return true;
  251. }
  252. }
  253. void UI::Clear()
  254. {
  255. rootElement_->RemoveAllChildren();
  256. rootModalElement_->RemoveAllChildren();
  257. if (cursor_)
  258. rootElement_->AddChild(cursor_);
  259. }
  260. void UI::Update(float timeStep)
  261. {
  262. assert(rootElement_ && rootModalElement_);
  263. PROFILE(UpdateUI);
  264. // Expire hovers
  265. for (HashMap<WeakPtr<UIElement>, bool>::Iterator i = hoveredElements_.Begin(); i != hoveredElements_.End(); ++i)
  266. i->second_ = false;
  267. Input* input = GetSubsystem<Input>();
  268. bool mouseGrabbed = input->IsMouseGrabbed();
  269. IntVector2 cursorPos;
  270. bool cursorVisible;
  271. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  272. // Drag begin based on time
  273. if (dragElementsCount_ > 0 && !mouseGrabbed)
  274. {
  275. for (HashMap<WeakPtr<UIElement>, UI::DragData*>::Iterator i = dragElements_.Begin(); i != dragElements_.End(); )
  276. {
  277. WeakPtr<UIElement> dragElement = i->first_;
  278. UI::DragData* dragData = i->second_;
  279. if (!dragElement)
  280. {
  281. i = DragElementErase(i);
  282. continue;
  283. }
  284. if (!dragData->dragBeginPending)
  285. {
  286. ++i;
  287. continue;
  288. }
  289. if (dragData->dragBeginTimer.GetMSec(false) >= (unsigned)(dragBeginInterval_ * 1000))
  290. {
  291. dragData->dragBeginPending = false;
  292. IntVector2 beginSendPos = dragData->dragBeginSumPos / dragData->numDragButtons;
  293. dragConfirmedCount_ ++;
  294. if (!usingTouchInput_)
  295. dragElement->OnDragBegin(dragElement->ScreenToElement(beginSendPos), beginSendPos, dragData->dragButtons, qualifiers_,cursor_);
  296. else
  297. dragElement->OnDragBegin(dragElement->ScreenToElement(beginSendPos), beginSendPos, dragData->dragButtons, 0, 0);
  298. SendDragOrHoverEvent(E_DRAGBEGIN, dragElement, beginSendPos, IntVector2::ZERO, dragData);
  299. }
  300. ++i;
  301. }
  302. }
  303. // Mouse hover
  304. if (!mouseGrabbed && !input->GetTouchEmulation())
  305. {
  306. if (!usingTouchInput_ && cursorVisible)
  307. ProcessHover(cursorPos, mouseButtons_, qualifiers_, cursor_);
  308. }
  309. // Touch hover
  310. unsigned numTouches = input->GetNumTouches();
  311. for (unsigned i = 0; i < numTouches; ++i)
  312. {
  313. TouchState* touch = input->GetTouch(i);
  314. ProcessHover(touch->position_, TOUCHID_MASK(touch->touchID_), 0, 0);
  315. }
  316. // End hovers that expired without refreshing
  317. for (HashMap<WeakPtr<UIElement>, bool>::Iterator i = hoveredElements_.Begin(); i != hoveredElements_.End();)
  318. {
  319. if (i->first_.Expired() || !i->second_)
  320. {
  321. UIElement* element = i->first_;
  322. if (element)
  323. {
  324. using namespace HoverEnd;
  325. VariantMap& eventData = GetEventDataMap();
  326. eventData[P_ELEMENT] = element;
  327. element->SendEvent(E_HOVEREND, eventData);
  328. }
  329. i = hoveredElements_.Erase(i);
  330. }
  331. else
  332. ++i;
  333. }
  334. Update(timeStep, rootElement_);
  335. Update(timeStep, rootModalElement_);
  336. }
  337. void UI::RenderUpdate()
  338. {
  339. assert(rootElement_ && rootModalElement_ && graphics_);
  340. PROFILE(GetUIBatches);
  341. uiRendered_ = false;
  342. // If the OS cursor is visible, do not render the UI's own cursor
  343. bool osCursorVisible = GetSubsystem<Input>()->IsMouseVisible();
  344. // Get rendering batches from the non-modal UI elements
  345. batches_.Clear();
  346. vertexData_.Clear();
  347. const IntVector2& rootSize = rootElement_->GetSize();
  348. IntRect currentScissor = IntRect(0, 0, rootSize.x_, rootSize.y_);
  349. GetBatches(rootElement_, currentScissor);
  350. // Save the batch size of the non-modal batches for later use
  351. nonModalBatchSize_ = batches_.Size();
  352. // Get rendering batches from the modal UI elements
  353. GetBatches(rootModalElement_, currentScissor);
  354. // Get batches from the cursor (and its possible children) last to draw it on top of everything
  355. if (cursor_ && cursor_->IsVisible() && !osCursorVisible)
  356. {
  357. currentScissor = IntRect(0, 0, rootSize.x_, rootSize.y_);
  358. cursor_->GetBatches(batches_, vertexData_, currentScissor);
  359. GetBatches(cursor_, currentScissor);
  360. }
  361. }
  362. void UI::Render(bool resetRenderTargets)
  363. {
  364. // Perform the default render only if not rendered yet
  365. if (resetRenderTargets && uiRendered_)
  366. return;
  367. PROFILE(RenderUI);
  368. // If the OS cursor is visible, apply its shape now if changed
  369. bool osCursorVisible = GetSubsystem<Input>()->IsMouseVisible();
  370. if (cursor_ && osCursorVisible)
  371. cursor_->ApplyOSCursorShape();
  372. SetVertexData(vertexBuffer_, vertexData_);
  373. SetVertexData(debugVertexBuffer_, debugVertexData_);
  374. // Render non-modal batches
  375. Render(resetRenderTargets, vertexBuffer_, batches_, 0, nonModalBatchSize_);
  376. // Render debug draw
  377. Render(resetRenderTargets, debugVertexBuffer_, debugDrawBatches_, 0, debugDrawBatches_.Size());
  378. // Render modal batches
  379. Render(resetRenderTargets, vertexBuffer_, batches_, nonModalBatchSize_, batches_.Size());
  380. // Clear the debug draw batches and data
  381. debugDrawBatches_.Clear();
  382. debugVertexData_.Clear();
  383. uiRendered_ = true;
  384. }
  385. void UI::DebugDraw(UIElement* element)
  386. {
  387. if (element)
  388. {
  389. const IntVector2& rootSize = rootElement_->GetSize();
  390. element->GetDebugDrawBatches(debugDrawBatches_, debugVertexData_, IntRect(0, 0, rootSize.x_, rootSize.y_));
  391. }
  392. }
  393. SharedPtr<UIElement> UI::LoadLayout(Deserializer& source, XMLFile* styleFile)
  394. {
  395. SharedPtr<XMLFile> xml(new XMLFile(context_));
  396. if (!xml->Load(source))
  397. return SharedPtr<UIElement>();
  398. else
  399. return LoadLayout(xml, styleFile);
  400. }
  401. SharedPtr<UIElement> UI::LoadLayout(XMLFile* file, XMLFile* styleFile)
  402. {
  403. PROFILE(LoadUILayout);
  404. SharedPtr<UIElement> root;
  405. if (!file)
  406. {
  407. LOGERROR("Null UI layout XML file");
  408. return root;
  409. }
  410. LOGDEBUG("Loading UI layout " + file->GetName());
  411. XMLElement rootElem = file->GetRoot("element");
  412. if (!rootElem)
  413. {
  414. LOGERROR("No root UI element in " + file->GetName());
  415. return root;
  416. }
  417. String typeName = rootElem.GetAttribute("type");
  418. if (typeName.Empty())
  419. typeName = "UIElement";
  420. root = DynamicCast<UIElement>(context_->CreateObject(typeName));
  421. if (!root)
  422. {
  423. LOGERROR("Could not create unknown UI element " + typeName);
  424. return root;
  425. }
  426. // Use default style file of the root element if it has one
  427. if (!styleFile)
  428. styleFile = rootElement_->GetDefaultStyle(false);
  429. // Set it as default for later use by children elements
  430. if (styleFile)
  431. root->SetDefaultStyle(styleFile);
  432. root->LoadXML(rootElem, styleFile);
  433. return root;
  434. }
  435. bool UI::SaveLayout(Serializer& dest, UIElement* element)
  436. {
  437. PROFILE(SaveUILayout);
  438. return element && element->SaveXML(dest);
  439. }
  440. void UI::SetClipboardText(const String& text)
  441. {
  442. clipBoard_ = text;
  443. if (useSystemClipboard_)
  444. SDL_SetClipboardText(text.CString());
  445. }
  446. void UI::SetDoubleClickInterval(float interval)
  447. {
  448. doubleClickInterval_ = Max(interval, 0.0f);
  449. }
  450. void UI::SetDragBeginInterval(float interval)
  451. {
  452. dragBeginInterval_ = Max(interval, 0.0f);
  453. }
  454. void UI::SetDragBeginDistance(int pixels)
  455. {
  456. dragBeginDistance_ = Max(pixels, 0);
  457. }
  458. void UI::SetDefaultToolTipDelay(float delay)
  459. {
  460. defaultToolTipDelay_ = Max(delay, 0.0f);
  461. }
  462. void UI::SetMaxFontTextureSize(int size)
  463. {
  464. if (IsPowerOfTwo(size) && size >= FONT_TEXTURE_MIN_SIZE)
  465. {
  466. if (size != maxFontTextureSize_)
  467. {
  468. maxFontTextureSize_ = size;
  469. ReleaseFontFaces();
  470. }
  471. }
  472. }
  473. void UI::SetNonFocusedMouseWheel(bool nonFocusedMouseWheel)
  474. {
  475. nonFocusedMouseWheel_ = nonFocusedMouseWheel;
  476. }
  477. void UI::SetUseSystemClipboard(bool enable)
  478. {
  479. useSystemClipboard_ = enable;
  480. }
  481. void UI::SetUseScreenKeyboard(bool enable)
  482. {
  483. useScreenKeyboard_ = enable;
  484. }
  485. void UI::SetUseMutableGlyphs(bool enable)
  486. {
  487. if (enable != useMutableGlyphs_)
  488. {
  489. useMutableGlyphs_ = enable;
  490. ReleaseFontFaces();
  491. }
  492. }
  493. void UI::SetForceAutoHint(bool enable)
  494. {
  495. if (enable != forceAutoHint_)
  496. {
  497. forceAutoHint_ = enable;
  498. ReleaseFontFaces();
  499. }
  500. }
  501. IntVector2 UI::GetCursorPosition() const
  502. {
  503. return cursor_ ? cursor_->GetPosition() : GetSubsystem<Input>()->GetMousePosition();
  504. }
  505. UIElement* UI::GetElementAt(const IntVector2& position, bool enabledOnly)
  506. {
  507. UIElement* result = 0;
  508. GetElementAt(result, HasModalElement() ? rootModalElement_ : rootElement_, position, enabledOnly);
  509. return result;
  510. }
  511. UIElement* UI::GetElementAt(int x, int y, bool enabledOnly)
  512. {
  513. return GetElementAt(IntVector2(x, y), enabledOnly);
  514. }
  515. UIElement* UI::GetFrontElement() const
  516. {
  517. const Vector<SharedPtr<UIElement> >& rootChildren = rootElement_->GetChildren();
  518. int maxPriority = M_MIN_INT;
  519. UIElement* front = 0;
  520. for (unsigned i = 0; i < rootChildren.Size(); ++i)
  521. {
  522. // Do not take into account input-disabled elements, hidden elements or those that are always in the front
  523. if (!rootChildren[i]->IsEnabled() || !rootChildren[i]->IsVisible() || !rootChildren[i]->GetBringToBack())
  524. continue;
  525. int priority = rootChildren[i]->GetPriority();
  526. if (priority > maxPriority)
  527. {
  528. maxPriority = priority;
  529. front = rootChildren[i];
  530. }
  531. }
  532. return front;
  533. }
  534. const Vector<UIElement*> UI::GetDragElements()
  535. {
  536. // Do not return the element until drag begin event has actually been posted
  537. if (!dragElementsConfirmed_.Empty())
  538. return dragElementsConfirmed_;
  539. for (HashMap<WeakPtr<UIElement>, UI::DragData*>::Iterator i = dragElements_.Begin(); i != dragElements_.End(); )
  540. {
  541. WeakPtr<UIElement> dragElement = i->first_;
  542. UI::DragData* dragData = i->second_;
  543. if (!dragElement)
  544. {
  545. i = DragElementErase(i);
  546. continue;
  547. }
  548. if (!dragData->dragBeginPending)
  549. dragElementsConfirmed_.Push(dragElement);
  550. ++i;
  551. }
  552. return dragElementsConfirmed_;
  553. }
  554. UIElement* UI::GetDragElement(unsigned index)
  555. {
  556. GetDragElements();
  557. if (index >= dragElementsConfirmed_.Size())
  558. return (UIElement*)0;
  559. return dragElementsConfirmed_[index];
  560. }
  561. const String& UI::GetClipboardText() const
  562. {
  563. if (useSystemClipboard_)
  564. {
  565. char* text = SDL_GetClipboardText();
  566. clipBoard_ = String(text);
  567. if (text)
  568. SDL_free(text);
  569. }
  570. return clipBoard_;
  571. }
  572. bool UI::HasModalElement() const
  573. {
  574. return rootModalElement_->GetNumChildren() > 0;
  575. }
  576. void UI::Initialize()
  577. {
  578. Graphics* graphics = GetSubsystem<Graphics>();
  579. if (!graphics || !graphics->IsInitialized())
  580. return;
  581. PROFILE(InitUI);
  582. graphics_ = graphics;
  583. UIBatch::posAdjust = Vector3(Graphics::GetPixelUVOffset(), 0.0f);
  584. rootElement_->SetSize(graphics->GetWidth(), graphics->GetHeight());
  585. rootModalElement_->SetSize(rootElement_->GetSize());
  586. vertexBuffer_ = new VertexBuffer(context_);
  587. debugVertexBuffer_ = new VertexBuffer(context_);
  588. initialized_ = true;
  589. SubscribeToEvent(E_BEGINFRAME, HANDLER(UI, HandleBeginFrame));
  590. SubscribeToEvent(E_POSTUPDATE, HANDLER(UI, HandlePostUpdate));
  591. SubscribeToEvent(E_RENDERUPDATE, HANDLER(UI, HandleRenderUpdate));
  592. LOGINFO("Initialized user interface");
  593. }
  594. void UI::Update(float timeStep, UIElement* element)
  595. {
  596. // Keep a weak pointer to the element in case it destroys itself on update
  597. WeakPtr<UIElement> elementWeak(element);
  598. element->Update(timeStep);
  599. if (elementWeak.Expired())
  600. return;
  601. const Vector<SharedPtr<UIElement> >& children = element->GetChildren();
  602. // Update of an element may modify its child vector. Use just index-based iteration to be safe
  603. for (unsigned i = 0; i < children.Size(); ++i)
  604. Update(timeStep, children[i]);
  605. }
  606. void UI::SetVertexData(VertexBuffer* dest, const PODVector<float>& vertexData)
  607. {
  608. if (vertexData.Empty())
  609. return;
  610. // Update quad geometry into the vertex buffer
  611. // Resize the vertex buffer first if too small or much too large
  612. unsigned numVertices = vertexData.Size() / UI_VERTEX_SIZE;
  613. if (dest->GetVertexCount() < numVertices || dest->GetVertexCount() > numVertices * 2)
  614. dest->SetSize(numVertices, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1, true);
  615. dest->SetData(&vertexData[0]);
  616. }
  617. void UI::Render(bool resetRenderTargets, VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigned batchStart, unsigned batchEnd)
  618. {
  619. // Engine does not render when window is closed or device is lost
  620. assert(graphics_ && graphics_->IsInitialized() && !graphics_->IsDeviceLost());
  621. if (batches.Empty())
  622. return;
  623. Vector2 invScreenSize(1.0f / (float)graphics_->GetWidth(), 1.0f / (float)graphics_->GetHeight());
  624. Vector2 scale(2.0f * invScreenSize.x_, -2.0f * invScreenSize.y_);
  625. Vector2 offset(-1.0f, 1.0f);
  626. Matrix4 projection(Matrix4::IDENTITY);
  627. projection.m00_ = scale.x_;
  628. projection.m03_ = offset.x_;
  629. projection.m11_ = scale.y_;
  630. projection.m13_ = offset.y_;
  631. projection.m22_ = 1.0f;
  632. projection.m23_ = 0.0f;
  633. projection.m33_ = 1.0f;
  634. graphics_->ClearParameterSources();
  635. graphics_->SetColorWrite(true);
  636. graphics_->SetCullMode(CULL_CCW);
  637. graphics_->SetDepthTest(CMP_ALWAYS);
  638. graphics_->SetDepthWrite(false);
  639. graphics_->SetFillMode(FILL_SOLID);
  640. graphics_->SetStencilTest(false);
  641. if (resetRenderTargets)
  642. graphics_->ResetRenderTargets();
  643. graphics_->SetVertexBuffer(buffer);
  644. ShaderVariation* noTextureVS = graphics_->GetShader(VS, "Basic", "VERTEXCOLOR");
  645. ShaderVariation* diffTextureVS = graphics_->GetShader(VS, "Basic", "DIFFMAP VERTEXCOLOR");
  646. ShaderVariation* noTexturePS = graphics_->GetShader(PS, "Basic", "VERTEXCOLOR");
  647. ShaderVariation* diffTexturePS = graphics_->GetShader(PS, "Basic", "DIFFMAP VERTEXCOLOR");
  648. ShaderVariation* diffMaskTexturePS = graphics_->GetShader(PS, "Basic", "DIFFMAP ALPHAMASK VERTEXCOLOR");
  649. ShaderVariation* alphaTexturePS = graphics_->GetShader(PS, "Basic", "ALPHAMAP VERTEXCOLOR");
  650. unsigned alphaFormat = Graphics::GetAlphaFormat();
  651. for (unsigned i = batchStart; i < batchEnd; ++i)
  652. {
  653. const UIBatch& batch = batches[i];
  654. if (batch.vertexStart_ == batch.vertexEnd_)
  655. continue;
  656. ShaderVariation* ps;
  657. ShaderVariation* vs;
  658. if (!batch.texture_)
  659. {
  660. ps = noTexturePS;
  661. vs = noTextureVS;
  662. }
  663. else
  664. {
  665. // If texture contains only an alpha channel, use alpha shader (for fonts)
  666. vs = diffTextureVS;
  667. if (batch.texture_->GetFormat() == alphaFormat)
  668. ps = alphaTexturePS;
  669. else if (batch.blendMode_ != BLEND_ALPHA && batch.blendMode_ != BLEND_ADDALPHA && batch.blendMode_ != BLEND_PREMULALPHA)
  670. ps = diffMaskTexturePS;
  671. else
  672. ps = diffTexturePS;
  673. }
  674. graphics_->SetShaders(vs, ps);
  675. if (graphics_->NeedParameterUpdate(SP_OBJECT, this))
  676. graphics_->SetShaderParameter(VSP_MODEL, Matrix3x4::IDENTITY);
  677. if (graphics_->NeedParameterUpdate(SP_CAMERA, this))
  678. graphics_->SetShaderParameter(VSP_VIEWPROJ, projection);
  679. if (graphics_->NeedParameterUpdate(SP_MATERIAL, this))
  680. graphics_->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f));
  681. graphics_->SetBlendMode(batch.blendMode_);
  682. graphics_->SetScissorTest(true, batch.scissor_);
  683. graphics_->SetTexture(0, batch.texture_);
  684. graphics_->Draw(TRIANGLE_LIST, batch.vertexStart_ / UI_VERTEX_SIZE, (batch.vertexEnd_ - batch.vertexStart_) /
  685. UI_VERTEX_SIZE);
  686. }
  687. }
  688. void UI::GetBatches(UIElement* element, IntRect currentScissor)
  689. {
  690. // Set clipping scissor for child elements. No need to draw if zero size
  691. element->AdjustScissor(currentScissor);
  692. if (currentScissor.left_ == currentScissor.right_ || currentScissor.top_ == currentScissor.bottom_)
  693. return;
  694. element->SortChildren();
  695. const Vector<SharedPtr<UIElement> >& children = element->GetChildren();
  696. if (children.Empty())
  697. return;
  698. // For non-root elements draw all children of same priority before recursing into their children: assumption is that they have
  699. // same renderstate
  700. Vector<SharedPtr<UIElement> >::ConstIterator i = children.Begin();
  701. if (element->GetTraversalMode() == TM_BREADTH_FIRST)
  702. {
  703. Vector<SharedPtr<UIElement> >::ConstIterator j = i;
  704. while (i != children.End())
  705. {
  706. int currentPriority = (*i)->GetPriority();
  707. while (j != children.End() && (*j)->GetPriority() == currentPriority)
  708. {
  709. if ((*j)->IsWithinScissor(currentScissor) && (*j) != cursor_)
  710. (*j)->GetBatches(batches_, vertexData_, currentScissor);
  711. ++j;
  712. }
  713. // Now recurse into the children
  714. while (i != j)
  715. {
  716. if ((*i)->IsVisible() && (*i) != cursor_)
  717. GetBatches(*i, currentScissor);
  718. ++i;
  719. }
  720. }
  721. }
  722. // On the root level draw each element and its children immediately after to avoid artifacts
  723. else
  724. {
  725. while (i != children.End())
  726. {
  727. if ((*i) != cursor_)
  728. {
  729. if ((*i)->IsWithinScissor(currentScissor))
  730. (*i)->GetBatches(batches_, vertexData_, currentScissor);
  731. if ((*i)->IsVisible())
  732. GetBatches(*i, currentScissor);
  733. }
  734. ++i;
  735. }
  736. }
  737. }
  738. void UI::GetElementAt(UIElement*& result, UIElement* current, const IntVector2& position, bool enabledOnly)
  739. {
  740. if (!current)
  741. return;
  742. current->SortChildren();
  743. const Vector<SharedPtr<UIElement> >& children = current->GetChildren();
  744. LayoutMode parentLayoutMode = current->GetLayoutMode();
  745. for (unsigned i = 0; i < children.Size(); ++i)
  746. {
  747. UIElement* element = children[i];
  748. bool hasChildren = element->GetNumChildren() > 0;
  749. if (element != cursor_.Get() && element->IsVisible())
  750. {
  751. if (element->IsInside(position, true))
  752. {
  753. // Store the current result, then recurse into its children. Because children
  754. // are sorted from lowest to highest priority, the topmost match should remain
  755. if (element->IsEnabled() || !enabledOnly)
  756. result = element;
  757. if (hasChildren)
  758. GetElementAt(result, element, position, enabledOnly);
  759. // Layout optimization: if the element has no children, can break out after the first match
  760. else if (parentLayoutMode != LM_FREE)
  761. break;
  762. }
  763. else
  764. {
  765. if (hasChildren)
  766. {
  767. if (element->IsInsideCombined(position, true))
  768. GetElementAt(result, element, position, enabledOnly);
  769. }
  770. // Layout optimization: if position is much beyond the visible screen, check how many elements we can skip,
  771. // or if we already passed all visible elements
  772. else if (parentLayoutMode != LM_FREE)
  773. {
  774. if (!i)
  775. {
  776. int screenPos = (parentLayoutMode == LM_HORIZONTAL) ? element->GetScreenPosition().x_ :
  777. element->GetScreenPosition().y_;
  778. int layoutMaxSize = current->GetLayoutMaxSize();
  779. if (screenPos < 0 && layoutMaxSize > 0)
  780. {
  781. unsigned toSkip = -screenPos / layoutMaxSize;
  782. if (toSkip > 0)
  783. i += (toSkip - 1);
  784. }
  785. }
  786. else if (parentLayoutMode == LM_HORIZONTAL)
  787. {
  788. if (element->GetScreenPosition().x_ >= rootElement_->GetSize().x_)
  789. break;
  790. }
  791. else if (parentLayoutMode == LM_VERTICAL)
  792. {
  793. if (element->GetScreenPosition().y_ >= rootElement_->GetSize().y_)
  794. break;
  795. }
  796. }
  797. }
  798. }
  799. }
  800. }
  801. UIElement* UI::GetFocusableElement(UIElement* element)
  802. {
  803. while (element)
  804. {
  805. if (element->GetFocusMode() != FM_NOTFOCUSABLE)
  806. break;
  807. element = element->GetParent();
  808. }
  809. return element;
  810. }
  811. void UI::GetCursorPositionAndVisible(IntVector2& pos, bool& visible)
  812. {
  813. // Prefer software cursor then OS-specific cursor
  814. if (cursor_ && cursor_->IsVisible())
  815. {
  816. pos = cursor_->GetPosition();
  817. visible = true;
  818. }
  819. else if (GetSubsystem<Input>()->GetMouseMode() == MM_RELATIVE)
  820. visible = true;
  821. else
  822. {
  823. Input* input = GetSubsystem<Input>();
  824. pos = input->GetMousePosition();
  825. visible = input->IsMouseVisible();
  826. if (!visible && cursor_)
  827. pos = cursor_->GetPosition();
  828. }
  829. }
  830. void UI::SetCursorShape(CursorShape shape)
  831. {
  832. if (cursor_)
  833. cursor_->SetShape(shape);
  834. }
  835. void UI::ReleaseFontFaces()
  836. {
  837. LOGDEBUG("Reloading font faces");
  838. PODVector<Font*> fonts;
  839. GetSubsystem<ResourceCache>()->GetResources<Font>(fonts);
  840. for (unsigned i = 0; i < fonts.Size(); ++i)
  841. fonts[i]->ReleaseFaces();
  842. }
  843. void UI::ProcessHover(const IntVector2& cursorPos, int buttons, int qualifiers, Cursor* cursor)
  844. {
  845. WeakPtr<UIElement> element(GetElementAt(cursorPos));
  846. for (HashMap<WeakPtr<UIElement>, UI::DragData*>::Iterator i = dragElements_.Begin(); i != dragElements_.End();)
  847. {
  848. WeakPtr<UIElement> dragElement = i->first_;
  849. UI::DragData* dragData = i->second_;
  850. if (!dragElement)
  851. {
  852. i = DragElementErase(i);
  853. continue;
  854. }
  855. bool dragSource = dragElement && (dragElement->GetDragDropMode() & DD_SOURCE) != 0;
  856. bool dragTarget = element && (element->GetDragDropMode() & DD_TARGET) != 0;
  857. bool dragDropTest = dragSource && dragTarget && element != dragElement;
  858. // If drag start event has not been posted yet, do not do drag handling here
  859. if (dragData->dragBeginPending)
  860. dragSource = dragTarget = dragDropTest = false;
  861. // Hover effect
  862. // If a drag is going on, transmit hover only to the element being dragged, unless it's a drop target
  863. if (element && element->IsEnabled())
  864. {
  865. if (dragElement == element || dragDropTest)
  866. {
  867. element->OnHover(element->ScreenToElement(cursorPos), cursorPos, buttons, qualifiers, cursor);
  868. // Begin hover event
  869. if (!hoveredElements_.Contains(element))
  870. {
  871. SendDragOrHoverEvent(E_HOVERBEGIN, element, cursorPos, IntVector2::ZERO, 0);
  872. // Exit if element is destroyed by the event handling
  873. if (!element)
  874. return;
  875. }
  876. hoveredElements_[element] = true;
  877. }
  878. }
  879. // Drag and drop test
  880. if (dragDropTest)
  881. {
  882. bool accept = element->OnDragDropTest(dragElement);
  883. if (accept)
  884. {
  885. using namespace DragDropTest;
  886. VariantMap& eventData = GetEventDataMap();
  887. eventData[P_SOURCE] = dragElement.Get();
  888. eventData[P_TARGET] = element.Get();
  889. eventData[P_ACCEPT] = accept;
  890. SendEvent(E_DRAGDROPTEST, eventData);
  891. accept = eventData[P_ACCEPT].GetBool();
  892. }
  893. if (cursor)
  894. cursor->SetShape(accept ? CS_ACCEPTDROP : CS_REJECTDROP);
  895. }
  896. else if (dragSource && cursor)
  897. cursor->SetShape(dragElement == element ? CS_ACCEPTDROP : CS_REJECTDROP);
  898. ++i;
  899. }
  900. // Hover effect
  901. // If no drag is going on, transmit hover event.
  902. if (element && element->IsEnabled())
  903. {
  904. if (dragElementsCount_ == 0)
  905. {
  906. element->OnHover(element->ScreenToElement(cursorPos), cursorPos, buttons, qualifiers, cursor);
  907. // Begin hover event
  908. if (!hoveredElements_.Contains(element))
  909. {
  910. SendDragOrHoverEvent(E_HOVERBEGIN, element, cursorPos, IntVector2::ZERO, 0);
  911. // Exit if element is destroyed by the event handling
  912. if (!element)
  913. return;
  914. }
  915. hoveredElements_[element] = true;
  916. }
  917. }
  918. }
  919. void UI::ProcessClickBegin(const IntVector2& cursorPos, int button, int buttons, int qualifiers, Cursor* cursor, bool cursorVisible)
  920. {
  921. if (cursorVisible)
  922. {
  923. WeakPtr<UIElement> element(GetElementAt(cursorPos));
  924. bool newButton;
  925. if (usingTouchInput_)
  926. newButton = (button & buttons) == 0;
  927. else
  928. newButton = true;
  929. buttons |= button;
  930. if (element)
  931. SetFocusElement (element);
  932. // Focus change events may destroy the element, check again.
  933. if (element)
  934. {
  935. // Handle focusing & bringing to front
  936. element->BringToFront();
  937. // Handle click
  938. element->OnClickBegin(element->ScreenToElement(cursorPos), cursorPos, button, buttons, qualifiers, cursor);
  939. SendClickEvent(E_UIMOUSECLICK, NULL, element, cursorPos, button, buttons, qualifiers);
  940. // Fire double click event if element matches and is in time
  941. if (doubleClickElement_ && element == doubleClickElement_ && clickTimer_.GetMSec(true) <
  942. (unsigned)(doubleClickInterval_ * 1000) && lastMouseButtons_ == buttons)
  943. {
  944. element->OnDoubleClick(element->ScreenToElement(cursorPos), cursorPos, button, buttons, qualifiers, cursor);
  945. doubleClickElement_.Reset();
  946. SendClickEvent(E_UIMOUSEDOUBLECLICK, NULL, element, cursorPos, button, buttons, qualifiers);
  947. }
  948. else
  949. {
  950. doubleClickElement_ = element;
  951. clickTimer_.Reset();
  952. }
  953. // Handle start of drag. Click handling may have caused destruction of the element, so check the pointer again
  954. bool dragElementsContain = dragElements_.Contains(element);
  955. if (element && !dragElementsContain)
  956. {
  957. DragData* dragData = new DragData();
  958. dragElements_[element] = dragData;
  959. dragData->dragBeginPending = true;
  960. dragData->sumPos = cursorPos;
  961. dragData->dragBeginSumPos = cursorPos;
  962. dragData->dragBeginTimer.Reset();
  963. dragData->dragButtons = button;
  964. dragData->numDragButtons = CountSetBits(dragData->dragButtons);
  965. dragElementsCount_++;
  966. dragElementsContain = dragElements_.Contains(element);
  967. }
  968. else if (element && dragElementsContain && newButton)
  969. {
  970. DragData* dragData = dragElements_[element];
  971. dragData->sumPos += cursorPos;
  972. dragData->dragBeginSumPos += cursorPos;
  973. dragData->dragButtons |= button;
  974. dragData->numDragButtons = CountSetBits(dragData->dragButtons);
  975. }
  976. }
  977. else
  978. {
  979. // If clicked over no element, or a disabled element, lose focus (but not if there is a modal element)
  980. if (!HasModalElement())
  981. SetFocusElement(0);
  982. SendClickEvent(E_UIMOUSECLICK, NULL, element, cursorPos, button, buttons, qualifiers);
  983. }
  984. lastMouseButtons_ = buttons;
  985. }
  986. }
  987. void UI::ProcessClickEnd(const IntVector2& cursorPos, int button, int buttons, int qualifiers, Cursor* cursor, bool cursorVisible)
  988. {
  989. if (cursorVisible)
  990. {
  991. WeakPtr<UIElement> element(GetElementAt(cursorPos));
  992. // Handle end of drag
  993. for (HashMap<WeakPtr<UIElement>, UI::DragData*>::Iterator i = dragElements_.Begin(); i != dragElements_.End();)
  994. {
  995. WeakPtr<UIElement> dragElement = i->first_;
  996. UI::DragData* dragData = i->second_;
  997. if (!dragElement)
  998. {
  999. i = DragElementErase(i);
  1000. continue;
  1001. }
  1002. if (dragData->dragButtons & button)
  1003. {
  1004. // Handle end of click
  1005. if (element)
  1006. element->OnClickEnd(element->ScreenToElement(cursorPos), cursorPos, button, buttons, qualifiers, cursor, dragElement);
  1007. SendClickEvent(E_UIMOUSECLICKEND, dragElement, element, cursorPos, button, buttons, qualifiers);
  1008. if (dragElement && dragElement->IsEnabled() && dragElement->IsVisible() && !dragData->dragBeginPending)
  1009. {
  1010. dragElement->OnDragEnd(dragElement->ScreenToElement(cursorPos), cursorPos, dragData->dragButtons, buttons, cursor);
  1011. SendDragOrHoverEvent(E_DRAGEND, dragElement, cursorPos, IntVector2::ZERO, dragData);
  1012. bool dragSource = dragElement && (dragElement->GetDragDropMode() & DD_SOURCE) != 0;
  1013. if (dragSource)
  1014. {
  1015. bool dragTarget = element && (element->GetDragDropMode() & DD_TARGET) != 0;
  1016. bool dragDropFinish = dragSource && dragTarget && element != dragElement;
  1017. if (dragDropFinish)
  1018. {
  1019. bool accept = element->OnDragDropFinish(dragElement);
  1020. // OnDragDropFinish() may have caused destruction of the elements, so check the pointers again
  1021. if (accept && dragElement && element)
  1022. {
  1023. using namespace DragDropFinish;
  1024. VariantMap& eventData = GetEventDataMap();
  1025. eventData[P_SOURCE] = dragElement.Get();
  1026. eventData[P_TARGET] = element.Get();
  1027. eventData[P_ACCEPT] = accept;
  1028. SendEvent(E_DRAGDROPFINISH, eventData);
  1029. }
  1030. }
  1031. }
  1032. }
  1033. i = DragElementErase(i);
  1034. }
  1035. else
  1036. ++i;
  1037. }
  1038. }
  1039. }
  1040. void UI::ProcessMove(const IntVector2& cursorPos, const IntVector2& cursorDeltaPos, int buttons, int qualifiers, Cursor* cursor, bool cursorVisible)
  1041. {
  1042. if (cursorVisible && dragElementsCount_ > 0 && buttons)
  1043. {
  1044. Input* input = GetSubsystem<Input>();
  1045. bool mouseGrabbed = input->IsMouseGrabbed();
  1046. for (HashMap<WeakPtr<UIElement>, UI::DragData*>::Iterator i = dragElements_.Begin(); i != dragElements_.End();)
  1047. {
  1048. WeakPtr<UIElement> dragElement = i->first_;
  1049. UI::DragData* dragData = i->second_;
  1050. if (!dragElement)
  1051. {
  1052. i = DragElementErase(i);
  1053. continue;
  1054. }
  1055. if (!(dragData->dragButtons & buttons))
  1056. {
  1057. ++i;
  1058. continue;
  1059. }
  1060. // Calculate the position that we should send for this drag event.
  1061. IntVector2 sendPos;
  1062. if (usingTouchInput_)
  1063. {
  1064. dragData->sumPos += cursorDeltaPos;
  1065. sendPos.x_ = dragData->sumPos.x_ / dragData->numDragButtons;
  1066. sendPos.y_ = dragData->sumPos.y_ / dragData->numDragButtons;
  1067. }
  1068. else
  1069. {
  1070. dragData->sumPos = cursorPos;
  1071. sendPos = cursorPos;
  1072. }
  1073. if (dragElement->IsEnabled() && dragElement->IsVisible())
  1074. {
  1075. // Signal drag begin if distance threshold was exceeded
  1076. if (dragData->dragBeginPending && !mouseGrabbed)
  1077. {
  1078. IntVector2 beginSendPos;
  1079. beginSendPos.x_ = dragData->dragBeginSumPos.x_ / dragData->numDragButtons;
  1080. beginSendPos.y_ = dragData->dragBeginSumPos.y_ / dragData->numDragButtons;
  1081. IntVector2 offset = cursorPos - beginSendPos;
  1082. if (Abs(offset.x_) >= dragBeginDistance_ || Abs(offset.y_) >= dragBeginDistance_)
  1083. {
  1084. dragData->dragBeginPending = false;
  1085. dragConfirmedCount_ ++;
  1086. dragElement->OnDragBegin(dragElement->ScreenToElement(beginSendPos), beginSendPos, buttons, qualifiers, cursor);
  1087. SendDragOrHoverEvent(E_DRAGBEGIN, dragElement, beginSendPos, IntVector2::ZERO, dragData);
  1088. }
  1089. }
  1090. if (!dragData->dragBeginPending)
  1091. {
  1092. dragElement->OnDragMove(dragElement->ScreenToElement(sendPos), sendPos, cursorDeltaPos, buttons, qualifiers, cursor);
  1093. SendDragOrHoverEvent(E_DRAGMOVE, dragElement, sendPos, cursorDeltaPos, dragData);
  1094. }
  1095. }
  1096. else
  1097. {
  1098. dragElement->OnDragEnd(dragElement->ScreenToElement(sendPos), sendPos, dragData->dragButtons, buttons, cursor);
  1099. SendDragOrHoverEvent(E_DRAGEND, dragElement, sendPos, IntVector2::ZERO, dragData);
  1100. dragElement.Reset();
  1101. }
  1102. ++i;
  1103. }
  1104. }
  1105. }
  1106. void UI::SendDragOrHoverEvent(StringHash eventType, UIElement* element, const IntVector2& screenPos, const IntVector2& deltaPos, UI::DragData* dragData)
  1107. {
  1108. if (!element)
  1109. return;
  1110. IntVector2 relativePos = element->ScreenToElement(screenPos);
  1111. using namespace DragMove;
  1112. VariantMap& eventData = GetEventDataMap();
  1113. eventData[P_ELEMENT] = element;
  1114. eventData[P_X] = screenPos.x_;
  1115. eventData[P_Y] = screenPos.y_;
  1116. eventData[P_ELEMENTX] = relativePos.x_;
  1117. eventData[P_ELEMENTY] = relativePos.y_;
  1118. if (eventType == E_DRAGMOVE)
  1119. {
  1120. eventData[P_DX] = deltaPos.x_;
  1121. eventData[P_DY] = deltaPos.y_;
  1122. }
  1123. if (dragData)
  1124. {
  1125. eventData[P_BUTTONS] = dragData->dragButtons;
  1126. eventData[P_NUMBUTTONS] = dragData->numDragButtons;
  1127. }
  1128. element->SendEvent(eventType, eventData);
  1129. }
  1130. void UI::SendClickEvent(StringHash eventType, UIElement* beginElement, UIElement* endElement, const IntVector2& pos, int button, int buttons, int qualifiers)
  1131. {
  1132. VariantMap& eventData = GetEventDataMap();
  1133. eventData[UIMouseClick::P_ELEMENT] = endElement;
  1134. eventData[UIMouseClick::P_X] = pos.x_;
  1135. eventData[UIMouseClick::P_Y] = pos.y_;
  1136. eventData[UIMouseClick::P_BUTTON] = button;
  1137. eventData[UIMouseClick::P_BUTTONS] = buttons;
  1138. eventData[UIMouseClick::P_QUALIFIERS] = qualifiers;
  1139. // For click end events, send also the element the click began on
  1140. if (eventType == E_UIMOUSECLICKEND)
  1141. eventData[UIMouseClickEnd::P_BEGINELEMENT] = beginElement;
  1142. SendEvent(eventType, eventData);
  1143. }
  1144. void UI::HandleScreenMode(StringHash eventType, VariantMap& eventData)
  1145. {
  1146. using namespace ScreenMode;
  1147. if (!initialized_)
  1148. Initialize();
  1149. else
  1150. {
  1151. rootElement_->SetSize(eventData[P_WIDTH].GetInt(), eventData[P_HEIGHT].GetInt());
  1152. rootModalElement_->SetSize(rootElement_->GetSize());
  1153. }
  1154. }
  1155. void UI::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
  1156. {
  1157. using namespace MouseButtonDown;
  1158. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  1159. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  1160. usingTouchInput_ = false;
  1161. IntVector2 cursorPos;
  1162. bool cursorVisible;
  1163. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  1164. // Handle drag cancelling
  1165. ProcessDragCancel();
  1166. Input* input = GetSubsystem<Input>();
  1167. if (!input->IsMouseGrabbed())
  1168. ProcessClickBegin(cursorPos, eventData[P_BUTTON].GetInt(), mouseButtons_, qualifiers_, cursor_, cursorVisible);
  1169. }
  1170. void UI::HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
  1171. {
  1172. using namespace MouseButtonUp;
  1173. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  1174. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  1175. IntVector2 cursorPos;
  1176. bool cursorVisible;
  1177. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  1178. ProcessClickEnd(cursorPos, eventData[P_BUTTON].GetInt(), mouseButtons_, qualifiers_, cursor_, cursorVisible);
  1179. }
  1180. void UI::HandleMouseMove(StringHash eventType, VariantMap& eventData)
  1181. {
  1182. using namespace MouseMove;
  1183. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  1184. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  1185. usingTouchInput_ = false;
  1186. Input* input = GetSubsystem<Input>();
  1187. const IntVector2& rootSize = rootElement_->GetSize();
  1188. IntVector2 DeltaP = IntVector2(eventData[P_DX].GetInt(), eventData[P_DY].GetInt());
  1189. if (cursor_)
  1190. {
  1191. if (!input->IsMouseVisible())
  1192. {
  1193. // Relative mouse motion: move cursor only when visible
  1194. if (cursor_->IsVisible())
  1195. {
  1196. IntVector2 pos = cursor_->GetPosition();
  1197. pos.x_ += eventData[P_DX].GetInt();
  1198. pos.y_ += eventData[P_DY].GetInt();
  1199. pos.x_ = Clamp(pos.x_, 0, rootSize.x_ - 1);
  1200. pos.y_ = Clamp(pos.y_, 0, rootSize.y_ - 1);
  1201. cursor_->SetPosition(pos);
  1202. }
  1203. }
  1204. else
  1205. {
  1206. // Absolute mouse motion: move always
  1207. cursor_->SetPosition(IntVector2(eventData[P_X].GetInt(), eventData[P_Y].GetInt()));
  1208. }
  1209. }
  1210. IntVector2 cursorPos;
  1211. bool cursorVisible;
  1212. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  1213. ProcessMove(cursorPos, DeltaP, mouseButtons_, qualifiers_, cursor_, cursorVisible);
  1214. }
  1215. void UI::HandleMouseWheel(StringHash eventType, VariantMap& eventData)
  1216. {
  1217. Input* input = GetSubsystem<Input>();
  1218. if (input->IsMouseGrabbed())
  1219. return;
  1220. using namespace MouseWheel;
  1221. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  1222. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  1223. int delta = eventData[P_WHEEL].GetInt();
  1224. usingTouchInput_ = false;
  1225. IntVector2 cursorPos;
  1226. bool cursorVisible;
  1227. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  1228. UIElement* element;
  1229. if (!nonFocusedMouseWheel_&& (element = focusElement_))
  1230. element->OnWheel(delta, mouseButtons_, qualifiers_);
  1231. else
  1232. {
  1233. // If no element has actual focus or in non-focused mode, get the element at cursor
  1234. if (cursorVisible)
  1235. {
  1236. element = GetElementAt(cursorPos);
  1237. if (nonFocusedMouseWheel_)
  1238. {
  1239. // Going up the hierarchy chain to find element that could handle mouse wheel
  1240. while (element)
  1241. {
  1242. if (element->GetType() == ListView::GetTypeStatic() ||
  1243. element->GetType() == ScrollView::GetTypeStatic())
  1244. break;
  1245. element = element->GetParent();
  1246. }
  1247. }
  1248. else
  1249. // If the element itself is not focusable, search for a focusable parent,
  1250. // although the focusable element may not actually handle mouse wheel
  1251. element = GetFocusableElement(element);
  1252. if (element && (nonFocusedMouseWheel_ || element->GetFocusMode() >= FM_FOCUSABLE))
  1253. element->OnWheel(delta, mouseButtons_, qualifiers_);
  1254. }
  1255. }
  1256. }
  1257. void UI::HandleTouchBegin(StringHash eventType, VariantMap& eventData)
  1258. {
  1259. Input* input = GetSubsystem<Input>();
  1260. if (input->IsMouseGrabbed())
  1261. return;
  1262. using namespace TouchBegin;
  1263. IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
  1264. usingTouchInput_ = true;
  1265. int touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
  1266. WeakPtr<UIElement> element(GetElementAt(pos));
  1267. if (element)
  1268. {
  1269. ProcessClickBegin(pos, touchId, touchDragElements_[element], 0, 0, true);
  1270. touchDragElements_[element] |= touchId;
  1271. }
  1272. else
  1273. ProcessClickBegin(pos, touchId, touchId, 0, 0, true);
  1274. }
  1275. void UI::HandleTouchEnd(StringHash eventType, VariantMap& eventData)
  1276. {
  1277. using namespace TouchEnd;
  1278. IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
  1279. // Get the touch index
  1280. int touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
  1281. // Transmit hover end to the position where the finger was lifted
  1282. WeakPtr<UIElement> element(GetElementAt(pos));
  1283. // Clear any drag events that were using the touch id
  1284. for (HashMap<WeakPtr<UIElement>, int>::Iterator i = touchDragElements_.Begin(); i != touchDragElements_.End(); )
  1285. {
  1286. int touches = i->second_;
  1287. if (touches & touchId)
  1288. i = touchDragElements_.Erase(i);
  1289. else
  1290. ++i;
  1291. }
  1292. if (element && element->IsEnabled())
  1293. element->OnHover(element->ScreenToElement(pos), pos, 0, 0, 0);
  1294. ProcessClickEnd(pos, touchId, 0, 0, 0, true);
  1295. }
  1296. void UI::HandleTouchMove(StringHash eventType, VariantMap& eventData)
  1297. {
  1298. using namespace TouchMove;
  1299. IntVector2 pos(eventData[P_X].GetInt(), eventData[P_Y].GetInt());
  1300. IntVector2 deltaPos(eventData[P_DX].GetInt(), eventData[P_DY].GetInt());
  1301. usingTouchInput_ = true;
  1302. int touchId = TOUCHID_MASK(eventData[P_TOUCHID].GetInt());
  1303. ProcessMove(pos, deltaPos, touchId, 0, 0, true);
  1304. }
  1305. void UI::HandleKeyDown(StringHash eventType, VariantMap& eventData)
  1306. {
  1307. using namespace KeyDown;
  1308. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  1309. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  1310. int key = eventData[P_KEY].GetInt();
  1311. // Cancel UI dragging
  1312. if (key == KEY_ESC && dragElementsCount_ > 0)
  1313. {
  1314. ProcessDragCancel();
  1315. return;
  1316. }
  1317. // Dismiss modal element if any when ESC key is pressed
  1318. if (key == KEY_ESC && HasModalElement())
  1319. {
  1320. UIElement* element = rootModalElement_->GetChild(rootModalElement_->GetNumChildren() - 1);
  1321. if (element->GetVars().Contains(VAR_ORIGIN))
  1322. // If it is a popup, dismiss by defocusing it
  1323. SetFocusElement(0);
  1324. else
  1325. {
  1326. // If it is a modal window, by resetting its modal flag
  1327. Window* window = dynamic_cast<Window*>(element);
  1328. if (window && window->GetModalAutoDismiss())
  1329. window->SetModal(false);
  1330. }
  1331. return;
  1332. }
  1333. UIElement* element = focusElement_;
  1334. if (element)
  1335. {
  1336. // Switch focus between focusable elements in the same top level window
  1337. if (key == KEY_TAB)
  1338. {
  1339. UIElement* topLevel = element->GetParent();
  1340. while (topLevel && topLevel->GetParent() != rootElement_ && topLevel->GetParent() != rootModalElement_)
  1341. topLevel = topLevel->GetParent();
  1342. if (topLevel)
  1343. {
  1344. topLevel->GetChildren(tempElements_, true);
  1345. for (PODVector<UIElement*>::Iterator i = tempElements_.Begin(); i != tempElements_.End();)
  1346. {
  1347. if ((*i)->GetFocusMode() < FM_FOCUSABLE)
  1348. i = tempElements_.Erase(i);
  1349. else
  1350. ++i;
  1351. }
  1352. for (unsigned i = 0; i < tempElements_.Size(); ++i)
  1353. {
  1354. if (tempElements_[i] == element)
  1355. {
  1356. int dir = (qualifiers_ & QUAL_SHIFT) ? -1 : 1;
  1357. unsigned nextIndex = (tempElements_.Size() + i + dir) % tempElements_.Size();
  1358. UIElement* next = tempElements_[nextIndex];
  1359. SetFocusElement(next, true);
  1360. return;
  1361. }
  1362. }
  1363. }
  1364. }
  1365. // Defocus the element
  1366. else if (key == KEY_ESC && element->GetFocusMode() == FM_FOCUSABLE_DEFOCUSABLE)
  1367. element->SetFocus(false);
  1368. // If none of the special keys, pass the key to the focused element
  1369. else
  1370. element->OnKey(key, mouseButtons_, qualifiers_);
  1371. }
  1372. }
  1373. void UI::HandleTextInput(StringHash eventType, VariantMap& eventData)
  1374. {
  1375. using namespace TextInput;
  1376. mouseButtons_ = eventData[P_BUTTONS].GetInt();
  1377. qualifiers_ = eventData[P_QUALIFIERS].GetInt();
  1378. UIElement* element = focusElement_;
  1379. if (element)
  1380. element->OnTextInput(eventData[P_TEXT].GetString(), mouseButtons_, qualifiers_);
  1381. }
  1382. void UI::HandleBeginFrame(StringHash eventType, VariantMap& eventData)
  1383. {
  1384. // If have a cursor, and a drag is not going on, reset the cursor shape. Application logic that wants to apply
  1385. // custom shapes can do it after this, but needs to do it each frame
  1386. if (cursor_ && dragElementsCount_ == 0)
  1387. cursor_->SetShape(CS_NORMAL);
  1388. }
  1389. void UI::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
  1390. {
  1391. using namespace PostUpdate;
  1392. Update(eventData[P_TIMESTEP].GetFloat());
  1393. }
  1394. void UI::HandleRenderUpdate(StringHash eventType, VariantMap& eventData)
  1395. {
  1396. RenderUpdate();
  1397. }
  1398. void UI::HandleDropFile(StringHash eventType, VariantMap& eventData)
  1399. {
  1400. Input* input = GetSubsystem<Input>();
  1401. // Sending the UI variant of the event only makes sense if the OS cursor is visible (not locked to window center)
  1402. if (input->IsMouseVisible())
  1403. {
  1404. IntVector2 screenPos = input->GetMousePosition();
  1405. UIElement* element = GetElementAt(screenPos);
  1406. using namespace UIDropFile;
  1407. VariantMap uiEventData;
  1408. uiEventData[P_FILENAME] = eventData[P_FILENAME];
  1409. uiEventData[P_X] = screenPos.x_;
  1410. uiEventData[P_Y] = screenPos.y_;
  1411. uiEventData[P_ELEMENT] = element;
  1412. if (element)
  1413. {
  1414. IntVector2 relativePos = element->ScreenToElement(screenPos);
  1415. uiEventData[P_ELEMENTX] = relativePos.x_;
  1416. uiEventData[P_ELEMENTY] = relativePos.y_;
  1417. }
  1418. SendEvent(E_UIDROPFILE, uiEventData);
  1419. }
  1420. }
  1421. HashMap<WeakPtr<UIElement>, UI::DragData*>::Iterator UI::DragElementErase(HashMap<WeakPtr<UIElement>, UI::DragData*>::Iterator i)
  1422. {
  1423. // If running the engine frame in response to an event (re-entering UI frame logic) the dragElements_ may already be empty
  1424. if (dragElements_.Empty())
  1425. return dragElements_.End();
  1426. dragElementsConfirmed_.Clear();
  1427. WeakPtr<UIElement> dragElement = i->first_;
  1428. DragData* dragData = i->second_;
  1429. if (!dragData->dragBeginPending)
  1430. --dragConfirmedCount_;
  1431. i = dragElements_.Erase(i);
  1432. --dragElementsCount_;
  1433. delete dragData;
  1434. return i;
  1435. }
  1436. void UI::ProcessDragCancel()
  1437. {
  1438. // How to tell difference between drag cancel and new selection on multi-touch?
  1439. if (usingTouchInput_)
  1440. return;
  1441. IntVector2 cursorPos;
  1442. bool cursorVisible;
  1443. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  1444. for (HashMap<WeakPtr<UIElement>, UI::DragData*>::Iterator i = dragElements_.Begin(); i != dragElements_.End();)
  1445. {
  1446. WeakPtr<UIElement> dragElement = i->first_;
  1447. UI::DragData* dragData = i->second_;
  1448. if (dragElement && dragElement->IsEnabled() && dragElement->IsVisible() && !dragData->dragBeginPending)
  1449. {
  1450. dragElement->OnDragCancel(dragElement->ScreenToElement(cursorPos), cursorPos, dragData->dragButtons, mouseButtons_, cursor_);
  1451. SendDragOrHoverEvent(E_DRAGCANCEL, dragElement, cursorPos, IntVector2::ZERO, dragData);
  1452. i = DragElementErase(i);
  1453. }
  1454. else
  1455. ++i;
  1456. }
  1457. }
  1458. IntVector2 UI::SumTouchPositions(UI::DragData* dragData, const IntVector2& oldSendPos)
  1459. {
  1460. IntVector2 sendPos = oldSendPos;
  1461. if (usingTouchInput_)
  1462. {
  1463. int buttons = dragData->dragButtons;
  1464. dragData->sumPos = IntVector2::ZERO;
  1465. Input* input = GetSubsystem<Input>();
  1466. for (int i = 0; (1 << i) <= buttons; i++)
  1467. {
  1468. if ((1 << i) & buttons)
  1469. {
  1470. TouchState* ts = input->GetTouch(i);
  1471. if (!ts)
  1472. break;
  1473. IntVector2 pos = ts->position_;
  1474. dragData->sumPos.x_ += pos.x_;
  1475. dragData->sumPos.y_ += pos.y_;
  1476. }
  1477. }
  1478. sendPos.x_ = dragData->sumPos.x_ / dragData->numDragButtons;
  1479. sendPos.y_ = dragData->sumPos.y_ / dragData->numDragButtons;
  1480. }
  1481. return sendPos;
  1482. }
  1483. void RegisterUILibrary(Context* context)
  1484. {
  1485. Font::RegisterObject(context);
  1486. UIElement::RegisterObject(context);
  1487. BorderImage::RegisterObject(context);
  1488. Sprite::RegisterObject(context);
  1489. Button::RegisterObject(context);
  1490. CheckBox::RegisterObject(context);
  1491. Cursor::RegisterObject(context);
  1492. Text::RegisterObject(context);
  1493. Text3D::RegisterObject(context);
  1494. Window::RegisterObject(context);
  1495. View3D::RegisterObject(context);
  1496. LineEdit::RegisterObject(context);
  1497. Slider::RegisterObject(context);
  1498. ScrollBar::RegisterObject(context);
  1499. ScrollView::RegisterObject(context);
  1500. ListView::RegisterObject(context);
  1501. Menu::RegisterObject(context);
  1502. DropDownList::RegisterObject(context);
  1503. FileSelector::RegisterObject(context);
  1504. MessageBox::RegisterObject(context);
  1505. ToolTip::RegisterObject(context);
  1506. }
  1507. }