Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | Friends

Control Class Reference

Basic Control upon which all other Control's are derived. More...

#include <Control.h>

Inheritance diagram for Control:
Broadcaster Listener Button CheckBox Container DropDown Label ListItem ProgressBar Slider TextField Window

List of all members.

Public Member Functions

 Control (const std::string &controlName, int minWidth=16, int minHeight=16)
 Control (const Control &src)
 ~Control ()
virtual void add (Control *child)
virtual void remove (Control *child)
virtual ControlgetChild (const std::string &childName) const
void setFont (Font *font)
void setFont (const std::string &fontName)
void setSkin (Skin *skin)
void setAbsolute (int x, int y)
void setRelative (int x, int y)
void setMinimumSize (Uint w, Uint h)
void setMaximumSize (Uint w, Uint h)
void setWidth (Uint w)
void setHeight (Uint h)
void setSize (Uint w, Uint h)
void setMargins (int top, int bottom, int left, int right)
void setBorderColor (int r, int g, int b)
void setBackgroundColor (int r, int g, int b)
void setForegroundColor (int r, int g, int b)
int getAbsoluteX () const
int getAbsoluteY () const
int getRelativeX () const
int getRelativeY () const
int getWidth () const
int getHeight () const
int getMinWidth () const
int getMinHeight () const
int getMaxWidth () const
int getMaxHeight () const
int getMarginTop () const
int getMarginBottom () const
int getMarginLeft () const
int getMarginRight () const
int getNumChildren () const
void drawBorder (bool)
void setFocus (bool focus)
bool hasFocus () const
void setName (const std::string &name)
std::string getName () const
void setCaption (const std::string &caption)
void isVisible (bool visible)
bool isVisible () const
void isHidden (bool hidden)
bool isHidden () const
void isAutosized (bool autosize)
bool isAutosized () const
void isAnchored (bool anchored)
bool isAnchored () const
void isEnabled (bool enabled)
bool isEnabled () const
void show ()
void hide ()
void update ()
void clearChildren ()
void sendToFront (Control *control)
void addEventListener (Listener *listener)
void removeEventListener (Listener *listener)
bool isSkinned () const
void setSkinState (ControlState state=STATE_NORMAL)
void setSkinPartType (const std::string &type)

Protected Types

typedef std::vector< Control * > ControlList
typedef std::map< string, Font * > FontList

Protected Member Functions

void push (Event *event)
void bringToFront (Control *control)
void setFontList (FontList fontList)
ControlgetParent ()
void setSkinState (const std::string &type, ControlState state=STATE_NORMAL)
void setDefaultColors ()
virtual void onNotify (Event *event)

Protected Attributes

ControlmParent
FontmFont
SkinmSkin
SkinPartmCurrentSkinPart
int mTop
int mBottom
int mLeft
int mRight
Uint mWidth
Uint mHeight
Uint mMinWidth
Uint mMinHeight
Uint mMaxWidth
Uint mMaxHeight
Uint mBgRed
Uint mBgGreen
Uint mBgBlue
Uint mBrRed
Uint mBrGreen
Uint mBrBlue
Uint mFgRed
Uint mFgGreen
Uint mFgBlue
bool mDrawBorder
bool mAnchored
bool mAutosize
bool mEnabled
bool mUsingSkin
ControlList mChildControls
std::string mCaption
std::string mName
std::string mSkinPartType

Private Member Functions

 Control ()
Controloperator= (const Control &)
void draw ()
void drawBorder ()
virtual void drawSkin ()
virtual void drawPlain ()
virtual void logic ()
virtual void initialize ()
virtual void onClick (Event *event)
virtual void onPressed (Event *event)
virtual void onMouseButtonUp (Event *event)
virtual void onMouseWheelMotion (Event *event)
virtual void onDrag (Event *event)
virtual void onResized ()
virtual void onFocus ()
virtual void onLostFocus ()
virtual void onMouseMove (Event *event)
virtual void onChanged (Event *event)
virtual void onEnabled ()
virtual void onKeyDown (Event *event)
virtual void onKeyUp (Event *event)

Private Attributes

int mMouseX
int mMouseY
int mRelativeX
int mRelativeY
int mNumChildren
int mParentIndex
bool mHasFocus
bool mIsVisible
bool mIsHidden
FontList mFontList
vector< Listener * > mGuiEventListener

Friends

class Gui

Detailed Description

Basic Control upon which all other Control's are derived.

The Control class provides all basic functions that are common to all Control objects within a GUI.

In order to have a derived Control appear differently than other Control objects, the Control::draw() function must be overridden.

Note:
Any derived Control that needs to render fonts differently than the base font must store a separate Font Resource.

Member Typedef Documentation

typedef std::vector<Control*> Control::ControlList [protected]
typedef std::map<string, Font*> Control::FontList [protected]

Constructor & Destructor Documentation

Control::Control ( const std::string &  controlName,
int  minWidth = 16,
int  minHeight = 16 
)
Control::Control ( const Control src  ) 
Control::~Control (  ) 
Control::Control (  )  [private]

Member Function Documentation

void Control::add ( Control child  )  [virtual]

Adds a new control of type ControlType to the Control List.

Reimplemented in Window.

void Control::addEventListener ( Listener listener  ) 
void Control::bringToFront ( Control control  )  [protected]

Brings the specified control to the front of the list.

void Control::clearChildren (  ) 

Tells this Control to clear all of its child Control's.

void Control::draw (  )  [private]

Determines if we can draw with skin or if we must default.

void Control::drawBorder ( bool  draw  ) 

Tells the Control whether or not to draw a border around itself.

Parameters:
bool True to draw border, False otherwise.
void Control::drawBorder (  )  [private]

Draws a border around the Control using the supplied Border Color.

virtual void Control::drawPlain (  )  [inline, private, virtual]
virtual void Control::drawSkin (  )  [inline, private, virtual]
int Control::getAbsoluteX (  )  const
int Control::getAbsoluteY (  )  const
virtual Control* Control::getChild ( const std::string &  childName  )  const [virtual]

Reimplemented in FileIO.

int Control::getHeight (  )  const
int Control::getMarginBottom (  )  const
int Control::getMarginLeft (  )  const
int Control::getMarginRight (  )  const
int Control::getMarginTop (  )  const
int Control::getMaxHeight (  )  const
int Control::getMaxWidth (  )  const
int Control::getMinHeight (  )  const
int Control::getMinWidth (  )  const
std::string Control::getName (  )  const

Gets the name of the Control.

Note:
Control's name is not the same as its caption although the two may be set to the same value.
int Control::getNumChildren (  )  const
Control * Control::getParent (  )  [protected]
int Control::getRelativeX (  )  const
int Control::getRelativeY (  )  const
int Control::getWidth (  )  const
bool Control::hasFocus (  )  const

Returns whether the control has Focus or not.

void Control::hide (  ) 

Hide's a Control and all if its children.

Note:
This function should not be mistaken with the isHidden() functions.
virtual void Control::initialize (  )  [inline, private, virtual]
void Control::isAnchored ( bool  anchored  ) 
bool Control::isAnchored (  )  const
void Control::isAutosized ( bool  autosize  ) 
bool Control::isAutosized (  )  const
void Control::isEnabled ( bool  enabled  ) 

Sets this Control to enabled or not.

bool Control::isEnabled (  )  const

Returns if this Control is enabled or not.

void Control::isHidden ( bool  hidden  ) 

Sets whether the Control is hidden or not.

Note:
A Control that's hidden should not be confused with a Control that's not visible that become visible when Control::show() is versus hidden controls which are not shown when Control::show() is called.
bool Control::isHidden (  )  const

Returns if this Control is hidden.

Note:
Controls that are hidden should not be confused with Controls that are simply not visible. Hidden Controls are not made visible when Control::show() is called.
bool Control::isSkinned (  )  const

Returns whether or not this Control is skinned.

void Control::isVisible ( bool  visible  ) 

Sets whether or not the Control is visible.

Parameters:
visible Can be true or false.
bool Control::isVisible (  )  const

Returns if this Control is visible.

virtual void Control::logic (  )  [inline, private, virtual]
virtual void Control::onChanged ( Event event  )  [inline, private, virtual]

Called whenever a Control's data changes.

Reimplemented in ScrollBar, Slider, and TextField.

virtual void Control::onClick ( Event event  )  [inline, private, virtual]

Reimplemented in Button, CheckBox, ListBox, Slider, TextField, and CloseButton.

virtual void Control::onDrag ( Event event  )  [inline, private, virtual]

Reimplemented in Slider, and Window.

virtual void Control::onEnabled (  )  [inline, private, virtual]

Called whenever a Control's setEnabled() function is called.

Reimplemented in Button, and CheckBox.

virtual void Control::onFocus (  )  [inline, private, virtual]

Called whenever a Control gains focus.

Note:
Default implementation sets focus. Overridden versions should either call the setFocus() function or explicitly call the default implementation.

Reimplemented in Window.

virtual void Control::onKeyDown ( Event event  )  [inline, private, virtual]

Called whenever an EVENT_KEYDOWN event is fired.

Reimplemented in ListBox, TextBox, and TextField.

virtual void Control::onKeyUp ( Event event  )  [inline, private, virtual]

Called whenever an EVENT_KEYUP event is fired.

Reimplemented in ListBox, and TextField.

virtual void Control::onLostFocus (  )  [inline, private, virtual]

Called whenever a Control loses focus.

Note:
Default implementation sets focus. Overridden versions should either call the setFocus() function or explicitly call the default implementation.

Reimplemented in Window.

virtual void Control::onMouseButtonUp ( Event event  )  [inline, private, virtual]

Reimplemented in Button, and CloseButton.

virtual void Control::onMouseMove ( Event event  )  [inline, private, virtual]
virtual void Control::onMouseWheelMotion ( Event event  )  [inline, private, virtual]

Called whenever a MOUSE_WHEEL_UP or MOUSE_WHEEL_DOWN are fired.

Reimplemented in ScrollArea.

virtual void Control::onNotify ( Event event  )  [inline, protected, virtual]

Use this function to send an event to all of the eventListeners.

virtual void Control::onPressed ( Event event  )  [inline, private, virtual]

Reimplemented in Button, Slider, and CloseButton.

virtual void Control::onResized (  )  [inline, private, virtual]

Called whenever a Control changes its size.

Reimplemented in Slider, and Window.

Control& Control::operator= ( const Control  )  [private]
void Control::push ( Event event  )  [protected, virtual]
void Control::remove ( Control child  )  [virtual]

Removes a Child Control from this Control's list.

Parameters:
child A pointer to a child Control of this Control.
Note:
This function is generally deemed safe.
Warning:
This function frees any memory allocated for the specified Control so all references or pointers to it will be invalid.

Reimplemented in Window.

void Control::removeEventListener ( Listener listener  ) 
void Control::sendToFront ( Control control  ) 

Brings the specified control to the front of the control stack.

void Control::setAbsolute ( int  x,
int  y 
)

Sets absolute position and size attributes of this Control.

Note:
This function will set the absolute coordinate values of a Control if it doesn't have a parent. Otherwise it will set coordinates relative to its parent.
void Control::setBackgroundColor ( int  r,
int  g,
int  b 
)

Sets the background color of the Control.

Parameters:
r Red value. Must be between 0 - 255.
g Green value. Must be between 0 - 255.
b Blue value. Must be between 0 - 255.
void Control::setBorderColor ( int  r,
int  g,
int  b 
)

Sets the border color of the Control.

Parameters:
r Red value. Must be between 0 - 255.
g Green value. Must be between 0 - 255.
b Blue value. Must be between 0 - 255.
void Control::setCaption ( const std::string &  caption  ) 
void Control::setDefaultColors (  )  [protected]
void Control::setFocus ( bool  focus  ) 

Sets whether the control has Focus or not.

Todo:
Make sure all child Control's lose focus when Parent loses focus. Make sure only 1 Child can have focus if Parent has focus.
void Control::setFont ( Font font  ) 

Sets the font from a pointer to a Font object.

Parameters:
font A pointer to a Font object. Must not be NULL.
Note:
There is no checking for NULL or invalid Font objects. This was a design decision to reduce the number of tests during Control rendering.
Warning:
Passing in a NULL or invalid pointer to a Font object will result in undefined behavior.
void Control::setFont ( const std::string &  fontName  ) 
void Control::setFontList ( FontList  fontList  )  [protected]
void Control::setForegroundColor ( int  r,
int  g,
int  b 
)

Sets the foreground color of the Control.

The Foreground color is typically used by the Control to render text although occasionally, depending on the Control, may be used drawing other things. See individual Control documentation.

Parameters:
r Red value. Must be between 0 - 255.
g Green value. Must be between 0 - 255.
b Blue value. Must be between 0 - 255.
void Control::setHeight ( Uint  h  ) 

Sets the height of this Control.

Note:
Value of 0 indicates that control should not be resized.
Controls cannot be set smaller than their defined minimum height.
Controls cannot be set larger than their defined maximum height.
Todo:
Doesn't take into account a parent's margins.
void Control::setMargins ( int  top,
int  bottom,
int  left,
int  right 
)

Sets the margins of this Control.

Child Control's added to this Control can only be positioned outside the margins set by this function.

void Control::setMaximumSize ( Uint  w,
Uint  h 
)
void Control::setMinimumSize ( Uint  w,
Uint  h 
)
void Control::setName ( const std::string &  name  ) 
void Control::setRelative ( int  x,
int  y 
)

Sets relative position relative to this Control's parent Control.

Todo:
This function does not check for constraints within the Parent Control.
void Control::setSize ( Uint  w,
Uint  h 
)

Sets the size of this Control.

Note:
Controls cannot be set smaller than their defined minimum width/height.
Controls cannot be set larger than their defined maximum width/height.
Todo:
Doesn't take into account a parent's margins.
void Control::setSkin ( Skin skin  ) 
Todo:
This should handle setting local copies of images and coordinates
void Control::setSkinPartType ( const std::string &  type  ) 
void Control::setSkinState ( ControlState  state = STATE_NORMAL  ) 

Attempts to set the skin graphics to this Control to the requested state.

Parameters:
state A state for the requested control type. Must be of type enum ControlState.
Note:
Paramter state is optional and defaults to STATE_NORMAL.
This function internally calls setSkinState(string, ControlState) with the part type defined by setSkinPartType().
void Control::setSkinState ( const std::string &  type,
ControlState  state = STATE_NORMAL 
) [protected]
void Control::setWidth ( Uint  w  ) 

Sets the width of this Control.

Note:
Value of 0 indicates that control should not be resized.
Controls cannot be set smaller than their defined minimum width.
Controls cannot be set larger than their defined maximum width.
Todo:
Doesn't take into account a parent's margins.
void Control::show (  ) 

Show's a Control and all if its children except for those that are hidden.

Note:
Showing a control also gives it input focus.
void Control::update (  ) 

Pumps events, runs logic and instructs all children to update.


Friends And Related Function Documentation

friend class Gui [friend]

Member Data Documentation

bool Control::mAnchored [protected]

Flag to determine whether or not this control can be dragged. Child controls that are anchored will still move with their parent.

bool Control::mAutosize [protected]

Flag used to determine if this control should automatically resize itself based on its content.

Uint Control::mBgBlue [protected]

Background Colors.

Uint Control::mBgGreen [protected]
Uint Control::mBgRed [protected]
int Control::mBottom [protected]
Uint Control::mBrBlue [protected]

Border Colors.

Uint Control::mBrGreen [protected]
Uint Control::mBrRed [protected]
std::string Control::mCaption [protected]

Caption Text

Internal list of Child Control's

The current graphics to use for rendering.

bool Control::mDrawBorder [protected]

Flag to tell Control whether or not to draw a border around itself.

bool Control::mEnabled [protected]

Internal flag indicating whether or not this Control is enabled.

Uint Control::mFgBlue [protected]

Foreground (typically caption text) Colors.

Uint Control::mFgGreen [protected]
Uint Control::mFgRed [protected]
Font* Control::mFont [protected]

Internal Font used to render text.

This will eventually be a grouping of Event Listeners. Right now we're only really dealing with clicks.

Todo:
Find a more sane way of dealing with this.
bool Control::mHasFocus [private]

Internal flag indicating whether or not this Control has focus.

Uint Control::mHeight [protected]

Absolute Width/Height

bool Control::mIsHidden [private]

Internal flag indicating that the Control is indefinitely hidden and should not be made visible by Control::show().

bool Control::mIsVisible [private]

Internal flag indicating whether or not this Control is visible.

int Control::mLeft [protected]

Maximum Width/Height

Uint Control::mMaxWidth [protected]

Minimum Width/Height

Uint Control::mMinWidth [protected]
int Control::mMouseX [private]

Reimplemented in Slider.

int Control::mMouseY [private]

Internal mouse pointer coordinates.

Reimplemented in Slider.

std::string Control::mName [protected]

Name of the Control.

int Control::mNumChildren [private]

Number of Child Control's directly contained in this Control.

Control* Control::mParent [protected]

Reference to a Parent Control.

int Control::mParentIndex [private]

Index in Parent Control's list.

int Control::mRelativeX [private]
int Control::mRelativeY [private]

Control's position relative to its Parent.

int Control::mRight [protected]

Margin Values.

Skin* Control::mSkin [protected]

Internal Skin used to render controls.

std::string Control::mSkinPartType [protected]

Type to look for when requesting a skin part.

int Control::mTop [protected]
bool Control::mUsingSkin [protected]

Flag used to indicate whether or not to render with a UI skin.

Uint Control::mWidth [protected]

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines