2014-03-29 06:56:30 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using DS4Library;
|
|
|
|
|
|
|
|
|
|
namespace DS4Control
|
|
|
|
|
{
|
|
|
|
|
class MouseCursor
|
|
|
|
|
{
|
|
|
|
|
private readonly int deviceNumber;
|
|
|
|
|
public MouseCursor(int deviceNum)
|
|
|
|
|
{
|
|
|
|
|
deviceNumber = deviceNum;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Keep track of remainders when performing moves or we lose fractional parts.
|
|
|
|
|
private double horizontalRemainder = 0.0, verticalRemainder = 0.0;
|
2014-03-31 22:33:16 +02:00
|
|
|
|
/** Indicate x/y direction for doing jitter compensation, etc. */
|
|
|
|
|
public enum Direction { Negative, Neutral, Positive }
|
|
|
|
|
// Track direction vector separately and very trivially for now.
|
|
|
|
|
private Direction horizontalDirection = Direction.Neutral, verticalDirection = Direction.Neutral;
|
2014-03-29 06:56:30 +01:00
|
|
|
|
|
|
|
|
|
public void touchesBegan(TouchpadEventArgs arg)
|
|
|
|
|
{
|
|
|
|
|
if (arg.touches.Length == 1)
|
2014-03-31 22:33:16 +02:00
|
|
|
|
{
|
2014-03-29 06:56:30 +01:00
|
|
|
|
horizontalRemainder = verticalRemainder = 0.0;
|
2014-03-31 22:33:16 +02:00
|
|
|
|
horizontalDirection = verticalDirection = Direction.Neutral;
|
|
|
|
|
}
|
2014-03-29 06:56:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private byte lastTouchID;
|
|
|
|
|
public void touchesMoved(TouchpadEventArgs arg)
|
|
|
|
|
{
|
|
|
|
|
if (arg.touches.Length != 1)
|
|
|
|
|
return;
|
|
|
|
|
int deltaX, deltaY;
|
|
|
|
|
if (arg.touches[0].touchID != lastTouchID)
|
|
|
|
|
{
|
|
|
|
|
deltaX = deltaY = 0;
|
|
|
|
|
horizontalRemainder = verticalRemainder = 0.0;
|
2014-03-31 22:33:16 +02:00
|
|
|
|
horizontalDirection = verticalDirection = Direction.Neutral;
|
2014-03-29 06:56:30 +01:00
|
|
|
|
lastTouchID = arg.touches[0].touchID;
|
|
|
|
|
}
|
|
|
|
|
else if (Global.getTouchpadJitterCompensation(deviceNumber))
|
|
|
|
|
{
|
|
|
|
|
// Often the DS4's internal jitter compensation kicks in and starts hiding changes, ironically creating jitter...
|
|
|
|
|
deltaX = arg.touches[0].deltaX;
|
|
|
|
|
deltaY = arg.touches[0].deltaY;
|
|
|
|
|
// allow only very fine, slow motions, when changing direction
|
|
|
|
|
if (deltaX < -1)
|
|
|
|
|
{
|
2014-03-31 22:33:16 +02:00
|
|
|
|
if (horizontalDirection == Direction.Positive)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
deltaX = -1;
|
|
|
|
|
horizontalRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (deltaX > 1)
|
|
|
|
|
{
|
2014-03-31 22:33:16 +02:00
|
|
|
|
if (horizontalDirection == Direction.Negative)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
deltaX = 1;
|
|
|
|
|
horizontalRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deltaY < -1)
|
|
|
|
|
{
|
2014-03-31 22:33:16 +02:00
|
|
|
|
if (verticalDirection == Direction.Positive)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
deltaY = -1;
|
|
|
|
|
verticalRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (deltaY > 1)
|
|
|
|
|
{
|
2014-03-31 22:33:16 +02:00
|
|
|
|
if (verticalDirection == Direction.Negative)
|
2014-03-29 06:56:30 +01:00
|
|
|
|
{
|
|
|
|
|
deltaY = 1;
|
|
|
|
|
verticalRemainder = 0.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
deltaX = arg.touches[0].deltaX;
|
|
|
|
|
deltaY = arg.touches[0].deltaY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double coefficient = Global.getTouchSensitivity(deviceNumber) / 100.0;
|
|
|
|
|
// Collect rounding errors instead of losing motion.
|
|
|
|
|
double xMotion = coefficient * deltaX;
|
|
|
|
|
if (xMotion > 0.0)
|
|
|
|
|
{
|
|
|
|
|
if (horizontalRemainder > 0.0)
|
|
|
|
|
xMotion += horizontalRemainder;
|
|
|
|
|
}
|
|
|
|
|
else if (xMotion < 0.0)
|
|
|
|
|
{
|
|
|
|
|
if (horizontalRemainder < 0.0)
|
|
|
|
|
xMotion += horizontalRemainder;
|
|
|
|
|
}
|
|
|
|
|
int xAction = (int)xMotion;
|
|
|
|
|
horizontalRemainder = xMotion - xAction;
|
|
|
|
|
|
|
|
|
|
double yMotion = coefficient * deltaY;
|
|
|
|
|
if (yMotion > 0.0)
|
|
|
|
|
{
|
|
|
|
|
if (verticalRemainder > 0.0)
|
|
|
|
|
yMotion += verticalRemainder;
|
|
|
|
|
}
|
|
|
|
|
else if (yMotion < 0.0)
|
|
|
|
|
{
|
|
|
|
|
if (verticalRemainder < 0.0)
|
|
|
|
|
yMotion += verticalRemainder;
|
|
|
|
|
}
|
|
|
|
|
int yAction = (int)yMotion;
|
|
|
|
|
verticalRemainder = yMotion - yAction;
|
|
|
|
|
|
|
|
|
|
if (yAction != 0 || xAction != 0)
|
|
|
|
|
InputMethods.MoveCursorBy(xAction, yAction);
|
2014-03-31 22:33:16 +02:00
|
|
|
|
|
|
|
|
|
horizontalDirection = xAction > 0.0 ? Direction.Positive : xAction < 0.0 ? Direction.Negative : Direction.Neutral;
|
|
|
|
|
verticalDirection = yAction > 0.0 ? Direction.Positive : yAction < 0.0 ? Direction.Negative : Direction.Neutral;
|
2014-03-29 06:56:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|