#include <button.hpp>
Inheritance diagram for gcn::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 77 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 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 |
gcn::Button::Button | ( | const std::string & | caption | ) |
Constructor.
caption | the caption of the Button. |
Definition at line 85 of file button.cpp.
References gcn::Widget::addKeyListener(), gcn::Widget::addMouseListener(), adjustSize(), mAlignment, mCaption, mKeyDown, mMouseDown, gcn::Widget::setBorderSize(), and gcn::Widget::setFocusable().
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.
graphics | a Graphics object to draw with. |
Implements gcn::Widget.
Definition at line 120 of file button.cpp.
References gcn::Color::a, gcn::Graphics::drawLine(), gcn::Graphics::drawRectangle(), gcn::Graphics::drawText(), gcn::Graphics::fillRectangle(), 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::isFocused(), isPressed(), gcn::Graphics::setColor(), and gcn::Graphics::setFont().
void gcn::Button::drawBorder | ( | Graphics * | graphics | ) | [virtual] |
Draws 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.
graphics | a Graphics object to draw with. |
Reimplemented from gcn::Widget.
Definition at line 192 of file button.cpp.
References gcn::Color::a, gcn::Graphics::drawLine(), gcn::Widget::getBaseColor(), gcn::Widget::getBorderSize(), gcn::Widget::getHeight(), gcn::Widget::getWidth(), and gcn::Graphics::setColor().
unsigned int gcn::Button::getAlignment | ( | ) | const [virtual] |
Gets the alignment for the caption.
Definition at line 115 of file button.cpp.
References mAlignment.
Referenced by draw().
const std::string & gcn::Button::getCaption | ( | ) | const [virtual] |
bool gcn::Button::isPressed | ( | ) | const [virtual] |
Checks if the button is pressed down.
Useful when drawing.
Definition at line 222 of file button.cpp.
References gcn::Widget::hasMouse(), mKeyDown, and mMouseDown.
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.
key | the key pressed. |
Reimplemented from gcn::KeyListener.
Definition at line 251 of file button.cpp.
References gcn::Key::getValue(), mKeyDown, and mMouseDown.
void gcn::Button::keyRelease | ( | const Key & | key | ) | [virtual] |
Called if a key is released when the widget has keyboard focus.
key | the key released. |
Reimplemented from gcn::KeyListener.
Definition at line 261 of file button.cpp.
References gcn::Widget::generateAction(), gcn::Key::getValue(), and mKeyDown.
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.
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 227 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.
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 235 of file button.cpp.
References gcn::Widget::hasMouse(), and mMouseDown.
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.
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 243 of file button.cpp.
References mMouseDown.
void gcn::Button::setAlignment | ( | unsigned int | alignment | ) | [virtual] |
Sets the alignment for the caption.
alignment | Graphics::LEFT, Graphics::CENTER or Graphics::RIGHT |
Definition at line 110 of file button.cpp.
References mAlignment.
void gcn::Button::setCaption | ( | const std::string & | caption | ) | [virtual] |
Sets the Button caption.
caption | the Button caption. |
Definition at line 100 of file button.cpp.
References mCaption.