diff --git a/VoidLink/Input/CustomTapGestureRecognizer.m b/VoidLink/Input/CustomTapGestureRecognizer.m index c2a0b6e4..d26cc33d 100644 --- a/VoidLink/Input/CustomTapGestureRecognizer.m +++ b/VoidLink/Input/CustomTapGestureRecognizer.m @@ -42,10 +42,11 @@ static CGFloat screenWidthInPoints; if ([[event allTouches] count] == _numberOfTouchesRequired) { _gestureCapturedTime = CACurrentMediaTime(); _gestureCaptured = true; + lowestTouchPointYCoord = 0; for(UITouch *touch in [event allTouches]){ if(lowestTouchPointYCoord < [touch locationInView:self.view].y) lowestTouchPointYCoord = [touch locationInView:self.view].y; + // NSLog(@"lowest point coord: %f, %f", lowestTouchPointYCoord, CACurrentMediaTime()); } - // this mechanism is deprecated. /* if(_numberOfTouchesRequired == 2){ NSArray *twoTouches = [[event allTouches] allObjects]; @@ -55,7 +56,7 @@ static CGFloat screenWidthInPoints; _lowestTouchPointHeight = screenHeightInPoints - lowestTouchPointYCoord; // NSLog(@"gen _lowestTouchPointHeight %f markmark", _lowestTouchPointHeight); if(_immediateTriggering){ - lowestTouchPointYCoord = 0.0; //reset for next recoginition + // lowestTouchPointYCoord = 0.0; //reset for next recoginition self.state = UIGestureRecognizerStateRecognized; return; } @@ -69,11 +70,6 @@ static CGFloat screenWidthInPoints; - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { // [super touchesEnded:touches withEvent:event]; - if(OnScreenWidgetView.tapGestureShallBeCancelled){ - self.state = UIGestureRecognizerStateFailed; - OnScreenWidgetView.tapGestureShallBeCancelled = false; - return; - } if(_immediateTriggering) return; uint8_t allTouchesCount = [[event allTouches] count]; @@ -81,18 +77,40 @@ static CGFloat screenWidthInPoints; _gestureCaptured = false; self.state = UIGestureRecognizerStateFailed; } - else if(_gestureCaptured && allTouchesCount == [touches count] && !_isOnScreenControllerBeingPressed){ //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 widget views in streamframeview + else if(_gestureCaptured && allTouchesCount == [touches count] && !_isOnScreenControllerBeingPressed && ![self isOnScreenWidgetViewBeingPressed]){ //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 widget views in streamframeview _gestureCaptured = false; //reset for next recognition if((CACurrentMediaTime() - _gestureCapturedTime) < _tapDownTimeThreshold){ - lowestTouchPointYCoord = 0.0; //reset for next recognition + // lowestTouchPointYCoord = 0.0; //reset for next recognition self.state = UIGestureRecognizerStateRecognized; // NSLog(@"gen _lowestTouchPointHeight %f markmark touchesEnd", _lowestTouchPointHeight); } } - if (allTouchesCount == [touches count]){ - _isOnScreenControllerBeingPressed = false; // need to reset this flag anyway, when all fingers are lefting - OnScreenWidgetView.tapGestureShallBeCancelled = false; + if (allTouchesCount == [touches count]) _isOnScreenControllerBeingPressed = false; // need to reset this flag anyway, when all fingers are lefting +} + + +// it was a not a perfect choice to code OnScreenWidgetView in Swift... +// 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 widget view instances. but it's basically ok since the number of widgetViews 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)isOnScreenWidgetViewBeingPressed { + 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 widget views based on tapDownTime + bool gotOneWidgetPressed = false; + // the tap gestures are all added to the streamFrameTopLayerView, where all the OnScreenWidgetViews are added. so we can iterate them in this way: + for(UIView* view in self.view.subviews){ + if ([view isKindOfClass:[OnScreenWidgetView class]]) { + OnScreenWidgetView* widgetView = (OnScreenWidgetView*) view; + if(gotOneWidgetPressed && 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 widgetViews. + widgetView.pressed = false; //reset the flag for widgetView + continue; + } + if(widgetView.pressed){ + gotOneWidgetPressed = true; //got one button pressed + if(allFingersTapDownTime <= _tapDownTimeThreshold) widgetView.pressed = false; // reset the flag for current widgetView if tapDowntime is still within the threshold, if not, leave the flag for mouse scroller gesture in relative touch mode. + } + } } + return gotOneWidgetPressed; } @end diff --git a/VoidLink/Input/OnScreenWidgetView.swift b/VoidLink/Input/OnScreenWidgetView.swift index acbf85a5..24c14e6e 100644 --- a/VoidLink/Input/OnScreenWidgetView.swift +++ b/VoidLink/Input/OnScreenWidgetView.swift @@ -30,9 +30,7 @@ import UIKit case button case touchPad } - - @objc static public var tapGestureShallBeCancelled: Bool = false - + @objc public var widgetType: WidgetTypeEnum = WidgetTypeEnum.uninitialized @objc static public var editMode: Bool = false @@ -1190,7 +1188,6 @@ import UIKit override func touchesBegan(_ touches: Set, with event: UIEvent?) { self.touchBegan = true self.firstTouchMoved = false - OnScreenWidgetView.tapGestureShallBeCancelled = true super.touchesBegan(touches, with: event) // self.isMultipleTouchEnabled = self.touchPadString == "MOUSEPAD" // only enable multi-touch in mousePad mode self.isMultipleTouchEnabled = self.widgetType == WidgetTypeEnum.button