UI.cpp 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  1. //
  2. // Copyright (c) 2008-2014 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 "../UI/CheckBox.h"
  24. #include "../Core/Context.h"
  25. #include "../Core/CoreEvents.h"
  26. #include "../UI/Cursor.h"
  27. #include "../UI/DropDownList.h"
  28. #include "../UI/FileSelector.h"
  29. #include "../UI/Font.h"
  30. #include "../Graphics/Graphics.h"
  31. #include "../Graphics/GraphicsEvents.h"
  32. #include "../Input/Input.h"
  33. #include "../Input/InputEvents.h"
  34. #include "../UI/LineEdit.h"
  35. #include "../UI/ListView.h"
  36. #include "../IO/Log.h"
  37. #include "../Math/Matrix3x4.h"
  38. #include "../UI/MessageBox.h"
  39. #include "../Core/Profiler.h"
  40. #include "../Resource/ResourceCache.h"
  41. #include "../UI/ScrollBar.h"
  42. #include "../Graphics/Shader.h"
  43. #include "../Graphics/ShaderVariation.h"
  44. #include "../UI/Slider.h"
  45. #include "../Container/Sort.h"
  46. #include "../UI/Sprite.h"
  47. #include "../UI/Text.h"
  48. #include "../UI/Text3D.h"
  49. #include "../Graphics/Texture2D.h"
  50. #include "../UI/ToolTip.h"
  51. #include "../UI/UI.h"
  52. #include "../UI/UIEvents.h"
  53. #include "../Graphics/VertexBuffer.h"
  54. #include "../UI/Window.h"
  55. #include "../UI/View3D.h"
  56. #include <SDL/include/SDL.h>
  57. #include "../DebugNew.h"
  58. #define TOUCHID_MASK(id) (1 << id)
  59. namespace Atomic
  60. {
  61. StringHash VAR_ORIGIN("Origin");
  62. const StringHash VAR_ORIGINAL_PARENT("OriginalParent");
  63. const StringHash VAR_ORIGINAL_CHILD_INDEX("OriginalChildIndex");
  64. const StringHash VAR_PARENT_CHANGED("ParentChanged");
  65. const float DEFAULT_DOUBLECLICK_INTERVAL = 0.5f;
  66. const float DEFAULT_DRAGBEGIN_INTERVAL = 0.5f;
  67. const float DEFAULT_TOOLTIP_DELAY = 0.5f;
  68. const int DEFAULT_DRAGBEGIN_DISTANCE = 5;
  69. const int DEFAULT_FONT_TEXTURE_MAX_SIZE = 2048;
  70. const char* UI_CATEGORY = "UI";
  71. UI::UI(Context* context) :
  72. Object(context),
  73. rootElement_(new UIElement(context)),
  74. rootModalElement_(new UIElement(context)),
  75. doubleClickInterval_(DEFAULT_DOUBLECLICK_INTERVAL),
  76. dragBeginInterval_(DEFAULT_DRAGBEGIN_INTERVAL),
  77. defaultToolTipDelay_(DEFAULT_TOOLTIP_DELAY),
  78. dragBeginDistance_(DEFAULT_DRAGBEGIN_DISTANCE),
  79. mouseButtons_(0),
  80. lastMouseButtons_(0),
  81. qualifiers_(0),
  82. maxFontTextureSize_(DEFAULT_FONT_TEXTURE_MAX_SIZE),
  83. dragElementsCount_(0),
  84. dragConfirmedCount_(0),
  85. initialized_(false),
  86. usingTouchInput_(false),
  87. #ifdef WIN32
  88. nonFocusedMouseWheel_(false), // Default MS Windows behaviour
  89. #else
  90. nonFocusedMouseWheel_(true), // Default Mac OS X and Linux behaviour
  91. #endif
  92. useSystemClipboard_(false),
  93. #if defined(ANDROID) || defined(IOS)
  94. useScreenKeyboard_(true),
  95. #else
  96. useScreenKeyboard_(false),
  97. #endif
  98. useMutableGlyphs_(false),
  99. forceAutoHint_(false),
  100. nonModalBatchSize_(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. rootElement_->SetSize(graphics->GetWidth(), graphics->GetHeight());
  584. rootModalElement_->SetSize(rootElement_->GetSize());
  585. vertexBuffer_ = new VertexBuffer(context_);
  586. debugVertexBuffer_ = new VertexBuffer(context_);
  587. initialized_ = true;
  588. SubscribeToEvent(E_BEGINFRAME, HANDLER(UI, HandleBeginFrame));
  589. SubscribeToEvent(E_POSTUPDATE, HANDLER(UI, HandlePostUpdate));
  590. SubscribeToEvent(E_RENDERUPDATE, HANDLER(UI, HandleRenderUpdate));
  591. LOGINFO("Initialized user interface");
  592. }
  593. void UI::Update(float timeStep, UIElement* element)
  594. {
  595. // Keep a weak pointer to the element in case it destroys itself on update
  596. WeakPtr<UIElement> elementWeak(element);
  597. element->Update(timeStep);
  598. if (elementWeak.Expired())
  599. return;
  600. const Vector<SharedPtr<UIElement> >& children = element->GetChildren();
  601. // Update of an element may modify its child vector. Use just index-based iteration to be safe
  602. for (unsigned i = 0; i < children.Size(); ++i)
  603. Update(timeStep, children[i]);
  604. }
  605. void UI::SetVertexData(VertexBuffer* dest, const PODVector<float>& vertexData)
  606. {
  607. if (vertexData.Empty())
  608. return;
  609. // Update quad geometry into the vertex buffer
  610. // Resize the vertex buffer first if too small or much too large
  611. unsigned numVertices = vertexData.Size() / UI_VERTEX_SIZE;
  612. if (dest->GetVertexCount() < numVertices || dest->GetVertexCount() > numVertices * 2)
  613. dest->SetSize(numVertices, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1, true);
  614. dest->SetData(&vertexData[0]);
  615. }
  616. void UI::Render(bool resetRenderTargets, VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigned batchStart, unsigned batchEnd)
  617. {
  618. // Engine does not render when window is closed or device is lost
  619. assert(graphics_ && graphics_->IsInitialized() && !graphics_->IsDeviceLost());
  620. if (batches.Empty())
  621. return;
  622. Vector2 invScreenSize(1.0f / (float)graphics_->GetWidth(), 1.0f / (float)graphics_->GetHeight());
  623. Vector2 scale(2.0f * invScreenSize.x_, -2.0f * invScreenSize.y_);
  624. Vector2 offset(-1.0f, 1.0f);
  625. Matrix4 projection(Matrix4::IDENTITY);
  626. projection.m00_ = scale.x_;
  627. projection.m03_ = offset.x_;
  628. projection.m11_ = scale.y_;
  629. projection.m13_ = offset.y_;
  630. projection.m22_ = 1.0f;
  631. projection.m23_ = 0.0f;
  632. projection.m33_ = 1.0f;
  633. graphics_->ClearParameterSources();
  634. graphics_->SetColorWrite(true);
  635. graphics_->SetCullMode(CULL_CCW);
  636. graphics_->SetDepthTest(CMP_ALWAYS);
  637. graphics_->SetDepthWrite(false);
  638. graphics_->SetDrawAntialiased(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_OBJECTTRANSFORM, 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. dragElementsConfirmed_.Clear();
  1424. WeakPtr<UIElement> dragElement = i->first_;
  1425. DragData* dragData = i->second_;
  1426. if (!dragData->dragBeginPending)
  1427. dragConfirmedCount_ --;
  1428. i = dragElements_.Erase(i);
  1429. dragElementsCount_ --;
  1430. delete dragData;
  1431. return i;
  1432. }
  1433. void UI::ProcessDragCancel()
  1434. {
  1435. // How to tell difference between drag cancel and new selection on multi-touch?
  1436. if (usingTouchInput_)
  1437. return;
  1438. IntVector2 cursorPos;
  1439. bool cursorVisible;
  1440. GetCursorPositionAndVisible(cursorPos, cursorVisible);
  1441. for (HashMap<WeakPtr<UIElement>, UI::DragData*>::Iterator i = dragElements_.Begin(); i != dragElements_.End();)
  1442. {
  1443. WeakPtr<UIElement> dragElement = i->first_;
  1444. UI::DragData* dragData = i->second_;
  1445. if (dragElement && dragElement->IsEnabled() && dragElement->IsVisible() && !dragData->dragBeginPending)
  1446. {
  1447. dragElement->OnDragCancel(dragElement->ScreenToElement(cursorPos), cursorPos, dragData->dragButtons, mouseButtons_, cursor_);
  1448. SendDragOrHoverEvent(E_DRAGCANCEL, dragElement, cursorPos, IntVector2::ZERO, dragData);
  1449. i = dragElementErase(i);
  1450. }
  1451. else
  1452. ++i;
  1453. }
  1454. }
  1455. IntVector2 UI::SumTouchPositions(UI::DragData* dragData, const IntVector2& oldSendPos)
  1456. {
  1457. IntVector2 sendPos = oldSendPos;
  1458. if (usingTouchInput_)
  1459. {
  1460. int buttons = dragData->dragButtons;
  1461. dragData->sumPos = IntVector2::ZERO;
  1462. Input* input = GetSubsystem<Input>();
  1463. for (int i = 0; (1 << i) <= buttons; i++)
  1464. {
  1465. if ((1 << i) & buttons)
  1466. {
  1467. TouchState* ts = input->GetTouch(i);
  1468. if (!ts)
  1469. break;
  1470. IntVector2 pos = ts->position_;
  1471. dragData->sumPos.x_ += pos.x_;
  1472. dragData->sumPos.y_ += pos.y_;
  1473. }
  1474. }
  1475. sendPos.x_ = dragData->sumPos.x_ / dragData->numDragButtons;
  1476. sendPos.y_ = dragData->sumPos.y_ / dragData->numDragButtons;
  1477. }
  1478. return sendPos;
  1479. }
  1480. void RegisterUILibrary(Context* context)
  1481. {
  1482. Font::RegisterObject(context);
  1483. UIElement::RegisterObject(context);
  1484. BorderImage::RegisterObject(context);
  1485. Sprite::RegisterObject(context);
  1486. Button::RegisterObject(context);
  1487. CheckBox::RegisterObject(context);
  1488. Cursor::RegisterObject(context);
  1489. Text::RegisterObject(context);
  1490. Text3D::RegisterObject(context);
  1491. Window::RegisterObject(context);
  1492. View3D::RegisterObject(context);
  1493. LineEdit::RegisterObject(context);
  1494. Slider::RegisterObject(context);
  1495. ScrollBar::RegisterObject(context);
  1496. ScrollView::RegisterObject(context);
  1497. ListView::RegisterObject(context);
  1498. Menu::RegisterObject(context);
  1499. DropDownList::RegisterObject(context);
  1500. FileSelector::RegisterObject(context);
  1501. MessageBox::RegisterObject(context);
  1502. ToolTip::RegisterObject(context);
  1503. }
  1504. }