____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

gcn::Button Class Reference

#include <button.h>

Inheritance diagram for gcn::Button:

gcn::Widget gcn::MouseListener gcn::KeyListener ButtonWidget ImageButton

List of all members.

Public Member Functions

 Button ()
 Button (const std::string &caption)
virtual void setCaption (const std::string &caption)
virtual const std::string & getCaption () const
virtual void setAlignment (unsigned int alignment)
virtual unsigned int getAlignment () const
virtual void adjustSize ()
virtual bool isPressed () const
virtual void draw (Graphics *graphics)
virtual void drawBorder (Graphics *graphics)
virtual void lostFocus ()
virtual void hotKeyPress ()
virtual void hotKeyRelease ()
virtual void mouseClick (int x, int y, int button, int count)
virtual void mousePress (int x, int y, int button)
virtual void mouseRelease (int x, int y, int button)
virtual bool keyPress (const Key &key)
virtual bool keyRelease (const Key &key)

Protected Attributes

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


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.h.


Constructor & Destructor Documentation

gcn::Button::Button (  ) 

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


Member Function Documentation

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

Sets the Button caption.

Parameters:
caption the Button caption.

Definition at line 90 of file button.cpp.

References mCaption, and gcn::Widget::setDirty().

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

Gets the Button caption.

Returns:
the Button caption.

Definition at line 96 of file button.cpp.

References mCaption.

Referenced by ImageButton::draw(), and draw().

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

Sets the alignment for the caption.

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

Definition at line 101 of file button.cpp.

References mAlignment.

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

Gets the alignment for the caption.

Returns:
alignment of caption.

Definition at line 106 of file button.cpp.

References mAlignment.

Referenced by ImageButton::draw(), and draw().

void gcn::Button::adjustSize (  )  [virtual]

Adjusts the buttons size to fit the content.

Reimplemented in ImageButton.

Definition at line 215 of file button.cpp.

References gcn::Widget::getFont(), gcn::Widget::getHeight(), gcn::Widget::getWidth(), mCaption, gcn::Widget::setHeight(), and gcn::Widget::setWidth().

Referenced by Button().

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 221 of file button.cpp.

References gcn::Widget::hasMouse(), mHotKeyDown, mKeyDown, and mMouseDown.

Referenced by ImageButton::draw(), and draw().

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.

Reimplemented in ImageButton.

Definition at line 111 of file button.cpp.

References gcn::Color::a, gcn::Graphics::CENTER, gcn::Graphics::drawLine(), gcn::Graphics::drawRectangle(), gcn::Graphics::drawText(), gcn::Graphics::fillRectangle(), GCN_EXCEPTION, getAlignment(), gcn::Widget::getBaseColor(), getCaption(), gcn::Widget::getDimension(), gcn::Widget::getDisabledColor(), gcn::Widget::getFont(), gcn::Widget::getForegroundColor(), gcn::Font::getHeight(), gcn::Widget::getHeight(), gcn::Widget::getWidth(), gcn::Widget::hasFocus(), gcn::Widget::isEnabled(), isPressed(), gcn::Graphics::LEFT, gcn::Graphics::RIGHT, gcn::Graphics::setColor(), and gcn::Graphics::setFont().

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 191 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().

void gcn::Button::lostFocus (  )  [virtual]

Called if the Widget loses focus.

Reimplemented from gcn::Widget.

Definition at line 293 of file button.cpp.

References mHotKeyDown, mKeyDown, and mMouseDown.

void gcn::Button::hotKeyPress (  )  [virtual]

Called when a Widget's hot key is pressed

Reimplemented from gcn::Widget.

Definition at line 278 of file button.cpp.

References mHotKeyDown, and mMouseDown.

void gcn::Button::hotKeyRelease (  )  [virtual]

Called when a Widget's hot key is released

Reimplemented from gcn::Widget.

Definition at line 284 of file button.cpp.

References gcn::Widget::generateAction(), and mHotKeyDown.

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 226 of file button.cpp.

References gcn::Widget::generateAction(), and gcn::MouseInput::LEFT.

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 234 of file button.cpp.

References gcn::Widget::hasMouse(), gcn::MouseInput::LEFT, 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.

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 242 of file button.cpp.

References gcn::MouseInput::LEFT, and mMouseDown.

bool 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 250 of file button.cpp.

References gcn::Key::ENTER, gcn::Key::getValue(), mHotKeyDown, mKeyDown, mMouseDown, and gcn::Key::SPACE.

bool 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 265 of file button.cpp.

References gcn::Key::ENTER, gcn::Widget::generateAction(), gcn::Key::getValue(), mKeyDown, and gcn::Key::SPACE.


Member Data Documentation

std::string gcn::Button::mCaption [protected]

Definition at line 159 of file button.h.

Referenced by adjustSize(), Button(), getCaption(), and setCaption().

bool gcn::Button::mMouseDown [protected]

Definition at line 160 of file button.h.

Referenced by Button(), hotKeyPress(), isPressed(), keyPress(), lostFocus(), mousePress(), and mouseRelease().

bool gcn::Button::mKeyDown [protected]

Definition at line 160 of file button.h.

Referenced by Button(), isPressed(), keyPress(), keyRelease(), and lostFocus().

bool gcn::Button::mHotKeyDown [protected]

Definition at line 160 of file button.h.

Referenced by Button(), hotKeyPress(), hotKeyRelease(), isPressed(), keyPress(), and lostFocus().

unsigned int gcn::Button::mAlignment [protected]

Definition at line 161 of file button.h.

Referenced by Button(), getAlignment(), and setAlignment().


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

Generated on Sat Feb 21 00:28:26 2009 for Bos Wars by  doxygen 1.5.6