Public Types | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends

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
}
 

scroll 'step size'.

More...

Public Member Functions

 tscrollbar_ ()
void scroll (const tscroll scroll)
 Sets the item position.
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?
bool all_items_visible () const
 Are all items visible?
void place (const tpoint &origin, const tpoint &size)
 Inherited from tcontrol.
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_item_count (const unsigned item_count)
unsigned get_item_count () 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.
unsigned get_item_position () const
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)

Protected Member Functions

unsigned get_positioner_offset () const
unsigned get_positioner_length () const
virtual void update_canvas ()
 After a recalculation the canvasses also need to be updated.
virtual void child_callback_positioner_moved ()
 Callback for subclasses to get notified about positioner movement.

Private Types

enum  tstate {
  ENABLED, DISABLED, PRESSED, FOCUSSED,
  COUNT
}
 

Possible states of the widget.

More...

Private Member Functions

void set_state (const tstate state)
virtual unsigned get_length () const =0
 Get the length of the scrollbar.
virtual unsigned minimum_positioner_length () const =0
 The minimum length of the positioner.
virtual unsigned maximum_positioner_length () const =0
 The maximum 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 coordinate on the positioner?
virtual int on_bar (const tpoint &coordinate) const =0
 Is the coordinate on the bar?
virtual int get_length_difference (const tpoint &original, const tpoint &current) const =0
 Gets the relevant difference in between the two positions.
void recalculate ()
 Updates the scrollbar.
void recalculate_positioner ()
 Updates the positioner.
void move_positioner (const int distance)
 Moves the positioner.
void load_config_extra ()
 Inherited from tcontrol.
void signal_handler_mouse_enter (const event::tevent event, bool &handled, bool &halt)
void signal_handler_mouse_motion (const event::tevent event, bool &handled, bool &halt, const tpoint &coordinate)
void signal_handler_mouse_leave (const event::tevent event, bool &handled)
void signal_handler_left_button_down (const event::tevent event, bool &handled)
void signal_handler_left_button_up (const event::tevent event, bool &handled)

Private Attributes

tstate state_
 Current state of the widget.
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_
 Number of items moved when scrolling.
float pixels_per_step_
 Number of pixels per 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.

Friends

class tslider

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.

The NOTIFY_MODIFIED event is send when the position of scrollbar is changed.

Common signal handlers:

Definition at line 41 of file scrollbar.hpp.


Member Enumeration Documentation

scroll 'step size'.

When scrolling we always scroll a 'fixed' amount, these are the parameters for these amounts.

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 55 of file scrollbar.hpp.

enum gui2::tscrollbar_::tstate [private]

Possible states of the widget.

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

Enumerator:
ENABLED 
DISABLED 
PRESSED 
FOCUSSED 
COUNT 

Definition at line 149 of file scrollbar.hpp.


Constructor & Destructor Documentation

gui2::tscrollbar_::tscrollbar_ (  ) 

Member Function Documentation

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

Are all items visible?

Definition at line 86 of file scrollbar.hpp.

References item_count_, and visible_items_.

Referenced by set_item_position(), and gui2::tscrollbar_container::set_scrollbar_button_status().

Here is the caller graph for this function:

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

Is the positioner at the beginning of the scrollbar?

Definition at line 75 of file scrollbar.hpp.

References item_position_.

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

Here is the caller graph for this function:

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 82 of file scrollbar.hpp.

References item_count_, item_position_, and visible_items_.

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

Here is the caller graph for this function:

virtual void gui2::tscrollbar_::child_callback_positioner_moved (  )  [inline, protected, virtual]

Callback for subclasses to get notified about positioner movement.

Todo:
This is a kind of hack due to the fact there's no simple callback slot mechanism. See whether we can implement a generic way to attach callback which would remove quite some extra code.

Definition at line 141 of file scrollbar.hpp.

Referenced by move_positioner().

Here is the caller graph for this function:

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

Inherited from tcontrol.

Implements gui2::tcontrol.

Definition at line 100 of file scrollbar.hpp.

References state_.

Referenced by set_active().

Here is the caller graph for this function:

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

Definition at line 109 of file scrollbar.hpp.

References item_count_.

Referenced by gui2::tslider::get_maximum_value(), and gui2::tslider::get_value_label().

Here is the caller graph for this function:

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

Get the length of the scrollbar.

Implemented in gui2::thorizontal_scrollbar, and gui2::tvertical_scrollbar.

Referenced by move_positioner(), and recalculate().

Here is the caller graph for this function:

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

Gets the relevant difference in between the two positions.

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

Implemented in gui2::thorizontal_scrollbar, and gui2::tvertical_scrollbar.

Referenced by signal_handler_mouse_motion().

Here is the caller graph for this function:

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

Inherited from tcontrol.

Implements gui2::tcontrol.

Definition at line 103 of file scrollbar.hpp.

References state_.

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

Definition at line 122 of file scrollbar.hpp.

References step_size_.

Referenced by gui2::tslider::get_value(), and gui2::tscrollbar_container::scrollbar_moved().

Here is the caller graph for this function:

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

Definition at line 118 of file scrollbar.hpp.

References visible_items_.

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

Inherited from tcontrol.

Reimplemented from gui2::tcontrol.

Definition at line 287 of file scrollbar.cpp.

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

Here is the call graph for this function:

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

The maximum length of the positioner.

Implemented in gui2::thorizontal_scrollbar, and gui2::tvertical_scrollbar.

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

Here is the caller graph for this function:

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

The minimum length of the positioner.

Implemented in gui2::thorizontal_scrollbar, and gui2::tvertical_scrollbar.

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

Here is the caller graph for this function:

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 236 of file scrollbar.cpp.

References child_callback_positioner_moved(), gui2::event::tdispatcher::fire(), get_length(), item_count_, item_position_, maximum_positioner_length(), minimum_positioner_length(), gui2::event::NOTIFY_MODIFIED, offset_after(), offset_before(), pixels_per_step_, positioner_length_, positioner_offset_, step_size_, update_canvas(), and visible_items_.

Referenced by signal_handler_mouse_motion().

Here is the call graph for this function:

Here is the caller graph for this function:

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::thorizontal_scrollbar, and gui2::tvertical_scrollbar.

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

Here is the caller graph for this function:

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::thorizontal_scrollbar, and gui2::tvertical_scrollbar.

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

Here is the caller graph for this function:

virtual int gui2::tscrollbar_::on_bar ( const tpoint coordinate  )  const [private, pure virtual]

Is the coordinate on the bar?

Parameters:
coordinate Coordinate to test whether it's on the bar.
Returns:
Whether the location on the bar is.
Return values:
-1 Coordinate is on the bar before positioner.
0 Coordinate is not on the bar.
1 Coordinate is on the bar after the positioner.

Implemented in gui2::thorizontal_scrollbar, and gui2::tvertical_scrollbar.

Referenced by signal_handler_left_button_down().

Here is the caller graph for this function:

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

Is the coordinate on the positioner?

Parameters:
coordinate Coordinate to test whether it's on the positioner.
Returns:
Whether the location on the positioner is.

Implemented in gui2::thorizontal_scrollbar, and gui2::tvertical_scrollbar.

Referenced by signal_handler_left_button_down(), signal_handler_left_button_up(), and signal_handler_mouse_motion().

Here is the caller graph for this function:

void gui2::tscrollbar_::place ( const tpoint origin,
const tpoint size 
) [virtual]

Inherited from tcontrol.

Reimplemented from gui2::tcontrol.

Definition at line 104 of file scrollbar.cpp.

References recalculate().

Here is the call graph for this function:

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

Updates the scrollbar.

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.

Todo:
In the MP lobby it can happen that a listbox has first zero items, then gets filled and since there are no visible items the second assert after this block will be triggered. Use this ugly hack to avoid that case. (This hack also added the gui/widgets/window.hpp include.)

Definition at line 150 of file scrollbar.cpp.

References ERR_GUI_G, get_length(), gui2::twidget::get_window(), gui2::twindow::invalidate_layout(), item_count_, item_position_, LOG_HEADER, maximum_positioner_length(), minimum_positioner_length(), offset_after(), offset_before(), pixels_per_step_, positioner_length_, positioner_offset_, recalculate_positioner(), set_item_position(), step_size_, update_canvas(), and visible_items_.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Updates the positioner.

This is a helper for recalculate().

Definition at line 222 of file scrollbar.cpp.

References maximum_positioner_length(), minimum_positioner_length(), and positioner_length_.

Referenced by recalculate().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Inherited from tcontrol.

Implements gui2::tcontrol.

Definition at line 96 of file scrollbar.hpp.

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

Referenced by gui2::tscrollbar_container::set_scrollbar_button_status(), and gui2::tchat_log::controller::update_view_from_model().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 107 of file scrollbar.hpp.

References item_count_, and recalculate().

Referenced by gui2::tslider::set_maximum_value(), gui2::tslider::set_minimum_value(), and gui2::set_scrollbar_mode().

Here is the call graph for this function:

Here is the caller graph for this function:

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 112 of file scrollbar.cpp.

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

Referenced by recalculate(), scroll(), gui2::tslider::set_maximum_value(), gui2::tslider::set_minimum_value(), gui2::set_scrollbar_mode(), gui2::tslider::set_value(), and gui2::tscrollbar_container::show_content_rect().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 142 of file scrollbar.cpp.

References gui2::twidget::set_dirty(), and state_.

Referenced by set_active(), signal_handler_left_button_down(), signal_handler_left_button_up(), signal_handler_mouse_leave(), and signal_handler_mouse_motion().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 123 of file scrollbar.hpp.

References recalculate(), and step_size_.

Here is the call graph for this function:

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

Definition at line 119 of file scrollbar.hpp.

References recalculate(), and visible_items_.

Referenced by gui2::set_scrollbar_mode().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::tscrollbar_::signal_handler_left_button_down ( const event::tevent  event,
bool &  handled 
) [private]
void gui2::tscrollbar_::signal_handler_left_button_up ( const event::tevent  event,
bool &  handled 
) [private]

Definition at line 395 of file scrollbar.cpp.

References DBG_GUI_E, ENABLED, FOCUSSED, gui2::get_mouse_position(), gui2::twidget::get_window(), gui2::twidget::get_x(), gui2::twidget::get_y(), LOG_HEADER, gui2::twindow::mouse_capture(), on_positioner(), PRESSED, set_state(), state_, gui2::tpoint::x, and gui2::tpoint::y.

Referenced by tscrollbar_().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::tscrollbar_::signal_handler_mouse_enter ( const event::tevent  event,
bool &  handled,
bool &  halt 
) [private]

Definition at line 296 of file scrollbar.cpp.

References DBG_GUI_E, gui2::get_mouse_position(), LOG_HEADER, and signal_handler_mouse_motion().

Referenced by tscrollbar_().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::tscrollbar_::signal_handler_mouse_leave ( const event::tevent  event,
bool &  handled 
) [private]

Definition at line 350 of file scrollbar.cpp.

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

Referenced by tscrollbar_().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::tscrollbar_::signal_handler_mouse_motion ( const event::tevent  event,
bool &  handled,
bool &  halt,
const tpoint coordinate 
) [private]

Definition at line 305 of file scrollbar.cpp.

References DBG_GUI_E, DISABLED, gui2::distance(), ENABLED, FOCUSSED, get_length_difference(), gui2::twidget::get_x(), gui2::twidget::get_y(), LOG_HEADER, mouse_, move_positioner(), on_positioner(), PRESSED, set_state(), state_, gui2::tpoint::x, and gui2::tpoint::y.

Referenced by signal_handler_mouse_enter(), and tscrollbar_().

Here is the call graph for this function:

Here is the caller graph for this function:

void gui2::tscrollbar_::update_canvas (  )  [protected, virtual]

After a recalculation the canvasses also need to be updated.

Reimplemented from gui2::tcontrol.

Definition at line 133 of file 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().

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class tslider [friend]
Todo:
Abstract the code so this friend is no longer needed.

Definition at line 44 of file scrollbar.hpp.


Member Data Documentation

unsigned gui2::tscrollbar_::item_count_ [private]

The number of items the scrollbar 'holds'.

Definition at line 161 of file scrollbar.hpp.

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

The item the positioner is at, starts at 0.

Definition at line 164 of file scrollbar.hpp.

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

The position the mouse was at the last movement.

This is used during dragging the positioner.

Definition at line 196 of file scrollbar.hpp.

Referenced by signal_handler_left_button_down(), and signal_handler_mouse_motion().

Number of pixels per step.

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 189 of file scrollbar.hpp.

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

The current length of the positioner.

Definition at line 206 of file scrollbar.hpp.

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

The start offset of the positioner.

This takes the offset before in consideration.

Definition at line 203 of file scrollbar.hpp.

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

Current state of the widget.

The state of the widget determines what to render and how the widget reacts to certain 'events'.

Definition at line 158 of file scrollbar.hpp.

Referenced by get_active(), get_state(), set_state(), signal_handler_left_button_up(), signal_handler_mouse_leave(), and signal_handler_mouse_motion().

unsigned gui2::tscrollbar_::step_size_ [private]

Number of items moved when scrolling.

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 180 of file scrollbar.hpp.

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

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 171 of file scrollbar.hpp.

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


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:23:18 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs