Skip to content

Commit 0b03e30

Browse files
committed
Add option to flush mouse messages from message queue after repositioning the cursor
1 parent 302eaae commit 0b03e30

6 files changed

Lines changed: 39 additions & 0 deletions

File tree

inc/utestres.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#define IDC_CHECK2 1026
5454
#define IDC_CHECK3 1027
5555
#define IDC_CHECK4 1028
56+
#define IDC_CHECK5 1029
5657
#define cidInfo 40038
5758
#define cidWriteBmps 40039
5859
#define cidHelpBook 40040

kauai/src/appb.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,21 @@ void APPB::PositionCurs(long xpScreen, long ypScreen)
267267

268268
// REVIEW shonk: implement on Mac
269269
MacWin(RawRtn(), SetCursorPos(xpScreen, ypScreen));
270+
271+
#ifdef WIN
272+
if (_fFlushCursor)
273+
{
274+
// APPB::TrackMouse gets the mouse position by peeking the message queue for WM_MOUSE* messages.
275+
// After the cursor position has been reset, there may still be some WM_MOUSEMOVE messages with old
276+
// cooordinates in the message queue. This can cause jitter when dragging actors around the stage.
277+
// Flush all mouse move messages from this thread's message queue.
278+
MSG msg;
279+
while (PeekMessage(&msg, hNil, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE | PM_NOYIELD))
280+
{
281+
// do nothing
282+
}
283+
}
284+
#endif // WIN
270285
}
271286

272287
/***************************************************************************
@@ -548,6 +563,7 @@ bool APPB::_FInit(ulong grfapp, ulong grfgob, long ginDef)
548563
AssertThis(0);
549564

550565
_fOffscreen = FPure(grfapp & fappOffscreen);
566+
_fFlushCursor = fTrue;
551567

552568
#ifdef DEBUG
553569
if (!_FInitDebug())
@@ -1418,6 +1434,10 @@ bool APPB::FSetProp(long prid, long lw)
14181434
ResetToolTip();
14191435
break;
14201436

1437+
case kpridReduceMouseJitter:
1438+
_fFlushCursor = FPure(lw);
1439+
break;
1440+
14211441
default:
14221442
return _FSetProp(prid, lw);
14231443
}
@@ -1454,6 +1474,10 @@ bool APPB::FGetProp(long prid, long *plw)
14541474
*plw = LwMulDivAway(_dtsToolTip, kdtimSecond, kdtsSecond);
14551475
break;
14561476

1477+
case kpridReduceMouseJitter:
1478+
*plw = FPure(_fFlushCursor);
1479+
break;
1480+
14571481
default:
14581482
if (!_FFindProp(prid, &prop))
14591483
return fFalse;

kauai/src/appb.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class APPB : public APPB_PAR
104104
bool _fToolTip : 1; // whether we're in tool-tip mode
105105
bool _fForeground : 1; // whether we're the foreground app
106106
bool _fEndModal : 1; // set to end the topmost modal loop
107+
bool _fFlushCursor : 1; // flush cursor events when setting cursor position
107108

108109
PGL _pglmkrgn; // list of marked regions for fast updating
109110
long _onnDefFixed; // default fixed pitch font

kauai/src/framedef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#define kpridMaximized 1
8787
#define kpridFullScreen 2
8888
#define kpridToolTipDelay 3
89+
#define kpridReduceMouseJitter 4
8990

9091
/***************************************************************************
9192
Transitions that Kauai knows how to do.

src/studio/utest.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3261,6 +3261,8 @@ enum
32613261
iditStartupSound,
32623262
iditStereoSound,
32633263
iditHighQualitySoundImport,
3264+
iditReduceMouseJitter,
3265+
32643266
iditLimInfo
32653267
};
32663268

@@ -3336,6 +3338,10 @@ bool APP::FCmdInfo(PCMD pcmd)
33363338
AssertDo(FGetProp(kpridHighQualitySoundImport, &lwValue), "can't get sound import property");
33373339
pdlg->PutCheck(iditHighQualitySoundImport, FPure(lwValue));
33383340

3341+
lwValue = 0;
3342+
AssertDo(FGetProp(kpridReduceMouseJitter, &lwValue), "can't get reduce mouse jitter property");
3343+
pdlg->PutCheck(iditReduceMouseJitter, FPure(lwValue));
3344+
33393345
// Show dialog
33403346
idit = pdlg->IditDo();
33413347

@@ -3445,6 +3451,9 @@ bool APP::FCmdInfo(PCMD pcmd)
34453451
fValue = pdlg->FGetCheck(iditHighQualitySoundImport);
34463452
AssertDo(FSetProp(kpridHighQualitySoundImport, fValue), "can't save sound import property");
34473453

3454+
fValue = pdlg->FGetCheck(iditReduceMouseJitter);
3455+
AssertDo(FSetProp(kpridReduceMouseJitter, fValue), "can't save reduce mouse jitter property");
3456+
34483457
if (fSaveChanges)
34493458
{
34503459
AssertDo(FGetProp(kpridHighQualitySoundImport, &lwValue), "can't get sound import property");
@@ -3454,6 +3463,8 @@ bool APP::FCmdInfo(PCMD pcmd)
34543463
AssertDo(FGetProp(kpridStereoSoundPlayback, &lwValue), "can't get stereo sound property");
34553464
AssertDo(FGetSetRegKey(kszStereoSound, &lwValue, size(lwValue), fregSetKey),
34563465
"can't save stereo sound preference to registry");
3466+
3467+
// TODO: Save "flush mouse" property to the registry
34573468
}
34583469

34593470
ReleasePpo(&pdlg);

src/studio/utest.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ BEGIN
199199
CONTROL "Play startup sound",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,102,174,12
200200
CONTROL "Stereo sound playback (requires restart)",IDC_CHECK3,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,120,174,12
201201
CONTROL "High quality sound import",IDC_CHECK4,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,138,174,12
202+
CONTROL "Reduce mouse jitter (experimental)",IDC_CHECK5,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,156,174,12
202203
END
203204

204205
dlidInitFailed DIALOG DISCARDABLE 0, 0, 187, 71

0 commit comments

Comments
 (0)