Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

gcn::Button Class Reference

#include <button.hpp>

Inheritance diagram for gcn::Button:

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

Detailed Description

A regular button.

Add an ActionListener to it to know when it has been clicked.

NOTE: You can only have text (a caption) on the button. If you want it to handle, for instance images, you can implement an ImageButton of your own and overload member functions from Button.

Definition at line 73 of file button.hpp.

Public Member Functions

 Button ()
 Constructor.
 Button (const std::string &caption)
 Constructor.
virtual void setCaption (const std::string &caption)
 Sets the Button caption.
virtual const std::string & getCaption () const
 Gets the Button caption.
virtual void setAlignment (unsigned int alignment)
 Sets the alignment for the caption.
virtual unsigned int getAlignment () const
 Gets the alignment for the caption.
virtual void adjustSize ()
 Adjusts the buttons size to fit the content.
virtual bool isPressed () const
 Checks if the button is pressed down.
virtual void draw (Graphics *graphics)
 Draws the Widget.
virtual void drawBorder (Graphics *graphics)
 Draws a the Widget border.
virtual void lostFocus ()
 Called if the Widget looses focus.
virtual void mouseClick (int x, int y, int button, int count)
 Called when a mouse button is pressed and released (clicked) when the mouse is in the Widget area or if the Widget has focus.
virtual void mousePress (int x, int y, int button)
 Called when a mouse button is pressed when the mouse is in the Widget area or if the Widget has focus.
virtual void mouseRelease (int x, int y, int button)
 Called when a mouse button is released when the mouse is in the Widget area or if the Widget has focus.
virtual void keyPress (const Key &key)
 Called if a key is pressed when the widget has keyboard focus.
virtual void keyRelease (const Key &key)
 Called if a key is released when the widget has keyboard focus.

Protected Attributes

std::string mCaption
bool mMouseDown
bool mKeyDown
unsigned int mAlignment


Constructor & Destructor Documentation

gcn::Button::Button const std::string &  caption  ) 
 

Constructor.

Parameters:
caption the caption of the Button.

Definition at line 74 of file button.cpp.

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


Member Function Documentation

void gcn::Button::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 Widgets dimension.

Parameters:
graphics a Graphics object to draw with.

Implements gcn::Widget.

Definition at line 109 of file button.cpp.

References gcn::Color::a, getAlignment(), gcn::Widget::getBaseColor(), getCaption(), gcn::Widget::getDimension(), gcn::Widget::getFont(), gcn::Widget::getForegroundColor(), gcn::Font::getHeight(), gcn::Widget::getHeight(), gcn::Widget::getWidth(), gcn::Widget::hasFocus(), and isPressed().

void gcn::Button::drawBorder Graphics graphics  )  [virtual]
 

Draws a the Widget border.

A border is drawn around a Widget. The width and height of the border is therefore the Widgets height+2*bordersize. Think of a painting that has a certain size, the border surrounds the painting.

Parameters:
graphics a Graphics object to draw with.

Reimplemented from gcn::Widget.

Definition at line 181 of file button.cpp.

References gcn::Color::a, gcn::Widget::getBaseColor(), gcn::Widget::getBorderSize(), gcn::Widget::getHeight(), and gcn::Widget::getWidth().

unsigned int gcn::Button::getAlignment  )  const [virtual]
 

Gets the alignment for the caption.

Returns:
alignment of caption.

Definition at line 104 of file button.cpp.

Referenced by draw().

const std::string & gcn::Button::getCaption  )  const [virtual]
 

Gets the Button caption.

Returns:
the Button caption.

Definition at line 94 of file button.cpp.

Referenced by draw().

bool gcn::Button::isPressed  )  const [virtual]
 

Checks if the button is pressed down.

Useful when drawing.

Returns:
true if the button is pressed down.

Definition at line 211 of file button.cpp.

References gcn::Widget::hasMouse().

Referenced by draw().

void gcn::Button::keyPress const Key key  )  [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:
key the key pressed.

Reimplemented from gcn::KeyListener.

Definition at line 240 of file button.cpp.

void gcn::Button::keyRelease const Key key  )  [virtual]
 

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

Parameters:
key the key released.

Reimplemented from gcn::KeyListener.

Definition at line 250 of file button.cpp.

References gcn::Widget::generateAction().

void gcn::Button::mouseClick int  x,
int  y,
int  button,
int  count
[virtual]
 

Called when a mouse button is pressed and released (clicked) when the mouse is in the Widget area or if the Widget has focus.

Parameters:
x the x coordinate of the mouse relative to the Widget itself.
y the y coordinate of the mouse relative to the Widget itself.
button the button clicked.
count the number of clicks.

Reimplemented from gcn::MouseListener.

Definition at line 216 of file button.cpp.

References gcn::Widget::generateAction().

void gcn::Button::mousePress int  x,
int  y,
int  button
[virtual]
 

Called when a mouse button is pressed when the mouse is in the Widget area or if the Widget has focus.

NOTE: A mouse press is NOT equal to a mouse click. Use mouseClickMessage to check for mouse clicks.

Parameters:
x the x coordinate of the mouse relative to the Widget itself.
y the y coordinate of the mouse relative to the Widget itself.
button the button pressed.

Reimplemented from gcn::MouseListener.

Definition at line 224 of file button.cpp.

References gcn::Widget::hasMouse().

void gcn::Button::mouseRelease int  x,
int  y,
int  button
[virtual]
 

Called when a mouse button is released when the mouse is in the Widget area or if the Widget has focus.

Parameters:
x the x coordinate of the mouse relative to the Widget itself.
y the y coordinate of the mouse relative to the Widget itself.
button the button released.

Reimplemented from gcn::MouseListener.

Definition at line 232 of file button.cpp.

void gcn::Button::setAlignment unsigned int  alignment  )  [virtual]
 

Sets the alignment for the caption.

Parameters:
alignemnt Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT
See also:
Graphics

Definition at line 99 of file button.cpp.

void gcn::Button::setCaption const std::string &  caption  )  [virtual]
 

Sets the Button caption.

Parameters:
caption the Button caption.

Definition at line 89 of file button.cpp.


The documentation for this class was generated from the following files:
Generated on Tue May 17 21:23:27 2005 for Guichan by  doxygen 1.4.1