Duckcpp 2.1.0
Duckcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
dcpp::gui::IGUIElement Class Reference

Base class of all GUI elements. More...

#include <duckcpp/core/engine/IGUIElement.hpp>

Inheritance diagram for dcpp::gui::IGUIElement:
Inheritance graph
Collaboration diagram for dcpp::gui::IGUIElement:
Collaboration graph

Public Member Functions

 IGUIElement (EGUI_ELEMENT_TYPE type, IGUIEnvironment *environment, IGUIElement *parent, i32 id, const nub::rect< i32 > &rectangle)
 Constructor.
 
virtual ~IGUIElement ()
 Destructor.
 
IGUIElementgetParent () const
 Returns parent of this element.
 
nub::rect< i32getRelativePosition () const
 Returns the relative rectangle of this element.
 
void setRelativePosition (const nub::rect< i32 > &r)
 Sets the relative rectangle of this element.
 
void setRelativePosition (const nub::position2di &position)
 Sets the relative rectangle of this element, maintaining its current width and height.
 
void setRelativePositionProportional (const nub::rect< f32 > &r)
 Sets the relative rectangle of this element as a proportion of its parent's area.
 
nub::rect< i32getAbsolutePosition () const
 Gets the absolute rectangle of this element.
 
nub::rect< i32getAbsoluteClippingRect () const
 Returns the visible area of the element.
 
void setNotClipped (bool noClip)
 Sets whether the element will ignore its parent's clipping rectangle.
 
bool isNotClipped () const
 Gets whether the element will ignore its parent's clipping rectangle.
 
void setMaxSize (nub::dimension2du size)
 Sets the maximum size allowed for this element.
 
void setMinSize (nub::dimension2du size)
 Sets the minimum size allowed for this element.
 
void setAlignment (EGUI_ALIGNMENT left, EGUI_ALIGNMENT right, EGUI_ALIGNMENT top, EGUI_ALIGNMENT bottom)
 The alignment defines how the borders of this element will be positioned when the parent element is resized.
 
EGUI_ALIGNMENT getAlignLeft () const
 How left element border is aligned when parent is resized.
 
EGUI_ALIGNMENT getAlignRight () const
 How right element border is aligned when parent is resized.
 
EGUI_ALIGNMENT getAlignTop () const
 How top element border is aligned when parent is resized.
 
EGUI_ALIGNMENT getAlignBottom () const
 How bottom element border is aligned when parent is resized.
 
virtual void updateAbsolutePosition ()
 Updates the absolute position.
 
virtual IGUIElementgetElementFromPoint (const nub::position2d< i32 > &point)
 Returns the topmost GUI element at the specific position.
 
virtual bool isPointInside (const nub::position2d< i32 > &point) const
 Returns true if a point is within this element.
 
virtual void addChild (IGUIElement *child)
 Adds a GUI element as new child of this element.
 
virtual void removeChild (IGUIElement *child)
 Removes a child.
 
virtual void remove ()
 Removes this element from its parent.
 
virtual void draw ()
 Draws the element and its children.
 
virtual void OnPostRender (u32 timeMs)
 animate the element and its children.
 
virtual void move (nub::position2d< i32 > absoluteMovement)
 Moves this element.
 
virtual bool isVisible () const
 Returns true if element is visible.
 
virtual bool isTrulyVisible () const
 Check whether the element is truly visible, taking into accounts its parents' visibility.
 
virtual void setVisible (bool visible)
 Sets the visible state of this element.
 
virtual bool isSubElement () const
 Returns true if this element was created as part of its parent control.
 
virtual void setSubElement (bool subElement)
 Sets whether this control was created as part of its parent.
 
void setTabStop (bool enable)
 If set to true, the focus will visit this element when using the tab key to cycle through elements.
 
bool isTabStop () const
 Returns true if this element can be focused by navigating with the tab key.
 
void setTabOrder (i32 index)
 Sets the priority of focus when using the tab key to navigate between a group of elements.
 
i32 getTabOrder () const
 Returns the number in the tab order sequence.
 
void setTabGroup (bool isGroup)
 Sets whether this element is a container for a group of elements which can be navigated using the tab key.
 
bool isTabGroup () const
 Returns true if this element is a tab group.
 
IGUIElementgetTabGroup ()
 Returns the container element which holds all elements in this element's tab group.
 
virtual bool isEnabled () const
 Returns true if element is enabled.
 
virtual void setEnabled (bool enabled)
 Sets the enabled state of this element.
 
virtual void setText (const wchar_t *text)
 Sets the new caption of this element.
 
virtual const wchar_t * getText () const
 Returns caption of this element.
 
virtual void setToolTipText (const wchar_t *text)
 Sets the new caption of this element.
 
virtual const nub::wstringgetToolTipText () const
 Returns caption of this element.
 
virtual i32 getID () const
 Returns id. Can be used to identify the element.
 
virtual void setID (i32 id)
 Sets the id of this element.
 
virtual bool OnEvent (const SEvent &event) override
 Called if an event happened.
 
virtual bool bringToFront (IGUIElement *element)
 Brings a child to front.
 
virtual bool sendToBack (IGUIElement *child)
 Moves a child to the back, so it's siblings are drawn on top of it.
 
virtual const nub::list< IGUIElement * > & getChildren () const
 Returns list with children of this element.
 
virtual IGUIElementgetElementFromId (i32 id, bool searchchildren=false) const
 Finds the first element with the given id.
 
bool isMyChild (IGUIElement *child) const
 
bool getNextElement (i32 startOrder, bool reverse, bool group, IGUIElement *&first, IGUIElement *&closest, bool includeInvisible=false, bool includeDisabled=false) const
 searches elements to find the closest next element to tab to
 
EGUI_ELEMENT_TYPE getType () const
 Returns the type of the gui element.
 
virtual bool hasType (EGUI_ELEMENT_TYPE type) const
 Returns true if the gui element supports the given type.
 
virtual const c8getTypeName () const
 Returns the type name of the gui element.
 
virtual const c8getName () const
 Returns the name of the element.
 
virtual void setName (const c8 *name)
 Sets the name of the element.
 
virtual void setName (const dcpp::nub::string &name)
 Sets the name of the element.
 
virtual void serializeAttributes (io::IAttributes *out, io::SAttributeReadWriteOptions *options=0) const override
 Writes attributes of the scene node.
 
virtual void deserializeAttributes (io::IAttributes *in, io::SAttributeReadWriteOptions *options=0) override
 Reads attributes of the scene node.
 
- Public Member Functions inherited from dcpp::IReferenceCounted
 IReferenceCounted ()
 Constructor.
 
virtual ~IReferenceCounted ()
 Destructor.
 
void grab () const
 Grabs the object. Increments the reference counter by one.
 
bool drop () const
 Drops the object. Decrements the reference counter by one.
 
i32 getReferenceCount () const
 Get the reference count.
 
const c8getDebugName () const
 Returns the debug name of the object.
 
- Public Member Functions inherited from dcpp::IEventReceiver
virtual ~IEventReceiver ()
 Destructor.
 

Protected Member Functions

void addChildToEnd (IGUIElement *child)
 
void recalculateAbsolutePosition (bool recursive)
 
- Protected Member Functions inherited from dcpp::IReferenceCounted
void setDebugName (const c8 *newName)
 Sets the debug name of the object.
 

Protected Attributes

nub::list< IGUIElement * > Children
 List of all children of this element.
 
IGUIElementParent
 Pointer to the parent.
 
nub::rect< i32RelativeRect
 relative rect of element
 
nub::rect< i32AbsoluteRect
 absolute rect of element
 
nub::rect< i32AbsoluteClippingRect
 absolute clipping rect of element
 
nub::rect< i32DesiredRect
 
nub::rect< i32LastParentRect
 for calculating the difference when resizing parent
 
nub::rect< f32ScaleRect
 relative scale of the element inside its parent
 
nub::dimension2du MaxSize
 maximum and minimum size of the element
 
nub::dimension2du MinSize
 
bool IsVisible
 is visible?
 
bool IsEnabled
 is enabled?
 
bool IsSubElement
 is a part of a larger whole and should not be serialized?
 
bool NoClip
 does this element ignore its parent's clipping rectangle?
 
nub::wstring Text
 caption
 
nub::wstring ToolTipText
 tooltip
 
nub::string Name
 users can set this for identifying the element by string
 
i32 ID
 users can set this for identifying the element by integer
 
bool IsTabStop
 tab stop like in windows
 
i32 TabOrder
 tab order
 
bool IsTabGroup
 tab groups are containers like windows, use ctrl+tab to navigate
 
EGUI_ALIGNMENT AlignLeft
 tells the element how to act when its parent is resized
 
EGUI_ALIGNMENT AlignRight
 
EGUI_ALIGNMENT AlignTop
 
EGUI_ALIGNMENT AlignBottom
 
IGUIEnvironmentEnvironment
 GUI Environment.
 
EGUI_ELEMENT_TYPE Type
 type of element
 

Detailed Description

Base class of all GUI elements.

Member Function Documentation

◆ bringToFront()

virtual bool dcpp::gui::IGUIElement::bringToFront ( IGUIElement element)
inlinevirtual

Brings a child to front.

Returns
True if successful, false if not.

◆ deserializeAttributes()

virtual void dcpp::gui::IGUIElement::deserializeAttributes ( io::IAttributes in,
io::SAttributeReadWriteOptions options = 0 
)
inlineoverridevirtual

Reads attributes of the scene node.

Implement this to set the attributes of your scene node for scripting languages, editors, debuggers or xml deserialization purposes.

Reimplemented from dcpp::io::IAttributeExchangingObject.

◆ getElementFromId()

virtual IGUIElement * dcpp::gui::IGUIElement::getElementFromId ( i32  id,
bool  searchchildren = false 
) const
inlinevirtual

Finds the first element with the given id.

Parameters
idId to search for.
searchchildrenSet this to true, if also children of this element may contain the element with the searched id and they should be searched too.
Returns
Returns the first element with the given id. If no element with this id was found, 0 is returned.

◆ getElementFromPoint()

virtual IGUIElement * dcpp::gui::IGUIElement::getElementFromPoint ( const nub::position2d< i32 > &  point)
inlinevirtual

Returns the topmost GUI element at the specific position.

This will check this GUI element and all of its descendants, so it may return this GUI element. To check all GUI elements, call this function on device->getGUIEnvironment()->getRootGUIElement(). Note that the root element is the size of the screen, so doing so (with an on-screen point) will always return the root element if no other element is above it at that point.

Parameters
pointThe point at which to find a GUI element.
Returns
The topmost GUI element at that point, or 0 if there are no candidate elements at this point.

◆ getName()

virtual const c8 * dcpp::gui::IGUIElement::getName ( ) const
inlinevirtual

Returns the name of the element.

Returns
Name as character string.

◆ getNextElement()

bool dcpp::gui::IGUIElement::getNextElement ( i32  startOrder,
bool  reverse,
bool  group,
IGUIElement *&  first,
IGUIElement *&  closest,
bool  includeInvisible = false,
bool  includeDisabled = false 
) const
inline

searches elements to find the closest next element to tab to

Parameters
startOrderThe TabOrder of the current element, -1 if none
reversetrue if searching for a lower number
grouptrue if searching for a higher one
firstelement with the highest/lowest known tab order depending on search direction
closestthe closest match, depending on tab order and direction
includeInvisibleincludes invisible elements in the search (default=false)
includeDisabledincludes disabled elements in the search (default=false)
Returns
true if successfully found an element, false to continue searching/fail

◆ getType()

EGUI_ELEMENT_TYPE dcpp::gui::IGUIElement::getType ( ) const
inline

Returns the type of the gui element.

This is needed for the .NET wrapper but will be used later for serializing and deserializing. If you wrote your own GUIElements, you need to set the type for your element as first parameter in the constructor of IGUIElement. For own (=unknown) elements, simply use EGUIET_ELEMENT as type

◆ getTypeName()

virtual const c8 * dcpp::gui::IGUIElement::getTypeName ( ) const
inlinevirtual

Returns the type name of the gui element.

This is needed serializing elements. For serializing your own elements, override this function and return your own type name which is created by your IGUIElementFactory

◆ hasType()

virtual bool dcpp::gui::IGUIElement::hasType ( EGUI_ELEMENT_TYPE  type) const
inlinevirtual

Returns true if the gui element supports the given type.

This is mostly used to check if you can cast a gui element to the class that goes with the type. Most gui elements will only support their own type, but if you derive your own classes from interfaces you can overload this function and add a check for the type of the base-class additionally. This allows for checks comparable to the dynamic_cast of c++ with enabled rtti. Note that you can't do that by calling BaseClass::hasType(type), but you have to do an explicit comparison check, because otherwise the base class usually just checks for the member variable Type which contains the type of your derived class.

◆ isEnabled()

virtual bool dcpp::gui::IGUIElement::isEnabled ( ) const
inlinevirtual

Returns true if element is enabled.

Currently elements do not care about parent-states. So if you want to affect children you have to enable/disable them all. The only exception to this are sub-elements which also check their parent.

◆ isMyChild()

bool dcpp::gui::IGUIElement::isMyChild ( IGUIElement child) const
inline

returns true if the given element is a child of this one.

Parameters
childThe child element to check

◆ isNotClipped()

bool dcpp::gui::IGUIElement::isNotClipped ( ) const
inline

Gets whether the element will ignore its parent's clipping rectangle.

Returns
true if the element is not clipped by its parent's clipping rectangle.

◆ isPointInside()

virtual bool dcpp::gui::IGUIElement::isPointInside ( const nub::position2d< i32 > &  point) const
inlinevirtual

Returns true if a point is within this element.

Elements with a shape other than a rectangle should override this method

◆ isTrulyVisible()

virtual bool dcpp::gui::IGUIElement::isTrulyVisible ( ) const
inlinevirtual

Check whether the element is truly visible, taking into accounts its parents' visibility.

Returns
true if the element and all its parents are visible, false if this or any parent element is invisible.

◆ OnEvent()

virtual bool dcpp::gui::IGUIElement::OnEvent ( const SEvent event)
inlineoverridevirtual

Called if an event happened.

Implements dcpp::IEventReceiver.

◆ sendToBack()

virtual bool dcpp::gui::IGUIElement::sendToBack ( IGUIElement child)
inlinevirtual

Moves a child to the back, so it's siblings are drawn on top of it.

Returns
True if successful, false if not.

◆ serializeAttributes()

virtual void dcpp::gui::IGUIElement::serializeAttributes ( io::IAttributes out,
io::SAttributeReadWriteOptions options = 0 
) const
inlineoverridevirtual

Writes attributes of the scene node.

Implement this to expose the attributes of your scene node for scripting languages, editors, debuggers or xml serialization purposes.

Reimplemented from dcpp::io::IAttributeExchangingObject.

◆ setMaxSize()

void dcpp::gui::IGUIElement::setMaxSize ( nub::dimension2du  size)
inline

Sets the maximum size allowed for this element.

If set to 0,0, there is no maximum size

◆ setName() [1/2]

virtual void dcpp::gui::IGUIElement::setName ( const c8 name)
inlinevirtual

Sets the name of the element.

Parameters
nameNew name of the gui element.

◆ setName() [2/2]

virtual void dcpp::gui::IGUIElement::setName ( const dcpp::nub::string name)
inlinevirtual

Sets the name of the element.

Parameters
nameNew name of the gui element.

◆ setNotClipped()

void dcpp::gui::IGUIElement::setNotClipped ( bool  noClip)
inline

Sets whether the element will ignore its parent's clipping rectangle.

Parameters
noClipIf true, the element will not be clipped by its parent's clipping rectangle.

◆ setRelativePosition() [1/2]

void dcpp::gui::IGUIElement::setRelativePosition ( const nub::position2di position)
inline

Sets the relative rectangle of this element, maintaining its current width and height.

Parameters
positionThe new relative position to set. Width and height will not be changed.

◆ setRelativePosition() [2/2]

void dcpp::gui::IGUIElement::setRelativePosition ( const nub::rect< i32 > &  r)
inline

Sets the relative rectangle of this element.

Parameters
rThe absolute position to set

◆ setRelativePositionProportional()

void dcpp::gui::IGUIElement::setRelativePositionProportional ( const nub::rect< f32 > &  r)
inline

Sets the relative rectangle of this element as a proportion of its parent's area.

Note
This method used to be 'void setRelativePosition(const nub::rect<f32>& r)'
Parameters
rThe rectangle to set, interpreted as a proportion of the parent's area. Meaningful values are in the range [0...1], unless you intend this element to spill outside its parent.

◆ setSubElement()

virtual void dcpp::gui::IGUIElement::setSubElement ( bool  subElement)
inlinevirtual

Sets whether this control was created as part of its parent.

For example, it is true when a scrollbar is part of a listbox. SubElements are not saved to disk when calling guiEnvironment->saveGUI()

◆ setTabGroup()

void dcpp::gui::IGUIElement::setTabGroup ( bool  isGroup)
inline

Sets whether this element is a container for a group of elements which can be navigated using the tab key.

For example, windows are tab groups. Groups can be navigated using ctrl+tab, providing isTabStop is true.

◆ setTabOrder()

void dcpp::gui::IGUIElement::setTabOrder ( i32  index)
inline

Sets the priority of focus when using the tab key to navigate between a group of elements.

See setTabGroup, isTabGroup and getTabGroup for information on tab groups. Elements with a lower number are focused first

◆ setTabStop()

void dcpp::gui::IGUIElement::setTabStop ( bool  enable)
inline

If set to true, the focus will visit this element when using the tab key to cycle through elements.

If this element is a tab group (see isTabGroup/setTabGroup) then ctrl+tab will be used instead.

Member Data Documentation

◆ DesiredRect

nub::rect<i32> dcpp::gui::IGUIElement::DesiredRect
protected

the rectangle the element would prefer to be, if it was not constrained by parent or max/min size


The documentation for this class was generated from the following file:

Duckcpp    @cppfx.xyz