UI subsystem. Manages the graphical user interface. More...

#include <Urho3D/UI/UI.h>

Inheritance diagram for Urho3D::UI:
[legend]
Collaboration diagram for Urho3D::UI:
[legend]

Classes

struct  DragData
 Data structure used to represent the drag data associated to a UIElement. More...
 

Public Member Functions

 UI (Context *context)
 Construct.
 
virtual ~UI () override
 Destruct.
 
void SetCursor (Cursor *cursor)
 Set cursor UI element.
 
void SetFocusElement (UIElement *element, bool byKey=false)
 Set focused UI element.
 
bool SetModalElement (UIElement *modalElement, bool enable)
 
void Clear ()
 Clear the UI (excluding the cursor.)
 
void Update (float timeStep)
 Update the UI logic. Called by HandlePostUpdate().
 
void RenderUpdate ()
 Update the UI for rendering. Called by HandleRenderUpdate().
 
void Render (bool renderUICommand=false)
 Render the UI. If renderUICommand is false (default), is assumed to be the default UI render to backbuffer called by Engine, and will be performed only once. Additional UI renders to a different rendertarget may be triggered from the renderpath.
 
void DebugDraw (UIElement *element)
 Debug draw a UI element.
 
SharedPtr< UIElementLoadLayout (Deserializer &source, XMLFile *styleFile=nullptr)
 Load a UI layout from an XML file. Optionally specify another XML file for element style. Return the root element.
 
SharedPtr< UIElementLoadLayout (XMLFile *file, XMLFile *styleFile=nullptr)
 Load a UI layout from an XML file. Optionally specify another XML file for element style. Return the root element.
 
bool SaveLayout (Serializer &dest, UIElement *element)
 Save a UI layout to an XML file. Return true if successful.
 
void SetClipboardText (const String &text)
 Set clipboard text.
 
void SetDoubleClickInterval (float interval)
 Set UI element double click interval in seconds.
 
void SetDragBeginInterval (float interval)
 Set UI drag event start interval in seconds.
 
void SetDragBeginDistance (int pixels)
 Set UI drag event start distance threshold in pixels.
 
void SetDefaultToolTipDelay (float delay)
 Set tooltip default display delay in seconds.
 
void SetMaxFontTextureSize (int size)
 Set maximum font face texture size. Must be a power of two. Default is 2048.
 
void SetNonFocusedMouseWheel (bool nonFocusedMouseWheel)
 Set whether mouse wheel can control also a non-focused element.
 
void SetUseSystemClipboard (bool enable)
 Set whether to use system clipboard. Default false.
 
void SetUseScreenKeyboard (bool enable)
 Set whether to show the on-screen keyboard (if supported) when a LineEdit is focused. Default true on mobile devices.
 
void SetUseMutableGlyphs (bool enable)
 Set whether to use mutable (eraseable) glyphs to ensure a font face never expands to more than one texture. Default false.
 
void SetForceAutoHint (bool enable)
 Set whether to force font autohinting instead of using FreeType's TTF bytecode interpreter.
 
void SetFontHintLevel (FontHintLevel level)
 Set the hinting level used by FreeType fonts.
 
void SetFontSubpixelThreshold (float threshold)
 Set the font subpixel threshold. Below this size, if the hint level is LIGHT or NONE, fonts will use subpixel positioning plus oversampling for higher-quality rendering. Has no effect at hint level NORMAL.
 
void SetFontOversampling (int oversampling)
 Set the oversampling (horizonal stretching) used to improve subpixel font rendering. Only affects fonts smaller than the subpixel limit.
 
void SetScale (float scale)
 Set UI scale. 1.0 is default (pixel perfect). Resize the root element to match.
 
void SetWidth (float width)
 Scale UI to the specified width in pixels.
 
void SetHeight (float height)
 Scale UI to the specified height in pixels.
 
void SetCustomSize (const IntVector2 &size)
 Set custom size of the root element. This disables automatic resizing of the root element according to window size. Set custom size 0,0 to return to automatic resizing.
 
void SetCustomSize (int width, int height)
 Set custom size of the root element.
 
UIElementGetRoot () const
 Return root UI element.
 
UIElementGetRootModalElement () const
 Return root modal element.
 
CursorGetCursor () const
 Return cursor.
 
IntVector2 GetCursorPosition () const
 Return cursor position.
 
UIElementGetElementAt (const IntVector2 &position, bool enabledOnly=true)
 Return UI element at global screen coordinates. By default returns only input-enabled elements.
 
UIElementGetElementAt (int x, int y, bool enabledOnly=true)
 Return UI element at global screen coordinates. By default returns only input-enabled elements.
 
UIElementGetElementAt (UIElement *root, const IntVector2 &position, bool enabledOnly=true)
 Get a child element at element's screen position relative to specified root element.
 
UIElementGetFocusElement () const
 Return focused element.
 
UIElementGetFrontElement () const
 Return topmost enabled root-level non-modal element.
 
const Vector< UIElement * > GetDragElements ()
 Return currently dragged elements.
 
unsigned GetNumDragElements () const
 Return the number of currently dragged elements.
 
UIElementGetDragElement (unsigned index)
 Return the drag element at index.
 
const StringGetClipboardText () const
 Return clipboard text.
 
float GetDoubleClickInterval () const
 Return UI element double click interval in seconds.
 
float GetDragBeginInterval () const
 Return UI drag start event interval in seconds.
 
int GetDragBeginDistance () const
 Return UI drag start event distance threshold in pixels.
 
float GetDefaultToolTipDelay () const
 Return tooltip default display delay in seconds.
 
int GetMaxFontTextureSize () const
 Return font texture maximum size.
 
bool IsNonFocusedMouseWheel () const
 Return whether mouse wheel can control also a non-focused element.
 
bool GetUseSystemClipboard () const
 Return whether is using the system clipboard.
 
bool GetUseScreenKeyboard () const
 Return whether focusing a LineEdit will show the on-screen keyboard.
 
bool GetUseMutableGlyphs () const
 Return whether is using mutable (eraseable) glyphs for fonts.
 
bool GetForceAutoHint () const
 Return whether is using forced autohinting.
 
FontHintLevel GetFontHintLevel () const
 Return the current FreeType font hinting level.
 
float GetFontSubpixelThreshold () const
 Get the font subpixel threshold. Below this size, if the hint level is LIGHT or NONE, fonts will use subpixel positioning plus oversampling for higher-quality rendering. Has no effect at hint level NORMAL.
 
int GetFontOversampling () const
 Get the oversampling (horizonal stretching) used to improve subpixel font rendering. Only affects fonts smaller than the subpixel limit.
 
bool HasModalElement () const
 Return true when UI has modal element(s).
 
bool IsDragging () const
 Return whether a drag is in progress.
 
float GetScale () const
 Return current UI scale.
 
const IntVector2GetCustomSize () const
 Return root element custom size. Returns 0,0 when custom size is not being used and automatic resizing according to window size is in use instead (default.)
 
void SetRenderToTexture (UIComponent *component, bool enable)
 Register UIElement for being rendered into a texture.
 
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
 
virtual ~Object () override
 Destruct. Clean up self from event sender & receiver structures.
 
virtual StringHash GetType () const =0
 Return type hash.
 
virtual const StringGetTypeName () const =0
 Return type name.
 
virtual const TypeInfoGetTypeInfo () const =0
 Return type info.
 
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
 
bool IsInstanceOf (StringHash type) const
 Check current instance is type of specified type.
 
bool IsInstanceOf (const TypeInfo *typeInfo) const
 Check current instance is type of specified type.
 
template<typename T >
bool IsInstanceOf () const
 Check current instance is type of specified class.
 
void SubscribeToEvent (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
 
void SubscribeToEvent (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
 
void SubscribeToEvent (StringHash eventType, const std::function< void(StringHash, VariantMap &)> &function, void *userData=nullptr)
 Subscribe to an event that can be sent by any sender.
 
void SubscribeToEvent (Object *sender, StringHash eventType, const std::function< void(StringHash, VariantMap &)> &function, void *userData=nullptr)
 Subscribe to a specific sender's event.
 
void UnsubscribeFromEvent (StringHash eventType)
 Unsubscribe from an event.
 
void UnsubscribeFromEvent (Object *sender, StringHash eventType)
 Unsubscribe from a specific sender's event.
 
void UnsubscribeFromEvents (Object *sender)
 Unsubscribe from a specific sender's events.
 
void UnsubscribeFromAllEvents ()
 Unsubscribe from all events.
 
void UnsubscribeFromAllEventsExcept (const PODVector< StringHash > &exceptions, bool onlyUserData)
 Unsubscribe from all events except those listed, and optionally only those with userdata (script registered events.)
 
void SendEvent (StringHash eventType)
 Send event to all subscribers.
 
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers.
 
VariantMapGetEventDataMap () const
 Return a preallocated map for event data. Used for optimization to avoid constant re-allocation of event data maps.
 
template<typename... Args>
void SendEvent (StringHash eventType, Args...args)
 Send event with variadic parameter pairs to all subscribers. The parameter pairs is a list of paramID and paramValue separated by comma, one pair after another.
 
ContextGetContext () const
 Return execution context.
 
const VariantGetGlobalVar (StringHash key) const
 Return global variable based on key.
 
const VariantMapGetGlobalVars () const
 Return all global variables.
 
void SetGlobalVar (StringHash key, const Variant &value)
 Set global variable with the respective key and value.
 
ObjectGetSubsystem (StringHash type) const
 Return subsystem by type.
 
ObjectGetEventSender () const
 Return active event sender. Null outside event handling.
 
EventHandlerGetEventHandler () const
 Return active event handler. Null outside event handling.
 
bool HasSubscribedToEvent (StringHash eventType) const
 Return whether has subscribed to an event without specific sender.
 
bool HasSubscribedToEvent (Object *sender, StringHash eventType) const
 Return whether has subscribed to a specific sender's event.
 
bool HasEventHandlers () const
 Return whether has subscribed to any event.
 
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
 
const StringGetCategory () const
 Return object category. Categories are (optionally) registered along with the object factory. Return an empty string if the object category is not registered.
 
- Public Member Functions inherited from Urho3D::RefCounted
 RefCounted ()
 Construct. Allocate the reference count structure and set an initial self weak reference.
 
virtual ~RefCounted ()
 Destruct. Mark as expired and also delete the reference count structure if no outside weak references exist.
 
void AddRef ()
 Increment reference count. Can also be called outside of a SharedPtr for traditional reference counting.
 
void ReleaseRef ()
 Decrement reference count and delete self if no more references. Can also be called outside of a SharedPtr for traditional reference counting.
 
int Refs () const
 Return reference count.
 
int WeakRefs () const
 Return weak reference count.
 
RefCountRefCountPtr ()
 Return pointer to the reference count structure.
 

Private Member Functions

 URHO3D_OBJECT (UI, Object)
 
void Initialize ()
 Initialize when screen mode initially set.
 
void Update (float timeStep, UIElement *element)
 Update UI element logic recursively.
 
void SetVertexData (VertexBuffer *dest, const PODVector< float > &vertexData)
 Upload UI geometry into a vertex buffer.
 
void Render (VertexBuffer *buffer, const PODVector< UIBatch > &batches, unsigned batchStart, unsigned batchEnd)
 Render UI batches to the current rendertarget. Geometry must have been uploaded first.
 
void GetBatches (PODVector< UIBatch > &batches, PODVector< float > &vertexData, UIElement *element, IntRect currentScissor)
 Generate batches from an UI element recursively. Skip the cursor element.
 
UIElementGetElementAt (const IntVector2 &position, bool enabledOnly, IntVector2 *elementScreenPosition)
 Return UI element at global screen coordinates. Return position converted to element's screen coordinates.
 
void GetElementAt (UIElement *&result, UIElement *current, const IntVector2 &position, bool enabledOnly)
 Return UI element at screen position recursively.
 
UIElementGetFocusableElement (UIElement *element)
 Return the first element in hierarchy that can alter focus.
 
void GetCursorPositionAndVisible (IntVector2 &pos, bool &visible)
 Return cursor position and visibility either from the cursor element, or the Input subsystem.
 
void SetCursorShape (CursorShape shape)
 Set active cursor's shape.
 
void ReleaseFontFaces ()
 Force release of font faces when global font properties change.
 
void ProcessHover (const IntVector2 &windowCursorPos, int buttons, int qualifiers, Cursor *cursor)
 Handle button or touch hover.
 
void ProcessClickBegin (const IntVector2 &windowCursorPos, int button, int buttons, int qualifiers, Cursor *cursor, bool cursorVisible)
 Handle button or touch begin.
 
void ProcessClickEnd (const IntVector2 &windowCursorPos, int button, int buttons, int qualifiers, Cursor *cursor, bool cursorVisible)
 Handle button or touch end.
 
void ProcessMove (const IntVector2 &windowCursorPos, const IntVector2 &cursorDeltaPos, int buttons, int qualifiers, Cursor *cursor, bool cursorVisible)
 Handle mouse or touch move.
 
void SendDragOrHoverEvent (StringHash eventType, UIElement *element, const IntVector2 &screenPos, const IntVector2 &deltaPos, UI::DragData *dragData)
 Send a UI element drag or hover begin event.
 
void SendClickEvent (StringHash eventType, UIElement *beginElement, UIElement *endElement, const IntVector2 &pos, int button, int buttons, int qualifiers)
 Send a UI click or double click event.
 
void HandleScreenMode (StringHash eventType, VariantMap &eventData)
 Handle screen mode event.
 
void HandleMouseButtonDown (StringHash eventType, VariantMap &eventData)
 Handle mouse button down event.
 
void HandleMouseButtonUp (StringHash eventType, VariantMap &eventData)
 Handle mouse button up event.
 
void HandleMouseMove (StringHash eventType, VariantMap &eventData)
 Handle mouse move event.
 
void HandleMouseWheel (StringHash eventType, VariantMap &eventData)
 Handle mouse wheel event.
 
void HandleTouchBegin (StringHash eventType, VariantMap &eventData)
 Handle touch begin event.
 
void HandleTouchEnd (StringHash eventType, VariantMap &eventData)
 Handle touch end event.
 
void HandleTouchMove (StringHash eventType, VariantMap &eventData)
 Handle touch move event.
 
void HandleKeyDown (StringHash eventType, VariantMap &eventData)
 Handle keypress event.
 
void HandleTextInput (StringHash eventType, VariantMap &eventData)
 Handle text input event.
 
void HandleBeginFrame (StringHash eventType, VariantMap &eventData)
 Handle frame begin event.
 
void HandlePostUpdate (StringHash eventType, VariantMap &eventData)
 Handle logic post-update event.
 
void HandleRenderUpdate (StringHash eventType, VariantMap &eventData)
 Handle render update event.
 
void HandleDropFile (StringHash eventType, VariantMap &eventData)
 Handle a file being drag-dropped into the application window.
 
HashMap< WeakPtr< UIElement >
, DragData * >::Iterator 
DragElementErase (HashMap< WeakPtr< UIElement >, DragData * >::Iterator dragElement)
 Remove drag data and return next iterator.
 
void ProcessDragCancel ()
 Handle clean up on a drag cancel.
 
IntVector2 SumTouchPositions (UI::DragData *dragData, const IntVector2 &oldSendPos)
 Sum touch positions and return the begin position ready to send.
 
void ResizeRootElement ()
 Resize root element to effective size.
 
IntVector2 GetEffectiveRootElementSize (bool applyScale=true) const
 Return effective size of the root element, according to UI scale and resolution / custom size.
 

Private Attributes

WeakPtr< Graphicsgraphics_
 Graphics subsystem.
 
SharedPtr< UIElementrootElement_
 UI root element.
 
SharedPtr< UIElementrootModalElement_
 UI root modal element.
 
SharedPtr< Cursorcursor_
 Cursor.
 
WeakPtr< UIElementfocusElement_
 Currently focused element.
 
PODVector< UIBatchbatches_
 UI rendering batches.
 
PODVector< float > vertexData_
 UI rendering vertex data.
 
PODVector< UIBatchdebugDrawBatches_
 UI rendering batches for debug draw.
 
PODVector< float > debugVertexData_
 UI rendering vertex data for debug draw.
 
SharedPtr< VertexBuffervertexBuffer_
 UI vertex buffer.
 
SharedPtr< VertexBufferdebugVertexBuffer_
 UI debug geometry vertex buffer.
 
PODVector< UIElement * > tempElements_
 UI element query vector.
 
String clipBoard_
 Clipboard text.
 
float doubleClickInterval_
 Seconds between clicks to register a double click.
 
float dragBeginInterval_
 Seconds from mouse button down to begin a drag if there has been no movement exceeding pixel threshold.
 
float defaultToolTipDelay_
 Tooltip default display delay in seconds.
 
int dragBeginDistance_
 Drag begin event distance threshold in pixels.
 
int mouseButtons_
 Mouse buttons held down.
 
int lastMouseButtons_
 Last mouse button pressed.
 
int qualifiers_
 Qualifier keys held down.
 
int maxFontTextureSize_
 Font texture maximum size.
 
bool initialized_
 Initialized flag.
 
bool usingTouchInput_
 Touch used flag.
 
bool nonFocusedMouseWheel_
 Flag to switch mouse wheel event to be sent to non-focused element at cursor.
 
bool useSystemClipboard_
 Flag for using operating system clipboard instead of internal.
 
bool useScreenKeyboard_
 Flag for showing the on-screen keyboard on focusing a LineEdit.
 
bool useMutableGlyphs_
 Flag for using mutable (erasable) font glyphs.
 
bool forceAutoHint_
 Flag for forcing FreeType auto hinting.
 
FontHintLevel fontHintLevel_
 FreeType hinting level (default is FONT_HINT_LEVEL_NORMAL).
 
float fontSubpixelThreshold_
 Maxmimum font size for subpixel glyph positioning and oversampling (default is 12).
 
int fontOversampling_
 Horizontal oversampling for subpixel fonts (default is 2).
 
bool uiRendered_
 Flag for UI already being rendered this frame.
 
unsigned nonModalBatchSize_
 Non-modal batch size (used internally for rendering).
 
Timer clickTimer_
 Timer used to trigger double click.
 
WeakPtr< UIElementdoubleClickElement_
 UI element last clicked for tracking double clicks.
 
HashMap< WeakPtr< UIElement >
, bool > 
hoveredElements_
 Currently hovered elements.
 
HashMap< WeakPtr< UIElement >
, DragData * > 
dragElements_
 Currently dragged elements.
 
int dragElementsCount_
 Number of elements in dragElements_.
 
int dragConfirmedCount_
 Number of elements in dragElements_ with dragPending = false.
 
HashMap< WeakPtr< UIElement >
, int > 
touchDragElements_
 UI elements that are being touched with touch input.
 
Vector< UIElement * > dragElementsConfirmed_
 Confirmed drag elements cache.
 
float uiScale_
 Current scale of UI.
 
IntVector2 customSize_
 Root element custom size. 0,0 for automatic resizing (default.)
 
Vector< WeakPtr< UIComponent > > renderToTexture_
 Elements that should be rendered to textures.
 

Friends

class UIComponent
 

Additional Inherited Members

- Static Public Member Functions inherited from Urho3D::Object
static const TypeInfoGetTypeInfoStatic ()
 Return type info static.
 
- Protected Attributes inherited from Urho3D::Object
Contextcontext_
 Execution context.
 

Detailed Description

UI subsystem. Manages the graphical user interface.

Member Function Documentation

bool Urho3D::UI::SetModalElement ( UIElement modalElement,
bool  enable 
)

Set modal element. Until all the modal elements are dismissed, all the inputs and events are only sent to them. Return true when successful. Only the modal element can clear its modal status or when it is being destructed.

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files:
  • Source/Urho3D/UI/UI.h
  • Source/Urho3D/UI/UI.cpp