#include <scrollbar.hpp>
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 ¤t) 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. |
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.
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.
Definition at line 130 of file gui/widgets/scrollbar.hpp.
gui2::tscrollbar_::tscrollbar_ | ( | ) | [inline] |
Definition at line 34 of file gui/widgets/scrollbar.hpp.
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] |
Inherited from twidget.
Reimplemented from gui2::tevent_executor.
Definition at line 47 of file gui/widgets/scrollbar.cpp.
References DBG_G_E, DISABLED, ENABLED, FOCUSSED, get_length_difference(), gui2::twidget::get_x(), gui2::twidget::get_y(), mouse_, move_positioner(), on_positioner(), PRESSED, set_state(), state_, gui2::tpoint::x, and gui2::tpoint::y.
Referenced by mouse_enter().
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] |
Inherited from twidget.
Reimplemented from gui2::tevent_executor.
Definition at line 91 of file gui/widgets/scrollbar.cpp.
References DBG_G_E, gui2::twidget::get_x(), gui2::twidget::get_y(), mouse_, on_positioner(), PRESSED, set_state(), gui2::tpoint::x, and gui2::tpoint::y.
void gui2::tscrollbar_::mouse_left_button_up | ( | tevent_handler & | event | ) | [virtual] |
Inherited from twidget.
Reimplemented from gui2::tevent_executor.
Definition at line 106 of file gui/widgets/scrollbar.cpp.
References DBG_G_E, ENABLED, FOCUSSED, gui2::twidget::get_x(), gui2::twidget::get_y(), on_positioner(), PRESSED, set_state(), state_, gui2::tpoint::x, and gui2::tpoint::y.
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] |
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] |
Definition at line 85 of file gui/widgets/scrollbar.hpp.
References item_position_.
Referenced by gui2::tlistbox::draw(), gui2::tlistbox::find_widget(), and gui2::tlistbox::list_item_selected().
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 | ) |
Sets the item position.
Definition at line 149 of file gui/widgets/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::tlistbox::scrollbar_click().
unsigned gui2::tscrollbar_::get_visible_items | ( | ) | const [inline] |
Definition at line 104 of file gui/widgets/scrollbar.hpp.
References visible_items_.
Referenced by gui2::tlistbox::draw(), gui2::tlistbox::find_widget(), and gui2::tlistbox::list_item_selected().
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] |
void gui2::tscrollbar_::set_step_size | ( | const unsigned | step_size | ) | [inline] |
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] |
Definition at line 193 of file gui/widgets/scrollbar.cpp.
References gui2::twidget::set_dirty(), and state_.
Referenced by mouse_leave(), mouse_left_button_down(), mouse_left_button_up(), mouse_move(), and set_active().
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.
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().
tstate gui2::tscrollbar_::state_ [private] |
Definition at line 133 of file gui/widgets/scrollbar.hpp.
Referenced by get_active(), get_state(), mouse_leave(), mouse_left_button_up(), mouse_move(), and set_state().
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().
unsigned gui2::tscrollbar_::item_position_ [private] |
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().
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 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().
float gui2::tscrollbar_::pixels_per_step_ [private] |
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().
tpoint gui2::tscrollbar_::mouse_ [private] |
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().
unsigned gui2::tscrollbar_::positioner_offset_ [private] |
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().
unsigned gui2::tscrollbar_::positioner_length_ [private] |
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().
void(* gui2::tscrollbar_::callback_positioner_move_)(twidget *) [private] |
This callback is used when the positioner is moved by the user.
Referenced by move_positioner(), and set_callback_positioner_move().
Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |