onScreen touchPad control test
This commit is contained in:
1 parent
8b2470faf8
commit
b5afe1fe29
7 files changed
+109
-23
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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<UITouch>, 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<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();
|
||||
}
|
||||
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)){
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
@class ControllerSupport;
|
||||
@class StreamConfiguration;
|
||||
|
||||
// sending self as an instance to OnScreenButtonView or other related classes
|
||||
@protocol InstanceProviderDelegate <NSObject>
|
||||
- (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<InstanceProviderDelegate> 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<UITouch* >* 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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user