1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __I_GUI_ELEMENT_H_INCLUDED__
\r
6 #define __I_GUI_ELEMENT_H_INCLUDED__
\r
8 #include "IReferenceCounted.h"
\r
10 #include "irrString.h"
\r
11 #include "IEventReceiver.h"
\r
12 #include "EGUIElementTypes.h"
\r
13 #include "EGUIAlignment.h"
\r
14 #include "IAttributes.h"
\r
15 #include "IGUIEnvironment.h"
\r
17 #include <algorithm>
\r
25 //! Base class of all GUI elements.
\r
26 class IGUIElement : virtual public IReferenceCounted, public IEventReceiver
\r
31 IGUIElement(EGUI_ELEMENT_TYPE type, IGUIEnvironment* environment, IGUIElement* parent,
\r
32 s32 id, const core::rect<s32>& rectangle)
\r
33 : Parent(0), RelativeRect(rectangle), AbsoluteRect(rectangle),
\r
34 AbsoluteClippingRect(rectangle), DesiredRect(rectangle),
\r
35 MaxSize(0,0), MinSize(1,1), IsVisible(true), IsEnabled(true),
\r
36 IsSubElement(false), NoClip(false), ID(id), IsTabStop(false), TabOrder(-1), IsTabGroup(false),
\r
37 AlignLeft(EGUIA_UPPERLEFT), AlignRight(EGUIA_UPPERLEFT), AlignTop(EGUIA_UPPERLEFT), AlignBottom(EGUIA_UPPERLEFT),
\r
38 Environment(environment), Type(type)
\r
41 setDebugName("IGUIElement");
\r
44 // if we were given a parent to attach to
\r
47 parent->addChildToEnd(this);
\r
48 recalculateAbsolutePosition(true);
\r
54 virtual ~IGUIElement()
\r
56 for (auto child : Children) {
\r
57 child->Parent = nullptr;
\r
63 //! Returns parent of this element.
\r
64 IGUIElement* getParent() const
\r
69 //! Returns the relative rectangle of this element.
\r
70 core::rect<s32> getRelativePosition() const
\r
72 return RelativeRect;
\r
76 //! Sets the relative rectangle of this element.
\r
77 /** \param r The absolute position to set */
\r
78 void setRelativePosition(const core::rect<s32>& r)
\r
82 const core::rect<s32>& r2 = Parent->getAbsolutePosition();
\r
84 core::dimension2df d((f32)(r2.getSize().Width), (f32)(r2.getSize().Height));
\r
86 if (AlignLeft == EGUIA_SCALE)
\r
87 ScaleRect.UpperLeftCorner.X = (f32)r.UpperLeftCorner.X / d.Width;
\r
88 if (AlignRight == EGUIA_SCALE)
\r
89 ScaleRect.LowerRightCorner.X = (f32)r.LowerRightCorner.X / d.Width;
\r
90 if (AlignTop == EGUIA_SCALE)
\r
91 ScaleRect.UpperLeftCorner.Y = (f32)r.UpperLeftCorner.Y / d.Height;
\r
92 if (AlignBottom == EGUIA_SCALE)
\r
93 ScaleRect.LowerRightCorner.Y = (f32)r.LowerRightCorner.Y / d.Height;
\r
97 updateAbsolutePosition();
\r
100 //! Sets the relative rectangle of this element, maintaining its current width and height
\r
101 /** \param position The new relative position to set. Width and height will not be changed. */
\r
102 void setRelativePosition(const core::position2di & position)
\r
104 const core::dimension2di mySize = RelativeRect.getSize();
\r
105 const core::rect<s32> rectangle(position.X, position.Y,
\r
106 position.X + mySize.Width, position.Y + mySize.Height);
\r
107 setRelativePosition(rectangle);
\r
111 //! Sets the relative rectangle of this element as a proportion of its parent's area.
\r
112 /** \note This method used to be 'void setRelativePosition(const core::rect<f32>& r)'
\r
113 \param r The rectangle to set, interpreted as a proportion of the parent's area.
\r
114 Meaningful values are in the range [0...1], unless you intend this element to spill
\r
115 outside its parent. */
\r
116 void setRelativePositionProportional(const core::rect<f32>& r)
\r
121 const core::dimension2di& d = Parent->getAbsolutePosition().getSize();
\r
123 DesiredRect = core::rect<s32>(
\r
124 core::floor32((f32)d.Width * r.UpperLeftCorner.X),
\r
125 core::floor32((f32)d.Height * r.UpperLeftCorner.Y),
\r
126 core::floor32((f32)d.Width * r.LowerRightCorner.X),
\r
127 core::floor32((f32)d.Height * r.LowerRightCorner.Y));
\r
131 updateAbsolutePosition();
\r
135 //! Gets the absolute rectangle of this element
\r
136 core::rect<s32> getAbsolutePosition() const
\r
138 return AbsoluteRect;
\r
142 //! Returns the visible area of the element.
\r
143 core::rect<s32> getAbsoluteClippingRect() const
\r
145 return AbsoluteClippingRect;
\r
149 //! Sets whether the element will ignore its parent's clipping rectangle
\r
150 /** \param noClip If true, the element will not be clipped by its parent's clipping rectangle. */
\r
151 void setNotClipped(bool noClip)
\r
154 updateAbsolutePosition();
\r
158 //! Gets whether the element will ignore its parent's clipping rectangle
\r
159 /** \return true if the element is not clipped by its parent's clipping rectangle. */
\r
160 bool isNotClipped() const
\r
166 //! Sets the maximum size allowed for this element
\r
167 /** If set to 0,0, there is no maximum size */
\r
168 void setMaxSize(core::dimension2du size)
\r
171 updateAbsolutePosition();
\r
175 //! Sets the minimum size allowed for this element
\r
176 void setMinSize(core::dimension2du size)
\r
179 if (MinSize.Width < 1)
\r
181 if (MinSize.Height < 1)
\r
182 MinSize.Height = 1;
\r
183 updateAbsolutePosition();
\r
187 //! The alignment defines how the borders of this element will be positioned when the parent element is resized.
\r
188 void setAlignment(EGUI_ALIGNMENT left, EGUI_ALIGNMENT right, EGUI_ALIGNMENT top, EGUI_ALIGNMENT bottom)
\r
191 AlignRight = right;
\r
193 AlignBottom = bottom;
\r
197 core::rect<s32> r(Parent->getAbsolutePosition());
\r
199 core::dimension2df d((f32)r.getSize().Width, (f32)r.getSize().Height);
\r
201 if (AlignLeft == EGUIA_SCALE)
\r
202 ScaleRect.UpperLeftCorner.X = (f32)DesiredRect.UpperLeftCorner.X / d.Width;
\r
203 if (AlignRight == EGUIA_SCALE)
\r
204 ScaleRect.LowerRightCorner.X = (f32)DesiredRect.LowerRightCorner.X / d.Width;
\r
205 if (AlignTop == EGUIA_SCALE)
\r
206 ScaleRect.UpperLeftCorner.Y = (f32)DesiredRect.UpperLeftCorner.Y / d.Height;
\r
207 if (AlignBottom == EGUIA_SCALE)
\r
208 ScaleRect.LowerRightCorner.Y = (f32)DesiredRect.LowerRightCorner.Y / d.Height;
\r
212 //! How left element border is aligned when parent is resized
\r
213 EGUI_ALIGNMENT getAlignLeft() const
\r
218 //! How right element border is aligned when parent is resized
\r
219 EGUI_ALIGNMENT getAlignRight() const
\r
224 //! How top element border is aligned when parent is resized
\r
225 EGUI_ALIGNMENT getAlignTop() const
\r
230 //! How bottom element border is aligned when parent is resized
\r
231 EGUI_ALIGNMENT getAlignBottom() const
\r
233 return AlignBottom;
\r
236 //! Updates the absolute position.
\r
237 virtual void updateAbsolutePosition()
\r
239 recalculateAbsolutePosition(false);
\r
241 // update all children
\r
242 for (auto child : Children)
\r
244 child->updateAbsolutePosition();
\r
249 //! Returns the topmost GUI element at the specific position.
\r
251 This will check this GUI element and all of its descendants, so it
\r
252 may return this GUI element. To check all GUI elements, call this
\r
253 function on device->getGUIEnvironment()->getRootGUIElement(). Note
\r
254 that the root element is the size of the screen, so doing so (with
\r
255 an on-screen point) will always return the root element if no other
\r
256 element is above it at that point.
\r
257 \param point: The point at which to find a GUI element.
\r
258 \return The topmost GUI element at that point, or 0 if there are
\r
259 no candidate elements at this point.
\r
261 virtual IGUIElement* getElementFromPoint(const core::position2d<s32>& point)
\r
263 IGUIElement* target = 0;
\r
267 // we have to search from back to front, because later children
\r
268 // might be drawn over the top of earlier ones.
\r
269 auto it = Children.rbegin();
\r
270 auto ie = Children.rend();
\r
273 target = (*it)->getElementFromPoint(point);
\r
281 if (isVisible() && isPointInside(point))
\r
288 //! Returns true if a point is within this element.
\r
289 /** Elements with a shape other than a rectangle should override this method */
\r
290 virtual bool isPointInside(const core::position2d<s32>& point) const
\r
292 return AbsoluteClippingRect.isPointInside(point);
\r
296 //! Adds a GUI element as new child of this element.
\r
297 virtual void addChild(IGUIElement* child)
\r
299 if ( child && child != this )
\r
301 addChildToEnd(child);
\r
302 child->updateAbsolutePosition();
\r
306 //! Removes a child.
\r
307 virtual void removeChild(IGUIElement* child)
\r
309 assert(child->Parent == this);
\r
310 Children.erase(child->ParentPos);
\r
311 child->Parent = nullptr;
\r
315 //! Removes all children.
\r
316 virtual void removeAllChildren() {
\r
317 while (!Children.empty()) {
\r
318 auto child = Children.back();
\r
323 //! Removes this element from its parent.
\r
324 virtual void remove()
\r
327 Parent->removeChild(this);
\r
331 //! Draws the element and its children.
\r
332 virtual void draw()
\r
336 for (auto child : Children)
\r
342 //! animate the element and its children.
\r
343 virtual void OnPostRender(u32 timeMs)
\r
347 for (auto child : Children)
\r
348 child->OnPostRender( timeMs );
\r
353 //! Moves this element.
\r
354 virtual void move(core::position2d<s32> absoluteMovement)
\r
356 setRelativePosition(DesiredRect + absoluteMovement);
\r
360 //! Returns true if element is visible.
\r
361 virtual bool isVisible() const
\r
366 //! Check whether the element is truly visible, taking into accounts its parents' visibility
\r
367 /** \return true if the element and all its parents are visible,
\r
368 false if this or any parent element is invisible. */
\r
369 virtual bool isTrulyVisible() const
\r
377 return Parent->isTrulyVisible();
\r
380 //! Sets the visible state of this element.
\r
381 virtual void setVisible(bool visible)
\r
383 IsVisible = visible;
\r
387 //! Returns true if this element was created as part of its parent control
\r
388 virtual bool isSubElement() const
\r
390 return IsSubElement;
\r
394 //! Sets whether this control was created as part of its parent.
\r
395 /** For example, it is true when a scrollbar is part of a listbox.
\r
396 SubElements are not saved to disk when calling guiEnvironment->saveGUI() */
\r
397 virtual void setSubElement(bool subElement)
\r
399 IsSubElement = subElement;
\r
403 //! If set to true, the focus will visit this element when using the tab key to cycle through elements.
\r
404 /** If this element is a tab group (see isTabGroup/setTabGroup) then
\r
405 ctrl+tab will be used instead. */
\r
406 void setTabStop(bool enable)
\r
408 IsTabStop = enable;
\r
412 //! Returns true if this element can be focused by navigating with the tab key
\r
413 bool isTabStop() const
\r
419 //! Sets the priority of focus when using the tab key to navigate between a group of elements.
\r
420 /** See setTabGroup, isTabGroup and getTabGroup for information on tab groups.
\r
421 Elements with a lower number are focused first */
\r
422 void setTabOrder(s32 index)
\r
424 // negative = autonumber
\r
428 IGUIElement *el = getTabGroup();
\r
429 while (IsTabGroup && el && el->Parent)
\r
432 IGUIElement *first=0, *closest=0;
\r
435 // find the highest element number
\r
436 el->getNextElement(-1, true, IsTabGroup, first, closest, true);
\r
439 TabOrder = first->getTabOrder() + 1;
\r
449 //! Returns the number in the tab order sequence
\r
450 s32 getTabOrder() const
\r
456 //! Sets whether this element is a container for a group of elements which can be navigated using the tab key.
\r
457 /** For example, windows are tab groups.
\r
458 Groups can be navigated using ctrl+tab, providing isTabStop is true. */
\r
459 void setTabGroup(bool isGroup)
\r
461 IsTabGroup = isGroup;
\r
465 //! Returns true if this element is a tab group.
\r
466 bool isTabGroup() const
\r
472 //! Returns the container element which holds all elements in this element's tab group.
\r
473 IGUIElement* getTabGroup()
\r
475 IGUIElement *ret=this;
\r
477 while (ret && !ret->isTabGroup())
\r
478 ret = ret->getParent();
\r
484 //! Returns true if element is enabled
\r
485 /** Currently elements do _not_ care about parent-states.
\r
486 So if you want to affect children you have to enable/disable them all.
\r
487 The only exception to this are sub-elements which also check their parent.
\r
489 virtual bool isEnabled() const
\r
491 if ( isSubElement() && IsEnabled && getParent() )
\r
492 return getParent()->isEnabled();
\r
498 //! Sets the enabled state of this element.
\r
499 virtual void setEnabled(bool enabled)
\r
501 IsEnabled = enabled;
\r
505 //! Sets the new caption of this element.
\r
506 virtual void setText(const wchar_t* text)
\r
512 //! Returns caption of this element.
\r
513 virtual const wchar_t* getText() const
\r
515 return Text.c_str();
\r
519 //! Sets the new caption of this element.
\r
520 virtual void setToolTipText(const wchar_t* text)
\r
522 ToolTipText = text;
\r
526 //! Returns caption of this element.
\r
527 virtual const core::stringw& getToolTipText() const
\r
529 return ToolTipText;
\r
533 //! Returns id. Can be used to identify the element.
\r
534 virtual s32 getID() const
\r
540 //! Sets the id of this element
\r
541 virtual void setID(s32 id)
\r
547 //! Called if an event happened.
\r
548 bool OnEvent(const SEvent& event) override
\r
550 return Parent ? Parent->OnEvent(event) : false;
\r
554 //! Brings a child to front
\r
555 /** \return True if successful, false if not. */
\r
556 virtual bool bringToFront(IGUIElement* child)
\r
558 if (child->Parent != this)
\r
560 if (std::next(child->ParentPos) == Children.end()) // already there
\r
562 Children.erase(child->ParentPos);
\r
563 child->ParentPos = Children.insert(Children.end(), child);
\r
568 //! Moves a child to the back, so it's siblings are drawn on top of it
\r
569 /** \return True if successful, false if not. */
\r
570 virtual bool sendToBack(IGUIElement* child)
\r
572 if (child->Parent != this)
\r
574 if (child->ParentPos == Children.begin()) // already there
\r
576 Children.erase(child->ParentPos);
\r
577 child->ParentPos = Children.insert(Children.begin(), child);
\r
581 //! Returns list with children of this element
\r
582 virtual const std::list<IGUIElement*>& getChildren() const
\r
588 //! Finds the first element with the given id.
\r
589 /** \param id: Id to search for.
\r
590 \param searchchildren: Set this to true, if also children of this
\r
591 element may contain the element with the searched id and they
\r
592 should be searched too.
\r
593 \return Returns the first element with the given id. If no element
\r
594 with this id was found, 0 is returned. */
\r
595 virtual IGUIElement* getElementFromId(s32 id, bool searchchildren=false) const
\r
597 IGUIElement* e = 0;
\r
599 for (auto child : Children)
\r
601 if (child->getID() == id)
\r
604 if (searchchildren)
\r
605 e = child->getElementFromId(id, true);
\r
615 //! returns true if the given element is a child of this one.
\r
616 //! \param child: The child element to check
\r
617 bool isMyChild(IGUIElement* child) const
\r
624 child = child->Parent;
\r
626 } while (child->Parent && child != this);
\r
629 return child == this;
\r
633 //! searches elements to find the closest next element to tab to
\r
634 /** \param startOrder: The TabOrder of the current element, -1 if none
\r
635 \param reverse: true if searching for a lower number
\r
636 \param group: true if searching for a higher one
\r
637 \param first: element with the highest/lowest known tab order depending on search direction
\r
638 \param closest: the closest match, depending on tab order and direction
\r
639 \param includeInvisible: includes invisible elements in the search (default=false)
\r
640 \param includeDisabled: includes disabled elements in the search (default=false)
\r
641 \return true if successfully found an element, false to continue searching/fail */
\r
642 bool getNextElement(s32 startOrder, bool reverse, bool group,
\r
643 IGUIElement*& first, IGUIElement*& closest, bool includeInvisible=false,
\r
644 bool includeDisabled=false) const
\r
646 // we'll stop searching if we find this number
\r
647 s32 wanted = startOrder + ( reverse ? -1 : 1 );
\r
649 wanted = 1073741824; // maximum s32
\r
651 auto it = Children.begin();
\r
653 s32 closestOrder, currentOrder;
\r
655 while(it != Children.end())
\r
657 // ignore invisible elements and their children
\r
658 if ( ( (*it)->isVisible() || includeInvisible ) &&
\r
659 (group == true || (*it)->isTabGroup() == false) )
\r
661 // ignore disabled, but children are checked (disabled is currently per element ignoring parent states)
\r
662 if ( (*it)->isEnabled() || includeDisabled )
\r
664 // only check tab stops and those with the same group status
\r
665 if ((*it)->isTabStop() && ((*it)->isTabGroup() == group))
\r
667 currentOrder = (*it)->getTabOrder();
\r
669 // is this what we're looking for?
\r
670 if (currentOrder == wanted)
\r
676 // is it closer than the current closest?
\r
679 closestOrder = closest->getTabOrder();
\r
680 if ( ( reverse && currentOrder > closestOrder && currentOrder < startOrder)
\r
681 ||(!reverse && currentOrder < closestOrder && currentOrder > startOrder))
\r
687 if ( (reverse && currentOrder < startOrder) || (!reverse && currentOrder > startOrder) )
\r
692 // is it before the current first?
\r
695 closestOrder = first->getTabOrder();
\r
697 if ( (reverse && closestOrder < currentOrder) || (!reverse && closestOrder > currentOrder) )
\r
708 // search within children
\r
709 if ((*it)->getNextElement(startOrder, reverse, group, first, closest))
\r
720 //! Returns the type of the gui element.
\r
721 /** This is needed for the .NET wrapper but will be used
\r
722 later for serializing and deserializing.
\r
723 If you wrote your own GUIElements, you need to set the type for your element as first parameter
\r
724 in the constructor of IGUIElement. For own (=unknown) elements, simply use EGUIET_ELEMENT as type */
\r
725 EGUI_ELEMENT_TYPE getType() const
\r
730 //! Returns true if the gui element supports the given type.
\r
731 /** This is mostly used to check if you can cast a gui element to the class that goes with the type.
\r
732 Most gui elements will only support their own type, but if you derive your own classes from interfaces
\r
733 you can overload this function and add a check for the type of the base-class additionally.
\r
734 This allows for checks comparable to the dynamic_cast of c++ with enabled rtti.
\r
735 Note that you can't do that by calling BaseClass::hasType(type), but you have to do an explicit
\r
736 comparison check, because otherwise the base class usually just checks for the member variable
\r
737 Type which contains the type of your derived class.
\r
739 virtual bool hasType(EGUI_ELEMENT_TYPE type) const
\r
741 return type == Type;
\r
745 //! Returns the type name of the gui element.
\r
746 /** This is needed serializing elements. */
\r
747 virtual const c8* getTypeName() const
\r
749 return GUIElementTypeNames[Type];
\r
752 //! Returns the name of the element.
\r
753 /** \return Name as character string. */
\r
754 virtual const c8* getName() const
\r
756 return Name.c_str();
\r
760 //! Sets the name of the element.
\r
761 /** \param name New name of the gui element. */
\r
762 virtual void setName(const c8* name)
\r
768 //! Sets the name of the element.
\r
769 /** \param name New name of the gui element. */
\r
770 virtual void setName(const core::stringc& name)
\r
776 //! Returns whether the element takes input from the IME
\r
777 virtual bool acceptsIME()
\r
784 // not virtual because needed in constructor
\r
785 void addChildToEnd(IGUIElement* child)
\r
789 child->grab(); // prevent destruction when removed
\r
790 child->remove(); // remove from old parent
\r
791 child->LastParentRect = getAbsolutePosition();
\r
792 child->Parent = this;
\r
793 child->ParentPos = Children.insert(Children.end(), child);
\r
798 template<typename Iterator>
\r
799 static size_t _fastSetChecksum(Iterator begin, Iterator end) {
\r
800 std::hash<typename Iterator::value_type> hasher;
\r
801 size_t checksum = 0;
\r
802 for (Iterator it = begin; it != end; ++it) {
\r
803 size_t h = hasher(*it);
\r
804 checksum ^= 966073049 + (h * 3432918353) + ((h >> 16) * 461845907);
\r
810 // Reorder children [from, to) to the order given by `neworder`
\r
811 void reorderChildren(
\r
812 std::list<IGUIElement*>::iterator from,
\r
813 std::list<IGUIElement*>::iterator to,
\r
814 const std::vector<IGUIElement*> &neworder)
\r
816 assert(_fastSetChecksum(from, to) == _fastSetChecksum(neworder.begin(), neworder.end()));
\r
817 for (auto e : neworder)
\r
820 e->ParentPos = from;
\r
823 assert(from == to);
\r
827 // not virtual because needed in constructor
\r
828 void recalculateAbsolutePosition(bool recursive)
\r
830 core::rect<s32> parentAbsolute(0,0,0,0);
\r
831 core::rect<s32> parentAbsoluteClip;
\r
832 f32 fw=0.f, fh=0.f;
\r
836 parentAbsolute = Parent->AbsoluteRect;
\r
840 IGUIElement* p=this;
\r
843 parentAbsoluteClip = p->AbsoluteClippingRect;
\r
846 parentAbsoluteClip = Parent->AbsoluteClippingRect;
\r
849 const s32 diffx = parentAbsolute.getWidth() - LastParentRect.getWidth();
\r
850 const s32 diffy = parentAbsolute.getHeight() - LastParentRect.getHeight();
\r
852 if (AlignLeft == EGUIA_SCALE || AlignRight == EGUIA_SCALE)
\r
853 fw = (f32)parentAbsolute.getWidth();
\r
855 if (AlignTop == EGUIA_SCALE || AlignBottom == EGUIA_SCALE)
\r
856 fh = (f32)parentAbsolute.getHeight();
\r
860 case EGUIA_UPPERLEFT:
\r
862 case EGUIA_LOWERRIGHT:
\r
863 DesiredRect.UpperLeftCorner.X += diffx;
\r
866 DesiredRect.UpperLeftCorner.X += diffx/2;
\r
869 DesiredRect.UpperLeftCorner.X = core::round32(ScaleRect.UpperLeftCorner.X * fw);
\r
873 switch (AlignRight)
\r
875 case EGUIA_UPPERLEFT:
\r
877 case EGUIA_LOWERRIGHT:
\r
878 DesiredRect.LowerRightCorner.X += diffx;
\r
881 DesiredRect.LowerRightCorner.X += diffx/2;
\r
884 DesiredRect.LowerRightCorner.X = core::round32(ScaleRect.LowerRightCorner.X * fw);
\r
890 case EGUIA_UPPERLEFT:
\r
892 case EGUIA_LOWERRIGHT:
\r
893 DesiredRect.UpperLeftCorner.Y += diffy;
\r
896 DesiredRect.UpperLeftCorner.Y += diffy/2;
\r
899 DesiredRect.UpperLeftCorner.Y = core::round32(ScaleRect.UpperLeftCorner.Y * fh);
\r
903 switch (AlignBottom)
\r
905 case EGUIA_UPPERLEFT:
\r
907 case EGUIA_LOWERRIGHT:
\r
908 DesiredRect.LowerRightCorner.Y += diffy;
\r
911 DesiredRect.LowerRightCorner.Y += diffy/2;
\r
914 DesiredRect.LowerRightCorner.Y = core::round32(ScaleRect.LowerRightCorner.Y * fh);
\r
918 RelativeRect = DesiredRect;
\r
920 const s32 w = RelativeRect.getWidth();
\r
921 const s32 h = RelativeRect.getHeight();
\r
923 // make sure the desired rectangle is allowed
\r
924 if (w < (s32)MinSize.Width)
\r
925 RelativeRect.LowerRightCorner.X = RelativeRect.UpperLeftCorner.X + MinSize.Width;
\r
926 if (h < (s32)MinSize.Height)
\r
927 RelativeRect.LowerRightCorner.Y = RelativeRect.UpperLeftCorner.Y + MinSize.Height;
\r
928 if (MaxSize.Width && w > (s32)MaxSize.Width)
\r
929 RelativeRect.LowerRightCorner.X = RelativeRect.UpperLeftCorner.X + MaxSize.Width;
\r
930 if (MaxSize.Height && h > (s32)MaxSize.Height)
\r
931 RelativeRect.LowerRightCorner.Y = RelativeRect.UpperLeftCorner.Y + MaxSize.Height;
\r
933 RelativeRect.repair();
\r
935 AbsoluteRect = RelativeRect + parentAbsolute.UpperLeftCorner;
\r
938 parentAbsoluteClip = AbsoluteRect;
\r
940 AbsoluteClippingRect = AbsoluteRect;
\r
941 AbsoluteClippingRect.clipAgainst(parentAbsoluteClip);
\r
943 LastParentRect = parentAbsolute;
\r
947 // update all children
\r
948 for (auto child : Children)
\r
950 child->recalculateAbsolutePosition(recursive);
\r
957 //! List of all children of this element
\r
958 std::list<IGUIElement*> Children;
\r
960 //! Pointer to the parent
\r
961 IGUIElement* Parent;
\r
963 //! Our position in the parent list. Only valid when Parent != nullptr
\r
964 std::list<IGUIElement*>::iterator ParentPos;
\r
966 //! relative rect of element
\r
967 core::rect<s32> RelativeRect;
\r
969 //! absolute rect of element
\r
970 core::rect<s32> AbsoluteRect;
\r
972 //! absolute clipping rect of element
\r
973 core::rect<s32> AbsoluteClippingRect;
\r
975 //! the rectangle the element would prefer to be,
\r
976 //! if it was not constrained by parent or max/min size
\r
977 core::rect<s32> DesiredRect;
\r
979 //! for calculating the difference when resizing parent
\r
980 core::rect<s32> LastParentRect;
\r
982 //! relative scale of the element inside its parent
\r
983 core::rect<f32> ScaleRect;
\r
985 //! maximum and minimum size of the element
\r
986 core::dimension2du MaxSize, MinSize;
\r
994 //! is a part of a larger whole and should not be serialized?
\r
997 //! does this element ignore its parent's clipping rectangle?
\r
1001 core::stringw Text;
\r
1004 core::stringw ToolTipText;
\r
1006 //! users can set this for identifying the element by string
\r
1007 core::stringc Name;
\r
1009 //! users can set this for identifying the element by integer
\r
1012 //! tab stop like in windows
\r
1018 //! tab groups are containers like windows, use ctrl+tab to navigate
\r
1021 //! tells the element how to act when its parent is resized
\r
1022 EGUI_ALIGNMENT AlignLeft, AlignRight, AlignTop, AlignBottom;
\r
1024 //! GUI Environment
\r
1025 IGUIEnvironment* Environment;
\r
1027 //! type of element
\r
1028 EGUI_ELEMENT_TYPE Type;
\r
1032 } // end namespace gui
\r
1033 } // end namespace irr
\r