syBR::Game::GUIWidget Class Reference

GUI widget class. More...

#include <GUIWidget.hpp>

Inheritance diagram for syBR::Game::GUIWidget:

syBR::Game::GUIContainer syBR::Game::GUIPicture syBR::Game::GUIText

List of all members.

Public Types

enum  Corner {
  Corner_TopLeft = 0, Corner_TopRight = 1, Corner_BottomLeft = 2, Corner_BottomRight = 3,
  Corner_All = 4
}
 Widget corners enumeration. More...

Public Member Functions

 GUIWidget (GUIManager *pManager)
 Constructor.
 GUIWidget (GUIManager *pManager, const std::string &name)
 Constructor.
virtual ~GUIWidget ()
 Destructor.
virtual bool load (Core::XMLNode *pNode)=0
 Load the widget.
virtual void render (std::vector< GUIManager::Quad > &renderList)
 Render the widget.
bool isPointInside (const float x, const float y) const
 Check if a point is in the widget.
void setName (const std::string &name)
 Set name.
const std::string & getName () const
 Get name.
void setVisible (const bool visible)
 Set visibility.
bool getVisible () const
 Get visibility.
void setPosition (const float left, const float top)
 Set position (top left corner).
void setPosition (const Ogre::Vector2 &position)
 Set position (top left corner).
const Ogre::Vector2 & getPosition () const
 Get position (top left corner).
void setSize (const float width, const float height)
 Set size.
const float getWidth () const
 Get width.
const float getHeight () const
 Get height.
void setColour (const float red, const float green, const float blue, const float alpha, Corner corner=Corner_All)
 Set the colour of a corner of the widget.
void setColour (const Ogre::ColourValue &colour, Corner corner=Corner_All)
 Set the colour of a corner of the widget.
const Ogre::ColourValue & getColour (Corner corner) const
 Get the colour of a corner of the widget.
void setTexture (const std::string &texture, Ogre::Vector2 topLeft=Ogre::Vector2(0.0, 0.0), Ogre::Vector2 topRight=Ogre::Vector2(1.0, 0.0), Ogre::Vector2 bottomLeft=Ogre::Vector2(0.0, 1.0), Ogre::Vector2 bottomRight=Ogre::Vector2(1.0, 1.0))
 Set the texture and the texture coordinates.
const std::string & getTexture () const
 Get the texture.
const Ogre::Vector2 & getTextureCoordinates (Corner corner)
 Get the texture coordinates.

Protected Member Functions

bool loadPosition (Core::XMLNode *pNode)
 Load the widget position from a XML file.
bool loadSize (Core::XMLNode *pNode)
 Load the widget size from a XML file.
bool loadColor (Core::XMLNode *pNode)
 Load the widget position from a XML file.

Protected Attributes

GUIManagerm_pManager
 Manager.
std::string m_name
 Name.
bool m_visible
 Visibility.
Ogre::Vector2 m_position
 Position.
float m_width
 Width.
float m_height
 Height.
std::string m_texture
 Texture.
Ogre::Vector2 m_textureCoordinates [4]
 Texture coordinates.
Ogre::ColourValue m_colour [4]
 Widget colour.


Detailed Description

GUI widget class.

It is the base composent of the GUI, from which every GUI component must inherit. It does nothing when being rendered.


Member Enumeration Documentation

enum syBR::Game::GUIWidget::Corner

Widget corners enumeration.

Enumerator:
Corner_TopLeft  Top left corner.
Corner_TopRight  Top right corner.
Corner_BottomLeft  Bottom left corner.
Corner_BottomRight  Bottom right corner.
Corner_All  All 4 corners.


Constructor & Destructor Documentation

syBR::Game::GUIWidget::GUIWidget ( GUIManager pManager  ) 

Constructor.

Set widget name to an empty string

Parameters:
pManager GUI manager using this widget

syBR::Game::GUIWidget::GUIWidget ( GUIManager pManager,
const std::string &  name 
)

Constructor.

Parameters:
pManager GUI manager using this widget
name Name of the widget

syBR::Game::GUIWidget::~GUIWidget (  )  [virtual]

Destructor.

Release used resources.


Member Function Documentation

virtual bool syBR::Game::GUIWidget::load ( Core::XMLNode pNode  )  [pure virtual]

Load the widget.

Parameters:
pNode Pointer to the XML node corresponding to this widget
Returns:
One of these:
  • true in case of success
  • false otherwise

Implemented in syBR::Game::GUIContainer, syBR::Game::GUIPicture, and syBR::Game::GUIText.

void syBR::Game::GUIWidget::render ( std::vector< GUIManager::Quad > &  renderList  )  [virtual]

Render the widget.

Render the widget and its subcomponents.

Parameters:
renderList List of renderables where all the renderables of this widget and its subcomponents will be pushed back

Reimplemented in syBR::Game::GUIContainer, syBR::Game::GUIPicture, and syBR::Game::GUIText.

bool syBR::Game::GUIWidget::isPointInside ( const float  x,
const float  y 
) const

Check if a point is in the widget.

Parameters:
x X coordinate of the point to be checked
y Y coordinate of the point to be checked
Returns:
One of these:
  • true if the point is in the widget
  • false otherwise

void syBR::Game::GUIWidget::setName ( const std::string &  name  ) 

Set name.

Parameters:
name Name to set to the widget

const std::string & syBR::Game::GUIWidget::getName (  )  const

Get name.

Returns:
Widget name

void syBR::Game::GUIWidget::setVisible ( const bool  visible  ) 

Set visibility.

when not visible, a widget and all its children aren't rendered.

Parameters:
visible true to show the widget and its children, false otherwise

bool syBR::Game::GUIWidget::getVisible (  )  const

Get visibility.

If not visible, a widget and its children aren't rendered.

Returns:
Boolean indicating if the widget is visible

void syBR::Game::GUIWidget::setPosition ( const float  left,
const float  top 
)

Set position (top left corner).

Parameters:
left X coordinate of the new position
top Y coordinate of the new position

void syBR::Game::GUIWidget::setPosition ( const Ogre::Vector2 &  position  ) 

Set position (top left corner).

Parameters:
position New position

const Ogre::Vector2 & syBR::Game::GUIWidget::getPosition (  )  const

Get position (top left corner).

Returns:
Position of the widget

void syBR::Game::GUIWidget::setSize ( const float  width,
const float  height 
)

Set size.

Parameters:
width Width of the new size of the widget
height Height of the new size of the widget

const float syBR::Game::GUIWidget::getWidth (  )  const

Get width.

Returns:
Width of the widget

const float syBR::Game::GUIWidget::getHeight (  )  const

Get height.

Returns:
Height of the widget

void syBR::Game::GUIWidget::setColour ( const float  red,
const float  green,
const float  blue,
const float  alpha,
Corner  corner = Corner_All 
)

Set the colour of a corner of the widget.

Parameters:
red Red component of the new colour
green Green component of the new colour
blue Blue component of the new colour
alpha Alpha component of the new colour
corner Corner of the widget whose colour must be modified, defaults to all corners (widget is made of only one colour)

void syBR::Game::GUIWidget::setColour ( const Ogre::ColourValue &  colour,
Corner  corner = Corner_All 
)

Set the colour of a corner of the widget.

Parameters:
colour New colour
corner Corner of the widget whose colour must be modified, defaults to all corners (widget is made of only one colour)

const Ogre::ColourValue & syBR::Game::GUIWidget::getColour ( Corner  corner  )  const

Get the colour of a corner of the widget.

Parameters:
corner Corner whose colour must be retrieved, if Corner_All is specified, top left corner colour will be returned
Returns:
Requested corner's colour

void syBR::Game::GUIWidget::setTexture ( const std::string &  texture,
Ogre::Vector2  topLeft = Ogre::Vector2(0.0, 0.0),
Ogre::Vector2  topRight = Ogre::Vector2(1.0, 0.0),
Ogre::Vector2  bottomLeft = Ogre::Vector2(0.0, 1.0),
Ogre::Vector2  bottomRight = Ogre::Vector2(1.0, 1.0) 
)

Set the texture and the texture coordinates.

Parameters:
texture Name of the new texture to be used when rendering
topLeft Texture coordinates of the top left corner of the widget
topRight Texture coordinates of the top right corner of the widget
bottomLeft Texture coordinates of the bottom left corner of the widget
bottomRight Texture coordinates of the bottom right corner of the widget
Note:
Coordinates are optional and default to using the full texture for the widget.

(0,0) is the top left corner of the texture and (1,1) is the bottom right corner of it.

const std::string & syBR::Game::GUIWidget::getTexture (  )  const

Get the texture.

Returns:
Name of the texture currently used when rendering

const Ogre::Vector2 & syBR::Game::GUIWidget::getTextureCoordinates ( Corner  corner  ) 

Get the texture coordinates.

Parameters:
corner Corner of the widget whose texture coordinates must be retrieved, if Corner_All is specified, top left corner colour will be returned

bool syBR::Game::GUIWidget::loadPosition ( Core::XMLNode pNode  )  [protected]

Load the widget position from a XML file.

The position node must have the following format: <position left="0.0" top="0.0"/>

Parameters:
pNode Pointer to the position node from the XML file
Returns:
One of these:
  • true in case of success
  • false otherwise

bool syBR::Game::GUIWidget::loadSize ( Core::XMLNode pNode  )  [protected]

Load the widget size from a XML file.

The size node must have the following format: <size width="0.2" height="0.1"/>

Parameters:
pNode Pointer to the size node from the XML file
Returns:
One of these:
  • true in case of success
  • false otherwise

bool syBR::Game::GUIWidget::loadColor ( Core::XMLNode pNode  )  [protected]

Load the widget position from a XML file.

The position node must have the following format: <color topLeft="1.0 0.0 0.0 1.0" bottomLeft="1.0 0.0 0.0 1.0" topRight="1.0 0.0 0.0 1.0" bottomRight="1.0 0.0 0.0 1.0"/> A color is described as "R G B A", each component being between 0 and 1.

Note that not all widget types will take the four colors in account.

Parameters:
pNode Pointer to the position node from the XML file
Returns:
One of these:
  • true in case of success
  • false otherwise


Member Data Documentation

GUIManager* syBR::Game::GUIWidget::m_pManager [protected]

Manager.

std::string syBR::Game::GUIWidget::m_name [protected]

Name.

bool syBR::Game::GUIWidget::m_visible [protected]

Visibility.

Ogre::Vector2 syBR::Game::GUIWidget::m_position [protected]

Position.

float syBR::Game::GUIWidget::m_width [protected]

Width.

float syBR::Game::GUIWidget::m_height [protected]

Height.

std::string syBR::Game::GUIWidget::m_texture [protected]

Texture.

Ogre::Vector2 syBR::Game::GUIWidget::m_textureCoordinates[4] [protected]

Texture coordinates.

Ogre::ColourValue syBR::Game::GUIWidget::m_colour[4] [protected]

Widget colour.


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

Copyright © 2008 by Sebastien Frippiat
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License.
Last modified Tue Dec 30 17:57:33 2008