gcn::CheckBox Class Reference

#include <checkbox.hpp>

Inheritance diagram for gcn::CheckBox:

gcn::Widget gcn::MouseListener gcn::KeyListener List of all members.

Detailed Description

An implementation of a check box where a user can select or deselect the check box and where the status of the check box is displayed to the user.

A check box is capable of displaying a caption.

If a check box's state changes an action event will be sent to all action listeners of the check box.

Definition at line 77 of file checkbox.hpp.

Public Member Functions

void adjustSize ()
 Adjusts the check box's size to fit the caption.
 CheckBox (const std::string &caption, bool selected=false)
 Constructor.
 CheckBox ()
 Contructor.
virtual void draw (Graphics *graphics)
 Draws the widget.
const std::string & getCaption () const
 Gets the caption of the check box.
bool isSelected () const
 Checks if the check box is selected.
virtual void keyPressed (KeyEvent &keyEvent)
 Called if a key is pressed when the widget has keyboard focus.
virtual void mouseClicked (MouseEvent &mouseEvent)
 Called when a mouse button is pressed and released (clicked) on the widget area.
virtual void mouseDragged (MouseEvent &mouseEvent)
 Called when the mouse has moved and the mouse has previously been pressed on the widget.
void setCaption (const std::string &caption)
 Sets the caption of the check box.
void setSelected (bool selected)
 Sets the check box to be selected or not.
virtual ~CheckBox ()
 Destructor.

Protected Member Functions

virtual void drawBox (Graphics *graphics)
 Draws the box of the check box.
virtual void toggleSelected ()
 Toggles the check box between being selected and not being selected.

Protected Attributes

std::string mCaption
 Holds the caption of the check box.
bool mSelected
 True if the check box is selected, false otherwise.


Constructor & Destructor Documentation

gcn::CheckBox::CheckBox ( const std::string &  caption,
bool  selected = false 
)

Constructor.

The check box will be automatically resized to fit the caption.

Parameters:
caption The caption of the check box.
marked True if the check box is selected, false otherwise.

Definition at line 80 of file checkbox.cpp.

References gcn::Widget::addKeyListener(), gcn::Widget::addMouseListener(), adjustSize(), setCaption(), gcn::Widget::setFocusable(), and setSelected().


Member Function Documentation

void gcn::CheckBox::draw ( Graphics graphics  )  [virtual]

Draws the widget.

It is called by the parent widget when it is time for the widget to draw itself. The graphics object is set up so that all drawing is relative to the widget, i.e coordinate (0,0) is the top left corner of the widget. It is not possible to draw outside of a widget's dimension.

Parameters:
graphics aA graphics object to draw with.
Since:
0.1.0

Implements gcn::Widget.

Definition at line 92 of file checkbox.cpp.

References drawBox(), gcn::Graphics::drawText(), getCaption(), gcn::Widget::getFont(), gcn::Widget::getForegroundColor(), gcn::Widget::getHeight(), gcn::Graphics::setColor(), and gcn::Graphics::setFont().

void gcn::CheckBox::drawBox ( Graphics graphics  )  [protected, virtual]

Draws the box of the check box.

Parameters:
graphics A Graphics object to draw with.

Definition at line 104 of file checkbox.cpp.

References gcn::Color::a, gcn::Graphics::drawLine(), gcn::Graphics::drawRectangle(), gcn::Graphics::fillRectangle(), gcn::Widget::getBackgroundColor(), gcn::Widget::getBaseColor(), gcn::Widget::getForegroundColor(), gcn::Widget::getHeight(), gcn::Widget::isFocused(), mSelected, and gcn::Graphics::setColor().

Referenced by draw().

const std::string & gcn::CheckBox::getCaption (  )  const

Gets the caption of the check box.

Returns:
The caption of the check box.
See also:
setCaption

Definition at line 154 of file checkbox.cpp.

References mCaption.

Referenced by draw().

bool gcn::CheckBox::isSelected (  )  const

Checks if the check box is selected.

Returns:
True if the check box is selected, false otherwise.
See also:
setSelected

Definition at line 144 of file checkbox.cpp.

References mSelected.

void gcn::CheckBox::keyPressed ( KeyEvent keyEvent  )  [virtual]

Called if a key is pressed when the widget has keyboard focus.

If a key is held down the widget will generate multiple key presses.

Parameters:
keyEvent Discribes the event.

Reimplemented from gcn::KeyListener.

Definition at line 164 of file checkbox.cpp.

References gcn::InputEvent::consume(), gcn::Key::ENTER, gcn::KeyEvent::getKey(), gcn::Key::getValue(), gcn::Key::SPACE, and toggleSelected().

void gcn::CheckBox::mouseClicked ( MouseEvent mouseEvent  )  [virtual]

Called when a mouse button is pressed and released (clicked) on the widget area.

Parameters:
mouseEvent Describes the event.
Since:
0.6.0

Reimplemented from gcn::MouseListener.

Definition at line 176 of file checkbox.cpp.

References gcn::MouseEvent::getButton(), gcn::MouseEvent::LEFT, and toggleSelected().

void gcn::CheckBox::mouseDragged ( MouseEvent mouseEvent  )  [virtual]

Called when the mouse has moved and the mouse has previously been pressed on the widget.

Parameters:
mouseEvent Describes the event.
Since:
0.6.0

Reimplemented from gcn::MouseListener.

Definition at line 184 of file checkbox.cpp.

References gcn::InputEvent::consume().

void gcn::CheckBox::setCaption ( const std::string &  caption  ) 

Sets the caption of the check box.

It's advisable to call adjustSize after setting of the caption to adjust the check box's size to fit the caption.

Parameters:
caption The caption of the check box.
See also:
getCaption, adjustSize

Definition at line 159 of file checkbox.cpp.

References mCaption.

Referenced by CheckBox().

void gcn::CheckBox::setSelected ( bool  selected  ) 

Sets the check box to be selected or not.

Parameters:
selected True if the check box should be set as selected.
See also:
isSelected

Definition at line 149 of file checkbox.cpp.

References mSelected.

Referenced by CheckBox().


The documentation for this class was generated from the following files:
Generated on Sun Jan 20 21:48:14 2008 for Guichan by  doxygen 1.5.2