#include <guielement.h>
Inheritance diagram for GuiElement:
Public Member Functions | |
DECLSPEC | GuiElement (const SDL_Rect &r, GuiElement *p, const char *name) |
DECLSPEC | GuiElement (TiXmlElement *el, GuiElement *p) |
virtual const char * | getClassName () |
virtual bool | isGuiElement () const |
| |
DECLSPEC void | resizeTo (Uint32 w, Uint32 h) |
DECLSPEC void | resizeBy (Sint32 dw, Sint32 dh) |
DECLSPEC void | moveTo (Sint32 x, Sint32 y) |
DECLSPEC void | moveRelCenterTo (Sint32 x, Sint32 y) |
DECLSPEC void | moveBy (Sint32 x, Sint32 y) |
DECLSPEC void | getWndSize (Uint32 &w, Uint32 &h) const |
DECLSPEC SDL_Rect | getRelWindow () const |
DECLSPEC void | setRelWindow (const SDL_Rect &r) |
DECLSPEC SDL_Rect | getAbsWindow () |
DECLSPEC void | setAbsWindow (const SDL_Rect &r) |
DECLSPEC SDL_Rect | getClientWindow () const |
DECLSPEC SDL_Rect | getDrawWindow () |
DECLSPEC void | getRelCenterPoint (Sint32 &x, Sint32 &y) |
DECLSPEC void | getAbsCenterPoint (Sint32 &x, Sint32 &y) |
DECLSPEC void | getClientCenterPoint (Sint32 &x, Sint32 &y) |
DECLSPEC SDL_Rect | getClip () |
DECLSPEC GuiElement * | getParent () const |
DECLSPEC GuiElement * | getToplevel () |
DECLSPEC void | setVisible (bool b) |
DECLSPEC bool | isVisible () const |
DECLSPEC void | setEnabled (bool b) |
DECLSPEC bool | isEnabled () const |
| |
DECLSPEC void | setRedraw () |
bool | getRedraw () |
| |
virtual bool | hasSurface () const |
Static Public Member Functions | |
static GuiElement * | create (TiXmlElement *el, GuiElement *parent=NULL) |
static GuiElement * | createWithoutChildren (TiXmlElement *el, GuiElement *parent=NULL) |
Behaves as create(), but does not create children elements. | |
static void | newelement (void *presult, BasicObject *o, void *xmldata) |
static void | togglevisibility (void *sender, BasicObject *aim, void *) |
Protected Member Functions | |
virtual DECLSPEC Uint32 | onMouseOver () |
virtual DECLSPEC Uint32 | onMouseOut () |
virtual Uint32 | onMouseMove (Uint32 x, Uint32 y) |
virtual Uint32 | onResize () |
virtual DECLSPEC Uint32 | onFrame (SdlSurface *dest) |
virtual DECLSPEC void | onInit () |
virtual DECLSPEC void | onDestroy () |
virtual DECLSPEC Uint32 | onThemeChanged (UiTheme *t) |
virtual DECLSPEC void | onEnabledChanged (bool enabled) |
virtual void | incRequireOnFrame () |
virtual void | decRequireOnFrame () |
Does the opposite of incRequireOnFrame(). | |
void | setDrawRectDirty () |
Friends | |
class | GuiManager |
All classes, derived from GuiElement, can be used to display 2D-graphics on the screen. Every graphical element, but one (the top level element), is placed on another one, called its "parent", whose "child" it is. If an element becomes invisible, all child elements (and their children, ...) are hidden, too. The same is with the enabled state. If an element is invisible, the onFrame-event is not called. If an element is disabled, the mouse-events are not called. Also an element cannot (or better should not) be drawn beyond the parent's borders. The method getClip() is used to arrange the rect, in which blitting... should be done.
When deriving a class from GuiElement and implementing an event (a on...() method), do not forget to call finally the GuiElement::on...() method. Otherwise some features will not be availible.
In order to be able to create elements from an XML-tree, it is required to have a class constructor with the params TiXmlElement* and GuiElement*. Furthermore it must be registered in GuiElement::create().
For some more information, have a look at UiObject.
GuiElement::GuiElement | ( | const SDL_Rect & | r, | |
GuiElement * | p, | |||
const char * | name | |||
) |
Constructor. There must be UiManager initialized before creating a GuiElement!
r | the rect of the element's appearance, relative to the parent's top-left position | |
p | the parent element (a GuiElement cannot have a child derived from UiObject or BasicObject and not from GuiElement), if NULL, GuiManager::the is its parent. | |
name | the element's name |
GuiElement::GuiElement | ( | TiXmlElement * | el, | |
GuiElement * | p | |||
) |
Constructor, used to create an element from XML data. There must be UiManager initialized before creating a GuiElement!
el | the XML data, the attribute "Rect" is required, optional are "Visible" (bool) and "Enabled" (bool) | |
p | the parent element, or NULL to take GuiManager::the as parent |
virtual const char* GuiElement::getClassName | ( | ) | [inline, virtual] |
This function should be overriden in every sub-class of BasicObject!
Reimplemented from UiObject.
Reimplemented in GuiBackground, GuiFrame, GuiBorder, GuiRadioContainer, GuiPictureBg, GuiFlowWindow, GuiPageControl, GuiCheck, GuiRadio, GuiNumScroller, GuiCursor, GuiDropDown, GuiDynamicButton, GuiClickableBtn, GuiCheckableBtn, GuiRadioBtn, GuiFileElement, GuiFlowMenu, GuiForm, GuiHint, GuiListBox, GuiMenuBar, GuiMenuItem, GuiMessageBox, GuiProgressBar, GuiRotator, GuiScroller, GuiScrollBg, GuiSurface, GuiText, GuiTextInput, GuiKeyControl, GuiFrameCounter, GuiTextField, and GuiUpDown.
void GuiElement::resizeTo | ( | Uint32 | w, | |
Uint32 | h | |||
) |
Resizes the rect of appearance of the element. The top-left corner will not be changed, but the right and bottom borders. After changing the rect, the onResize() event is called.
w | the new width | |
h | the new height |
void GuiElement::resizeBy | ( | Sint32 | dw, | |
Sint32 | dh | |||
) |
Resizes the rect of appearance of the element. The top-left corner will not be changed, but the right and bottom borders. After changing the rect, the onResize() event is called.
dw | the value to add to the width | |
dh | the value to add to the height |
void GuiElement::moveTo | ( | Sint32 | x, | |
Sint32 | y | |||
) |
Moves the rect of appearance of the element. The width and height will not be affected, but the relative position. After changing the rect, the onResize() event is called.
x | the new x coordinate of the rect's left border | |
y | the new y coordinate of the rect's top border |
void GuiElement::moveRelCenterTo | ( | Sint32 | x, | |
Sint32 | y | |||
) |
Moves the rect of appearance of the element. The width and height will not be affected, but the relative position. After changing the rect, the onResize() event is called.
x | the new x coordinate of the rect's center | |
y | the new y coordinate of the rect's center |
void GuiElement::moveBy | ( | Sint32 | x, | |
Sint32 | y | |||
) |
Moves the rect of appearance of the element. The width and height will not be affected, but the relative position. After changing the rect, the onResize() event is called.
x | the value to add to the relative x position | |
y | the value to add to the relative y position |
void GuiElement::getWndSize | ( | Uint32 & | w, | |
Uint32 & | h | |||
) | const |
Gets the size of the rect of apperance.
w | the width will be stored there | |
h | the height will be stored there |
SDL_Rect GuiElement::getRelWindow | ( | ) | const |
Gets the relative (to the parent's top-left) rect of apperance.
void GuiElement::setRelWindow | ( | const SDL_Rect & | r | ) |
Sets the relative (to the parent's top-left) rect of apperance.
r | the window's relative rect |
SDL_Rect GuiElement::getAbsWindow | ( | ) |
Gets the absolute rect of apperance (distance from the screen's top-left)
void GuiElement::setAbsWindow | ( | const SDL_Rect & | r | ) |
Sets the absolute rect of apperance (distance from the screen's top-left)
r | the window's new, absolute rect |
SDL_Rect GuiElement::getClientWindow | ( | ) | const |
Get the rect of apperance, relative to the window itself, so the x and y coordinates are zero. So the result contains the same information as getWndSize(w,h)
SDL_Rect GuiElement::getDrawWindow | ( | ) |
Get the rect of apperance on the surface on which to draw (not limited to the surface's borders).
void GuiElement::getRelCenterPoint | ( | Sint32 & | x, | |
Sint32 & | y | |||
) |
Get the relative center of apperance.
x | the x coordinate will be stored there | |
y | the y coordinate will be stored there |
void GuiElement::getAbsCenterPoint | ( | Sint32 & | x, | |
Sint32 & | y | |||
) |
Get the absolute center of apperance.
x | the x coordinate will be stored there | |
y | the y coordinate will be stored there |
void GuiElement::getClientCenterPoint | ( | Sint32 & | x, | |
Sint32 & | y | |||
) |
Get the center of apperance, relative to the rect itself. The assigned values equal the half values of getWndSize(x,y).
x | the x coordinate will be stored there | |
y | the y coordinate will be stored there |
SDL_Rect GuiElement::getClip | ( | ) |
Get the absolute, visible rect of appearance. You should not draw anything beyond its borders.
GuiElement * GuiElement::getParent | ( | ) | const |
GuiElement * GuiElement::getToplevel | ( | ) |
void GuiElement::setVisible | ( | bool | b | ) |
Changes the visible-state. (All children will become invisible, if this element becomes invisible)
b | true, to show it; false, to hide it |
bool GuiElement::isVisible | ( | ) | const |
void GuiElement::setEnabled | ( | bool | b | ) |
Changes the enabled state. (All children will become disabled, if this element is disabled)
b | true, to enable it; false to disable it |
void GuiElement::setRedraw | ( | ) |
Sets the redraw-state, so that the element (and it's children) will be redrawn in the next frame.
virtual bool GuiElement::hasSurface | ( | ) | const [inline, virtual] |
Reimplemented in GuiSurface.
GuiElement * GuiElement::create | ( | TiXmlElement * | el, | |
GuiElement * | parent = NULL | |||
) | [static] |
Creates a new GuiElement object (or from a derived class) with all information taken from the XML element. If the XML element has children, they are recursively created as well. The XML code looks like:
<TYPE name="name of the object" rect="X,Y,W,H" [ parent="parent name"] [...]>[...]</TYPE>
el | the XML element with all necessary data | |
parent | the parent object (only used, if not specified in the XML data) |
static void GuiElement::togglevisibility | ( | void * | sender, | |
BasicObject * | aim, | |||
void * | ||||
) | [inline, static] |
Toggles the element's visibility. Name of slot: "ToggleVisibility". Param is ignored.
Uint32 GuiElement::onMouseOver | ( | ) | [protected, virtual] |
This event is called, when the mouse cursor just moved into the object's rect.
Reimplemented in GuiFrame, and GuiClickableBtn.
Uint32 GuiElement::onMouseOut | ( | ) | [protected, virtual] |
This event is called, when the mouse cursor just moved out of the object's rect.
Reimplemented in GuiFrame, and GuiClickableBtn.
virtual Uint32 GuiElement::onMouseMove | ( | Uint32 | x, | |
Uint32 | y | |||
) | [inline, protected, virtual] |
This event is called, when the mouse cursor is moved over the object.
x | the absolute x coordinate of the cursor (distance from left) | |
y | the absolute y coordinate of the cursor (distance from top) |
Reimplemented in GuiCursor.
virtual Uint32 GuiElement::onResize | ( | ) | [inline, protected, virtual] |
This event is called, when the element changed its place or size.
Reimplemented in GuiBorder, GuiPageControl, GuiCheck, GuiRadio, GuiNumScroller, GuiDropDown, GuiHint, GuiMessageBox, GuiProgressBar, GuiScroller, GuiScrollBg, GuiSurface, and GuiUpDown.
Uint32 GuiElement::onFrame | ( | SdlSurface * | dest | ) | [protected, virtual] |
This event is called, when a frame is drawn. If the object should be visible, is has to draw it's look to a valid surface. This method calls the children's function, if visible.
Reimplemented in GuiBackground, GuiBorder, GuiPictureBg, GuiFlowWindow, GuiDynamicButton, GuiProgressBar, GuiRotator, GuiSurface, GuiText, GuiTextInput, GuiKeyControl, and GuiFrameCounter.
void GuiElement::onInit | ( | ) | [protected, virtual] |
Initializes the object's variables by reading data from the XML element. If there were no XML data used for creation, nothing is done. This function calls onInit() of its children recursively (after it has inited itself). It is highly recommended to call BasicObject::onInit(), usually at the end of the onInit() method, when overwriting it in a derived class.
Reimplemented from BasicObject.
Reimplemented in GuiBackground, GuiFrame, GuiBorder, GuiRadioContainer, GuiPictureBg, GuiFlowWindow, GuiPageControl, GuiCheck, GuiRadio, GuiNumScroller, GuiCursor, GuiDropDown, GuiDynamicButton, GuiClickableBtn, GuiCheckableBtn, GuiRadioBtn, GuiFileElement, GuiFlowMenu, GuiFlowMenuItem, GuiForm, GuiHint, GuiListBox, GuiMessageBox, GuiProgressBar, GuiRotator, GuiScroller, GuiScrollBg, GuiSurface, GuiText, GuiTextInput, GuiKeyControl, GuiFrameCounter, GuiTextField, and GuiUpDown.
void GuiElement::onDestroy | ( | ) | [protected, virtual] |
May be called to reinitialise this object or stop an initialised module. Calls all children's onDestroy(). Most classes do not use this method. But sometimes it is useful to reset the functionality of an object.
Reimplemented from UiObject.
Uint32 GuiElement::onThemeChanged | ( | UiTheme * | t | ) | [protected, virtual] |
This event is called, when the theme changes. Perform here the changes of the object's look and feel.
t | pointer to the new used theme |
Reimplemented from UiObject.
Reimplemented in GuiBackground, GuiBorder, GuiPictureBg, GuiFlowWindow, GuiPageControl, GuiDropDown, GuiDynamicButton, GuiClickableBtn, GuiCheckableBtn, GuiRadioBtn, GuiForm, GuiHint, GuiProgressBar, GuiScroller, GuiText, GuiTextInput, and GuiUpDown.
void GuiElement::onEnabledChanged | ( | bool | enabled | ) | [protected, virtual] |
Called, after the object became enabled or disabled. (Only when the result of isEnabled() changed.)
enabled | is true if the object became enabled |
Reimplemented in GuiClickableBtn.
virtual void GuiElement::incRequireOnFrame | ( | ) | [inline, protected, virtual] |
Increments the reference counters of parent GuiSurfaces, to disable their off-screen surface blitting. So the onFrame-Method will always be called when drawing a frame.
Reimplemented in GuiSurface.
void GuiElement::setDrawRectDirty | ( | ) | [protected] |
Sets the draw rect dirty, so that it is recalculated at the next call to getDrawRect(). This method is required by the GuiSurface class.