Logic improvement for native (absolute) touch
This commit is contained in:
1 parent
42efa1f2c8
commit
1e54c2d16f
1 file changed
+79
-83
@@ -62,9 +62,6 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
self->streamAspectRatio = (float)streamConfig.width / (float)streamConfig.height;
|
self->streamAspectRatio = (float)streamConfig.width / (float)streamConfig.height;
|
||||||
|
|
||||||
settings = [[[DataManager alloc] init] getSettings];
|
settings = [[[DataManager alloc] init] getSettings];
|
||||||
[TouchPointer setPointerVelocityDivider:settings.pointerVelocityModeDivider.floatValue];
|
|
||||||
[TouchPointer setPointerVelocityFactor:settings.touchPointerVelocityFactor.floatValue];
|
|
||||||
[TouchPointer initContextWith:self];
|
|
||||||
|
|
||||||
keysDown = [[NSMutableSet alloc] init];
|
keysDown = [[NSMutableSet alloc] init];
|
||||||
keyInputField = [[KeyboardInputField alloc] initWithFrame:CGRectZero];
|
keyInputField = [[KeyboardInputField alloc] initWithFrame:CGRectZero];
|
||||||
@@ -97,7 +94,10 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
#else
|
#else
|
||||||
// iOS uses RelativeTouchHandler or AbsoluteTouchHandler depending on user preference
|
// iOS uses RelativeTouchHandler or AbsoluteTouchHandler depending on user preference
|
||||||
if (settings.absoluteTouchMode) {
|
if (settings.absoluteTouchMode) {
|
||||||
self->touchHandler = [[AbsoluteTouchHandler alloc] initWithView:self];
|
// self->touchHandler = [[AbsoluteTouchHandler alloc] initWithView:self];
|
||||||
|
[TouchPointer setPointerVelocityDivider:settings.pointerVelocityModeDivider.floatValue];
|
||||||
|
[TouchPointer setPointerVelocityFactor:settings.touchPointerVelocityFactor.floatValue];
|
||||||
|
[TouchPointer initContextWith:self];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
self->touchHandler = [[RelativeTouchHandler alloc] initWithView:self];
|
self->touchHandler = [[RelativeTouchHandler alloc] initWithView:self];
|
||||||
@@ -345,8 +345,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
|
|
||||||
- (void)handleUITouch:(UITouch*)event index:(int)index{
|
- (void)handleUITouch:(UITouch*)event index:(int)index{
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
BOOL pointerVelocityScaleEnabled = (settings.pointerVelocityModeDivider.floatValue != 1.0); // when the divider is 1.0, means 0% of screen shall pass velocity-scaled pointer to sunshine.
|
//BOOL pointerVelocityScaleEnabled = (settings.pointerVelocityModeDivider.floatValue != 1.0); // when the divider is 1.0, means 0% of screen shall pass velocity-scaled pointer to sunshine.
|
||||||
|
|
||||||
// NSLog(@"handleUITouch %ld,%d",(long)event.phase,(uint32_t)event);
|
// NSLog(@"handleUITouch %ld,%d",(long)event.phase,(uint32_t)event);
|
||||||
//#define LI_TOUCH_EVENT_HOVER 0x00
|
//#define LI_TOUCH_EVENT_HOVER 0x00
|
||||||
//#define LI_TOUCH_EVENT_DOWN 0x01
|
//#define LI_TOUCH_EVENT_DOWN 0x01
|
||||||
@@ -358,7 +357,6 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
//#define LI_TOUCH_EVENT_CANCEL_ALL 0x07
|
//#define LI_TOUCH_EVENT_CANCEL_ALL 0x07
|
||||||
//#define LI_ROT_UNKNOWN 0xFFFF
|
//#define LI_ROT_UNKNOWN 0xFFFF
|
||||||
|
|
||||||
|
|
||||||
// UITouchPhaseBegan, // whenever a finger touches the surface.
|
// UITouchPhaseBegan, // whenever a finger touches the surface.
|
||||||
// UITouchPhaseMoved, // whenever a finger moves on the surface.
|
// UITouchPhaseMoved, // whenever a finger moves on the surface.
|
||||||
// UITouchPhaseStationary, // whenever a finger is touching the surface but hasn't moved since the previous event.
|
// UITouchPhaseStationary, // whenever a finger is touching the surface but hasn't moved since the previous event.
|
||||||
@@ -372,29 +370,29 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
case UITouchPhaseBegan://开始触摸
|
case UITouchPhaseBegan://开始触摸
|
||||||
type = LI_TOUCH_EVENT_DOWN;
|
type = LI_TOUCH_EVENT_DOWN;
|
||||||
[TouchPointer populatePointerId:event]; //获取并记录pointerId
|
[TouchPointer populatePointerId:event]; //获取并记录pointerId
|
||||||
if(pointerVelocityScaleEnabled) [TouchPointer populatePointerObjIntoDict:event];
|
if(settings.pointerVelocityModeDivider.floatValue != 1.0) [TouchPointer populatePointerObjIntoDict:event];
|
||||||
break;
|
break;
|
||||||
case UITouchPhaseMoved://移动
|
case UITouchPhaseMoved://移动
|
||||||
case UITouchPhaseStationary:
|
case UITouchPhaseStationary:
|
||||||
type = LI_TOUCH_EVENT_MOVE;
|
type = LI_TOUCH_EVENT_MOVE;
|
||||||
if(pointerVelocityScaleEnabled) [TouchPointer updatePointerObjInDict:event];
|
if(settings.pointerVelocityModeDivider.floatValue != 1.0) [TouchPointer updatePointerObjInDict:event];
|
||||||
break;
|
break;
|
||||||
case UITouchPhaseRegionEntered://停留
|
|
||||||
case UITouchPhaseRegionMoved://停留
|
|
||||||
type = LI_TOUCH_EVENT_HOVER;
|
|
||||||
break;
|
|
||||||
case UITouchPhaseCancelled://触摸取消
|
|
||||||
type = LI_TOUCH_EVENT_CANCEL;
|
|
||||||
[self sendTouchEvent:event touchType:type]; //先发送,再删除
|
|
||||||
[TouchPointer removePointerId:event]; //删除pointerId
|
|
||||||
if(pointerVelocityScaleEnabled) [TouchPointer removePointerObjFromDict:event];
|
|
||||||
return;
|
|
||||||
case UITouchPhaseEnded://触摸结束
|
case UITouchPhaseEnded://触摸结束
|
||||||
type = LI_TOUCH_EVENT_UP;
|
type = LI_TOUCH_EVENT_UP;
|
||||||
[self sendTouchEvent:event touchType:type]; //先发送,再删除
|
[self sendTouchEvent:event touchType:type]; //先发送,再删除
|
||||||
[TouchPointer removePointerId:event]; //删除pointerId
|
[TouchPointer removePointerId:event]; //删除pointerId
|
||||||
if(pointerVelocityScaleEnabled) [TouchPointer removePointerObjFromDict:event];
|
if(settings.pointerVelocityModeDivider.floatValue != 1.0) [TouchPointer removePointerObjFromDict:event];
|
||||||
return;
|
return;
|
||||||
|
case UITouchPhaseCancelled://触摸取消
|
||||||
|
type = LI_TOUCH_EVENT_CANCEL;
|
||||||
|
[self sendTouchEvent:event touchType:type]; //先发送,再删除
|
||||||
|
[TouchPointer removePointerId:event]; //删除pointerId
|
||||||
|
if(settings.pointerVelocityModeDivider.floatValue != 1.0) [TouchPointer removePointerObjFromDict:event];
|
||||||
|
return;
|
||||||
|
case UITouchPhaseRegionEntered://停留
|
||||||
|
case UITouchPhaseRegionMoved://停留
|
||||||
|
type = LI_TOUCH_EVENT_HOVER;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -482,17 +480,6 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
if ([self handleMouseButtonEvent:BUTTON_ACTION_PRESS
|
|
||||||
forTouches:touches
|
|
||||||
withEvent:event]) {
|
|
||||||
// If it's a mouse event, we're done
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log(LOG_D, @"Touch down");
|
|
||||||
|
|
||||||
// Notify of user interaction and start expiration timer
|
|
||||||
[self startInteractionTimer];
|
|
||||||
|
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
if (@available(iOS 13.4, *)) {
|
if (@available(iOS 13.4, *)) {
|
||||||
@@ -512,22 +499,32 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
for (UITouch* touch in touches) {
|
|
||||||
if (touch.type == UITouchTypePencil) {
|
|
||||||
if ([self sendStylusEvent:touch]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TemporarySettings* settings = [[[DataManager alloc] init] getSettings];
|
|
||||||
if (settings.absoluteTouchMode) {
|
|
||||||
[self handleUITouch:touch index:0];
|
|
||||||
|
|
||||||
// return;
|
if (settings.absoluteTouchMode) {
|
||||||
|
for (UITouch* touch in touches) [self handleUITouch:touch index:0];// Native touch (absoluteTouch) first!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
for (UITouch* touch in touches) {
|
||||||
|
if (touch.type == UITouchTypePencil) {
|
||||||
|
if ([self sendStylusEvent:touch]) return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// NSLog(@"touchesBegan - allTouches %lu, pointerSet count %lu",[[event allTouches] count], [pointerIdSet count]);
|
// NSLog(@"touchesBegan - allTouches %lu, pointerSet count %lu",[[event allTouches] count], [pointerIdSet count]);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
if ([self handleMouseButtonEvent:BUTTON_ACTION_PRESS
|
||||||
|
forTouches:touches
|
||||||
|
withEvent:event]) {
|
||||||
|
// If it's a mouse event, we're done
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log(LOG_D, @"Touch down");
|
||||||
|
|
||||||
|
// Notify of user interaction and start expiration timer
|
||||||
|
[self startInteractionTimer];
|
||||||
|
|
||||||
if (![onScreenControls handleTouchDownEvent:touches]) {
|
if (![onScreenControls handleTouchDownEvent:touches]) {
|
||||||
// We still inform the touch handler even if we're going trigger the
|
// We still inform the touch handler even if we're going trigger the
|
||||||
@@ -662,18 +659,18 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
if (@available(iOS 13.4, *)) {
|
if (@available(iOS 13.4, *)) {
|
||||||
for (UITouch* touch in touches) {
|
if (settings.absoluteTouchMode) {
|
||||||
if (touch.type == UITouchTypePencil) {
|
for (UITouch* touch in touches) [self handleUITouch:touch index:0];// Native touch (absoluteTouch) first!
|
||||||
if ([self sendStylusEvent:touch]) {
|
return;
|
||||||
return;
|
}
|
||||||
|
else{
|
||||||
|
for (UITouch* touch in touches) {
|
||||||
|
if (touch.type == UITouchTypePencil) {
|
||||||
|
if ([self sendStylusEvent:touch]) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TemporarySettings* settings = [[[DataManager alloc] init] getSettings];
|
|
||||||
if (settings.absoluteTouchMode) {
|
|
||||||
[self handleUITouch:touch index:0];
|
|
||||||
// return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NSLog(@"touchesMoved - allTouches %lu, pointerSet count %lu",[[event allTouches] count], [pointerIdSet count]);
|
// NSLog(@"touchesMoved - allTouches %lu, pointerSet count %lu",[[event allTouches] count], [pointerIdSet count]);
|
||||||
UITouch *touch = [touches anyObject];
|
UITouch *touch = [touches anyObject];
|
||||||
if (touch.type == UITouchTypeIndirectPointer) {
|
if (touch.type == UITouchTypeIndirectPointer) {
|
||||||
@@ -742,6 +739,22 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
|
#if !TARGET_OS_TV
|
||||||
|
if (@available(iOS 13.4, *)) {
|
||||||
|
if (settings.absoluteTouchMode) {
|
||||||
|
for (UITouch* touch in touches) [self handleUITouch:touch index:0];// Native touch (absoluteTouch) first!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
for (UITouch* touch in touches) {
|
||||||
|
if (touch.type == UITouchTypePencil) {
|
||||||
|
if ([self sendStylusEvent:touch]) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// NSLog(@"touchesEnded - allTouches %lu, pointerSet count %lu",[[event allTouches] count], [pointerIdSet count]);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if ([self handleMouseButtonEvent:BUTTON_ACTION_RELEASE
|
if ([self handleMouseButtonEvent:BUTTON_ACTION_RELEASE
|
||||||
forTouches:touches
|
forTouches:touches
|
||||||
withEvent:event]) {
|
withEvent:event]) {
|
||||||
@@ -753,24 +766,6 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
|
|
||||||
hasUserInteracted = YES;
|
hasUserInteracted = YES;
|
||||||
|
|
||||||
#if !TARGET_OS_TV
|
|
||||||
if (@available(iOS 13.4, *)) {
|
|
||||||
for (UITouch* touch in touches) {
|
|
||||||
if (touch.type == UITouchTypePencil) {
|
|
||||||
if ([self sendStylusEvent:touch]) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TemporarySettings* settings = [[[DataManager alloc] init] getSettings];
|
|
||||||
if (settings.absoluteTouchMode) {
|
|
||||||
[self handleUITouch:touch index:0];
|
|
||||||
// return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// NSLog(@"touchesEnded - allTouches %lu, pointerSet count %lu",[[event allTouches] count], [pointerIdSet count]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (![onScreenControls handleTouchUpEvent:touches]) {
|
if (![onScreenControls handleTouchUpEvent:touches]) {
|
||||||
[touchHandler touchesEnded:touches withEvent:event];
|
[touchHandler touchesEnded:touches withEvent:event];
|
||||||
}
|
}
|
||||||
@@ -778,24 +773,25 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
|
|
||||||
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
|
||||||
[touchHandler touchesCancelled:touches withEvent:event];
|
[touchHandler touchesCancelled:touches withEvent:event];
|
||||||
|
#if !TARGET_OS_TV
|
||||||
|
if (@available(iOS 13.4, *)) {
|
||||||
|
if (settings.absoluteTouchMode) {
|
||||||
|
for (UITouch* touch in touches) [self handleUITouch:touch index:0];// Native touch (absoluteTouch) first!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
for (UITouch* touch in touches) {
|
||||||
|
if (touch.type == UITouchTypePencil) {
|
||||||
|
if ([self sendStylusEvent:touch]) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// NSLog(@"touchesCancelled - allTouches %lu, pointerSet count %lu",[[event allTouches] count], [pointerIdSet count]);
|
||||||
|
#endif
|
||||||
[self handleMouseButtonEvent:BUTTON_ACTION_RELEASE
|
[self handleMouseButtonEvent:BUTTON_ACTION_RELEASE
|
||||||
forTouches:touches
|
forTouches:touches
|
||||||
withEvent:event];
|
withEvent:event];
|
||||||
#if !TARGET_OS_TV
|
|
||||||
if (@available(iOS 13.4, *)) {
|
|
||||||
for (UITouch* touch in touches) {
|
|
||||||
if (touch.type == UITouchTypePencil) {
|
|
||||||
[self sendStylusEvent:touch];
|
|
||||||
}
|
|
||||||
// TemporarySettings* settings = [[[DataManager alloc] init] getSettings];
|
|
||||||
if (settings.absoluteTouchMode) {
|
|
||||||
[self handleUITouch:touch index:0];
|
|
||||||
// return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// NSLog(@"touchesCancelled - allTouches %lu, pointerSet count %lu",[[event allTouches] count], [pointerIdSet count]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !TARGET_OS_TV
|
#if !TARGET_OS_TV
|
||||||
|
|||||||
Reference in new issue
Block a user