optimize _areVirtualControllerTap mechanism, fix onscreen game controller button stuck
This commit is contained in:
commit
9618b7bb94
7 files changed
+30
-14
No files matched your search
@@ -18,9 +18,9 @@
|
|||||||
@property (nonatomic, assign) uint8_t numberOfTouchesRequired;
|
@property (nonatomic, assign) uint8_t numberOfTouchesRequired;
|
||||||
@property (nonatomic, assign) bool immediateTriggering; // if enabled, trigger the signal on touchesBegan stage.
|
@property (nonatomic, assign) bool immediateTriggering; // if enabled, trigger the signal on touchesBegan stage.
|
||||||
@property (nonatomic, assign) double tapDownTimeThreshold; // tap down threshold in seconds.
|
@property (nonatomic, assign) double tapDownTimeThreshold; // tap down threshold in seconds.
|
||||||
|
@property (nonatomic, assign) bool areVirtualControllerTaps; // will be set by the onscreencontrol class
|
||||||
@property (nonatomic, readonly) CGFloat lowestTouchPointHeight;
|
@property (nonatomic, readonly) CGFloat lowestTouchPointHeight;
|
||||||
@property (nonatomic, readonly) bool gestureCaptured;
|
@property (nonatomic, readonly) bool gestureCaptured;
|
||||||
@property (nonatomic, readonly) bool areVirtualControllerTaps;
|
|
||||||
@property (nonatomic, readonly) NSTimeInterval gestureCapturedTime;
|
@property (nonatomic, readonly) NSTimeInterval gestureCapturedTime;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -45,10 +45,11 @@ static CGFloat screenWidthInPoints;
|
|||||||
if(lowestTouchPointYCoord < [touch locationInView:self.view].y) lowestTouchPointYCoord = [touch locationInView:self.view].y;
|
if(lowestTouchPointYCoord < [touch locationInView:self.view].y) lowestTouchPointYCoord = [touch locationInView:self.view].y;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_numberOfTouchesRequired == 2){
|
// this mechanism is deprecated.
|
||||||
|
/* if(_numberOfTouchesRequired == 2){
|
||||||
NSArray *twoTouches = [[event allTouches] allObjects];
|
NSArray *twoTouches = [[event allTouches] allObjects];
|
||||||
_areVirtualControllerTaps = fabs([twoTouches[1] locationInView:self.view].x - [twoTouches[0] locationInView:self.view].x) > screenWidthInPoints/3;
|
_areVirtualControllerTaps = fabs([twoTouches[1] locationInView:self.view].x - [twoTouches[0] locationInView:self.view].x) > screenWidthInPoints/3;
|
||||||
}
|
} */
|
||||||
|
|
||||||
_lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord;
|
_lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord;
|
||||||
if(_immediateTriggering){
|
if(_immediateTriggering){
|
||||||
@@ -67,17 +68,19 @@ static CGFloat screenWidthInPoints;
|
|||||||
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
|
||||||
// [super touchesEnded:touches withEvent:event];
|
// [super touchesEnded:touches withEvent:event];
|
||||||
if(_immediateTriggering) return;
|
if(_immediateTriggering) return;
|
||||||
if([[event allTouches] count] > _numberOfTouchesRequired) {
|
uint8_t allTouchesCount = [[event allTouches] count];
|
||||||
|
if(allTouchesCount > _numberOfTouchesRequired) {
|
||||||
_gestureCaptured = false;
|
_gestureCaptured = false;
|
||||||
self.state = UIGestureRecognizerStateFailed;
|
self.state = UIGestureRecognizerStateFailed;
|
||||||
}
|
}
|
||||||
else if(_gestureCaptured && [[event allTouches] count] == [touches count] && !_areVirtualControllerTaps){ //must exclude virtual controller taps here to prevent stucked button
|
else if(_gestureCaptured && allTouchesCount == [touches count] && !_areVirtualControllerTaps){ //must exclude virtual controller taps here to prevent stucked button, _areVirtualControllerTaps flag is set by onscreencontrols or anyother related classes.
|
||||||
_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;
|
self.state = UIGestureRecognizerStateRecognized;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (allTouchesCount == [touches count]) _areVirtualControllerTaps = false; // need to reset this flag anyway, when all fingers are lefting
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "ControllerSupport.h"
|
#import "ControllerSupport.h"
|
||||||
|
#import "CustomTapGestureRecognizer.h"
|
||||||
#import "OSCProfile.h"
|
#import "OSCProfile.h"
|
||||||
|
|
||||||
@class ControllerSupport;
|
@class ControllerSupport;
|
||||||
@@ -31,6 +32,8 @@ typedef NS_ENUM(NSInteger, OnScreenControlsLevel) {
|
|||||||
OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons
|
OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@property (nonatomic, assign) CustomTapGestureRecognizer* mouseRightClickTapRecognizer; // this object will be passed to onscreencontrols class for areVirtualControllerTaps flag setting
|
||||||
@property CALayer* _aButton;
|
@property CALayer* _aButton;
|
||||||
@property CALayer* _bButton;
|
@property CALayer* _bButton;
|
||||||
@property CALayer* _xButton;
|
@property CALayer* _xButton;
|
||||||
|
|||||||
@@ -1037,6 +1037,8 @@ static float L3_Y;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (updated) {
|
if (updated) {
|
||||||
|
_mouseRightClickTapRecognizer.areVirtualControllerTaps = true; //inform the tap recognizer that this will be a controller tap.
|
||||||
|
|
||||||
[_controllerSupport updateFinished:_controller];
|
[_controllerSupport updateFinished:_controller];
|
||||||
}
|
}
|
||||||
return updated || stickTouch;
|
return updated || stickTouch;
|
||||||
|
|||||||
@@ -8,10 +8,14 @@
|
|||||||
|
|
||||||
#import "StreamView.h"
|
#import "StreamView.h"
|
||||||
#import "DataManager.h"
|
#import "DataManager.h"
|
||||||
|
#import "CustomTapGestureRecognizer.h"
|
||||||
|
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_BEGIN
|
NS_ASSUME_NONNULL_BEGIN
|
||||||
|
|
||||||
@interface RelativeTouchHandler : UIResponder
|
@interface RelativeTouchHandler : UIResponder
|
||||||
|
@property (nonatomic, readonly) CustomTapGestureRecognizer* mouseRightClickTapRecognizer; // this object will be passed to onscreencontrol class for areVirtualControllerTaps flag setting
|
||||||
|
|
||||||
|
|
||||||
- (id)initWithView:(StreamView*)view andSettings:(TemporarySettings*)settings;
|
- (id)initWithView:(StreamView*)view andSettings:(TemporarySettings*)settings;
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "RelativeTouchHandler.h"
|
#import "RelativeTouchHandler.h"
|
||||||
#import "CustomTapGestureRecognizer.h"
|
|
||||||
#import "DataManager.h"
|
#import "DataManager.h"
|
||||||
|
|
||||||
#include <Limelight.h>
|
#include <Limelight.h>
|
||||||
@@ -24,7 +23,6 @@ static const int REFERENCE_HEIGHT = 720;
|
|||||||
BOOL isDragging;
|
BOOL isDragging;
|
||||||
NSTimer* dragTimer;
|
NSTimer* dragTimer;
|
||||||
NSUInteger peakTouchCount;
|
NSUInteger peakTouchCount;
|
||||||
CustomTapGestureRecognizer* rightClickTapRecognizer;
|
|
||||||
|
|
||||||
#if TARGET_OS_TV
|
#if TARGET_OS_TV
|
||||||
UIGestureRecognizer* remotePressRecognizer;
|
UIGestureRecognizer* remotePressRecognizer;
|
||||||
@@ -39,12 +37,12 @@ static const int REFERENCE_HEIGHT = 720;
|
|||||||
self->view = view;
|
self->view = view;
|
||||||
self->currentSettings = settings;
|
self->currentSettings = settings;
|
||||||
// replace righclick recoginizing with my CustomTapGestureRecognizer for better experience, higher recoginizing rate.
|
// replace righclick recoginizing with my CustomTapGestureRecognizer for better experience, higher recoginizing rate.
|
||||||
rightClickTapRecognizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(mouseRightClick)];
|
_mouseRightClickTapRecognizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(mouseRightClick)];
|
||||||
rightClickTapRecognizer.numberOfTouchesRequired = 2;
|
_mouseRightClickTapRecognizer.numberOfTouchesRequired = 2;
|
||||||
rightClickTapRecognizer.tapDownTimeThreshold = RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S; // tap down time in seconds.
|
_mouseRightClickTapRecognizer.tapDownTimeThreshold = RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S; // tap down time in seconds.
|
||||||
rightClickTapRecognizer.delaysTouchesBegan = NO;
|
_mouseRightClickTapRecognizer.delaysTouchesBegan = NO;
|
||||||
rightClickTapRecognizer.delaysTouchesEnded = NO;
|
_mouseRightClickTapRecognizer.delaysTouchesEnded = NO;
|
||||||
[self->view addGestureRecognizer:rightClickTapRecognizer];
|
[self->view addGestureRecognizer:_mouseRightClickTapRecognizer];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -134,7 +132,7 @@ static const int REFERENCE_HEIGHT = 720;
|
|||||||
CGPoint secondLocation = [[[[event allTouches] allObjects] objectAtIndex:1] locationInView:view];
|
CGPoint secondLocation = [[[[event allTouches] allObjects] objectAtIndex:1] locationInView:view];
|
||||||
|
|
||||||
CGPoint avgLocation = CGPointMake((firstLocation.x + secondLocation.x) / 2, (firstLocation.y + secondLocation.y) / 2);
|
CGPoint avgLocation = CGPointMake((firstLocation.x + secondLocation.x) / 2, (firstLocation.y + secondLocation.y) / 2);
|
||||||
if ((CACurrentMediaTime() - rightClickTapRecognizer.gestureCapturedTime > RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S) && touchLocation.y != avgLocation.y) { //prevent sending scrollevent while right click gesture is being recognized. The time threshold is only 150ms, resulting in a barely noticeable delay before the scroll event is activated.
|
if ((CACurrentMediaTime() - _mouseRightClickTapRecognizer.gestureCapturedTime > RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S) && touchLocation.y != avgLocation.y) { //prevent sending scrollevent while right click gesture is being recognized. The time threshold is only 150ms, resulting in a barely noticeable delay before the scroll event is activated.
|
||||||
LiSendHighResScrollEvent((avgLocation.y - touchLocation.y) * 10);
|
LiSendHighResScrollEvent((avgLocation.y - touchLocation.y) * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,12 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
|
|||||||
}
|
}
|
||||||
|
|
||||||
onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport streamConfig:streamConfig];
|
onScreenControls = [[OnScreenControls alloc] initWithView:self controllerSup:controllerSupport streamConfig:streamConfig];
|
||||||
|
// here we pass the tap recognizer to the onscreencontrols obj
|
||||||
|
if (settings.touchMode.intValue == RELATIVE_TOUCH){
|
||||||
|
RelativeTouchHandler* relativeTouchHandler = (RelativeTouchHandler*) touchHandler;
|
||||||
|
onScreenControls.mouseRightClickTapRecognizer = relativeTouchHandler.mouseRightClickTapRecognizer;
|
||||||
|
}
|
||||||
|
|
||||||
OnScreenControlsLevel level = (OnScreenControlsLevel)[settings.onscreenControls integerValue];
|
OnScreenControlsLevel level = (OnScreenControlsLevel)[settings.onscreenControls integerValue];
|
||||||
if (settings.touchMode.intValue != RELATIVE_TOUCH && settings.touchMode.intValue != REGULAR_NATIVE_TOUCH ) {
|
if (settings.touchMode.intValue != RELATIVE_TOUCH && settings.touchMode.intValue != REGULAR_NATIVE_TOUCH ) {
|
||||||
Log(LOG_I, @"On-screen controls disabled in non-relative touch mode");
|
Log(LOG_I, @"On-screen controls disabled in non-relative touch mode");
|
||||||
|
|||||||
Reference in new issue
Block a user