From b5afe1fe29b66feb1a85dcc27e01470cd9787875 Mon Sep 17 00:00:00 2001 From: TrueZhuangjia Date: Sun, 24 Nov 2024 21:30:23 +0800 Subject: [PATCH] onScreen touchPad control test --- Limelight/Input/ControllerSupport.h | 2 + Limelight/Input/OnScreenButtonView.swift | 41 ++++++++++++++++++-- Limelight/Input/OnScreenControls.h | 16 ++++++++ Limelight/Input/OnScreenControls.m | 48 +++++++++++++++++++++++- Limelight/Input/StreamView.m | 4 ++ Limelight/Moonlight-Bridging-Header.h | 2 +- Moonlight.xcodeproj/project.pbxproj | 19 +--------- 7 files changed, 109 insertions(+), 23 deletions(-) diff --git a/Limelight/Input/ControllerSupport.h b/Limelight/Input/ControllerSupport.h index a805c670..2dc3fb21 100644 --- a/Limelight/Input/ControllerSupport.h +++ b/Limelight/Input/ControllerSupport.h @@ -46,6 +46,8 @@ -(void) setMotionEventState:(uint16_t)controllerNumber motionType:(uint8_t)motionType reportRateHz:(uint16_t)reportRateHz; -(void) setControllerLed:(uint16_t)controllerNumber r:(uint8_t)r g:(uint8_t)g b:(uint8_t)b; +-(uint16_t) getActiveGamepadMask; + +(int) getConnectedGamepadMask:(StreamConfiguration*)streamConfig; -(NSUInteger) getConnectedGamepadCount; diff --git a/Limelight/Input/OnScreenButtonView.swift b/Limelight/Input/OnScreenButtonView.swift index fa78e9cd..00559b7d 100644 --- a/Limelight/Input/OnScreenButtonView.swift +++ b/Limelight/Input/OnScreenButtonView.swift @@ -9,7 +9,17 @@ import UIKit -@objc class OnScreenButtonView: UIView { +@objc class OnScreenButtonView: UIView, InstanceProviderDelegate { + // receiving the OnScreenControls instance from delegate + @objc func getOnScreenControlsInstance(_ sender: Any) { + if let controls = sender as? OnScreenControls { + self.onScreenControls = controls + print("ClassA received OnScreenControls instance: \(controls)") + } else { + print("ClassA received an unknown sender") + } + } + @objc static public var editMode: Bool = false @objc static public var timestampOfButtonBeingDragged: TimeInterval = 0 @objc public var keyLabel: String @@ -19,7 +29,11 @@ import UIKit @objc public var widthFactor: CGFloat @objc public var heightFactor: CGFloat @objc public var backgroundAlpha: CGFloat - + @objc public var latestMousePointerLocation: CGPoint + @objc public var deltaX: CGFloat + @objc public var deltaY: CGFloat + + private var onScreenControls: OnScreenControls private let label: UILabel // private let originalBackgroundColor: UIColor private var storedLocation: CGPoint = .zero @@ -37,6 +51,10 @@ import UIKit self.widthFactor = 1.0 self.heightFactor = 1.0 self.backgroundAlpha = 0.5 + self.latestMousePointerLocation = CGPoint(x: 0, y: 0) + self.deltaX = 0 + self.deltaY = 0 + self.onScreenControls = OnScreenControls() super.init(frame: .zero) setupView() } @@ -205,12 +223,17 @@ import UIKit // Touch event handling override func touchesBegan(_ touches: Set, with event: UIEvent?) { // print("touchDown: %f", CACurrentMediaTime()) + + if(touches.count == 1){ + self.latestMousePointerLocation = (touches.first?.location(in: self))! + } + self.pressed = true super.touchesBegan(touches, with: event) //self.backgroundColor = UIColor(red: 0.0, green: 0.0, blue: 1.0, alpha: 0.7) OnScreenControls.testMethod(); - RelativeTouchHandler.testMethod(); + // RelativeTouchHandler.testMethod(); if !OnScreenButtonView.editMode { // self.backgroundColor = UIColor.systemBlue.withAlphaComponent(0.7) @@ -260,12 +283,24 @@ import UIKit storedLocation = currentLocation // Update initial center for next movement } } + else{ + if touches.count == 1 && false{ + let currentLocation: CGPoint = (touches.first?.location(in: self))! + deltaX = currentLocation.x - self.latestMousePointerLocation.x + deltaY = currentLocation.y - self.latestMousePointerLocation.y + // NSLog("coord test deltaX: %f, deltaY: %f", deltaX, deltaY) + self.onScreenControls.sendLeftStickTouchPadEvent(withDeltaX: deltaX, deltaY: deltaY); + } + } } override func touchesEnded(_ touches: Set, 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(); + } if !OnScreenButtonView.editMode && !self.keyString.contains("+") { // if the command(keystring contains "+", it's a multi-key command rather than a single key button if(CommandManager.mouseButtonMappings.keys.contains(self.keyString)){ diff --git a/Limelight/Input/OnScreenControls.h b/Limelight/Input/OnScreenControls.h index 0f0f7392..39ed8b1d 100644 --- a/Limelight/Input/OnScreenControls.h +++ b/Limelight/Input/OnScreenControls.h @@ -15,6 +15,12 @@ @class ControllerSupport; @class StreamConfiguration; +// sending self as an instance to OnScreenButtonView or other related classes +@protocol InstanceProviderDelegate +- (void)getOnScreenControlsInstance:(id)sender; // Renamed delegate method +@end + + static const float D_PAD_DIST = 10; static const float BUTTON_DIST = 20; @@ -41,6 +47,11 @@ typedef NS_ENUM(NSInteger, OnScreenControlsLevel) { }; + + +@property (nonatomic, weak) id delegate; // Delegate property +- (void)sendInstance; + // @property (nonatomic, assign) CustomTapGestureRecognizer* mouseRightClickTapRecognizer; // this object will be passed to onscreencontrols class for areVirtualControllerTaps flag setting @property (nonatomic, assign) bool isLayingOut; //@property (nonatomic) NSMutableSet* touchesCapturedByOnScreenButtons; @@ -94,6 +105,11 @@ typedef NS_ENUM(NSInteger, OnScreenControlsLevel) { + (NSMutableSet* )touchAddrsCapturedByOnScreenControls; + (void) testMethod; +- (void) sendRightStickTouchPadEventWithDeltaX:(CGFloat) deltaX deltaY: (CGFloat) deltaY; +- (void) clearRightStickTouchPadFlag; +- (void) sendLeftStickTouchPadEventWithDeltaX:(CGFloat) deltaX deltaY: (CGFloat) deltaY; +- (void) clearLeftStickTouchPadFlag; + - (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport streamConfig:(StreamConfiguration*)streamConfig; - (BOOL) handleTouchDownEvent:(NSSet*)touches; - (BOOL) handleTouchUpEvent:(NSSet*)touches; diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index ff9a12f1..2850e3d9 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -146,6 +146,50 @@ static float L3_Y; NSLog(@"swift calling test"); } +- (void) sendRightStickTouchPadEventWithDeltaX:(CGFloat) deltaX deltaY: (CGFloat) deltaY{ + CGFloat controllerX = 0x7FFE * deltaX / 50; + if(controllerX > 0x7FFE) controllerX = 0x7FFE; + if(controllerX < -0x7FFE) controllerX = -0x7FFE; + CGFloat controllerY = 0x7FFE * deltaY / 50; + if(controllerY > 0x7FFE) controllerY = 0x7FFE; + if(controllerY < -0x7FFE) controllerY = -0x7FFE; + [_controllerSupport updateRightStick:_controller x: controllerX y: - controllerY]; // stick value populated to the controllerSupport here + [_controllerSupport updateFinished:_controller]; +} + +- (void) clearRightStickTouchPadFlag{ + [_controllerSupport updateRightStick:_controller x:0 y:0]; + [_controllerSupport clearButtonFlag:_controller flags:RS_CLK_FLAG]; + [_controllerSupport updateFinished:_controller]; +} + +- (void) sendLeftStickTouchPadEventWithDeltaX:(CGFloat) deltaX deltaY: (CGFloat) deltaY{ + CGFloat controllerX = 0x7FFE * deltaX / 50; + if(controllerX > 0x7FFE) controllerX = 0x7FFE; + if(controllerX < -0x7FFE) controllerX = -0x7FFE; + CGFloat controllerY = 0x7FFE * deltaY / 50; + if(controllerY > 0x7FFE) controllerY = 0x7FFE; + if(controllerY < -0x7FFE) controllerY = -0x7FFE; + [_controllerSupport updateLeftStick:_controller x: controllerX y: - controllerY]; // stick value populated to the controllerSupport here + [_controllerSupport updateFinished:_controller]; +} + +- (void) clearLeftStickTouchPadFlag{ + [_controllerSupport updateLeftStick:_controller x:0 y:0]; + [_controllerSupport clearButtonFlag:_controller flags:LS_CLK_FLAG]; + [_controllerSupport updateFinished:_controller]; +} + + +// sending self as an instance to OnScreenButtonView +- (void)sendInstance{ + NSLog(@"OnScreenControls is sending its instance..."); + if ([self.delegate respondsToSelector:@selector(getOnScreenControlsInstance:)]) { + [self.delegate getOnScreenControlsInstance:self]; + } else { + NSLog(@"Delegate not set or does not respond to getOnScreenControlsInstance:"); + } +} - (id) initWithView:(UIView*)view controllerSup:(ControllerSupport*)controllerSupport streamConfig:(StreamConfiguration*)streamConfig { self = [self init]; @@ -1021,7 +1065,9 @@ static float L3_Y; if (fabsf(yStickVal) < STICK_DEAD_ZONE) yStickVal = 0; [_controllerSupport updateRightStick:_controller x:0x7FFE * xStickVal y:0x7FFE * -yStickVal]; // stick value populated to the controllerSupport here - + NSLog(@"rStickValue, x: %f, y: %f", 0x7FFE * xStickVal, 0x7FFE * yStickVal); + NSLog(@"real controlled instance: %@", self); + updated = true; } else if (touch == _dpadTouch) { [_controllerSupport clearButtonFlag:_controller diff --git a/Limelight/Input/StreamView.m b/Limelight/Input/StreamView.m index c39126ad..70a49db2 100644 --- a/Limelight/Input/StreamView.m +++ b/Limelight/Input/StreamView.m @@ -382,6 +382,10 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5; OnScreenButtonState* buttonState = [NSKeyedUnarchiver unarchivedObjectOfClass:[OnScreenButtonState class] fromData:buttonStateEncoded error:nil]; if(buttonState.buttonType == KeyboardOrMouseButton){ OnScreenButtonView* buttonView = [[OnScreenButtonView alloc] initWithKeyString:buttonState.name keyLabel:buttonState.alias]; //reconstruct buttonView + //-------------------------------------------------- + onScreenControls.delegate = buttonView; // connecting onScreenControls to OnScreenButtonView, sending the active instance for touchPad stick control + [onScreenControls sendInstance]; + //-------------------------------------------------- buttonView.translatesAutoresizingMaskIntoConstraints = NO; // weird but this is mandatory, or you will find no key views added to the right place buttonView.widthFactor = buttonState.widthFactor; buttonView.heightFactor = buttonState.heightFactor; diff --git a/Limelight/Moonlight-Bridging-Header.h b/Limelight/Moonlight-Bridging-Header.h index 40222c8b..f1856fc6 100644 --- a/Limelight/Moonlight-Bridging-Header.h +++ b/Limelight/Moonlight-Bridging-Header.h @@ -4,4 +4,4 @@ #include #import "OnScreenControls.h" -#import "RelativeTouchHandler.h" +// #import "RelativeTouchHandler.h" diff --git a/Moonlight.xcodeproj/project.pbxproj b/Moonlight.xcodeproj/project.pbxproj index 5e3699dd..01400c33 100644 --- a/Moonlight.xcodeproj/project.pbxproj +++ b/Moonlight.xcodeproj/project.pbxproj @@ -25,7 +25,6 @@ 8454AC662C31907F00F0A302 /* iPad.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8454AC682C31907F00F0A302 /* iPad.storyboard */; }; 8454AC6A2C319BDA00F0A302 /* iPhone.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8454AC6C2C319BDA00F0A302 /* iPhone.storyboard */; }; 84591A512BE1625E006AAB10 /* CustomEdgeSlideGestureRecognizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 84591A502BE1625E006AAB10 /* CustomEdgeSlideGestureRecognizer.m */; }; - 8473AE382CED9E3100E7D3FE /* Limelight.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 8473AE262CED9E3100E7D3FE /* Limelight.xcdatamodeld */; }; 84E1CDEC2C4F67D300547904 /* CommandManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E1CDEB2C4F67D300547904 /* CommandManager.swift */; }; 84E1CDEF2C4F688E00547904 /* CommandManagerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E1CDEE2C4F688E00547904 /* CommandManagerViewController.swift */; }; 84E1CDFA2C4FE83400547904 /* SwiftLocalizationHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E1CDF92C4FE83400547904 /* SwiftLocalizationHelper.swift */; }; @@ -159,22 +158,6 @@ 8454AC6D2C319BDA00F0A302 /* mul */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; name = mul; path = mul.lproj/iPhone.xcstrings; sourceTree = ""; }; 84591A4F2BE16240006AAB10 /* CustomEdgeSlideGestureRecognizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomEdgeSlideGestureRecognizer.h; sourceTree = ""; }; 84591A502BE1625E006AAB10 /* CustomEdgeSlideGestureRecognizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomEdgeSlideGestureRecognizer.m; sourceTree = ""; }; - 8473AE272CED9E3100E7D3FE /* Moonlight v1.4.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.4.xcdatamodel"; sourceTree = ""; }; - 8473AE282CED9E3100E7D3FE /* Moonlight v1.10.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.10.xcdatamodel"; sourceTree = ""; }; - 8473AE292CED9E3100E7D3FE /* Limelight.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Limelight.xcdatamodel; sourceTree = ""; }; - 8473AE2A2CED9E3100E7D3FE /* Moonlight v1.8.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.8.xcdatamodel"; sourceTree = ""; }; - 8473AE2B2CED9E3100E7D3FE /* Moonlight v1.1.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.1.xcdatamodel"; sourceTree = ""; }; - 8473AE2C2CED9E3100E7D3FE /* Moonlight v1.2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.2.xcdatamodel"; sourceTree = ""; }; - 8473AE2D2CED9E3100E7D3FE /* Moonlight v1.0-2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.0-2.xcdatamodel"; sourceTree = ""; }; - 8473AE2E2CED9E3100E7D3FE /* Limelight 0.3.1.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Limelight 0.3.1.xcdatamodel"; sourceTree = ""; }; - 8473AE2F2CED9E3100E7D3FE /* Moonlight v1.7.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.7.xcdatamodel"; sourceTree = ""; }; - 8473AE302CED9E3100E7D3FE /* Moonlight v1.0.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.0.xcdatamodel"; sourceTree = ""; }; - 8473AE312CED9E3100E7D3FE /* Moonlight v1.9.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.9.xcdatamodel"; sourceTree = ""; }; - 8473AE322CED9E3100E7D3FE /* Moonlight v1.11.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.11.xcdatamodel"; sourceTree = ""; }; - 8473AE332CED9E3100E7D3FE /* Moonlight v1.5.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.5.xcdatamodel"; sourceTree = ""; }; - 8473AE342CED9E3100E7D3FE /* Limelight 0.3.0.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Limelight 0.3.0.xcdatamodel"; sourceTree = ""; }; - 8473AE352CED9E3100E7D3FE /* Moonlight v1.6.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.6.xcdatamodel"; sourceTree = ""; }; - 8473AE362CED9E3100E7D3FE /* Moonlight v1.3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.3.xcdatamodel"; sourceTree = ""; }; 84D8EB932C5146AD00FC10A9 /* Moonlight-Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Moonlight-Bridging-Header.h"; sourceTree = ""; }; 84E1CDEB2C4F67D300547904 /* CommandManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandManager.swift; sourceTree = ""; }; 84E1CDEE2C4F688E00547904 /* CommandManagerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandManagerViewController.swift; sourceTree = ""; }; @@ -1300,7 +1283,7 @@ "$(PROJECT_DIR)/libs/FFmpeg/lib/iOS-Sim", ); MARKETING_VERSION = 9.0.263; - PRODUCT_BUNDLE_IDENTIFIER = "com.moonlight-trzj.iOS"; + PRODUCT_BUNDLE_IDENTIFIER = "com.moonlight-trzj2.iOS"; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = "";