inertial scroll for touchpad gesture
This commit is contained in:
1 parent
7caa778ff8
commit
03817bcfd7
4 files changed
+35
-6
No files matched your search
@@ -90,7 +90,16 @@ static CGFloat screenWidthInPoints;
|
|||||||
_gestureCaptured = false; //reset for next recognition
|
_gestureCaptured = false; //reset for next recognition
|
||||||
if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){
|
if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){
|
||||||
// lowestTouchPointYCoord = 0.0; //reset for next recognition
|
// lowestTouchPointYCoord = 0.0; //reset for next recognition
|
||||||
self.state = UIGestureRecognizerStateRecognized;
|
|
||||||
|
for(UITouch* touch in touches){
|
||||||
|
CGVector vector = [UITouchUtil vectorOf:touch in:self.view];
|
||||||
|
if(hypot(vector.dx, vector.dy)>2){
|
||||||
|
self.state = UIGestureRecognizerStateFailed;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(self.state != UIGestureRecognizerStateFailed) self.state = UIGestureRecognizerStateRecognized;
|
||||||
// NSLog(@"gen _lowestTouchPointHeight %f markmark touchesEnd", _lowestTouchPointHeight);
|
// NSLog(@"gen _lowestTouchPointHeight %f markmark touchesEnd", _lowestTouchPointHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,10 +193,12 @@ static const float QUICK_TAP_TIME_INTERVAL = 0.2;
|
|||||||
|
|
||||||
if(TouchPadGestureHandler.ctrlDown) LiSendKeyboardEvent(CommandManager.keyboardButtonMappings[@"CTRL"].shortValue,KEY_ACTION_UP,0);
|
if(TouchPadGestureHandler.ctrlDown) LiSendKeyboardEvent(CommandManager.keyboardButtonMappings[@"CTRL"].shortValue,KEY_ACTION_UP,0);
|
||||||
|
|
||||||
|
[TouchPadGestureHandler startInertialScroll];
|
||||||
|
|
||||||
if(multiTouchesDetected){
|
if(multiTouchesDetected){
|
||||||
if([UITouchUtil touchesIn:streamView from:event].count == touches.count){
|
if([UITouchUtil touchesIn:streamView from:event].count == touches.count){
|
||||||
|
multiTouchesDetected = false;
|
||||||
multiTouchesDetected = false;}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if([UITouchUtil touchesIn:streamView from:event].count == touches.count) multiTouchesDetected = false;
|
if([UITouchUtil touchesIn:streamView from:event].count == touches.count) multiTouchesDetected = false;
|
||||||
|
|||||||
@@ -16,7 +16,21 @@ import UIKit
|
|||||||
@objc public static var enableHorizontalScroll:Bool = true
|
@objc public static var enableHorizontalScroll:Bool = true
|
||||||
@objc public static var scrollSensitivity:CGFloat = 1.0
|
@objc public static var scrollSensitivity:CGFloat = 1.0
|
||||||
@objc public static var pinchSensitivity:CGFloat = 1.0
|
@objc public static var pinchSensitivity:CGFloat = 1.0
|
||||||
|
@objc public static var displayLinkRate:CGFloat = 60
|
||||||
|
|
||||||
|
private static var inertialScroller: InertialScroller = InertialScroller(decelerationRate: 0.915, displayLinkRate: displayLinkRate) {
|
||||||
|
if ctrlDown {return}
|
||||||
|
LiSendHighResScrollEvent(Int16(inertialScroller.vector.dy*7*scrollSensitivity))
|
||||||
|
if TouchPadGestureHandler.enableHorizontalScroll {LiSendHighResHScrollEvent(Int16(-inertialScroller.vector.dx*7*scrollSensitivity))}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc public static func startInertialScroll(){
|
||||||
|
inertialScroller.timer?.restart()
|
||||||
|
}
|
||||||
|
|
||||||
@objc public static func handleGesture(in view: UIView, with event: UIEvent) {
|
@objc public static func handleGesture(in view: UIView, with event: UIEvent) {
|
||||||
|
inertialScroller.timer?.pause()
|
||||||
|
|
||||||
let currentTouches = UITouchUtil.touches(in: view, from: event)
|
let currentTouches = UITouchUtil.touches(in: view, from: event)
|
||||||
guard currentTouches.count == 2 else { return }
|
guard currentTouches.count == 2 else { return }
|
||||||
|
|
||||||
@@ -35,14 +49,16 @@ import UIKit
|
|||||||
let midPointDeltaX = midPointVector.dx
|
let midPointDeltaX = midPointVector.dx
|
||||||
let midPointDeltaY = midPointVector.dy
|
let midPointDeltaY = midPointVector.dy
|
||||||
|
|
||||||
|
inertialScroller.vector = CGVector(dx: midPointDeltaX, dy: midPointDeltaY)
|
||||||
|
|
||||||
let originalPinchDelta = currentDistance-previousDistance;
|
let originalPinchDelta = currentDistance-previousDistance;
|
||||||
let pinchDelta = enablePinch ? originalPinchDelta*7*pinchSensitivity : 0;
|
let pinchDelta = enablePinch ? originalPinchDelta*7*pinchSensitivity : 0;
|
||||||
LiSendHighResScrollEvent(Int16(pinchDelta + midPointDeltaY*7*scrollSensitivity))
|
LiSendHighResScrollEvent(Int16(pinchDelta + midPointDeltaY*7*scrollSensitivity))
|
||||||
if enableHorizontalScroll {LiSendHighResHScrollEvent(Int16(-midPointDeltaX*7*scrollSensitivity))}
|
if enableHorizontalScroll {LiSendHighResHScrollEvent(Int16(-midPointDeltaX*7*scrollSensitivity))}
|
||||||
|
|
||||||
if !enablePinch || !ctrlDownForPinch {return};
|
if enablePinch, ctrlDownForPinch {
|
||||||
|
let midPointDelta = hypot(midPointDeltaX, midPointDeltaY)
|
||||||
if abs(originalPinchDelta) > abs(midPointDeltaY)*1.3, abs(originalPinchDelta) > abs(midPointDeltaX)*1.3 {
|
if abs(originalPinchDelta) > midPointDelta*1.3, midPointDelta < 2 {
|
||||||
LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["CTRL"]!, CChar(KEY_ACTION_DOWN), 0)
|
LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["CTRL"]!, CChar(KEY_ACTION_DOWN), 0)
|
||||||
ctrlDown = true
|
ctrlDown = true
|
||||||
} else {
|
} else {
|
||||||
@@ -50,4 +66,5 @@ import UIKit
|
|||||||
ctrlDown = false
|
ctrlDown = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -451,6 +451,7 @@
|
|||||||
TouchPadGestureHandler.ctrlDownForPinch = _settings.ctrlDownForPinch;
|
TouchPadGestureHandler.ctrlDownForPinch = _settings.ctrlDownForPinch;
|
||||||
TouchPadGestureHandler.scrollSensitivity = _settings.scrollSensitivity.floatValue;
|
TouchPadGestureHandler.scrollSensitivity = _settings.scrollSensitivity.floatValue;
|
||||||
TouchPadGestureHandler.pinchSensitivity = _settings.pinchSensitivity.floatValue;
|
TouchPadGestureHandler.pinchSensitivity = _settings.pinchSensitivity.floatValue;
|
||||||
|
TouchPadGestureHandler.displayLinkRate = _settings.framerate.intValue;
|
||||||
|
|
||||||
NSLog(@"frameview gestures: %d", (uint32_t)[self.view.gestureRecognizers count]);
|
NSLog(@"frameview gestures: %d", (uint32_t)[self.view.gestureRecognizers count]);
|
||||||
NSLog(@"streamview gestures: %d", (uint32_t)[_streamView.gestureRecognizers count]);
|
NSLog(@"streamview gestures: %d", (uint32_t)[_streamView.gestureRecognizers count]);
|
||||||
|
|||||||
Reference in new issue
Block a user