gui2::tscrollbar_ Class Reference

Base class for a scroll bar. More...

#include <scrollbar.hpp>

Inheritance diagram for gui2::tscrollbar_:

Inheritance graph
[legend]
Collaboration diagram for gui2::tscrollbar_:

Collaboration graph
[legend]

List of all members.

Public Types

enum  tscroll {
  BEGIN, ITEM_BACKWARDS, HALF_JUMP_BACKWARDS, JUMP_BACKWARDS,
  END, ITEM_FORWARD, HALF_JUMP_FORWARD, JUMP_FORWARD
}

Public Member Functions

 tscrollbar_ ()
void mouse_enter (tevent_handler &event)
 Inherited from twidget.
void mouse_move (tevent_handler &event)
 Inherited from twidget.
void mouse_leave (tevent_handler &)
 Inherited from twidget.
void mouse_left_button_down (tevent_handler &event)
 Inherited from twidget.
void mouse_left_button_up (tevent_handler &event)
 Inherited from twidget.
void set_active (const bool active)
 Inherited from tcontrol.
bool get_active () const
 Inherited from tcontrol.
unsigned get_state () const
 Inherited from tcontrol.
void set_size (const SDL_Rect &rect)
 Inherited from tcontrol.
unsigned get_item_count () const
void set_item_count (const unsigned item_count)
unsigned get_item_position () const
void set_item_position (const unsigned item_position)
 Note the position isn't guaranteed to be the wanted position the step size is honoured.
void scroll (const tscroll scroll)
 Sets the item position.
unsigned get_visible_items () const
void set_visible_items (const unsigned visible_items)
unsigned get_step_size () const
void set_step_size (const unsigned step_size)
bool at_begin () const
 Is the positioner at the beginning of the scrollbar.
bool at_end () const
 Is the positioner at the and of the scrollbar, note both begin and end might be true at the same time.
void set_callback_positioner_move (void(*callback)(twidget *))

Protected Member Functions

unsigned get_positioner_offset () const
unsigned get_positioner_length () const

Private Types

enum  tstate {
  ENABLED, DISABLED, PRESSED, FOCUSSED,
  COUNT
}
 Note the order of the states must be the same as defined in settings.hpp. More...

Private Member Functions

void set_state (const tstate state)
void load_config_extra ()
 Inherited from tcontrol.
virtual unsigned get_length () const =0
 Get the length of the object.
virtual unsigned minimum_positioner_length () const =0
 The minimum length of the positioner.
virtual unsigned offset_before () const =0
 The number of pixels we can't use since they're used for borders.
virtual unsigned offset_after () const =0
 The number of pixels we can't use since they're used for borders.
virtual bool on_positioner (const tpoint &coordinate) const =0
 Is the current location on the positioner?
virtual int get_length_difference (const tpoint &original, const tpoint &current) const =0
 Gets the relevent difference in between the two positions.
void recalculate ()
 Updates the scrollbar.
void update_canvas ()
 After a recalculation the canvasses also need to be updated.
void move_positioner (const int distance)
 Moves the positioner.

Private Attributes

tstate state_
unsigned item_count_
 The number of items the scrollbar 'holds'.
unsigned item_position_
 The item the positioner is at, starts at 0.
unsigned visible_items_
 The number of items which can be shown at the same time.
unsigned step_size_
 The step size is the minimum number of items we scroll through when we move.
float pixels_per_step_
 The number of pixels the positioner needs to move to go to the next step.
tpoint mouse_
 The position the mouse was at the last movement.
unsigned positioner_offset_
 The start offset of the positioner.
unsigned positioner_length_
 The current length of the positioner.
void(* callback_positioner_move_ )(twidget *)
 This callback is used when the positioner is moved by the user.


Detailed Description

Base class for a scroll bar.

class will be subclassed for the horizontal and vertical scroll bar. It might be subclassed for a slider class.

To make this class generic we talk a lot about offset and length and use pure virtual functions. The classes implementing us can use the heights or widths, whichever is applicable.

Definition at line 30 of file gui/widgets/scrollbar.hpp.


Member Enumeration Documentation

Enumerator:
BEGIN  Go to begin position.

ITEM_BACKWARDS  Go one item towards the begin.

HALF_JUMP_BACKWARDS  Go half the visible items towards the begin.

JUMP_BACKWARDS  Go the visibile items towards the begin.

END  Go to the end position.

ITEM_FORWARD  Go one item towards the end.

HALF_JUMP_FORWARD  Go half the visible items towards the end.

JUMP_FORWARD 

Definition at line 91 of file gui/widgets/scrollbar.hpp.

enum gui2::tscrollbar_::tstate [private]

Note the order of the states must be the same as defined in settings.hpp.

Enumerator:
ENABLED 
DISABLED 
PRESSED 
FOCUSSED 
COUNT 

Definition at line 130 of file gui/widgets/scrollbar.hpp.


Constructor & Destructor Documentation

gui2::tscrollbar_::tscrollbar_ (  )  [inline]

Definition at line 34 of file gui/widgets/scrollbar.hpp.


Member Function Documentation

void gui2::tscrollbar_::mouse_enter ( tevent_handler event  )  [inline, virtual]

Inherited from twidget.

We only need to track the mouse if it's on the positioner so the normal enter doesn't help so transfer the control.

Reimplemented from gui2::tevent_executor.

Definition at line 52 of file gui/widgets/scrollbar.hpp.

References mouse_move().

void gui2::tscrollbar_::mouse_move ( tevent_handler event  )  [virtual]

void gui2::tscrollbar_::mouse_leave ( tevent_handler  )  [virtual]

Inherited from twidget.

Leave doesn't have the problem which mouse_enter has so it does it's own job.

Reimplemented from gui2::tevent_executor.

Definition at line 84 of file gui/widgets/scrollbar.cpp.

References ENABLED, FOCUSSED, set_state(), and state_.

void gui2::tscrollbar_::mouse_left_button_down ( tevent_handler event  )  [virtual]

void gui2::tscrollbar_::mouse_left_button_up ( tevent_handler event  )  [virtual]

void gui2::tscrollbar_::set_active ( const bool  active  )  [inline, virtual]

Inherited from tcontrol.

Implements gui2::tcontrol.

Definition at line 69 of file gui/widgets/scrollbar.hpp.

References DISABLED, ENABLED, get_active(), and set_state().

Referenced by gui2::tlistbox::set_scrollbar_button_status().

bool gui2::tscrollbar_::get_active (  )  const [inline, virtual]

Inherited from tcontrol.

Implements gui2::tcontrol.

Definition at line 73 of file gui/widgets/scrollbar.hpp.

References DISABLED, and state_.

Referenced by set_active().

unsigned gui2::tscrollbar_::get_state (  )  const [inline, virtual]

Inherited from tcontrol.

Implements gui2::tcontrol.

Definition at line 76 of file gui/widgets/scrollbar.hpp.

References state_.

void gui2::tscrollbar_::set_size ( const SDL_Rect &  rect  )  [virtual]

Inherited from tcontrol.

Reimplemented from gui2::tcontrol.

Definition at line 127 of file gui/widgets/scrollbar.cpp.

References recalculate(), and gui2::tcontrol::set_size().

unsigned gui2::tscrollbar_::get_item_count (  )  const [inline]

Definition at line 81 of file gui/widgets/scrollbar.hpp.

References item_count_.

void gui2::tscrollbar_::set_item_count ( const unsigned  item_count  )  [inline]

Definition at line 82 of file gui/widgets/scrollbar.hpp.

References item_count_, and recalculate().

Referenced by gui2::tlistbox::add_item().

unsigned gui2::tscrollbar_::get_item_position (  )  const [inline]

void gui2::tscrollbar_::set_item_position ( const unsigned  item_position  ) 

Note the position isn't guaranteed to be the wanted position the step size is honoured.

The value will be rouded down

Definition at line 135 of file gui/widgets/scrollbar.cpp.

References item_count_, item_position_, pixels_per_step_, positioner_offset_, step_size_, update_canvas(), and visible_items_.

Referenced by recalculate(), and scroll().

void gui2::tscrollbar_::scroll ( const tscroll  scroll  ) 

unsigned gui2::tscrollbar_::get_visible_items (  )  const [inline]

void gui2::tscrollbar_::set_visible_items ( const unsigned  visible_items  )  [inline]

Definition at line 105 of file gui/widgets/scrollbar.hpp.

References recalculate(), and visible_items_.

Referenced by gui2::tlistbox::set_size().

unsigned gui2::tscrollbar_::get_step_size (  )  const [inline]

Definition at line 108 of file gui/widgets/scrollbar.hpp.

References step_size_.

void gui2::tscrollbar_::set_step_size ( const unsigned  step_size  )  [inline]

Definition at line 109 of file gui/widgets/scrollbar.hpp.

References recalculate(), and step_size_.

bool gui2::tscrollbar_::at_begin (  )  const [inline]

Is the positioner at the beginning of the scrollbar.

Definition at line 113 of file gui/widgets/scrollbar.hpp.

References item_position_.

bool gui2::tscrollbar_::at_end (  )  const [inline]

Is the positioner at the and of the scrollbar, note both begin and end might be true at the same time.

Definition at line 117 of file gui/widgets/scrollbar.hpp.

References item_count_, item_position_, and visible_items_.

void gui2::tscrollbar_::set_callback_positioner_move ( void(*)(twidget *)  callback  )  [inline]

Definition at line 120 of file gui/widgets/scrollbar.hpp.

References callback_positioner_move_.

Referenced by gui2::tlistbox::finalize_setup().

unsigned gui2::tscrollbar_::get_positioner_offset (  )  const [inline, protected]

Definition at line 124 of file gui/widgets/scrollbar.hpp.

References positioner_offset_.

Referenced by gui2::tvertical_scrollbar::on_positioner().

unsigned gui2::tscrollbar_::get_positioner_length (  )  const [inline, protected]

Definition at line 126 of file gui/widgets/scrollbar.hpp.

References positioner_length_.

Referenced by gui2::tvertical_scrollbar::on_positioner().

void gui2::tscrollbar_::set_state ( const tstate  state  )  [private]

void gui2::tscrollbar_::load_config_extra (  )  [private, virtual]

Inherited from tcontrol.

Reimplemented from gui2::tcontrol.

Definition at line 202 of file gui/widgets/scrollbar.cpp.

References gui2::tcontrol::canvas(), offset_after(), offset_before(), and gui2::tcanvas::set_variable().

virtual unsigned gui2::tscrollbar_::get_length (  )  const [private, pure virtual]

Get the length of the object.

Implemented in gui2::tvertical_scrollbar.

Referenced by move_positioner(), and recalculate().

virtual unsigned gui2::tscrollbar_::minimum_positioner_length (  )  const [private, pure virtual]

The minimum length of the positioner.

Implemented in gui2::tvertical_scrollbar.

Referenced by recalculate().

virtual unsigned gui2::tscrollbar_::offset_before (  )  const [private, pure virtual]

The number of pixels we can't use since they're used for borders.

These are the pixels before the widget (left side if horizontal, top side if vertical).

Implemented in gui2::tvertical_scrollbar.

Referenced by load_config_extra(), move_positioner(), and recalculate().

virtual unsigned gui2::tscrollbar_::offset_after (  )  const [private, pure virtual]

The number of pixels we can't use since they're used for borders.

These are the pixels after the widget (right side if horizontal, bottom side if vertical).

Implemented in gui2::tvertical_scrollbar.

Referenced by load_config_extra(), move_positioner(), and recalculate().

virtual bool gui2::tscrollbar_::on_positioner ( const tpoint coordinate  )  const [private, pure virtual]

Is the current location on the positioner?

Implemented in gui2::tvertical_scrollbar.

Referenced by mouse_left_button_down(), mouse_left_button_up(), and mouse_move().

virtual int gui2::tscrollbar_::get_length_difference ( const tpoint original,
const tpoint current 
) const [private, pure virtual]

Gets the relevent difference in between the two positions.

This function is used to determine how much the positioner needs to be moved.

Implemented in gui2::tvertical_scrollbar.

Referenced by mouse_move().

void gui2::tscrollbar_::recalculate (  )  [private]

Updates the scrollbar.

Updates the size of the scroll bar.

Needs to be called when someting changes eg number of items or available size. It can only be called once we have a size otherwise we can't calulate a thing.

Definition at line 212 of file gui/widgets/scrollbar.cpp.

References get_length(), item_count_, item_position_, minimum_positioner_length(), offset_after(), offset_before(), pixels_per_step_, positioner_length_, positioner_offset_, set_item_position(), step_size_, update_canvas(), visible_items_, and WRN_G.

Referenced by set_item_count(), set_size(), set_step_size(), and set_visible_items().

void gui2::tscrollbar_::update_canvas (  )  [private]

After a recalculation the canvasses also need to be updated.

Definition at line 262 of file gui/widgets/scrollbar.cpp.

References gui2::tcontrol::canvas(), positioner_length_, positioner_offset_, gui2::twidget::set_dirty(), and gui2::tcanvas::set_variable().

Referenced by move_positioner(), recalculate(), and set_item_position().

void gui2::tscrollbar_::move_positioner ( const int  distance  )  [private]

Moves the positioner.

Parameters:
distance The distance moved, negative to begin, positive to end.

Definition at line 271 of file gui/widgets/scrollbar.cpp.

References callback_positioner_move_, get_length(), item_position_, offset_after(), offset_before(), pixels_per_step_, positioner_length_, positioner_offset_, and update_canvas().

Referenced by mouse_move().


Member Data Documentation

unsigned gui2::tscrollbar_::item_count_ [private]

The number of items the scrollbar 'holds'.

Definition at line 139 of file gui/widgets/scrollbar.hpp.

Referenced by at_end(), get_item_count(), recalculate(), scroll(), set_item_count(), and set_item_position().

The item the positioner is at, starts at 0.

Definition at line 142 of file gui/widgets/scrollbar.hpp.

Referenced by at_begin(), at_end(), get_item_position(), move_positioner(), recalculate(), scroll(), and set_item_position().

The number of items which can be shown at the same time.

As long as all items are visible we don't need to scroll.

Definition at line 146 of file gui/widgets/scrollbar.hpp.

Referenced by at_end(), get_visible_items(), recalculate(), scroll(), set_item_position(), and set_visible_items().

unsigned gui2::tscrollbar_::step_size_ [private]

The step size is the minimum number of items we scroll through when we move.

Normally this value is 1, we can move per item. But for example sliders want for example to move per 5 items.

Definition at line 151 of file gui/widgets/scrollbar.hpp.

Referenced by get_step_size(), recalculate(), set_item_position(), and set_step_size().

The number of pixels the positioner needs to move to go to the next step.

Note if there is too little space it can happen 1 pixel does more than 1 step.

Definition at line 156 of file gui/widgets/scrollbar.hpp.

Referenced by move_positioner(), recalculate(), and set_item_position().

The position the mouse was at the last movement.

This is used during dragging the positioner.

Definition at line 186 of file gui/widgets/scrollbar.hpp.

Referenced by mouse_left_button_down(), and mouse_move().

The start offset of the positioner.

This takes the offset before in consideration.

Definition at line 190 of file gui/widgets/scrollbar.hpp.

Referenced by get_positioner_offset(), move_positioner(), recalculate(), set_item_position(), and update_canvas().

The current length of the positioner.

Definition at line 193 of file gui/widgets/scrollbar.hpp.

Referenced by get_positioner_length(), move_positioner(), recalculate(), and update_canvas().

This callback is used when the positioner is moved by the user.

Referenced by move_positioner(), and set_callback_positioner_move().


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

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs