00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef __GUI_WIDGETS_SCROLLBAR_HPP_INCLUDED__
00016 #define __GUI_WIDGETS_SCROLLBAR_HPP_INCLUDED__
00017
00018 #include "gui/widgets/control.hpp"
00019
00020 namespace gui2 {
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 class tscrollbar_ : public tcontrol
00031 {
00032 public:
00033
00034 tscrollbar_() :
00035 tcontrol(COUNT),
00036 state_(ENABLED),
00037 item_count_(0),
00038 item_position_(0),
00039 visible_items_(1),
00040 step_size_(1),
00041 pixels_per_step_(0.0),
00042 mouse_(0, 0),
00043 positioner_offset_(0),
00044 positioner_length_(0),
00045 callback_positioner_move_(0)
00046 {
00047 }
00048
00049
00050
00051
00052 void mouse_enter(tevent_handler& event) { mouse_move(event); }
00053
00054
00055 void mouse_move(tevent_handler& event);
00056
00057
00058
00059
00060 void mouse_leave(tevent_handler&);
00061
00062
00063 void mouse_left_button_down(tevent_handler& event);
00064
00065
00066 void mouse_left_button_up(tevent_handler& event);
00067
00068
00069 void set_active(const bool active)
00070 { if(get_active() != active) set_state(active ? ENABLED : DISABLED); };
00071
00072
00073 bool get_active() const { return state_ != DISABLED; }
00074
00075
00076 unsigned get_state() const { return state_; }
00077
00078
00079 void set_size(const SDL_Rect& rect);
00080
00081 unsigned get_item_count() const { return item_count_; }
00082 void set_item_count(const unsigned item_count)
00083 { item_count_ = item_count; recalculate(); }
00084
00085 unsigned get_item_position() const { return item_position_; }
00086
00087
00088
00089 void set_item_position(const unsigned item_position);
00090
00091 enum tscroll {
00092 BEGIN,
00093 ITEM_BACKWARDS,
00094 HALF_JUMP_BACKWARDS,
00095 JUMP_BACKWARDS,
00096 END,
00097 ITEM_FORWARD,
00098 HALF_JUMP_FORWARD,
00099 JUMP_FORWARD };
00100
00101
00102 void scroll(const tscroll scroll);
00103
00104 unsigned get_visible_items() const { return visible_items_; }
00105 void set_visible_items(const unsigned visible_items)
00106 { visible_items_ = visible_items; recalculate(); }
00107
00108 unsigned get_step_size() const { return step_size_; }
00109 void set_step_size(const unsigned step_size)
00110 { step_size_ = step_size; recalculate(); }
00111
00112
00113 bool at_begin() const { return item_position_ == 0; }
00114
00115
00116
00117 bool at_end() const
00118 { return item_position_ + visible_items_ == item_count_; }
00119
00120 void set_callback_positioner_move(void (*callback) (twidget*))
00121 { callback_positioner_move_ = callback; }
00122
00123 protected:
00124 unsigned get_positioner_offset() const { return positioner_offset_; }
00125
00126 unsigned get_positioner_length() const { return positioner_length_; }
00127
00128 private:
00129
00130 enum tstate { ENABLED, DISABLED, PRESSED, FOCUSSED, COUNT };
00131
00132 void set_state(const tstate state);
00133 tstate state_;
00134
00135
00136 void load_config_extra();
00137
00138
00139 unsigned item_count_;
00140
00141
00142 unsigned item_position_;
00143
00144
00145
00146 unsigned visible_items_;
00147
00148
00149
00150
00151 unsigned step_size_;
00152
00153
00154
00155
00156 float pixels_per_step_;
00157
00158
00159 virtual unsigned get_length() const = 0;
00160
00161
00162 virtual unsigned minimum_positioner_length() const = 0;
00163
00164
00165
00166
00167 virtual unsigned offset_before() const = 0;
00168
00169
00170
00171
00172 virtual unsigned offset_after() const = 0;
00173
00174
00175 virtual bool on_positioner(const tpoint& coordinate) const = 0;
00176
00177
00178
00179
00180
00181 virtual int get_length_difference(
00182 const tpoint& original, const tpoint& current) const = 0;
00183
00184
00185
00186 tpoint mouse_;
00187
00188
00189
00190 unsigned positioner_offset_;
00191
00192
00193 unsigned positioner_length_;
00194
00195
00196
00197
00198
00199
00200 void recalculate();
00201
00202
00203 void update_canvas();
00204
00205
00206
00207
00208
00209 void move_positioner(const int distance);
00210
00211
00212
00213
00214 void (*callback_positioner_move_) (twidget*);
00215 };
00216
00217 }
00218
00219 #endif
00220