gcn::DropDown Class Reference

#include <dropdown.hpp>

Inheritance diagram for gcn::DropDown:

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

Detailed Description

A drop down box from which you can select different values.

It is one of the most complicated Widgets you will find in Guichan. For drawing the DroppedDown box it uses one ScrollArea and one ListBox. It also uses an internal FocusHandler to handle the focus of the internal ScollArea and ListBox. DropDown uses a ListModel to handle the list. To be able to use DropDown you must give DropDown an implemented ListModel which represents your list.

Definition at line 81 of file dropdown.hpp.

Public Member Functions

 DropDown (ListModel *listModel=NULL, ScrollArea *scrollArea=NULL, ListBox *listBox=NULL)
 Contructor.
virtual ~DropDown ()
 Destructor.
virtual int getSelected ()
 Gets the index int the ListModel of the selected element.
virtual void setSelected (int selected)
 Sets the ListModel index of the selected element.
virtual void setListModel (ListModel *listModel)
 Sets the ListModel to use.
virtual ListModelgetListModel ()
 Gets the ListModel used.
virtual void adjustHeight ()
 Adjusts the height of the DropDown fitting it's parents height.
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 setBaseColor (const Color &color)
 Sets the base color.
virtual void setBackgroundColor (const Color &color)
 Sets the background color.
virtual void setForegroundColor (const Color &color)
 Sets the foreground color.
virtual void logic ()
 Called for all Widgets in the gui each time Gui::logic is called.
virtual void setFont (Font *font)
 Sets the font.
virtual void _announceDeath (Widget *widget)
 Called when a child of the BasicContainer gets destroyed.
virtual Rectangle getChildrenArea ()
 Gets the subarea of the BasicContainer that the children occupy.
virtual void action (const std::string &eventId, Widget *widget)
 Called whan an action is recieved from a Widget.
virtual void keyPress (const Key &key)
 Called if a key is pressed when the widget has keyboard 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.

Protected Member Functions

virtual void drawButton (Graphics *graphics)
 Draws the button with the little down arrow.
virtual void dropDown ()
 Sets the DropDown Widget to dropped-down mode.
virtual void foldUp ()
 Sets the DropDown Widget to folded-up mode.

Protected Attributes

bool mDroppedDown
bool mPushed
int mOldH
ScrollAreamScrollArea
ListBoxmListBox
FocusHandler mFocusHandler
bool mInternalScrollArea
bool mInternalListBox


Constructor & Destructor Documentation

gcn::DropDown::DropDown ( ListModel listModel = NULL,
ScrollArea scrollArea = NULL,
ListBox listBox = NULL 
)

Contructor.

Parameters:
listModel the ListModel to use.
scrollArea the ScrollArea to use.
listBox the listBox to use.
See also:
ListModel, ScrollArea, ListBox.

Definition at line 71 of file dropdown.cpp.

References gcn::BasicContainer::add(), gcn::Widget::addActionListener(), gcn::Widget::addKeyListener(), gcn::Widget::addMouseListener(), adjustHeight(), gcn::ListBox::getSelected(), mDroppedDown, mFocusHandler, mInternalListBox, mInternalScrollArea, mListBox, mPushed, mScrollArea, gcn::Widget::setBorderSize(), gcn::ScrollArea::setContent(), gcn::Widget::setFocusable(), gcn::BasicContainer::setInternalFocusHandler(), setListModel(), gcn::ListBox::setSelected(), gcn::ScrollArea::setVerticalScrollPolicy(), and gcn::Widget::setWidth().


Member Function Documentation

void gcn::DropDown::_announceDeath ( Widget widget  )  [virtual]

Called when a child of the BasicContainer gets destroyed.

Parameters:
widget the destroyed Widget.

Reimplemented from gcn::BasicContainer.

Definition at line 418 of file dropdown.cpp.

References gcn::BasicContainer::_announceDeath(), and mScrollArea.

void gcn::DropDown::action ( const std::string &  eventId,
Widget widget 
) [virtual]

Called whan an action is recieved from a Widget.

It is used to be able to recieve a notification that an action has occured.

Parameters:
eventId the identifier of the Widget.
widget a pointer to the Widget who called this function.

Implements gcn::ActionListener.

Definition at line 431 of file dropdown.cpp.

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

void gcn::DropDown::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 140 of file dropdown.cpp.

References gcn::Color::a, drawButton(), gcn::BasicContainer::drawChildren(), gcn::Graphics::drawRectangle(), gcn::Graphics::drawText(), gcn::Graphics::fillRectangle(), gcn::Widget::getBackgroundColor(), gcn::Widget::getBaseColor(), gcn::ListModel::getElementAt(), gcn::Widget::getFont(), gcn::Widget::getForegroundColor(), gcn::Widget::getHeight(), gcn::ListBox::getListModel(), gcn::ListBox::getSelected(), gcn::Widget::getWidth(), gcn::Widget::isFocused(), mDroppedDown, mListBox, mOldH, gcn::Graphics::setColor(), and gcn::Graphics::setFont().

void gcn::DropDown::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.

Parameters:
graphics a Graphics object to draw with.

Reimplemented from gcn::Widget.

Definition at line 193 of file dropdown.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::DropDown::drawButton ( Graphics graphics  )  [protected, virtual]

Draws the button with the little down arrow.

Parameters:
graphics a Graphics object to draw with.

Definition at line 217 of file dropdown.cpp.

References gcn::Color::a, gcn::Graphics::drawLine(), gcn::Graphics::fillRectangle(), gcn::Widget::getBaseColor(), gcn::Widget::getForegroundColor(), gcn::Widget::getHeight(), gcn::Widget::getWidth(), mDroppedDown, mOldH, mPushed, and gcn::Graphics::setColor().

Referenced by draw().

Rectangle gcn::DropDown::getChildrenArea (  )  [virtual]

Gets the subarea of the BasicContainer that the children occupy.

Returns:
the subarea as a Rectangle.

Reimplemented from gcn::BasicContainer.

Definition at line 437 of file dropdown.cpp.

References gcn::Widget::getHeight(), gcn::Widget::getWidth(), mDroppedDown, and mOldH.

ListModel * gcn::DropDown::getListModel (  )  [virtual]

Gets the ListModel used.

Returns:
the ListModel used.

Definition at line 343 of file dropdown.cpp.

References gcn::ListBox::getListModel(), and mListBox.

int gcn::DropDown::getSelected (  )  [virtual]

Gets the index int the ListModel of the selected element.

Returns:
the selected element.

Definition at line 282 of file dropdown.cpp.

References gcn::ListBox::getSelected(), and mListBox.

void gcn::DropDown::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 295 of file dropdown.cpp.

References dropDown(), gcn::Key::getValue(), and mDroppedDown.

void gcn::DropDown::logic (  )  [virtual]

Called for all Widgets in the gui each time Gui::logic is called.

You can do logic stuff here like playing an animation.

See also:
Gui

Reimplemented from gcn::BasicContainer.

Definition at line 492 of file dropdown.cpp.

References gcn::FocusHandler::applyChanges(), gcn::BasicContainer::logic(), and mFocusHandler.

void gcn::DropDown::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 304 of file dropdown.cpp.

References dropDown(), foldUp(), gcn::Widget::hasMouse(), mDroppedDown, mOldH, and mPushed.

void gcn::DropDown::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 323 of file dropdown.cpp.

References mPushed.

void gcn::DropDown::setBackgroundColor ( const Color color  )  [virtual]

Sets the background color.

Parameters:
color the background Color.

Reimplemented from gcn::Widget.

Definition at line 462 of file dropdown.cpp.

References mInternalListBox, mInternalScrollArea, mListBox, mScrollArea, and gcn::Widget::setBackgroundColor().

void gcn::DropDown::setBaseColor ( const Color color  )  [virtual]

Sets the base color.

The base color is the background color for many Widgets like the Button and Contianer Widgets.

Parameters:
color the baseground Color.

Reimplemented from gcn::Widget.

Definition at line 447 of file dropdown.cpp.

References mInternalListBox, mInternalScrollArea, mListBox, mScrollArea, and gcn::Widget::setBaseColor().

void gcn::DropDown::setFont ( Font font  )  [virtual]

Sets the font.

If font is NULL, the global font will be used.

Parameters:
font the Font.

Reimplemented from gcn::Widget.

Definition at line 498 of file dropdown.cpp.

References mInternalListBox, mInternalScrollArea, mListBox, mScrollArea, and gcn::Widget::setFont().

void gcn::DropDown::setForegroundColor ( const Color color  )  [virtual]

Sets the foreground color.

Parameters:
color the foreground Color.

Reimplemented from gcn::Widget.

Definition at line 477 of file dropdown.cpp.

References mInternalListBox, mInternalScrollArea, mListBox, mScrollArea, and gcn::Widget::setForegroundColor().

void gcn::DropDown::setListModel ( ListModel listModel  )  [virtual]

Sets the ListModel to use.

Parameters:
listModel the ListModel to use.

Definition at line 331 of file dropdown.cpp.

References adjustHeight(), gcn::ListBox::getSelected(), mListBox, gcn::ListBox::setListModel(), and gcn::ListBox::setSelected().

Referenced by DropDown().

void gcn::DropDown::setSelected ( int  selected  )  [virtual]

Sets the ListModel index of the selected element.

Parameters:
selected the ListModel index of the selected element.

Definition at line 287 of file dropdown.cpp.

References mListBox, and gcn::ListBox::setSelected().


The documentation for this class was generated from the following files:
Generated on Sat Jul 29 19:38:49 2006 for Guichan by  doxygen 1.4.7