SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
PanScrolling Class Reference

#include <ImGuiWrapper.h>

Public Member Functions

void enable ()
 
void disable ()
 
void moveTo (const float yPos)
 
void start (const float yPos)
 
float getScrollInMouseWheelCoords (const bool mouseDown, const float fontSize, const float t)
 
bool enabled () const
 

Private Attributes

bool _enabled = false
 
float _lastPosY = 0.f
 mouse down start position More...
 
float _diff = 0.f
 Summed up y difference between mouse move events. More...
 
float _vMW = 0.f
 Mouse wheel velocity: used after pan scrolling for additional scrolling. More...
 
float _tOld = 0.f
 Time at last call to getScrollInMouseWheelCoords. More...
 
const float _aMW = 20.0f
 Mouse wheel acceleration (subtended velocity direction) More...
 

Detailed Description

Definition at line 129 of file ImGuiWrapper.h.

Member Function Documentation

◆ disable()

void PanScrolling::disable ( )
inline

Definition at line 141 of file ImGuiWrapper.h.

142  {
143  _enabled = false;
144  }

◆ enable()

void PanScrolling::enable ( )
inline

Definition at line 132 of file ImGuiWrapper.h.

133  {
134  _enabled = true;
135  _lastPosY = 0.f;
136  _diff = 0.f;
137  _vMW = 0.f;
138  _tOld = 0.f;
139  }
float _vMW
Mouse wheel velocity: used after pan scrolling for additional scrolling.
Definition: ImGuiWrapper.h:216
float _diff
Summed up y difference between mouse move events.
Definition: ImGuiWrapper.h:215
float _tOld
Time at last call to getScrollInMouseWheelCoords.
Definition: ImGuiWrapper.h:217
float _lastPosY
mouse down start position
Definition: ImGuiWrapper.h:214

◆ enabled()

bool PanScrolling::enabled ( ) const
inline

Definition at line 210 of file ImGuiWrapper.h.

210 { return _enabled; }

◆ getScrollInMouseWheelCoords()

float PanScrolling::getScrollInMouseWheelCoords ( const bool  mouseDown,
const float  fontSize,
const float  t 
)
inline

Definition at line 165 of file ImGuiWrapper.h.

166  {
167  float dt = t - _tOld;
168  _tOld = t;
169 
170  if (mouseDown)
171  {
172  // Convertion to mouse wheel coords: One mouse wheel unit scrolls about 5 lines of text
173  //(see io.MouseWheel comment)
174  float diffMW = _diff / (fontSize * 5.f);
175  _diff = 0; // diff consumed, reset it
176 
177  // calculate v (of mouse wheel), we need it when left mouse button goes up
178  if (dt > 0.000001f)
179  {
180  // v = s / t
181  _vMW = diffMW / dt;
182  }
183 
184  return diffMW;
185  }
186  else if (std::abs(_vMW) > 0.000001f)
187  {
188  // velocity damping
189  // v = v - a * t
190  if (_vMW > 0)
191  {
192  _vMW = _vMW - _aMW * dt;
193  if (_vMW < 0.f)
194  _vMW = 0.f;
195  }
196  else
197  {
198  _vMW = _vMW + _aMW * dt;
199  if (_vMW > 0.f)
200  _vMW = 0.f;
201  }
202 
203  // s = v * t
204  return _vMW * dt;
205  }
206  else
207  return 0.f;
208  }
const float _aMW
Mouse wheel acceleration (subtended velocity direction)
Definition: ImGuiWrapper.h:218
T abs(T a)
Definition: Utils.h:249

◆ moveTo()

void PanScrolling::moveTo ( const float  yPos)
inline

Definition at line 147 of file ImGuiWrapper.h.

148  {
149  _diff -= (_lastPosY - yPos);
150  _lastPosY = yPos;
151  }

◆ start()

void PanScrolling::start ( const float  yPos)
inline

Definition at line 154 of file ImGuiWrapper.h.

155  {
156  _lastPosY = yPos;
157  _diff = 0.f;
158  _vMW = 0.f;
159  _tOld = 0.f;
160  }

Member Data Documentation

◆ _aMW

const float PanScrolling::_aMW = 20.0f
private

Mouse wheel acceleration (subtended velocity direction)

Definition at line 218 of file ImGuiWrapper.h.

◆ _diff

float PanScrolling::_diff = 0.f
private

Summed up y difference between mouse move events.

Definition at line 215 of file ImGuiWrapper.h.

◆ _enabled

bool PanScrolling::_enabled = false
private

Definition at line 213 of file ImGuiWrapper.h.

◆ _lastPosY

float PanScrolling::_lastPosY = 0.f
private

mouse down start position

Definition at line 214 of file ImGuiWrapper.h.

◆ _tOld

float PanScrolling::_tOld = 0.f
private

Time at last call to getScrollInMouseWheelCoords.

Definition at line 217 of file ImGuiWrapper.h.

◆ _vMW

float PanScrolling::_vMW = 0.f
private

Mouse wheel velocity: used after pan scrolling for additional scrolling.

Definition at line 216 of file ImGuiWrapper.h.


The documentation for this class was generated from the following file: