@@ -26,7 +26,7 @@ GUIScrollBar::GUIScrollBar(IGUIEnvironment *environment, IGUIElement *parent, s3
26
26
dragged_by_slider(false ), tray_clicked(false ), scroll_pos(0 ),
27
27
draw_center(0 ), thumb_size(0 ), min_pos(0 ), max_pos(100 ), small_step(10 ),
28
28
large_step(50 ), drag_offset(0 ), page_size(100 ), border_size(0 ),
29
- m_tsrc(tsrc)
29
+ m_tsrc(tsrc), target_pos( 0 . 0f ), variable_step( 0 . 0f )
30
30
{
31
31
refreshControls ();
32
32
setNotClipped (false );
@@ -90,7 +90,10 @@ bool GUIScrollBar::OnEvent(const SEvent &event)
90
90
if (Environment->hasFocus (this )) {
91
91
s8 d = event.MouseInput .Wheel < 0 ? -1 : 1 ;
92
92
s8 h = is_horizontal ? 1 : -1 ;
93
- setPosInterpolated (getTargetPos () + (d * small_step * h));
93
+
94
+ // NOTE: Is this noticable at all?
95
+ variable_step += d;
96
+ setPosInterpolated (getTargetPos () + ((event.MouseInput .Wheel + variable_step) * small_step * h));
94
97
return true ;
95
98
}
96
99
break ;
@@ -192,30 +195,25 @@ void GUIScrollBar::draw()
192
195
static inline f32 interpolate_scroll (f32 from, f32 to, f32 amount)
193
196
{
194
197
f32 step = /* core::round32*/ ((to - from) * amount);
195
- std::cout << " step: " << step << " " ;
196
198
if (step == 0 )
197
199
return to;
198
200
return from + step;
199
201
}
200
202
201
203
void GUIScrollBar::interpolatePos ()
202
204
{
203
- if (target_pos.has_value ()) {
204
- // Adjust to match 60 FPS. This also means that interpolation is
205
- // effectively disabled at <= 30 FPS.
206
- f32 amount = 0 .1f * (last_delta_ms / 16 .667f );
207
- setPosRaw (interpolate_scroll (scroll_pos, *target_pos, amount));
208
- std::cout << " Amount: " << amount << " | at:" << scroll_pos << " , want:" << *target_pos << std::endl;
209
- // if (scroll_pos == target_pos)
210
- // target_pos = std::nullopt;
211
-
212
- SEvent e;
213
- e.EventType = EET_GUI_EVENT;
214
- e.GUIEvent .Caller = this ;
215
- e.GUIEvent .Element = nullptr ;
216
- e.GUIEvent .EventType = EGET_SCROLL_BAR_CHANGED;
217
- Parent->OnEvent (e);
218
- }
205
+ // Adjust to match 60 FPS. This also means that interpolation is
206
+ // effectively disabled at <= 30 FPS.
207
+ f32 amount = 0 .2f * (last_delta_ms / 16 .667f );
208
+ setPosRaw (interpolate_scroll (scroll_pos, target_pos, amount));
209
+ variable_step *= 0 .9f ;
210
+
211
+ SEvent e;
212
+ e.EventType = EET_GUI_EVENT;
213
+ e.GUIEvent .Caller = this ;
214
+ e.GUIEvent .Element = nullptr ;
215
+ e.GUIEvent .EventType = EGET_SCROLL_BAR_CHANGED;
216
+ Parent->OnEvent (e);
219
217
}
220
218
221
219
void GUIScrollBar::OnPostRender (u32 time_ms)
@@ -275,12 +273,13 @@ void GUIScrollBar::setPosRaw(const s32 &pos)
275
273
276
274
if (!is_dragging)
277
275
{
278
- if (scroll_pos < 0 ) {
279
- *target_pos = (*target_pos * 0.9 );
280
- }
281
- else if (scroll_pos > max_pos) {
282
- *target_pos += ((*target_pos) - max_pos) * -0.3 ;
283
- }
276
+ // TODO support deltatime
277
+ if (scroll_pos < 0 ) {
278
+ target_pos = (target_pos * 0.9 );
279
+ }
280
+ else if (scroll_pos > max_pos) {
281
+ target_pos += (target_pos - max_pos) * -0.3 ;
282
+ }
284
283
}
285
284
286
285
f32 f = core::isnotzero (range ()) ? (f32 (thumb_area) - f32 (thumb_size)) / range ()
@@ -293,7 +292,6 @@ void GUIScrollBar::setPos(const s32 &pos)
293
292
{
294
293
setPosRaw (pos);
295
294
target_pos = pos;
296
- // target_pos = std::nullopt;
297
295
}
298
296
299
297
void GUIScrollBar::setPosAndSend (const s32 &pos)
@@ -316,14 +314,9 @@ void GUIScrollBar::setPosInterpolated(const s32 &pos)
316
314
setPosAndSend (pos);
317
315
return ;
318
316
}
319
-
320
- s32 clamped = pos;// core::s32_clamp(pos, min_pos, max_pos);
321
- if (scroll_pos != clamped) {
322
- target_pos = clamped;
323
- interpolatePos ();
324
- } else {
325
- // target_pos = std::nullopt;
326
- }
317
+
318
+ target_pos = pos;
319
+ interpolatePos ();
327
320
}
328
321
329
322
void GUIScrollBar::setSmallStep (const s32 &step)
@@ -379,10 +372,7 @@ s32 GUIScrollBar::getPos() const
379
372
380
373
s32 GUIScrollBar::getTargetPos () const
381
374
{
382
- if (target_pos.has_value ()) {
383
- return *target_pos;
384
- }
385
- return scroll_pos;
375
+ return target_pos;
386
376
}
387
377
388
378
void GUIScrollBar::refreshControls ()
0 commit comments