newTouchPad test phase2

This commit is contained in:
TrueZhuangjia
2025-01-04 19:48:57 +08:00
parent b99172d932
commit 4074823e4e
5 changed files with 21 additions and 15 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 containOnScreenControllerTaps; // will be set by the onscreencontrol class
@property (nonatomic, assign) bool isOnScreenControllerBeingPressed; // will be set by the onscreencontrol class
//@property (nonatomic, assign) bool haveOnScreenButtonsOnStreamview;
@property (nonatomic, readonly) CGFloat lowestTouchPointHeight;
@property (nonatomic, readonly) bool gestureCaptured;
+4 -4
View File
@@ -33,7 +33,7 @@ static CGFloat screenWidthInPoints;
_immediateTriggering = false;
_tapDownTimeThreshold = 0.3;
_gestureCaptured = false;
_containOnScreenControllerTaps = false;
_isOnScreenControllerBeingPressed = false;
return self;
}
@@ -74,14 +74,14 @@ static CGFloat screenWidthInPoints;
_gestureCaptured = false;
self.state = UIGestureRecognizerStateFailed;
}
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
else if(_gestureCaptured && allTouchesCount == [touches count] && !_isOnScreenControllerBeingPressed && ![self isOnScreenButtonViewBeingPressed]){ //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]) _containOnScreenControllerTaps = false; // need to reset this flag anyway, when all fingers are lefting
if (allTouchesCount == [touches count]) _isOnScreenControllerBeingPressed = false; // need to reset this flag anyway, when all fingers are lefting
}
@@ -89,7 +89,7 @@ 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)containOnScreenButtonTaps {
- (bool)isOnScreenButtonViewBeingPressed {
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;
// the tap gestures are all added to the streamFrameTopLayerView, where all the onScreenButtonViews are added. so we can iterate them in this way:
+11 -5
View File
@@ -246,7 +246,7 @@ import UIKit
super.touchesBegan(touches, with: event)
//self.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 0.7)
OnScreenControls.testMethod();
// OnScreenControls.testMethod();
// RelativeTouchHandler.testMethod();
if !OnScreenButtonView.editMode {
@@ -297,7 +297,7 @@ import UIKit
storedLocation = currentLocation // Update initial center for next movement
}
}
else if true{
if CommandManager.touchPadCmds.contains(self.keyString){
handleTouchPadEvent(touches: touches)
}
}
@@ -323,9 +323,15 @@ import UIKit
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
// self.pressed = false // will be reset outside the class
super.touchesEnded(touches, with: event)
if !OnScreenButtonView.editMode && touches.count == 1 {
self.onScreenControls.clearLeftStickTouchPadFlag()
self.onScreenControls.clearRightStickTouchPadFlag()
if !OnScreenButtonView.editMode && CommandManager.touchPadCmds.contains(self.keyString) && touches.count == 1 {
switch self.keyString {
case "LS_PAD":
self.onScreenControls.clearLeftStickTouchPadFlag()
case "RS_PAD":
self.onScreenControls.clearRightStickTouchPadFlag()
default:
break
}
}
if !OnScreenButtonView.editMode && !self.keyString.contains("+") { // if the command(keystring contains "+", it's a multi-key command rather than a single key button
+1 -1
View File
@@ -1376,7 +1376,7 @@ static float L3_Y;
if ([gesture isKindOfClass:[CustomTapGestureRecognizer class]]) {
// This is a CustomTapGestureRecognizer
CustomTapGestureRecognizer *tapGesture = (CustomTapGestureRecognizer *)gesture;
tapGesture.containOnScreenControllerTaps = true;
tapGesture.isOnScreenControllerBeingPressed = true;
// Perform actions with tapGesture
}
}
+4 -4
View File
@@ -83,7 +83,7 @@ static const float QUICK_TAP_TIME_INTERVAL = 0.2;
}
- (bool)containOnScreenControllerTaps:(NSSet* )touches{
- (bool)isOnScreenControllerBeingPressed:(NSSet* )touches{
for(UITouch* touch in touches){
if([OnScreenControls.touchAddrsCapturedByOnScreenControls containsObject:@((uintptr_t)touch)]) return true;
}
@@ -91,7 +91,7 @@ static const float QUICK_TAP_TIME_INTERVAL = 0.2;
}
- (bool)containOnScreenButtonTaps {
- (bool)isOnScreenButtonViewBeingPressed {
bool gotOneButtonPressed = false;
for(UIView* view in self->streamView.superview.subviews){ // iterates all on-screen button views in StreamFrameView
if ([view isKindOfClass:[OnScreenButtonView class]]) {
@@ -146,7 +146,7 @@ static const float QUICK_TAP_TIME_INTERVAL = 0.2;
touchPointSpawnedAtUpperScreenEdge = false; // reset this flag immediately if we get a touch event passing the check above, this fixes irresponsive touch after closing the command tool menu.
if([[event allTouches] count] == 2 && ![self containOnScreenButtonTaps] && ![self containOnScreenControllerTaps:[event allTouches]]){
if([[event allTouches] count] == 2 && ![self isOnScreenButtonViewBeingPressed] && ![self isOnScreenControllerBeingPressed:[event allTouches]]){
NSLog(@"get in scrolling mode");
isInMouseWheelScrollingMode = true;
return; // if we got 2 touches on the blank area, it's gonna be a mouse scroll touch, and must prevent UITtouch object for mouse pointer being captured & locked
@@ -190,7 +190,7 @@ static const float QUICK_TAP_TIME_INTERVAL = 0.2;
//NSLog(@"%f, touchesMoved callback, is scrolling: %d, touches count: %d", CACurrentMediaTime(), isInMouseWheelScrollingMode, (uint32_t)[touches count]);
if(isInMouseWheelScrollingMode && [[event allTouches] count] == 2 && ![self containOnScreenButtonTaps] && ![self containOnScreenControllerTaps:touches]){
if(isInMouseWheelScrollingMode && [[event allTouches] count] == 2 && ![self isOnScreenButtonViewBeingPressed] && ![self isOnScreenControllerBeingPressed:touches]){
NSSet* twoTouches = [event allTouches];
CGPoint firstLocation = [[[twoTouches allObjects] objectAtIndex:0] locationInView:streamView];
CGPoint secondLocation = [[[twoTouches allObjects] objectAtIndex:1] locationInView:streamView];