excludes on-screen controller & button taps for mouse scroller gesture in relative touch mode

This commit is contained in:
True Zhuanjia
2024-09-02 22:01:30 +08:00
parent 2b5a1c0551
commit dcdfbc7394
7 changed files with 51 additions and 17 deletions
+1 -1
View File
@@ -18,7 +18,7 @@
@property (nonatomic, assign) uint8_t numberOfTouchesRequired;
@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) bool areOnScreenControllerTaps; // will be set by the onscreencontrol or other related class
@property (nonatomic, assign) bool containOnScreenControllerTaps; // will be set by the onscreencontrol class
//@property (nonatomic, assign) bool haveOnScreenButtonsOnStreamview;
@property (nonatomic, readonly) CGFloat lowestTouchPointHeight;
@property (nonatomic, readonly) bool gestureCaptured;
+7 -7
View File
@@ -33,7 +33,7 @@ static CGFloat screenWidthInPoints;
_immediateTriggering = false;
_tapDownTimeThreshold = 0.3;
_gestureCaptured = false;
_areOnScreenControllerTaps = false;
_containOnScreenControllerTaps = false;
return self;
}
@@ -74,14 +74,14 @@ static CGFloat screenWidthInPoints;
_gestureCaptured = false;
self.state = UIGestureRecognizerStateFailed;
}
else if(_gestureCaptured && allTouchesCount == [touches count] && !_areOnScreenControllerTaps && ![self areOnScreenButtonsTaps]){ //must exclude virtual controller & onscreen button taps here to prevent stucked button, _areVirtualControllerTaps flag is set by onscreencontrols, areOnScreenButtonsTaps will be done by iterating all button views in streamframview
else if(_gestureCaptured && allTouchesCount == [touches count] && !_containOnScreenControllerTaps && ![self containOnScreenButtonTaps]){ //must exclude virtual controller & onscreen button taps here to prevent stucked button, _areVirtualControllerTaps flag is set by onscreencontrols, containOnScreenButtonsTaps will be returned by iterating all button views in streamframeview
_gestureCaptured = false; //reset for next recognition
if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){
lowestTouchPointYCoord = 0.0; //reset for next recognition
self.state = UIGestureRecognizerStateRecognized;
}
}
if (allTouchesCount == [touches count]) _areOnScreenControllerTaps = false; // need to reset this flag anyway, when all fingers are lefting
if (allTouchesCount == [touches count]) _containOnScreenControllerTaps = false; // need to reset this flag anyway, when all fingers are lefting
}
@@ -89,19 +89,19 @@ static CGFloat screenWidthInPoints;
// we're unable to import this class to swift codebase by the bridging header,and have to exlucde the onscreen button taps here
// by iterating every button view instances. but it's basically ok since the number of buttonViews are always limited.
// and this method will only be called when the recognizer is active & and the taps passes all the checks and is about to ge triggered.
- (bool)areOnScreenButtonsTaps {
NSTimeInterval t1 = CACurrentMediaTime();
- (bool)containOnScreenButtonTaps {
NSTimeInterval allFingersTapDownTime = CACurrentMediaTime() - _gestureCapturedTime; //RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S has been passed to this recognizer as _tapDownTimeShreshold, we'll decide how to deal with pressed flag of on-screen button views based on tapDownTime
bool gotOneButtonPressed = false;
for(UIView* view in self.view.subviews){
if ([view isKindOfClass:[OnScreenButtonView class]]) {
OnScreenButtonView* buttonView = (OnScreenButtonView*) view;
if(gotOneButtonPressed){ // once we have just 1 button pressed already, reset pressed flag for the all the buttonViews
if(gotOneButtonPressed && allFingersTapDownTime <= _tapDownTimeThreshold){ // once we have just 1 button pressed already,& the tapDownTime has not exceeded the threshold, we'll reset pressed flag for the all the buttonViews.
buttonView.pressed = false; //reset the flag for buttonView
continue;
}
if(buttonView.pressed){
gotOneButtonPressed = true; //got one button pressed
buttonView.pressed = false; // reset the flag for current buttonView
if(allFingersTapDownTime <= _tapDownTimeThreshold) buttonView.pressed = false; // reset the flag for current buttonView if tapDowntime is still within the threshold, if not, leave the flag for mouse scroller gesture in relative touch mode.
}
}
}
+2 -2
View File
@@ -910,7 +910,7 @@ static float L3_Y;
button.cornerRadius = 45;
// 使用 shadowPath 定义阴影形状和扩展范围
CGFloat spread = 15; // 扩散的大小gggkkkoooovv
CGFloat spread = 15; // 扩散的大小
if([button.name isEqualToString:@"leftStick"] || [button.name isEqualToString:@"rightStick"]) spread = 12;
CGRect largerRect = CGRectInset(button.bounds, -spread, -spread);
UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRoundedRect:largerRect cornerRadius:button.cornerRadius];
@@ -1100,7 +1100,7 @@ static float L3_Y;
if ([gesture isKindOfClass:[CustomTapGestureRecognizer class]]) {
// This is a CustomTapGestureRecognizer
CustomTapGestureRecognizer *tapGesture = (CustomTapGestureRecognizer *)gesture;
tapGesture.areOnScreenControllerTaps = true;
tapGesture.containOnScreenControllerTaps = true;
// Perform actions with tapGesture
}
}
+1
View File
@@ -10,6 +10,7 @@
#import "DataManager.h"
#import "CustomTapGestureRecognizer.h"
#define RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S 0.15
NS_ASSUME_NONNULL_BEGIN
+38 -5
View File
@@ -10,7 +10,6 @@
#import "DataManager.h"
#include <Limelight.h>
#define RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S 0.15
static const int REFERENCE_WIDTH = 1280;
@@ -60,6 +59,37 @@ static const int REFERENCE_HEIGHT = 720;
return self;
}
- (bool)containOnScreenControllerTaps: (NSSet* )touches{
for(UITouch* touch in touches){
if([OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) return true;
}
return false;
}
- (bool)containOnScreenButtonTaps {
bool gotOneButtonPressed = false;
for(UIView* view in self->view.superview.subviews){ // iterates all on-screen button views in StreamFrameView
if ([view isKindOfClass:[OnScreenButtonView class]]) {
OnScreenButtonView* buttonView = (OnScreenButtonView*) view;
if(buttonView.pressed){
gotOneButtonPressed = true; //got one button pressed
}
}
}
return gotOneButtonPressed;
}
- (void)resetAllPressedFlagsForOnscreenButtonViews {
for(UIView* view in self->view.superview.subviews){ // iterates all on-screen button views in StreamFrameView
if ([view isKindOfClass:[OnScreenButtonView class]]) {
OnScreenButtonView* buttonView = (OnScreenButtonView*) view;
buttonView.pressed = false;
}
}
}
- (void)mouseRightClick {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
Log(LOG_D, @"Sending right mouse button press");
@@ -128,11 +158,13 @@ static const int REFERENCE_HEIGHT = 720;
}
} else if ([[event allTouches] count] == 2) { // mouse wheel scroll & right button click are both triggered by 2 finger gesture, some times cause competing (right click fails & scroll view jumps around).
//I'll deal with this in coming code.
CGPoint firstLocation = [[[[event allTouches] allObjects] objectAtIndex:0] locationInView:view];
CGPoint secondLocation = [[[[event allTouches] allObjects] objectAtIndex:1] locationInView:view];
NSSet* twoTouches = [event allTouches];
CGPoint firstLocation = [[[twoTouches allObjects] objectAtIndex:0] locationInView:view];
CGPoint secondLocation = [[[twoTouches allObjects] objectAtIndex:1] locationInView:view];
CGPoint avgLocation = CGPointMake((firstLocation.x + secondLocation.x) / 2, (firstLocation.y + secondLocation.y) / 2);
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.
if ((CACurrentMediaTime() - _mouseRightClickTapRecognizer.gestureCapturedTime > RIGHTCLICK_TAP_DOWN_TIME_THRESHOLD_S) && touchLocation.y != avgLocation.y && ![self containOnScreenButtonTaps] && ![self containOnScreenControllerTaps:twoTouches]) { //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.
// and we must exclude onscreen button taps & on-screen controller taps
LiSendHighResScrollEvent((avgLocation.y - touchLocation.y) * 10);
}
@@ -141,7 +173,6 @@ static const int REFERENCE_HEIGHT = 720;
if ([self isConfirmedMove:firstLocation from:originalLocation]) {
touchMoved = true;
}
touchLocation = avgLocation;
}
}
@@ -193,6 +224,8 @@ static const int REFERENCE_HEIGHT = 720;
// right clicks without moving their other finger.
touchMoved = true;
}
if([[event allTouches] count] == [touches count]) [self resetAllPressedFlagsForOnscreenButtonViews]; // reset all pressed flag for on-screen button views after all fingers lifted from screen.
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
+1 -1
View File
@@ -84,7 +84,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
isInputingText = false;
keyboardToggleRecognizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleKeyboard)];
keyboardToggleRecognizer.numberOfTouchesRequired = settings.keyboardToggleFingers.intValue; //will be changed accordinly by touch modes.
keyboardToggleRecognizer.tapDownTimeThreshold = 0.3; // tap down time threshold in seconds.
keyboardToggleRecognizer.tapDownTimeThreshold = 0.2; // tap down time threshold in seconds.
keyboardToggleRecognizer.delaysTouchesBegan = NO;
keyboardToggleRecognizer.delaysTouchesEnded = NO;
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -67,7 +67,7 @@
if((_settings.touchMode.intValue == RELATIVE_TOUCH || _settings.touchMode.intValue == REGULAR_NATIVE_TOUCH) && _settings.onscreenControls.intValue == OnScreenControlsLevelCustom){
_oscLayoutTapRecoginizer = [[CustomTapGestureRecognizer alloc] initWithTarget:self action:@selector(layoutOSC)];
_oscLayoutTapRecoginizer.numberOfTouchesRequired = _settings.oscLayoutToolFingers.intValue; //tap a predefined number of fingers to open osc layout tool
_oscLayoutTapRecoginizer.tapDownTimeThreshold = 1;
_oscLayoutTapRecoginizer.tapDownTimeThreshold = 0.2;
_oscLayoutTapRecoginizer.delaysTouchesBegan = NO;
_oscLayoutTapRecoginizer.delaysTouchesEnded = NO;