Crazy Eddie's GUI System 0.8.7
Loading...
Searching...
No Matches
Element.h
1/***********************************************************************
2 created: 18/8/2011
3 author: Martin Preisler
4
5 purpose: Defines a class representing an item in a graph
6 (deals with relative positions, relative dimensions, ...)
7*************************************************************************/
8/***************************************************************************
9 * Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining
12 * a copy of this software and associated documentation files (the
13 * "Software"), to deal in the Software without restriction, including
14 * without limitation the rights to use, copy, modify, merge, publish,
15 * distribute, sublicense, and/or sell copies of the Software, and to
16 * permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be
20 * included in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
29 ***************************************************************************/
30
31#ifndef _CEGUIElement_h_
32#define _CEGUIElement_h_
33
34#include "CEGUI/Base.h"
35#include "CEGUI/PropertySet.h"
36#include "CEGUI/EventSet.h"
37#include "CEGUI/EventArgs.h"
38
39#if defined(_MSC_VER)
40# pragma warning(push)
41# pragma warning(disable : 4251)
42#endif
43
44namespace CEGUI
45{
46
70
71template<>
73{
74public:
79
80 static const String& getDataTypeName()
81 {
82 static String type("HorizontalAlignment");
83
84 return type;
85 }
86
87 static return_type fromString(const String& str)
88 {
89 if (str == "Centre")
90 {
91 return HA_CENTRE;
92 }
93 else if (str == "Right")
94 {
95 return HA_RIGHT;
96 }
97 else
98 {
99 return HA_LEFT;
100 }
101 }
102
103 static string_return_type toString(pass_type val)
104 {
105 if (val == HA_CENTRE)
106 {
107 return "Centre";
108 }
109 else if (val == HA_RIGHT)
110 {
111 return "Right";
112 }
113 else if (val == HA_LEFT)
114 {
115 return "Left";
116 }
117 else
118 {
119 assert(false && "Invalid horizontal alignment");
120 return "Centre";
121 }
122 }
123};
148
149template<>
151{
152public:
156 typedef String string_return_type;
157
158 static const String& getDataTypeName()
159 {
160 static String type("VerticalAlignment");
161
162 return type;
163 }
164
165 static return_type fromString(const String& str)
166 {
167 if (str == "Centre")
168 {
169 return VA_CENTRE;
170 }
171 else if (str == "Bottom")
172 {
173 return VA_BOTTOM;
174 }
175 else
176 {
177 return VA_TOP;
178 }
179 }
180
181 static string_return_type toString(pass_type val)
182 {
183 if (val == VA_CENTRE)
184 {
185 return "Centre";
186 }
187 else if (val == VA_BOTTOM)
188 {
189 return "Bottom";
190 }
191 else if (val == VA_TOP)
192 {
193 return "Top";
194 }
195 else
196 {
197 assert(false && "Invalid vertical alignment");
198 return "Centre";
199 }
200 }
201};
202
210class CEGUIEXPORT ElementEventArgs : public EventArgs
211{
212public:
213 ElementEventArgs(Element* element):
214 element(element)
215 {}
216
219};
220
242class CEGUIEXPORT Element :
243 public PropertySet,
244 public EventSet,
245 public AllocatedObject<Element>
246{
247public:
249 static const String EventNamespace;
250
255 static const String EventSized;
266 static const String EventMoved;
283 static const String EventRotated;
306
315 {
316 public:
323 typedef Rectf (Element::*DataGenerator)(bool) const;
324
325 CachedRectf(Element const* element, DataGenerator generator):
326 d_element(element),
327 d_generator(generator),
328 // we don't have to initialise d_cachedData here, it will get
329 // regenerated and reset anyways
330 d_cacheValid(false)
331 {}
332
336 inline const Rectf& get() const
337 {
338 if (!d_cacheValid)
339 {
340 regenerateCache();
341 }
342
343 return d_cachedData;
344 }
345
352 inline Rectf getFresh(bool skipAllPixelAlignment = false) const
353 {
354 // if the cache is not valid we will use this chance to regenerate it
355 // of course this is only applicable if we are allowed to use pixel alignment where applicable
356 if (!d_cacheValid && !skipAllPixelAlignment)
357 {
358 return get();
359 }
360
361 return CEGUI_CALL_MEMBER_FN(*d_element, d_generator)(skipAllPixelAlignment);
362 }
363
370 inline void invalidateCache() const
371 {
372 d_cacheValid = false;
373 }
374
375 inline bool isCacheValid() const
376 {
377 return d_cacheValid;
378 }
379
380 inline void regenerateCache() const
381 {
382 // false, since when we are caching we don't want to skip anything, we want everything to act
383 // exactly as it was setup
384 d_cachedData = CEGUI_CALL_MEMBER_FN(*d_element, d_generator)(false);
385
386 d_cacheValid = true;
387 }
388
389 private:
390 Element const* d_element;
391 const DataGenerator d_generator;
392
393 mutable Rectf d_cachedData;
394 mutable bool d_cacheValid;
395 };
396
401
405 virtual ~Element();
406
414 inline Element* getParentElement() const
415 {
416 return d_parent;
417 }
418
438 virtual void setArea(const UVector2& pos, const USize& size);
439
441 inline void setArea(const UDim& xpos, const UDim& ypos,
442 const UDim& width, const UDim& height)
443 {
444 setArea(UVector2(xpos, ypos), USize(width, height));
445 }
446
448 inline void setArea(const URect& area)
449 {
450 setArea(area.d_min, area.getSize());
451 }
452
467 inline const URect& getArea() const
468 {
469 return d_area;
470 }
471
487 inline void setPosition(const UVector2& pos)
488 {
489 setArea_impl(pos, d_area.getSize());
490 }
491
493 inline void setXPosition(const UDim& pos)
494 {
495 setPosition(UVector2(pos, getYPosition()));
496 }
497
499 inline void setYPosition(const UDim& pos)
500 {
501 setPosition(UVector2(getXPosition(), pos));
502 }
503
518 inline const UVector2& getPosition() const
519 {
520 return d_area.getPosition();
521 }
522
524 inline const UDim& getXPosition() const
525 {
526 return getPosition().d_x;
527 }
528
530 inline const UDim& getYPosition() const
531 {
532 return getPosition().d_y;
533 }
534
545 virtual void setHorizontalAlignment(const HorizontalAlignment alignment);
546
558 {
559 return d_horizontalAlignment;
560 }
561
572 virtual void setVerticalAlignment(const VerticalAlignment alignment);
573
585 {
586 return d_verticalAlignment;
587 }
588
600 inline void setSize(const USize& size)
601 {
602 setArea(d_area.getPosition(), size);
603 }
604
606 inline void setWidth(const UDim& width)
607 {
608 setSize(USize(width, getSize().d_height));
609 }
610
612 inline void setHeight(const UDim& height)
613 {
614 setSize(USize(getSize().d_width, height));
615 }
616
628 inline USize getSize() const
629 {
630 return d_area.getSize();
631 }
632
634 inline UDim getWidth() const
635 {
636 return getSize().d_width;
637 }
638
640 inline UDim getHeight() const
641 {
642 return getSize().d_height;
643 }
644
662 void setMinSize(const USize& size);
663
677 inline const USize& getMinSize() const
678 {
679 return d_minSize;
680 }
681
701 void setMaxSize(const USize& size);
702
716 inline const USize& getMaxSize() const
717 {
718 return d_maxSize;
719 }
720
729 void setAspectMode(const AspectMode mode);
730
738 {
739 return d_aspectMode;
740 }
741
755 void setAspectRatio(const float ratio);
756
763 inline float getAspectRatio() const
764 {
765 return d_aspectRatio;
766 }
767
789 void setPixelAligned(const bool setting);
790
798 inline bool isPixelAligned() const
799 {
800 return d_pixelAligned;
801 }
802
810 inline const Vector2f& getPixelPosition() const
811 {
812 return getUnclippedOuterRect().get().d_min;
813 }
814
822 inline const Sizef& getPixelSize() const
823 {
824 return d_pixelSize;
825 }
826
837 Sizef calculatePixelSize(bool skipAllPixelAlignment = false) const;
838
848 Sizef getParentPixelSize(bool skipAllPixelAlignment = false) const;
849
862 void setRotation(const Quaternion& rotation);
863
869 inline const Quaternion& getRotation() const
870 {
871 return d_rotation;
872 }
873
894 void addChild(Element* element);
895
906 void removeChild(Element* element);
907
921 inline Element* getChildElementAtIdx(size_t idx) const
922 {
923 return d_children[idx];
924 }
925
929 inline size_t getChildCount() const
930 {
931 return d_children.size();
932 }
933
937 bool isChild(const Element* element) const;
938
952 bool isAncestor(const Element* element) const;
953
967 void setNonClient(const bool setting);
968
974 inline bool isNonClient() const
975 {
976 return d_nonClient;
977 }
978
992 inline const CachedRectf& getUnclippedOuterRect() const
993 {
994 return d_unclippedOuterRect;
995 }
996
1011 {
1012 return d_unclippedInnerRect;
1013 }
1014
1028 inline const CachedRectf& getUnclippedRect(const bool inner) const
1029 {
1030 return inner ? getUnclippedInnerRect() : getUnclippedOuterRect();
1031 }
1032
1042
1052
1074 inline const CachedRectf& getChildContentArea(const bool non_client = false) const
1075 {
1076 return non_client ? getNonClientChildContentArea() : getClientChildContentArea();
1077 }
1078
1092 virtual void notifyScreenAreaChanged(bool recursive = true);
1093
1103 virtual const Sizef& getRootContainerSize() const;
1104
1105protected:
1111
1142 virtual void setArea_impl(const UVector2& pos, const USize& size,
1143 bool topLeftSizing = false, bool fireEvents = true);
1144
1146 inline bool isInnerRectSizeChanged() const
1147 {
1148 const Sizef old_sz(d_unclippedInnerRect.get().getSize());
1149 d_unclippedInnerRect.invalidateCache();
1150 return old_sz != d_unclippedInnerRect.get().getSize();
1151 }
1152
1164 virtual void setParent(Element* parent);
1165
1170 virtual void addChild_impl(Element* element);
1171
1176 virtual void removeChild_impl(Element* element);
1177
1179 virtual Rectf getUnclippedOuterRect_impl(bool skipAllPixelAlignment) const;
1181 virtual Rectf getUnclippedInnerRect_impl(bool skipAllPixelAlignment) const;
1182
1184 void fireAreaChangeEvents(const bool moved, const bool sized);
1185 void notifyChildrenOfSizeChange(const bool non_client,
1186 const bool client);
1187
1188 /*************************************************************************
1189 Event trigger methods
1190 *************************************************************************/
1199 virtual void onSized(ElementEventArgs& e);
1200
1213
1222 virtual void onMoved(ElementEventArgs& e);
1223
1235
1247
1256 virtual void onRotated(ElementEventArgs& e);
1257
1267
1277
1289
1290 /*************************************************************************
1291 Implementation Data
1292 *************************************************************************/
1294 typedef std::vector<Element*
1295 CEGUI_VECTOR_ALLOC(Element*)> ChildList;
1296
1301
1304
1325
1330
1331private:
1332 /*************************************************************************
1333 May not copy or assign Element objects
1334 *************************************************************************/
1335 Element(const Element&);
1336
1337 Element& operator=(const Element&) {return *this;}
1338};
1339
1340} // End of CEGUI namespace section
1341
1342
1343#if defined(_MSC_VER)
1344# pragma warning(pop)
1345#endif
1346
1347#endif // end of guard _CEGUIElement_h_
Definition MemoryAllocatedObject.h:110
EventArgs based class that is used for objects passed to handlers triggered for events concerning som...
Definition Element.h:211
Element * element
pointer to an Element object of relevance to the event.
Definition Element.h:218
A tiny wrapper to hide some of the dirty work of rect caching.
Definition Element.h:315
const Rectf & get() const
Retrieves cached Rectf or generated a fresh one and caches it.
Definition Element.h:336
void invalidateCache() const
Invalidates the cached Rectf causing it to be regenerated.
Definition Element.h:370
Rectf getFresh(bool skipAllPixelAlignment=false) const
Skips all caching and calls the generator.
Definition Element.h:352
A positioned and sized rectangular node in a tree graph.
Definition Element.h:246
static const String EventHorizontalAlignmentChanged
Definition Element.h:272
USize d_minSize
current minimum size for the element.
Definition Element.h:1312
virtual void setArea(const UVector2 &pos, const USize &size)
Set the Element area.
virtual void onChildRemoved(ElementEventArgs &e)
Handler called when a child element is removed from this element.
static const String EventSized
Definition Element.h:255
const CachedRectf & getUnclippedOuterRect() const
Return a Rect that describes the unclipped outer rect area of the Element.
Definition Element.h:992
HorizontalAlignment d_horizontalAlignment
Specifies the base for horizontal alignment.
Definition Element.h:1308
CachedRectf d_unclippedOuterRect
outer area rect in screen pixels
Definition Element.h:1327
const UVector2 & getPosition() const
Get the element's position.
Definition Element.h:518
void setRotation(const Quaternion &rotation)
sets rotation of this widget
static const String EventVerticalAlignmentChanged
Definition Element.h:278
void addElementProperties()
Add standard CEGUI::Element properties.
virtual void onMoved(ElementEventArgs &e)
Handler called when the element's position changes.
virtual Rectf getUnclippedInnerRect_impl(bool skipAllPixelAlignment) const
Default implementation of function to return Element's inner rect area.
bool isAncestor(const Element *element) const
Checks whether the specified Element is an ancestor of this Element.
virtual void onRotated(ElementEventArgs &e)
Handler called when the element's rotation is changed.
void setXPosition(const UDim &pos)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Element.h:493
void setAspectRatio(const float ratio)
Sets target aspect ratio.
void setSize(const USize &size)
Set the element's size.
Definition Element.h:600
void setAspectMode(const AspectMode mode)
Sets current aspect mode and recalculates the area rect.
Element * getChildElementAtIdx(size_t idx) const
return a pointer to the child element that is attached to 'this' at the given index.
Definition Element.h:921
bool isInnerRectSizeChanged() const
helper to return whether the inner rect size has changed
Definition Element.h:1146
static const String EventNamespace
Namespace for global events.
Definition Element.h:249
const UDim & getXPosition() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Element.h:524
URect d_area
This element objects area as defined by a URect.
Definition Element.h:1306
CachedRectf d_unclippedInnerRect
inner area rect in screen pixels
Definition Element.h:1329
Quaternion d_rotation
Rotation of this element (relative to the parent)
Definition Element.h:1324
virtual void setHorizontalAlignment(const HorizontalAlignment alignment)
Set the horizontal alignment.
const Sizef & getPixelSize() const
Return the element's size in pixels.
Definition Element.h:822
virtual void onNonClientChanged(ElementEventArgs &e)
Handler called when the element's non-client setting, affecting it's position and size relative to it...
USize getSize() const
Get the element's size.
Definition Element.h:628
virtual void addChild_impl(Element *element)
Add given element to child list at an appropriate position.
virtual void setParent(Element *parent)
Set the parent element for this element object.
const CachedRectf & getUnclippedRect(const bool inner) const
Return a Rect that describes the unclipped area covered by the Element.
Definition Element.h:1028
virtual void setVerticalAlignment(const VerticalAlignment alignment)
Set the vertical alignment.
size_t getChildCount() const
Returns number of child elements attached to this Element.
Definition Element.h:929
virtual void onParentSized(ElementEventArgs &e)
Handler called when this element's parent element has been resized. If this element is the root / GUI...
void setPosition(const UVector2 &pos)
Set the element's position.
Definition Element.h:487
const USize & getMinSize() const
Get the element's minimum size.
Definition Element.h:677
float getAspectRatio() const
Retrieves target aspect ratio.
Definition Element.h:763
bool isNonClient() const
Checks whether this element was set to be non client.
Definition Element.h:974
static const String EventNonClientChanged
Definition Element.h:305
virtual ~Element()
Destructor.
bool isChild(const Element *element) const
Checks whether given element is attached to this Element.
const USize & getMaxSize() const
Get the element's maximum size.
Definition Element.h:716
AspectMode getAspectMode() const
Retrieves currently used aspect mode.
Definition Element.h:737
virtual void onVerticalAlignmentChanged(ElementEventArgs &e)
Handler called when the vertical alignment setting for the element is changed.
virtual const CachedRectf & getClientChildContentArea() const
Return a Rect that is used by client child elements as content area.
VerticalAlignment getVerticalAlignment() const
Get the vertical alignment.
Definition Element.h:584
float d_aspectRatio
The target aspect ratio.
Definition Element.h:1318
ChildList d_children
The list of child element objects attached to this.
Definition Element.h:1298
bool isPixelAligned() const
Checks whether this Element is pixel aligned.
Definition Element.h:798
virtual const Sizef & getRootContainerSize() const
Return the size of the root container (such as screen size).
void setArea(const URect &area)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Element.h:448
static const String EventRotated
Definition Element.h:283
AspectMode d_aspectMode
How to satisfy current aspect ratio.
Definition Element.h:1316
void setMinSize(const USize &size)
Set the element's minimum size.
const URect & getArea() const
Return the element's area.
Definition Element.h:467
Element * getParentElement() const
Retrieves parent of this element.
Definition Element.h:414
void setYPosition(const UDim &pos)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Element.h:499
virtual void setArea_impl(const UVector2 &pos, const USize &size, bool topLeftSizing=false, bool fireEvents=true)
Implementation method to modify element area while correctly applying min / max size processing,...
VerticalAlignment d_verticalAlignment
Specifies the base for vertical alignment.
Definition Element.h:1310
const Quaternion & getRotation() const
retrieves rotation of this widget
Definition Element.h:869
virtual void removeChild_impl(Element *element)
Remove given element from child list.
static const String EventZOrderChanged
Definition Element.h:299
virtual void onChildAdded(ElementEventArgs &e)
Handler called when a child element is added to this element.
static const String EventChildRemoved
Definition Element.h:293
Sizef getParentPixelSize(bool skipAllPixelAlignment=false) const
Return the pixel size of the parent element.
void fireAreaChangeEvents(const bool moved, const bool sized)
helper to fire events based on changes to area rect
virtual void onHorizontalAlignmentChanged(ElementEventArgs &e)
Handler called when the horizontal alignment setting for the element is changed.
const Vector2f & getPixelPosition() const
Return the element's absolute (or screen, depending on the type of the element) position in pixels.
Definition Element.h:810
Sizef d_pixelSize
Current constrained pixel size of the element.
Definition Element.h:1322
void setHeight(const UDim &height)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Element.h:612
const UDim & getYPosition() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Element.h:530
static const String EventMoved
Definition Element.h:266
static const String EventChildAdded
Definition Element.h:288
bool d_pixelAligned
If true, the position and size are pixel aligned.
Definition Element.h:1320
void addChild(Element *element)
Add the specified Element as a child of this Element.
USize d_maxSize
current maximum size for the element.
Definition Element.h:1314
virtual void notifyScreenAreaChanged(bool recursive=true)
Inform the element and (optionally) all children that screen area has changed.
void setMaxSize(const USize &size)
Set the element's maximum size.
const CachedRectf & getUnclippedInnerRect() const
Return a Rect that describes the unclipped inner rect area of the Element.
Definition Element.h:1010
std::vector< Element *CEGUI_VECTOR_ALLOC(Element *)> ChildList
definition of type used for the list of attached child elements.
Definition Element.h:1295
UDim getWidth() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Element.h:634
Sizef calculatePixelSize(bool skipAllPixelAlignment=false) const
Calculates this element's pixel size.
void removeChild(Element *element)
Remove the Element Element's child list.
virtual void onSized(ElementEventArgs &e)
Handler called when the element's size changes.
virtual Rectf getUnclippedOuterRect_impl(bool skipAllPixelAlignment) const
Default implementation of function to return Element's outer rect area.
void setNonClient(const bool setting)
Set whether the Element is non-client.
const CachedRectf & getChildContentArea(const bool non_client=false) const
Return a Rect that is used to position and size child elements.
Definition Element.h:1074
HorizontalAlignment getHorizontalAlignment() const
Get the horizontal alignment.
Definition Element.h:557
Element * d_parent
Holds pointer to the parent element.
Definition Element.h:1300
void setArea(const UDim &xpos, const UDim &ypos, const UDim &width, const UDim &height)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Element.h:441
static const String EventParentSized
Definition Element.h:261
void setWidth(const UDim &width)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Element.h:606
void setPixelAligned(const bool setting)
Sets whether this Element is pixel aligned (both position and size, basically the 4 "corners").
virtual const CachedRectf & getNonClientChildContentArea() const
Return a Rect that is used by client child elements as content area.
UDim getHeight() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition Element.h:640
Element()
Constructor.
bool d_nonClient
true if element is in non-client (outside InnerRect) area of parent.
Definition Element.h:1303
Base class used as the argument to all subscribers Event object.
Definition EventArgs.h:51
Interface providing event signaling and handling.
Definition EventSet.h:167
Helper class used to convert various data types to and from the format expected in Property strings.
Definition PropertyHelper.h:84
Interface providing introspection capabilities.
Definition PropertySet.h:108
Class to represent rotation, avoids Gimbal lock.
Definition Quaternion.h:69
Size< T > getSize() const
return the size of the Rect area
Definition Rect.h:149
String class used within the GUI system.
Definition String.h:64
Dimension that has both a relative 'scale' portion and and absolute 'offset' portion.
Definition UDim.h:94
Main namespace for Crazy Eddie's GUI Library.
Definition arch_overview.dox:1
HorizontalAlignment
Enumerated type used when specifying horizontal alignments for Element.
Definition Element.h:53
@ HA_LEFT
Definition Element.h:58
@ HA_RIGHT
Definition Element.h:68
@ HA_CENTRE
Definition Element.h:63
AspectMode
How aspect ratio should be maintained.
Definition Size.h:46
VerticalAlignment
Enumerated type used when specifying vertical alignments for Element.
Definition Element.h:131
@ VA_CENTRE
Definition Element.h:141
@ VA_BOTTOM
Definition Element.h:146
@ VA_TOP
Definition Element.h:136