Skip to content

Commit 500e9ac

Browse files
committed
StWindow, Windows - fix enhanced scroll input
1 parent 3cbf26c commit 500e9ac

File tree

5 files changed

+99
-25
lines changed

5 files changed

+99
-25
lines changed

StCore/StWindowImpl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ StWindowImpl::StWindowImpl(const StHandle<StResourceManager>& theResMgr,
9797
myIsMouseMoved(false) {
9898
stMemZero(&attribs, sizeof(attribs));
9999
stMemZero(&signals, sizeof(signals));
100+
myStEvent .Type = stEvent_None;
101+
myStEvent2 .Type = stEvent_None;
102+
myStEventAux.Type = stEvent_None;
103+
myScrollAcc.reset();
100104
attribs.IsNoDecor = false;
101105
attribs.IsStereoOutput = false;
102106
attribs.IsGlStereo = false;

StCore/StWindowImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ class StWindowImpl {
477477
StEvent myStEvent; //!< temporary event object (to be used in message loop thread)
478478
StEvent myStEvent2; //!< temporary event object (to be used in message loop thread)
479479
StEvent myStEventAux; //!< extra temporary event object (to be used in StWindow creation thread)
480+
StScrollEvent myScrollAcc; //!< extra temporary event object accumulating mouse scroll events
480481
int myAlignDL; //!< extra window shift applied for alignment (left)
481482
int myAlignDR; //!< extra window shift applied for alignment (right)
482483
int myAlignDT; //!< extra window shift applied for alignment (top)

StCore/StWindowImplWin.cpp

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -875,25 +875,32 @@ LRESULT StWindowImpl::stWndProc(HWND theWin, UINT uMsg, WPARAM wParam, LPARAM lP
875875
return 0;
876876
}
877877
case WM_MOUSEWHEEL: // vertical wheel
878-
//case WM_MOUSEHWHEEL: // horizontal wheel (only Vista+)
878+
case WM_MOUSEHWHEEL: // horizontal wheel (only Vista+)
879879
{
880880
const StRectI_t aWinRect = getPlacement();
881881
int aMouseXPx = int(short(LOWORD(lParam))) - aWinRect.left();
882882
int aMouseYPx = int(short(HIWORD(lParam))) - aWinRect.top();
883883

884-
int aZDelta = GET_WHEEL_DELTA_WPARAM(wParam); // / WHEEL_DELTA;
885-
//if(GET_X_LPARAM(lParam) != 0)
886-
887-
myStEvent.Type = stEvent_Scroll;
888-
myStEvent.Scroll.Time = getEventTime(myEvent.time);
889-
myStEvent.Scroll.PointX = double(aMouseXPx) / double(aWinRect.width());
890-
myStEvent.Scroll.PointY = double(aMouseYPx) / double(aWinRect.height());
891-
myStEvent.Scroll.StepsX = 0;
892-
myStEvent.Scroll.StepsY = (aZDelta > 0) ? 1 : -1;
893-
myStEvent.Scroll.DeltaX = 0.0;
894-
myStEvent.Scroll.DeltaY = 10.0f * myStEvent.Scroll.StepsY;
895-
myStEvent.Scroll.IsFromMultiTouch = false;
896-
884+
const bool isVert = (uMsg == WM_MOUSEWHEEL);
885+
const int aZDelta = GET_WHEEL_DELTA_WPARAM(wParam);
886+
const float aDeltaSt = 10.0f * (float(aZDelta) / float(WHEEL_DELTA));
887+
888+
myStEvent.Scroll.init(getEventTime(myEvent.time),
889+
double(aMouseXPx) / double(aWinRect.width()),
890+
double(aMouseYPx) / double(aWinRect.height()),
891+
!isVert ? aDeltaSt : 0.0f,
892+
isVert ? aDeltaSt : 0.0f,
893+
false);
894+
if((myStEvent.Scroll.Time - myScrollAcc.Time) > 0.1
895+
|| std::abs(aMouseXPx - (int)myScrollAcc.PointX) > 10
896+
|| std::abs(aMouseYPx - (int)myScrollAcc.PointY) > 10) {
897+
myScrollAcc.reset();
898+
}
899+
myScrollAcc.Time = myStEvent.Scroll.Time;
900+
myScrollAcc.PointX = aMouseXPx;
901+
myScrollAcc.PointY = aMouseYPx;
902+
myStEvent.Scroll.StepsX = myScrollAcc.accumulateStepsX(!isVert ? aZDelta : 0, WHEEL_DELTA);
903+
myStEvent.Scroll.StepsY = myScrollAcc.accumulateStepsY( isVert ? aZDelta : 0, WHEEL_DELTA);
897904
myEventsBuffer.append(myStEvent);
898905
return 0;
899906
}

StOutPageFlip/StDXNVWindow.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,22 @@ LRESULT StDXNVWindow::wndProcFunction(HWND theWnd,
112112
LPARAM theParamL) {
113113
// we do stupid checks here...
114114
if(myStWin->isFullScreen() && myStWin->isStereoOutput()) {
115-
if(theMsg == WM_MOUSEWHEEL) {
116-
int zDelta = GET_WHEEL_DELTA_WPARAM(theParamW);
115+
if(theMsg == WM_MOUSEWHEEL
116+
|| theMsg == WM_MOUSEHWHEEL) {
117+
const bool isVert = (theMsg == WM_MOUSEWHEEL);
118+
const int aZDelta = GET_WHEEL_DELTA_WPARAM(theParamW);
119+
const int aNbSteps = (aZDelta > 0) ? 1 : -1;
120+
const float aDeltaSt = 10.0f * (float(aZDelta) / float(WHEEL_DELTA));
117121
const StPointD_t aPnt = myStWin->getMousePos();
118122
StEvent anEvent;
119-
anEvent.Type = stEvent_Scroll;
120-
anEvent.Scroll.Time = 0.0; //getEventTime(myEvent.time);
121-
anEvent.Scroll.PointX = aPnt.x();
122-
anEvent.Scroll.PointY = aPnt.y();
123-
anEvent.Scroll.StepsX = 0;
124-
anEvent.Scroll.StepsY = (zDelta > 0) ? 1 : -1;
125-
anEvent.Scroll.DeltaX = 0.0;
126-
anEvent.Scroll.DeltaY = 10.0f * anEvent.Scroll.StepsY;
127-
anEvent.Scroll.IsFromMultiTouch = false;
123+
anEvent.Scroll.init(0.0, //getEventTime(myEvent.time);
124+
aPnt.x(),
125+
aPnt.y(),
126+
!isVert ? aDeltaSt : 0.0f,
127+
isVert ? aDeltaSt : 0.0f,
128+
false);
129+
anEvent.Scroll.StepsX = !isVert ? aNbSteps : 0;
130+
anEvent.Scroll.StepsY = isVert ? aNbSteps : 0;
128131
myStWin->post(anEvent);
129132
}
130133

include/StCore/StEvent.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,65 @@ struct StScrollEvent {
186186
float DeltaY; //!< precise delta for vertical scroll
187187
bool IsFromMultiTouch; //!< when true, scrolling is simulated from multi-touch gesture by system (OS X) and touches will come in parallel
188188

189+
/**
190+
* Reset event.
191+
*/
192+
void reset() {
193+
Type = stEvent_Scroll;
194+
Time = 0.0;
195+
PointX = 0.0;
196+
PointY = 0.0;
197+
StepsX = 0;
198+
StepsY = 0;
199+
DeltaX = 0.0f;
200+
DeltaY = 0.0f;
201+
IsFromMultiTouch = false;
202+
}
203+
204+
/**
205+
* Initialize event.
206+
*/
207+
void init(double theTime,
208+
double thePointX,
209+
double thePointY,
210+
float theDeltaX,
211+
float theDeltaY,
212+
bool theIsFromMultiTouch) {
213+
Type = stEvent_Scroll;
214+
Time = theTime;
215+
PointX = thePointX;
216+
PointY = thePointY;
217+
StepsX = 0;
218+
StepsY = 0;
219+
DeltaX = theDeltaX;
220+
DeltaY = theDeltaY;
221+
IsFromMultiTouch = theIsFromMultiTouch;
222+
}
223+
224+
/**
225+
* Compute accumulated integer steps from X scroll event.
226+
*/
227+
int accumulateStepsX(int theInc, int theStepSize) { return accumulateSteps(StepsX, theInc, theStepSize); }
228+
229+
/**
230+
* Compute accumulated integer steps from Y scroll event.
231+
*/
232+
int accumulateStepsY(int theInc, int theStepSize) { return accumulateSteps(StepsY, theInc, theStepSize); }
233+
234+
/**
235+
* Compute accumulated integer steps from scroll event.
236+
*/
237+
static int accumulateSteps(int& theAcc, int theInc, int theStepSize) {
238+
theAcc += theInc;
239+
int aNbSteps = 0;
240+
for(; theAcc <= -theStepSize; theAcc += theStepSize) {
241+
--aNbSteps;
242+
}
243+
for(; theAcc >= theStepSize; theAcc -= theStepSize) {
244+
++aNbSteps;
245+
}
246+
return aNbSteps;
247+
}
189248
};
190249

191250
/**

0 commit comments

Comments
 (0)