Skip to content

Commit 532ecb8

Browse files
committed
Consolidate canCross into single function
1 parent 5a238c4 commit 532ecb8

File tree

1 file changed

+40
-74
lines changed

1 file changed

+40
-74
lines changed

LittleBigMouse.Daemon/LittleBigMouse.Engine/MouseEngine.cpp

+40-74
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,45 @@ void MouseEngine::OnMouseMoveCross(MouseEventArg& e)
238238

239239
int stallCount = 0;
240240

241+
bool canCross(bool checkEdge, MouseEngine* engine, MouseEventArg& e) {
242+
if (!checkEdge) {
243+
#if defined(_DEBUG)
244+
std::cout << "edge not checked\n";
245+
#endif
246+
stallCount = 0;
247+
// Allow transistion
248+
return true;
249+
}
250+
251+
bool isTriggerKeyPressed = engine->enableCtrlKeyCrossing && ((GetAsyncKeyState(VK_CONTROL) & 0x8000) == 0x8000);
252+
if (isTriggerKeyPressed) {
253+
#if defined(_DEBUG)
254+
std::cout << "trigger key pressed\n";
255+
#endif
256+
stallCount = 0;
257+
// Allow transistion
258+
return true;
259+
}
260+
261+
stallCount++;
262+
#if defined(_DEBUG)
263+
std::cout << "count " << stallCount << "\n";
264+
#endif
265+
if (stallCount < engine->controlCrossingThreshold) {
266+
// Cannot cross yet
267+
return false;
268+
}
269+
270+
stallCount = 0;
271+
// Allow transistion
272+
return true;
273+
}
274+
241275
void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)
242276
{
243277
ResetClip();
244278
if(CheckForStopped(e)) return;
245279

246-
int triggerKey = VK_CONTROL;
247280
const auto pIn = e.Point;
248281

249282
const ZoneLink* zoneOut;
@@ -254,26 +287,8 @@ void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)
254287
if (pIn.X() >= bounds.Right())
255288
{
256289
zoneOut = _oldZone->RightZones->AtPixel(pIn.Y());
257-
if (zoneOut->Target)
290+
if (zoneOut->Target && canCross(enableControlVertEdgeCrossing, this, e))
258291
{
259-
bool isTriggerKeyPressed = enableCtrlKeyCrossing && ((GetAsyncKeyState(triggerKey) & 0x8000) == 0x8000);
260-
if (enableControlVertEdgeCrossing && !isTriggerKeyPressed)
261-
{
262-
stallCount++;
263-
if (stallCount < controlCrossingThreshold) {
264-
#if defined(_DEBUG)
265-
std::cout << "count " << stallCount << "\n";
266-
#endif
267-
NoZoneMatches(e);
268-
return;
269-
}
270-
else {
271-
stallCount = 0;
272-
}
273-
}
274-
stallCount = 0;
275-
pOut = { zoneOut->ToTargetPixel(pIn.X()), zoneOut->Target->PixelsBounds().Top() };
276-
277292
pOut = { zoneOut->Target->PixelsBounds().Left(),zoneOut->ToTargetPixel(pIn.Y()) };
278293
}
279294
else
@@ -286,26 +301,8 @@ void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)
286301
else if (pIn.X() < bounds.Left())
287302
{
288303
zoneOut = _oldZone->LeftZones->AtPixel(pIn.Y());
289-
if (zoneOut->Target)
304+
if (zoneOut->Target && canCross(enableControlVertEdgeCrossing, this, e))
290305
{
291-
bool isTriggerKeyPressed = enableCtrlKeyCrossing && ((GetAsyncKeyState(triggerKey) & 0x8000) == 0x8000);
292-
if (enableControlVertEdgeCrossing && !isTriggerKeyPressed)
293-
{
294-
stallCount++;
295-
if (stallCount < controlCrossingThreshold) {
296-
#if defined(_DEBUG)
297-
std::cout << "count " << stallCount << "\n";
298-
#endif
299-
NoZoneMatches(e);
300-
return;
301-
}
302-
else {
303-
stallCount = 0;
304-
}
305-
}
306-
stallCount = 0;
307-
pOut = { zoneOut->ToTargetPixel(pIn.X()), zoneOut->Target->PixelsBounds().Top() };
308-
309306
pOut = { zoneOut->Target->PixelsBounds().Right() - 1,zoneOut->ToTargetPixel(pIn.Y()) };
310307
}
311308
else
@@ -318,29 +315,13 @@ void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)
318315
else if (pIn.Y() >= bounds.Bottom())
319316
{
320317
zoneOut = _oldZone->BottomZones->AtPixel(pIn.X());
321-
if (zoneOut->Target)
318+
if (zoneOut->Target && canCross(enableControlHorzEdgeCrossing, this, e))
322319
{
323-
bool isTriggerKeyPressed = enableCtrlKeyCrossing && ((GetAsyncKeyState(triggerKey) & 0x8000) == 0x8000);
324-
if (enableControlHorzEdgeCrossing && !isTriggerKeyPressed)
325-
{
326-
stallCount++;
327-
if (stallCount < controlCrossingThreshold) {
328-
#if defined(_DEBUG)
329-
std::cout << "count " << stallCount << "\n";
330-
#endif
331-
NoZoneMatches(e);
332-
return;
333-
}
334-
else {
335-
stallCount = 0;
336-
}
337-
}
338-
stallCount = 0;
339320
pOut = { zoneOut->ToTargetPixel(pIn.X()), zoneOut->Target->PixelsBounds().Top() };
340321
}
341322
else
342323
{
343-
stallCount = 0;
324+
//stallCount = 0;
344325
NoZoneMatches(e);
345326
return;
346327
}
@@ -349,28 +330,13 @@ void MouseEngine::OnMouseMoveStraight(MouseEventArg& e)
349330
else if (pIn.Y() < _oldZone->PixelsBounds().Top())
350331
{
351332
zoneOut = _oldZone->TopZones->AtPixel(pIn.X());
352-
if (zoneOut->Target)
333+
if (zoneOut->Target && canCross(enableControlHorzEdgeCrossing, this, e))
353334
{
354-
bool isTriggerKeyPressed = enableCtrlKeyCrossing && ((GetAsyncKeyState(triggerKey) & 0x8000) == 0x8000);
355-
if (enableControlHorzEdgeCrossing && !isTriggerKeyPressed)
356-
{
357-
stallCount++;
358-
if (stallCount < controlCrossingThreshold) {
359-
#if defined(_DEBUG)
360-
std::cout << "count " << stallCount << "\n";
361-
#endif
362-
NoZoneMatches(e);
363-
return;
364-
}
365-
else {
366-
stallCount = 0;
367-
}
368-
}
369335
pOut = { zoneOut->ToTargetPixel(pIn.X()),zoneOut->Target->PixelsBounds().Bottom() - 1 };
370336
}
371337
else
372338
{
373-
stallCount = 0;
339+
//stallCount = 0;
374340
NoZoneMatches(e);
375341
return;
376342
}

0 commit comments

Comments
 (0)