gcn::Slider Class Reference

#include <slider.hpp>

Inheritance diagram for gcn::Slider:

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

Detailed Description

An implementation of a slider where a user can select different values by sliding between a start value and an end value of a scale.

If the selected value is changed an action event will be sent to all action listeners of the slider.

Definition at line 74 of file slider.hpp.

Public Types

enum  Orientation { HORIZONTAL = 0, VERTICAL }
 Draw orientations for the slider. More...

Public Member Functions

virtual void draw (Graphics *graphics)
 Draws the widget.
int getMarkerLength () const
 Gets the length of the marker.
Orientation getOrientation () const
 Gets the orientation of the slider.
double getScaleEnd () const
 Gets the end value of the scale.
double getScaleStart () const
 Gets the start value of the scale.
double getStepLength () const
 Gets the step length.
double getValue () const
 Gets the current selected value.
virtual void keyPressed (KeyEvent &keyEvent)
 Called if a key is pressed when the widget has keyboard focus.
virtual void mouseDragged (MouseEvent &mouseEvent)
 Called when the mouse has moved and the mouse has previously been pressed on the widget.
virtual void mousePressed (MouseEvent &mouseEvent)
 Called when a mouse button has been pressed on the widget area.
virtual void mouseWheelMovedDown (MouseEvent &mouseEvent)
 Called when the mouse wheel has moved down on the widget area.
virtual void mouseWheelMovedUp (MouseEvent &mouseEvent)
 Called when the mouse wheel has moved up on the widget area.
void setMarkerLength (int length)
 Sets the length of the marker.
void setOrientation (Orientation orientation)
 Sets the orientation of the slider.
void setScale (double scaleStart, double scaleEnd)
 Sets the scale of the slider.
void setScaleEnd (double scaleEnd)
 Sets the end value of the scale.
void setScaleStart (double scaleStart)
 Sets the start value of the scale.
void setStepLength (double length)
 Sets the step length.
void setValue (double value)
 Sets the current selected value.
 Slider (double scaleStart, double scaleEnd)
 Constructor.
 Slider (double scaleEnd=1.0)
 Constructor.
virtual ~Slider ()
 Destructor.

Protected Member Functions

virtual void drawMarker (gcn::Graphics *graphics)
 Draws the marker.
virtual int getMarkerPosition () const
 Gets the marker position of the current selected value.
virtual double markerPositionToValue (int position) const
 Converts a marker position to a value in the scale.
virtual int valueToMarkerPosition (double value) const
 Converts a value to a marker position.

Protected Attributes

bool mDragged
 True if the slider is dragged, false otherwise.
int mMarkerLength
 Holds the length of the marker.
Orientation mOrientation
 Holds the orientation of the slider.
double mScaleEnd
 Holds the end value of the scale.
double mScaleStart
 Holds the start value of the scale.
double mStepLength
 Holds the step length.
double mValue
 Holds the current selected value.


Member Enumeration Documentation

enum gcn::Slider::Orientation

Draw orientations for the slider.

A slider can be drawn vertically or horizontally.

Enumerator:
HORIZONTAL 
VERTICAL 

Definition at line 85 of file slider.hpp.


Constructor & Destructor Documentation

gcn::Slider::Slider ( double  scaleEnd = 1.0  ) 

Constructor.

The default start value of the slider scale is zero.

Parameters:
scaleEnd The end value of the slider scale.

Definition at line 69 of file slider.cpp.

References gcn::Widget::addKeyListener(), gcn::Widget::addMouseListener(), HORIZONTAL, mDragged, mScaleEnd, mScaleStart, gcn::Widget::setFocusable(), gcn::Widget::setFrameSize(), setMarkerLength(), setOrientation(), setStepLength(), and setValue().

gcn::Slider::Slider ( double  scaleStart,
double  scaleEnd 
)

Constructor.

Parameters:
scaleStart The start value of the slider scale.
scaleEnd The end value of the slider scale.

Definition at line 87 of file slider.cpp.

References gcn::Widget::addKeyListener(), gcn::Widget::addMouseListener(), HORIZONTAL, mDragged, mScaleEnd, mScaleStart, gcn::Widget::setFocusable(), gcn::Widget::setFrameSize(), setMarkerLength(), setOrientation(), setStepLength(), and setValue().


Member Function Documentation

void gcn::Slider::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 131 of file slider.cpp.

References gcn::Color::a, drawMarker(), gcn::Graphics::fillRectangle(), gcn::Widget::getBaseColor(), gcn::Widget::getHeight(), gcn::Widget::getWidth(), and gcn::Graphics::setColor().

void gcn::Slider::drawMarker ( gcn::Graphics graphics  )  [protected, virtual]

Draws the marker.

Parameters:
graphics A graphics object to draw with.

Definition at line 143 of file slider.cpp.

References gcn::Color::a, gcn::Graphics::drawLine(), gcn::Graphics::drawRectangle(), gcn::Graphics::fillRectangle(), gcn::Widget::getBaseColor(), gcn::Widget::getForegroundColor(), gcn::Widget::getHeight(), getMarkerLength(), getMarkerPosition(), getOrientation(), gcn::Widget::getWidth(), HORIZONTAL, gcn::Widget::isFocused(), and gcn::Graphics::setColor().

Referenced by draw().

int gcn::Slider::getMarkerLength (  )  const

Gets the length of the marker.

Returns:
The length of the marker.
See also:
setMarkerLength

Definition at line 250 of file slider.cpp.

References mMarkerLength.

Referenced by drawMarker(), markerPositionToValue(), mouseDragged(), mousePressed(), and valueToMarkerPosition().

int gcn::Slider::getMarkerPosition (  )  const [protected, virtual]

Gets the marker position of the current selected value.

Returns:
The marker position of the current selected value.

Definition at line 362 of file slider.cpp.

References getValue(), and valueToMarkerPosition().

Referenced by drawMarker().

Slider::Orientation gcn::Slider::getOrientation (  )  const

Gets the orientation of the slider.

A slider can be drawn vertically or horizontally.

Returns:
The orientation of the slider.
See also:
setOrientation

Definition at line 301 of file slider.cpp.

References mOrientation.

Referenced by drawMarker(), keyPressed(), markerPositionToValue(), mouseDragged(), mousePressed(), and valueToMarkerPosition().

double gcn::Slider::getScaleEnd (  )  const

Gets the end value of the scale.

Returns:
The end value of the scale.
See also:
setScaleEnd, setScale

Definition at line 121 of file slider.cpp.

References mScaleEnd.

Referenced by markerPositionToValue(), setValue(), and valueToMarkerPosition().

double gcn::Slider::getScaleStart (  )  const

Gets the start value of the scale.

Returns:
The start value of the scale.
See also:
setScaleStart, setScale

Definition at line 111 of file slider.cpp.

References mScaleStart.

Referenced by markerPositionToValue(), setValue(), and valueToMarkerPosition().

double gcn::Slider::getStepLength (  )  const

Gets the step length.

The step length is used when the keys LEFT and RIGHT are pressed to step in the scale.

Returns:
the step length.
See also:
setStepLength

Definition at line 357 of file slider.cpp.

References mStepLength.

Referenced by keyPressed(), mouseWheelMovedDown(), and mouseWheelMovedUp().

double gcn::Slider::getValue (  )  const

Gets the current selected value.

Returns:
The current selected value.
See also:
setValue

Definition at line 245 of file slider.cpp.

References mValue.

Referenced by getMarkerPosition(), keyPressed(), mouseWheelMovedDown(), and mouseWheelMovedUp().

void gcn::Slider::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 260 of file slider.cpp.

References gcn::InputEvent::consume(), gcn::Widget::distributeActionEvent(), gcn::Key::DOWN, gcn::KeyEvent::getKey(), getOrientation(), getStepLength(), getValue(), gcn::Key::getValue(), HORIZONTAL, gcn::Key::LEFT, gcn::Key::RIGHT, setValue(), and gcn::Key::UP.

double gcn::Slider::markerPositionToValue ( int  position  )  const [protected, virtual]

Converts a marker position to a value in the scale.

Parameters:
position The position to convert.
Returns:
A scale value corresponding to the position.
See also:
valueToMarkerPosition

Definition at line 306 of file slider.cpp.

References gcn::Widget::getHeight(), getMarkerLength(), getOrientation(), getScaleEnd(), getScaleStart(), gcn::Widget::getWidth(), and HORIZONTAL.

Referenced by mouseDragged(), and mousePressed().

void gcn::Slider::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 212 of file slider.cpp.

References gcn::InputEvent::consume(), gcn::Widget::distributeActionEvent(), gcn::Widget::getHeight(), getMarkerLength(), getOrientation(), gcn::MouseEvent::getX(), gcn::MouseEvent::getY(), HORIZONTAL, markerPositionToValue(), and setValue().

void gcn::Slider::mousePressed ( MouseEvent mouseEvent  )  [virtual]

Called when a mouse button has been pressed on the widget area.

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

Parameters:
mouseEvent Describes the event.
Since:
0.6.0

Reimplemented from gcn::MouseListener.

Definition at line 191 of file slider.cpp.

References gcn::Widget::distributeActionEvent(), gcn::MouseEvent::getButton(), gcn::Widget::getHeight(), getMarkerLength(), getOrientation(), gcn::Widget::getWidth(), gcn::MouseEvent::getX(), gcn::MouseEvent::getY(), HORIZONTAL, gcn::MouseEvent::LEFT, markerPositionToValue(), and setValue().

void gcn::Slider::mouseWheelMovedDown ( MouseEvent mouseEvent  )  [virtual]

Called when the mouse wheel has moved down on the widget area.

Parameters:
mousEvent Describes the event.
Since:
0.6.0

Reimplemented from gcn::MouseListener.

Definition at line 375 of file slider.cpp.

References gcn::InputEvent::consume(), gcn::Widget::distributeActionEvent(), getStepLength(), getValue(), and setValue().

void gcn::Slider::mouseWheelMovedUp ( MouseEvent mouseEvent  )  [virtual]

Called when the mouse wheel has moved up on the widget area.

Parameters:
mouseEvent Describes the event.
Since:
0.6.0

Reimplemented from gcn::MouseListener.

Definition at line 367 of file slider.cpp.

References gcn::InputEvent::consume(), gcn::Widget::distributeActionEvent(), getStepLength(), getValue(), and setValue().

void gcn::Slider::setMarkerLength ( int  length  ) 

Sets the length of the marker.

Parameters:
length The length for the marker.
See also:
getMarkerLength

Definition at line 255 of file slider.cpp.

References mMarkerLength.

Referenced by Slider().

void gcn::Slider::setOrientation ( Orientation  orientation  ) 

Sets the orientation of the slider.

A slider can be drawn vertically or horizontally.

Parameters:
orientation The orientation of the slider.
See also:
getOrientation

Definition at line 296 of file slider.cpp.

References mOrientation.

Referenced by Slider().

void gcn::Slider::setScale ( double  scaleStart,
double  scaleEnd 
)

Sets the scale of the slider.

Parameters:
scaleStart The start value of the scale.
scaleEnd tThe end of value the scale.
See also:
getScaleStart, getScaleEnd

Definition at line 105 of file slider.cpp.

References mScaleEnd, and mScaleStart.

void gcn::Slider::setScaleEnd ( double  scaleEnd  ) 

Sets the end value of the scale.

Parameters:
scaleEnd The end value of the scale.
See also:
getScaleEnd

Definition at line 126 of file slider.cpp.

References mScaleEnd.

void gcn::Slider::setScaleStart ( double  scaleStart  ) 

Sets the start value of the scale.

Parameters:
scaleStart The start value of the scale.
See also:
getScaleStart

Definition at line 116 of file slider.cpp.

References mScaleStart.

void gcn::Slider::setStepLength ( double  length  ) 

Sets the step length.

The step length is used when the keys LEFT and RIGHT are pressed to step in the scale.

Parameters:
length The step length.
See also:
getStepLength

Definition at line 352 of file slider.cpp.

References mStepLength.

Referenced by Slider().

void gcn::Slider::setValue ( double  value  ) 

Sets the current selected value.

Parameters:
value The current selected value.
See also:
getValue

Definition at line 228 of file slider.cpp.

References getScaleEnd(), getScaleStart(), and mValue.

Referenced by keyPressed(), mouseDragged(), mousePressed(), mouseWheelMovedDown(), mouseWheelMovedUp(), and Slider().

int gcn::Slider::valueToMarkerPosition ( double  value  )  const [protected, virtual]

Converts a value to a marker position.

Parameters:
value The value to convert.
Returns:
A marker position corresponding to the value.
See also:
markerPositionToValue

Definition at line 323 of file slider.cpp.

References gcn::Widget::getHeight(), getMarkerLength(), getOrientation(), getScaleEnd(), getScaleStart(), gcn::Widget::getWidth(), and HORIZONTAL.

Referenced by getMarkerPosition().


Member Data Documentation

Orientation gcn::Slider::mOrientation [protected]

Holds the orientation of the slider.

A slider can be drawn vertically or horizontally.

Definition at line 309 of file slider.hpp.

Referenced by getOrientation(), and setOrientation().

double gcn::Slider::mStepLength [protected]

Holds the step length.

The step length is used when the keys LEFT and RIGHT are pressed to step in the scale.

Definition at line 288 of file slider.hpp.

Referenced by getStepLength(), and setStepLength().


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