00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "elements/CEGUIScrollbar.h"
00027 #include "elements/CEGUIThumb.h"
00028
00029
00030
00031 namespace CEGUI
00032 {
00033 const String Scrollbar::EventNamespace("Scrollbar");
00034
00035
00036
00037
00038 ScrollbarProperties::DocumentSize Scrollbar::d_documentSizeProperty;
00039 ScrollbarProperties::PageSize Scrollbar::d_pageSizeProperty;
00040 ScrollbarProperties::StepSize Scrollbar::d_stepSizeProperty;
00041 ScrollbarProperties::OverlapSize Scrollbar::d_overlapSizeProperty;
00042 ScrollbarProperties::ScrollPosition Scrollbar::d_scrollPositionProperty;
00043
00044
00045
00046
00047
00048 const String Scrollbar::EventScrollPositionChanged( (utf8*)"ScrollPosChanged" );
00049 const String Scrollbar::EventThumbTrackStarted( (utf8*)"ThumbTrackStarted" );
00050 const String Scrollbar::EventThumbTrackEnded( (utf8*)"ThumbTrackEnded" );
00051 const String Scrollbar::EventScrollConfigChanged( (utf8*)"ScrollConfigChanged" );
00052
00053
00054
00055
00056
00057 Scrollbar::Scrollbar(const String& type, const String& name) :
00058 Window(type, name),
00059 d_documentSize(1.0f),
00060 d_pageSize(0.0f),
00061 d_stepSize(1.0f),
00062 d_overlapSize(0.0f),
00063 d_position(0.0f)
00064 {
00065 addScrollbarEvents();
00066 addScrollbarProperties();
00067 }
00068
00069
00070
00071
00072
00073 Scrollbar::~Scrollbar(void)
00074 {
00075 }
00076
00077
00078
00079
00080
00081 void Scrollbar::initialise(void)
00082 {
00083
00084 d_thumb = createThumb(getName() + "__auto_thumb__");
00085 addChildWindow(d_thumb);
00086 d_thumb->subscribeEvent(Thumb::EventThumbPositionChanged, Event::Subscriber(&CEGUI::Scrollbar::handleThumbMoved, this));
00087 d_thumb->subscribeEvent(Thumb::EventThumbTrackStarted, Event::Subscriber(&CEGUI::Scrollbar::handleThumbTrackStarted, this));
00088 d_thumb->subscribeEvent(Thumb::EventThumbTrackEnded, Event::Subscriber(&CEGUI::Scrollbar::handleThumbTrackEnded, this));
00089
00090
00091 d_increase = createIncreaseButton(getName() + "__auto_incbtn__");
00092 addChildWindow(d_increase);
00093 d_increase->subscribeEvent(PushButton::EventMouseButtonDown, Event::Subscriber(&CEGUI::Scrollbar::handleIncreaseClicked, this));
00094
00095
00096 d_decrease = createDecreaseButton(getName() + "__auto_decbtn__");
00097 addChildWindow(d_decrease);
00098 d_decrease->subscribeEvent(PushButton::EventMouseButtonDown, Event::Subscriber(&CEGUI::Scrollbar::handleDecreaseClicked, this));
00099
00100
00101 performChildWindowLayout();
00102 }
00103
00104
00105
00106
00107
00108 void Scrollbar::setDocumentSize(float document_size)
00109 {
00110 if (d_documentSize != document_size)
00111 {
00112 d_documentSize = document_size;
00113 updateThumb();
00114
00115 WindowEventArgs args(this);
00116 onScrollConfigChanged(args);
00117 }
00118
00119 }
00120
00121
00122
00123
00124
00125 void Scrollbar::setPageSize(float page_size)
00126 {
00127 if (d_pageSize != page_size)
00128 {
00129 d_pageSize = page_size;
00130 updateThumb();
00131
00132 WindowEventArgs args(this);
00133 onScrollConfigChanged(args);
00134 }
00135
00136 }
00137
00138
00139
00140
00141
00142 void Scrollbar::setStepSize(float step_size)
00143 {
00144 if (d_stepSize != step_size)
00145 {
00146 d_stepSize = step_size;
00147
00148 WindowEventArgs args(this);
00149 onScrollConfigChanged(args);
00150 }
00151
00152 }
00153
00154
00155
00156
00157
00158 void Scrollbar::setOverlapSize(float overlap_size)
00159 {
00160 if (d_overlapSize != overlap_size)
00161 {
00162 d_overlapSize = overlap_size;
00163
00164 WindowEventArgs args(this);
00165 onScrollConfigChanged(args);
00166 }
00167
00168 }
00169
00170
00171
00172
00173
00174 void Scrollbar::setScrollPosition(float position)
00175 {
00176 float old_pos = d_position;
00177
00178
00179 float max_pos = ceguimax((d_documentSize - d_pageSize), 0.0f);
00180
00181
00182 d_position = (position >= 0) ? ((position <= max_pos) ? position : max_pos) : 0.0f;
00183
00184 updateThumb();
00185
00186
00187 if (d_position != old_pos)
00188 {
00189 WindowEventArgs args(this);
00190 onScrollPositionChanged(args);
00191 }
00192
00193 }
00194
00195
00196
00197
00198
00199 void Scrollbar::addScrollbarEvents(void)
00200 {
00201 addEvent(EventScrollPositionChanged);
00202 addEvent(EventThumbTrackStarted);
00203 addEvent(EventThumbTrackEnded);
00204 addEvent(EventScrollConfigChanged);
00205 }
00206
00207
00208
00209
00210
00211 void Scrollbar::onScrollPositionChanged(WindowEventArgs& e)
00212 {
00213 fireEvent(EventScrollPositionChanged, e, EventNamespace);
00214 }
00215
00216
00217
00218
00219
00220 void Scrollbar::onThumbTrackStarted(WindowEventArgs& e)
00221 {
00222 fireEvent(EventThumbTrackStarted, e, EventNamespace);
00223 }
00224
00225
00226
00227
00228
00229 void Scrollbar::onThumbTrackEnded(WindowEventArgs& e)
00230 {
00231 fireEvent(EventThumbTrackEnded, e, EventNamespace);
00232 }
00233
00234
00235
00236
00237
00238 void Scrollbar::onScrollConfigChanged(WindowEventArgs& e)
00239 {
00240 fireEvent(EventScrollConfigChanged, e, EventNamespace);
00241 }
00242
00243
00244
00245
00246
00247
00248 void Scrollbar::onMouseButtonDown(MouseEventArgs& e)
00249 {
00250
00251 Window::onMouseButtonDown(e);
00252
00253 if (e.button == LeftButton)
00254 {
00255 float adj = getAdjustDirectionFromPoint(e.position);
00256
00257
00258 if (adj != 0)
00259 {
00260 setScrollPosition(d_position + ((d_pageSize - d_overlapSize) * adj));
00261 }
00262
00263 e.handled = true;
00264 }
00265
00266 }
00267
00268
00269
00270
00271
00272 void Scrollbar::onMouseWheel(MouseEventArgs& e)
00273 {
00274
00275 Window::onMouseWheel(e);
00276
00277
00278 setScrollPosition(d_position + d_stepSize * -e.wheelChange);
00279
00280
00281 e.handled = true;
00282 }
00283
00284
00285
00286
00287
00288 bool Scrollbar::handleThumbMoved(const EventArgs& e)
00289 {
00290
00291 setScrollPosition(getValueFromThumb());
00292
00293 return true;
00294 }
00295
00296
00297
00298
00299
00300 bool Scrollbar::handleIncreaseClicked(const EventArgs& e)
00301 {
00302 if (((const MouseEventArgs&)e).button == LeftButton)
00303 {
00304
00305 setScrollPosition(d_position + d_stepSize);
00306
00307 return true;
00308 }
00309 else
00310 {
00311 return false;
00312 }
00313
00314 }
00315
00316
00317
00318
00319
00320 bool Scrollbar::handleDecreaseClicked(const EventArgs& e)
00321 {
00322 if (((const MouseEventArgs&)e).button == LeftButton)
00323 {
00324
00325 setScrollPosition(d_position - d_stepSize);
00326
00327 return true;
00328 }
00329 else
00330 {
00331 return false;
00332 }
00333 }
00334
00335
00336
00337
00338
00339 bool Scrollbar::handleThumbTrackStarted(const EventArgs& e)
00340 {
00341
00342 WindowEventArgs args(this);
00343 onThumbTrackStarted(args);
00344
00345 return true;
00346 }
00347
00348
00349
00350
00351
00352 bool Scrollbar::handleThumbTrackEnded(const EventArgs& e)
00353 {
00354
00355 WindowEventArgs args(this);
00356 onThumbTrackEnded(args);
00357
00358 return true;
00359 }
00360
00361
00362
00363
00364
00365 void Scrollbar::addScrollbarProperties(void)
00366 {
00367 addProperty(&d_documentSizeProperty);
00368 addProperty(&d_pageSizeProperty);
00369 addProperty(&d_stepSizeProperty);
00370 addProperty(&d_overlapSizeProperty);
00371 addProperty(&d_scrollPositionProperty);
00372 }
00373
00374
00375
00376 }