// // Urho3D Engine // Copyright (c) 2008-2011 Lasse Öörni // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // #include "Precompiled.h" #include "CheckBox.h" #include "Context.h" #include "CoreEvents.h" #include "Cursor.h" #include "DropDownList.h" #include "FileSelector.h" #include "Font.h" #include "Graphics.h" #include "GraphicsEvents.h" #include "InputEvents.h" #include "LineEdit.h" #include "ListView.h" #include "Log.h" #include "Matrix3x4.h" #include "Profiler.h" #include "ResourceCache.h" #include "ScrollBar.h" #include "Shader.h" #include "ShaderVariation.h" #include "Slider.h" #include "Text.h" #include "Texture2D.h" #include "UI.h" #include "UIEvents.h" #include "VertexBuffer.h" #include "Window.h" #include "Sort.h" #include "DebugNew.h" OBJECTTYPESTATIC(UI); UI::UI(Context* context) : Object(context), mouseButtons_(0), qualifiers_(0), initialized_(false) { SubscribeToEvent(E_SCREENMODE, HANDLER(UI, HandleScreenMode)); SubscribeToEvent(E_MOUSEMOVE, HANDLER(UI, HandleMouseMove)); SubscribeToEvent(E_MOUSEBUTTONDOWN, HANDLER(UI, HandleMouseButtonDown)); SubscribeToEvent(E_MOUSEBUTTONUP, HANDLER(UI, HandleMouseButtonUp)); SubscribeToEvent(E_MOUSEWHEEL, HANDLER(UI, HandleMouseWheel)); SubscribeToEvent(E_KEYDOWN, HANDLER(UI, HandleKeyDown)); SubscribeToEvent(E_CHAR, HANDLER(UI, HandleChar)); SubscribeToEvent(E_POSTUPDATE, HANDLER(UI, HandlePostUpdate)); SubscribeToEvent(E_RENDERUPDATE, HANDLER(UI, HandleRenderUpdate)); // Try to initialize right now, but skip if screen mode is not yet set Initialize(); } UI::~UI() { } void UI::SetCursor(Cursor* cursor) { if (!rootElement_) return; // Remove old cursor (if any) and set new if (cursor_) { rootElement_->RemoveChild(cursor_); cursor_.Reset(); } if (cursor) { rootElement_->AddChild(cursor); cursor_ = cursor; IntVector2 pos = cursor_->GetPosition(); const IntVector2& rootSize = rootElement_->GetSize(); pos.x_ = Clamp(pos.x_, 0, rootSize.x_ - 1); pos.y_ = Clamp(pos.y_, 0, rootSize.y_ - 1); cursor_->SetPosition(pos); } } void UI::SetFocusElement(UIElement* element) { if (!rootElement_) return; using namespace FocusChanged; VariantMap eventData; eventData[P_ORIGINALELEMENT] = (void*)element; if (element) { // Return if already has focus if (focusElement_ == element) return; // Search for an element in the hierarchy that can alter focus. If none found, exit element = GetFocusableElement(element); if (!element) return; } // Remove focus from the old element if (focusElement_) { UIElement* oldFocusElement = focusElement_; focusElement_.Reset(); oldFocusElement->OnDefocus(); VariantMap focusEventData; focusEventData[Defocused::P_ELEMENT] = oldFocusElement; oldFocusElement->SendEvent(E_DEFOCUSED, focusEventData); } // Then set focus to the new if (element && element->GetFocusMode() >= FM_FOCUSABLE) { focusElement_ = element; element->OnFocus(); VariantMap focusEventData; focusEventData[Focused::P_ELEMENT] = element; element->SendEvent(E_FOCUSED, focusEventData); } eventData[P_ELEMENT] = (void*)element; SendEvent(E_FOCUSCHANGED, eventData); } void UI::Clear() { if (!rootElement_) return; rootElement_->RemoveAllChildren(); if (cursor_) rootElement_->AddChild(cursor_); } void UI::Update(float timeStep) { if (!rootElement_) return; PROFILE(UpdateUI); if (cursor_ && cursor_->IsVisible()) { IntVector2 pos = cursor_->GetPosition(); WeakPtr element(GetElementAt(pos)); bool dragSource = dragElement_ && (dragElement_->GetDragDropMode() & DD_SOURCE) != 0; bool dragTarget = element && (element->GetDragDropMode() & DD_TARGET) != 0; bool dragDropTest = dragSource && dragTarget && element != dragElement_; // Hover effect // If a drag is going on, transmit hover only to the element being dragged, unless it's a drop target if (element) { if (!dragElement_ || dragElement_ == element || dragDropTest) element->OnHover(element->ScreenToElement(pos), pos, mouseButtons_, qualifiers_, cursor_); } // Drag and drop test if (dragDropTest) { bool accept = element->OnDragDropTest(dragElement_); if (accept) { using namespace DragDropTest; VariantMap eventData; eventData[P_SOURCE] = (void*)dragElement_.Get(); eventData[P_TARGET] = (void*)element.Get(); eventData[P_ACCEPT] = accept; SendEvent(E_DRAGDROPTEST, eventData); accept = eventData[P_ACCEPT].GetBool(); } cursor_->SetShape(accept ? CS_ACCEPTDROP : CS_REJECTDROP); } else if (dragSource) cursor_->SetShape(dragElement_ == element ? CS_ACCEPTDROP : CS_REJECTDROP); } Update(timeStep, rootElement_); } void UI::RenderUpdate() { if (!rootElement_ || !graphics_) return; PROFILE(GetUIBatches); // Get batches & quads from the UI elements batches_.Clear(); quads_.Clear(); const IntVector2& rootSize = rootElement_->GetSize(); GetBatches(rootElement_, IntRect(0, 0, rootSize.x_, rootSize.y_)); // If no drag, reset cursor shape for next frame if (cursor_ && !dragElement_) cursor_->SetShape(CS_NORMAL); } void UI::Render() { PROFILE(RenderUI); if (!graphics_ || graphics_->IsDeviceLost() || !quads_.Size()) return; // Update quad geometry into the vertex buffer unsigned numVertices = quads_.Size() * 6; // Resize the vertex buffer if too small or much too large if (vertexBuffer_->GetVertexCount() < numVertices || vertexBuffer_->GetVertexCount() > numVertices * 2) vertexBuffer_->SetSize(numVertices, MASK_POSITION | MASK_COLOR | MASK_TEXCOORD1, true); unsigned vertexSize = vertexBuffer_->GetVertexSize(); void* lockedData = vertexBuffer_->Lock(0, numVertices, LOCK_DISCARD); if (!lockedData) return; for (unsigned i = 0; i < batches_.Size(); ++i) batches_[i].UpdateGeometry(graphics_, ((unsigned char*)lockedData) + batches_[i].quadStart_ * vertexSize * 6); vertexBuffer_->Unlock(); Vector2 scale(2.0f, -2.0f); Vector2 offset(-1.0f, 1.0f); Matrix4 projection(Matrix4::IDENTITY); projection.m00_ = scale.x_; projection.m03_ = offset.x_; projection.m11_ = scale.y_; projection.m13_ = offset.y_; projection.m22_ = 1.0f; projection.m23_ = 0.0f; projection.m33_ = 1.0f; graphics_->ClearParameterSources(); graphics_->ResetRenderTargets(); graphics_->SetAlphaTest(false); graphics_->SetCullMode(CULL_CCW); graphics_->SetDepthTest(CMP_ALWAYS); graphics_->SetDepthWrite(false); graphics_->SetFillMode(FILL_SOLID); graphics_->SetStencilTest(false); ShaderVariation* ps = 0; ShaderVariation* vs = 0; unsigned alphaFormat = Graphics::GetAlphaFormat(); for (unsigned i = 0; i < batches_.Size(); ++i) { const UIBatch& batch = batches_[i]; if (!batch.quadCount_) continue; if (!batch.texture_) { ps = noTexturePS_; vs = noTextureVS_; } else { // If texture contains only an alpha channel, use alpha shader (for fonts) vs = diffTextureVS_; if (batch.texture_->GetFormat() == alphaFormat) ps = alphaTexturePS_; else ps = diffTexturePS_; } graphics_->SetShaders(vs, ps); if (graphics_->NeedParameterUpdate(VSP_MODEL, this)) graphics_->SetShaderParameter(VSP_MODEL, Matrix3x4::IDENTITY); if (graphics_->NeedParameterUpdate(VSP_VIEWPROJ, this)) graphics_->SetShaderParameter(VSP_VIEWPROJ, projection); if (graphics_->NeedParameterUpdate(PSP_MATDIFFCOLOR, this)) graphics_->SetShaderParameter(PSP_MATDIFFCOLOR, Color(1.0f, 1.0f, 1.0f, 1.0f)); // Use alpha test if not alpha blending if (batch.blendMode_ != BLEND_ALPHA && batch.blendMode_ != BLEND_ADDALPHA && batch.blendMode_ != BLEND_PREMULALPHA) graphics_->SetAlphaTest(true, CMP_GREATEREQUAL, 0.5f); else graphics_->SetAlphaTest(false); graphics_->SetBlendMode(batch.blendMode_); graphics_->SetScissorTest(true, batch.scissor_); graphics_->SetTexture(0, batch.texture_); graphics_->SetVertexBuffer(vertexBuffer_); graphics_->Draw(TRIANGLE_LIST, batch.quadStart_ * 6, batch.quadCount_ * 6); } } SharedPtr UI::LoadLayout(XMLFile* file, XMLFile* styleFile) { PROFILE(LoadUILayout); SharedPtr root; if (!file) { LOGERROR("Null UI layout XML file"); return root; } LOGDEBUG("Loading UI layout " + file->GetName()); XMLElement rootElem = file->GetRoot("element"); if (!rootElem) { LOGERROR("No root UI element in " + file->GetName()); return root; } String type = rootElem.GetString("type"); if (type.Empty()) type = "UIElement"; root = DynamicCast(context_->CreateObject(ShortStringHash(type))); if (!root) { LOGERROR("Could not create UI element " + type); return root; } root->SetName(rootElem.GetString("name")); String styleName = rootElem.HasAttribute("style") ? rootElem.GetString("style") : rootElem.GetString("type"); // First set the base style from the style file if exists, then apply UI layout overrides if (styleFile) root->SetStyle(styleFile, styleName); root->SetStyle(rootElem); // Load rest of the elements recursively LoadLayout(root, rootElem, styleFile); return root; } void UI::SetClipBoardText(const String& text) { clipBoard_ = text; } UIElement* UI::GetElementAt(const IntVector2& position, bool activeOnly) { if (!rootElement_) return 0; UIElement* result = 0; GetElementAt(result, rootElement_, position, activeOnly); return result; } UIElement* UI::GetElementAt(int x, int y, bool activeOnly) { return GetElementAt(IntVector2(x, y), activeOnly); } UIElement* UI::GetFocusElement() const { return focusElement_; } UIElement* UI::GetFrontElement() const { if (!rootElement_) return 0; const Vector >& rootChildren = rootElement_->GetChildren(); int maxPriority = M_MIN_INT; UIElement* front = 0; for (unsigned i = 0; i < rootChildren.Size(); ++i) { // Do not take into account input-disabled elements, hidden elements or those that are always in the front if (!rootChildren[i]->IsActive() || !rootChildren[i]->IsVisible() || !rootChildren[i]->GetBringToBack()) continue; int priority = rootChildren[i]->GetPriority(); if (priority > maxPriority) { maxPriority = priority; front = rootChildren[i]; } } return front; } IntVector2 UI::GetCursorPosition() { if (!cursor_) return IntVector2::ZERO; else return cursor_->GetPosition(); } void UI::Initialize() { Graphics* graphics = GetSubsystem(); ResourceCache* cache = GetSubsystem(); if (!graphics || !graphics->IsInitialized() || !cache) return; PROFILE(InitUI); graphics_ = graphics; cache_ = cache; rootElement_ = new UIElement(context_); rootElement_->SetSize(graphics->GetWidth(), graphics->GetHeight()); #ifdef USE_OPENGL Shader* basicVS = cache->GetResource("Shaders/GLSL/Basic.vert"); Shader* basicPS = cache->GetResource("Shaders/GLSL/Basic.frag"); #else Shader* basicVS = cache->GetResource("Shaders/SM2/Basic.vs2"); Shader* basicPS = cache->GetResource("Shaders/SM2/Basic.ps2"); #endif if (basicVS && basicPS) { noTextureVS_ = basicVS->GetVariation("VCol"); diffTextureVS_ = basicVS->GetVariation("DiffVCol"); noTexturePS_ = basicPS->GetVariation("VCol"); diffTexturePS_ = basicPS->GetVariation("DiffVCol"); alphaTexturePS_ = basicPS->GetVariation("AlphaVCol"); } vertexBuffer_ = new VertexBuffer(context_); LOGINFO("Initialized user interface"); initialized_ = true; } void UI::Update(float timeStep, UIElement* element) { element->Update(timeStep); const Vector >& children = element->GetChildren(); for (Vector >::ConstIterator i = children.Begin(); i != children.End(); ++i) Update(timeStep, *i); } void UI::GetBatches(UIElement* element, IntRect currentScissor) { // Set clipping scissor for child elements. No need to draw if zero size element->AdjustScissor(currentScissor); if (currentScissor.left_ == currentScissor.right_ || currentScissor.top_ == currentScissor.bottom_) return; element->SortChildren(); const Vector >& children = element->GetChildren(); if (children.Empty()) return; // For non-root elements draw all children of same priority before recursing into their children: assumption is that they have // same renderstate Vector >::ConstIterator i = children.Begin(); if (element != rootElement_) { Vector >::ConstIterator j = i; int currentPriority = children.Front()->GetPriority(); while (i != children.End()) { while (j != children.End() && (*j)->GetPriority() == currentPriority) { if (IsVisible(*j, currentScissor)) (*j)->GetBatches(batches_, quads_, currentScissor); ++j; } // Now recurse into the children while (i != j) { if (IsVisible(*i, currentScissor)) GetBatches(*i, currentScissor); ++i; } if (i != children.End()) currentPriority = (*i)->GetPriority(); } } // On the root level draw each element and its children immediately after to avoid artifacts else { while (i != children.End()) { if ((*i)->IsVisible()) { if (IsVisible(*i, currentScissor)) (*i)->GetBatches(batches_, quads_, currentScissor); GetBatches(*i, currentScissor); } ++i; } } } bool UI::IsVisible(UIElement* element, const IntRect& currentScissor) { // First check element's visibility if (!element->IsVisible()) return false; // Then check element dimensions against the scissor rectangle const IntVector2& screenPos = element->GetScreenPosition(); if (screenPos.x_ >= currentScissor.right_ || screenPos.x_ + element->GetWidth() <= currentScissor.left_ || screenPos.y_ >= currentScissor.bottom_ || screenPos.y_ + element->GetHeight() <= currentScissor.top_) return false; else return true; } void UI::GetElementAt(UIElement*& result, UIElement* current, const IntVector2& position, bool activeOnly) { if (!current) return; current->SortChildren(); const Vector >& children = current->GetChildren(); for (Vector >::ConstIterator i = children.Begin(); i != children.End(); ++i) { UIElement* element = *i; bool hasChildren = element->GetNumChildren() > 0; if (element != cursor_.Get() && element->IsVisible()) { if (element->IsInside(position, true)) { // Store the current result, then recurse into its children. Because children // are sorted from lowest to highest priority, the topmost match should remain if (element->IsActive() || !activeOnly) result = element; if (hasChildren) GetElementAt(result, element, position, activeOnly); } else { if (hasChildren && element->IsInsideCombined(position, true)) GetElementAt(result, element, position, activeOnly); } } } } UIElement* UI::GetFocusableElement(UIElement* element) { while (element) { if (element->GetFocusMode() != FM_NOTFOCUSABLE) break; element = element->GetParent(); } return element; } void UI::LoadLayout(UIElement* current, const XMLElement& elem, XMLFile* styleFile) { XMLElement childElem = elem.GetChild("element"); while (childElem) { // Create element String type = childElem.GetString("type"); if (type.Empty()) type = "UIElement"; SharedPtr child = DynamicCast(context_->CreateObject(ShortStringHash(type))); if (!child) { LOGERROR("Could not create UI element " + type); childElem = childElem.GetNext("element"); continue; } child->SetName(childElem.GetString("name")); // Add to the hierarchy current->AddChild(child); // First set the base style from the style file if exists, then apply UI layout overrides String styleName = childElem.HasAttribute("style") ? childElem.GetString("style") : childElem.GetString("type"); if (styleFile) child->SetStyle(styleFile, styleName); child->SetStyle(childElem); // Load the children recursively LoadLayout(child, childElem, styleFile); childElem = childElem.GetNext("element"); } } void UI::HandleScreenMode(StringHash eventType, VariantMap& eventData) { using namespace ScreenMode; if (!initialized_) Initialize(); else rootElement_->SetSize(eventData[P_WIDTH].GetInt(), eventData[P_HEIGHT].GetInt()); } void UI::HandleMouseMove(StringHash eventType, VariantMap& eventData) { using namespace MouseMove; mouseButtons_ = eventData[P_BUTTONS].GetInt(); qualifiers_ = eventData[P_QUALIFIERS].GetInt(); if (cursor_) { const IntVector2& rootSize = rootElement_->GetSize(); // Move cursor only when visible if (cursor_->IsVisible()) { IntVector2 pos = cursor_->GetPosition(); pos.x_ += eventData[P_DX].GetInt(); pos.y_ += eventData[P_DY].GetInt(); pos.x_ = Clamp(pos.x_, 0, rootSize.x_ - 1); pos.y_ = Clamp(pos.y_, 0, rootSize.y_ - 1); cursor_->SetPosition(pos); } if (dragElement_ && mouseButtons_) { IntVector2 pos = cursor_->GetPosition(); if (dragElement_->IsActive() && dragElement_->IsVisible()) dragElement_->OnDragMove(dragElement_->ScreenToElement(pos), pos, mouseButtons_, qualifiers_, cursor_); else { dragElement_->OnDragEnd(dragElement_->ScreenToElement(pos), pos, cursor_); dragElement_.Reset(); } } } } void UI::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData) { mouseButtons_ = eventData[MouseButtonDown::P_BUTTONS].GetInt(); qualifiers_ = eventData[MouseButtonDown::P_QUALIFIERS].GetInt(); int button = eventData[MouseButtonDown::P_BUTTON].GetInt(); if (cursor_ && cursor_->IsVisible()) { IntVector2 pos = cursor_->GetPosition(); WeakPtr element(GetElementAt(pos)); if (element) { // Handle focusing & bringing to front if (button == MOUSEB_LEFT) { SetFocusElement(element); element->BringToFront(); } // Handle click element->OnClick(element->ScreenToElement(pos), pos, mouseButtons_, qualifiers_, cursor_); // Handle start of drag. OnClick() may have caused destruction of the element, so check the pointer again if (element && !dragElement_ && mouseButtons_ == MOUSEB_LEFT) { dragElement_ = element; element->OnDragStart(element->ScreenToElement(pos), pos, mouseButtons_, qualifiers_, cursor_); } } else { // If clicked over no element, or a disabled element, lose focus SetFocusElement(0); } using namespace UIMouseClick; VariantMap eventData; eventData[UIMouseClick::P_ELEMENT] = (void*)element.Get(); eventData[UIMouseClick::P_X] = pos.x_; eventData[UIMouseClick::P_Y] = pos.y_; eventData[UIMouseClick::P_BUTTON] = button; eventData[UIMouseClick::P_BUTTONS] = mouseButtons_; eventData[UIMouseClick::P_QUALIFIERS] = qualifiers_; SendEvent(E_UIMOUSECLICK, eventData); } } void UI::HandleMouseButtonUp(StringHash eventType, VariantMap& eventData) { using namespace MouseButtonUp; mouseButtons_ = eventData[P_BUTTONS].GetInt(); qualifiers_ = eventData[P_QUALIFIERS].GetInt(); if (cursor_ && (cursor_->IsVisible())|| (dragElement_)) { IntVector2 pos = cursor_->GetPosition(); if (dragElement_ && !mouseButtons_) { if (dragElement_->IsActive() && dragElement_->IsVisible()) { dragElement_->OnDragEnd(dragElement_->ScreenToElement(pos), pos, cursor_); // Drag and drop finish bool dragSource = dragElement_ && (dragElement_->GetDragDropMode() & DD_SOURCE) != 0; if (dragSource) { WeakPtr target(GetElementAt(pos)); bool dragTarget = target && (target->GetDragDropMode() & DD_TARGET) != 0; bool dragDropFinish = dragSource && dragTarget && target != dragElement_; if (dragDropFinish) { bool accept = target->OnDragDropFinish(dragElement_); // OnDragDropFinish() may have caused destruction of the elements, so check the pointers again if (accept && dragElement_ && target) { using namespace DragDropFinish; VariantMap eventData; eventData[P_SOURCE] = (void*)dragElement_.Get(); eventData[P_TARGET] = (void*)target.Get(); eventData[P_ACCEPT] = accept; SendEvent(E_DRAGDROPFINISH, eventData); } } } } dragElement_.Reset(); } } } void UI::HandleMouseWheel(StringHash eventType, VariantMap& eventData) { using namespace MouseWheel; mouseButtons_ = eventData[P_BUTTONS].GetInt(); qualifiers_ = eventData[P_QUALIFIERS].GetInt(); int delta = eventData[P_WHEEL].GetInt(); UIElement* element = GetFocusElement(); if (element) element->OnWheel(delta, mouseButtons_, qualifiers_); else { // If no element has actual focus, get the element at cursor if (cursor_) { IntVector2 pos = cursor_->GetPosition(); UIElement* element = GetElementAt(pos); // If the element itself is not focusable, search for a focusable parent element = GetFocusableElement(element); if (element && element->GetFocusMode() >= FM_FOCUSABLE) element->OnWheel(delta, mouseButtons_, qualifiers_); } } } void UI::HandleKeyDown(StringHash eventType, VariantMap& eventData) { using namespace KeyDown; mouseButtons_ = eventData[P_BUTTONS].GetInt(); qualifiers_ = eventData[P_QUALIFIERS].GetInt(); int key = eventData[P_KEY].GetInt(); UIElement* element = GetFocusElement(); if (element) { // Switch focus between focusable elements in the same top level window if (key == KEY_TAB) { UIElement* topLevel = element->GetParent(); while (topLevel && topLevel->GetParent() != rootElement_) topLevel = topLevel->GetParent(); if (topLevel) { topLevel->GetChildren(tempElements_, true); for (PODVector::Iterator i = tempElements_.Begin(); i != tempElements_.End();) { if ((*i)->GetFocusMode() < FM_FOCUSABLE) i = tempElements_.Erase(i); else ++i; } for (unsigned i = 0; i < tempElements_.Size(); ++i) { if (tempElements_[i] == element) { UIElement* next = tempElements_[(i + 1) % tempElements_.Size()]; SetFocusElement(next); return; } } } } // Defocus the element else if (key == KEY_ESC && element->GetFocusMode() == FM_FOCUSABLE_DEFOCUSABLE) element->SetFocus(false); // If none of the special keys, pass the key to the focused element else element->OnKey(key, mouseButtons_, qualifiers_); } } void UI::HandleChar(StringHash eventType, VariantMap& eventData) { using namespace Char; mouseButtons_ = eventData[P_BUTTONS].GetInt(); qualifiers_ = eventData[P_QUALIFIERS].GetInt(); UIElement* element = GetFocusElement(); if (element) element->OnChar(eventData[P_CHAR].GetInt(), mouseButtons_, qualifiers_); } void UI::HandlePostUpdate(StringHash eventType, VariantMap& eventData) { if (initialized_) { using namespace PostUpdate; Update(eventData[P_TIMESTEP].GetFloat()); } } void UI::HandleRenderUpdate(StringHash eventType, VariantMap& eventData) { if (initialized_) RenderUpdate(); } void RegisterUILibrary(Context* context) { Font::RegisterObject(context); UIElement::RegisterObject(context); BorderImage::RegisterObject(context); Button::RegisterObject(context); CheckBox::RegisterObject(context); Cursor::RegisterObject(context); Text::RegisterObject(context); Window::RegisterObject(context); LineEdit::RegisterObject(context); Slider::RegisterObject(context); ScrollBar::RegisterObject(context); ScrollView::RegisterObject(context); ListView::RegisterObject(context); Menu::RegisterObject(context); DropDownList::RegisterObject(context); FileSelector::RegisterObject(context); }