Base class for a scroll bar. More...
#include <scrollbar.hpp>


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 ¤t) 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 |
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.
scroll 'step size'.
When scrolling we always scroll a 'fixed' amount, these are the parameters for these amounts.
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.
Definition at line 149 of file scrollbar.hpp.
| gui2::tscrollbar_::tscrollbar_ | ( | ) |
Definition at line 31 of file scrollbar.cpp.
References signal_handler_left_button_down(), signal_handler_left_button_up(), signal_handler_mouse_enter(), signal_handler_mouse_leave(), and signal_handler_mouse_motion().

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

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

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

| virtual void gui2::tscrollbar_::child_callback_positioner_moved | ( | ) | [inline, protected, virtual] |
Callback for subclasses to get notified about positioner movement.
Definition at line 141 of file scrollbar.hpp.
Referenced by move_positioner().

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

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

| unsigned gui2::tscrollbar_::get_item_position | ( | ) | const [inline] |
Definition at line 116 of file scrollbar.hpp.
References item_position_.
Referenced by gui2::tslider::get_value(), gui2::tslider::get_value_label(), gui2::tscrollbar_container::scrollbar_moved(), and gui2::tscrollbar_container::show_content_rect().

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

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

| unsigned gui2::tscrollbar_::get_positioner_length | ( | ) | const [inline, protected] |
Definition at line 129 of file scrollbar.hpp.
References positioner_length_.
Referenced by gui2::tvertical_scrollbar::on_bar(), gui2::tslider::on_bar(), gui2::thorizontal_scrollbar::on_bar(), gui2::tvertical_scrollbar::on_positioner(), gui2::tslider::on_positioner(), and gui2::thorizontal_scrollbar::on_positioner().

| unsigned gui2::tscrollbar_::get_positioner_offset | ( | ) | const [inline, protected] |
Definition at line 127 of file scrollbar.hpp.
References positioner_offset_.
Referenced by gui2::tvertical_scrollbar::on_bar(), gui2::tslider::on_bar(), gui2::thorizontal_scrollbar::on_bar(), gui2::tvertical_scrollbar::on_positioner(), gui2::tslider::on_positioner(), and gui2::thorizontal_scrollbar::on_positioner().

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

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

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

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

| void gui2::tscrollbar_::move_positioner | ( | const int | distance | ) | [private] |
Moves the positioner.
| 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().


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

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

| virtual int gui2::tscrollbar_::on_bar | ( | const tpoint & | coordinate | ) | const [private, pure virtual] |
Is the coordinate on the bar?
| coordinate | Coordinate to test whether it's on the bar. |
| -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().

| virtual bool gui2::tscrollbar_::on_positioner | ( | const tpoint & | coordinate | ) | const [private, pure virtual] |
Is the coordinate on the positioner?
| coordinate | Coordinate to test whether it's on the positioner. |
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().

Inherited from tcontrol.
Reimplemented from gui2::tcontrol.
Definition at line 104 of file scrollbar.cpp.
References recalculate().

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


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


| void gui2::tscrollbar_::scroll | ( | const tscroll | scroll | ) |
Sets the item position.
We scroll a predefined step.
| scroll | 'step size' to scroll. |
Definition at line 60 of file scrollbar.cpp.
References BEGIN, END, HALF_JUMP_BACKWARDS, HALF_JUMP_FORWARD, ITEM_BACKWARDS, item_count_, ITEM_FORWARD, item_position_, JUMP_BACKWARDS, JUMP_FORWARD, set_item_position(), and visible_items_.
Referenced by gui2::tslider::handle_key_decrease(), gui2::tscrollbar_container::handle_key_down_arrow(), gui2::tscrollbar_container::handle_key_end(), gui2::tscrollbar_container::handle_key_home(), gui2::tslider::handle_key_increase(), gui2::tscrollbar_container::handle_key_page_down(), gui2::tscrollbar_container::handle_key_page_up(), gui2::tscrollbar_container::handle_key_up_arrow(), gui2::tscrollbar_container::scroll_horizontal_scrollbar(), gui2::tscrollbar_container::scroll_vertical_scrollbar(), signal_handler_left_button_down(), gui2::tscrollbar_container::signal_handler_sdl_wheel_down(), gui2::tscrollbar_container::signal_handler_sdl_wheel_left(), gui2::tscrollbar_container::signal_handler_sdl_wheel_right(), and gui2::tscrollbar_container::signal_handler_sdl_wheel_up().


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


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


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


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


| void gui2::tscrollbar_::set_step_size | ( | const unsigned | step_size | ) | [inline] |
Definition at line 123 of file scrollbar.hpp.
References recalculate(), and step_size_.

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


| void gui2::tscrollbar_::signal_handler_left_button_down | ( | const event::tevent | event, | |
| bool & | handled | |||
| ) | [private] |
Definition at line 362 of file scrollbar.cpp.
References DBG_GUI_E, gui2::event::tdispatcher::fire(), gui2::get_mouse_position(), gui2::twidget::get_window(), gui2::twidget::get_x(), gui2::twidget::get_y(), HALF_JUMP_BACKWARDS, HALF_JUMP_FORWARD, LOG_HEADER, mouse_, gui2::twindow::mouse_capture(), gui2::event::NOTIFY_MODIFIED, on_bar(), on_positioner(), PRESSED, scroll(), set_state(), gui2::tpoint::x, and gui2::tpoint::y.
Referenced by tscrollbar_().


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


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


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


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


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


friend class tslider [friend] |
Definition at line 44 of file scrollbar.hpp.
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().
unsigned gui2::tscrollbar_::item_position_ [private] |
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().
tpoint gui2::tscrollbar_::mouse_ [private] |
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().
float gui2::tscrollbar_::pixels_per_step_ [private] |
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().
unsigned gui2::tscrollbar_::positioner_length_ [private] |
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().
unsigned gui2::tscrollbar_::positioner_offset_ [private] |
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().
tstate gui2::tscrollbar_::state_ [private] |
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().
unsigned gui2::tscrollbar_::visible_items_ [private] |
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().
| Generated by doxygen 1.7.1 on Thu May 24 2012 01:23:18 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |