DS4Touch on-screen widget
This commit is contained in:
1 parent
3536bf06ba
commit
2b11f12763
2 files changed
+62
-15
No files matched your search
@@ -90,6 +90,7 @@ import UIKit
|
|||||||
"OSCDOWN" : DOWN_FLAG,
|
"OSCDOWN" : DOWN_FLAG,
|
||||||
"OSCLEFT" : LEFT_FLAG,
|
"OSCLEFT" : LEFT_FLAG,
|
||||||
"OSCRIGHT" : RIGHT_FLAG,
|
"OSCRIGHT" : RIGHT_FLAG,
|
||||||
|
"DS4TOUCH" : TOUCHPAD_FLAG,
|
||||||
"OSCL2" : 0,
|
"OSCL2" : 0,
|
||||||
"L2" : 0,
|
"L2" : 0,
|
||||||
"LT" : 0,
|
"LT" : 0,
|
||||||
@@ -109,7 +110,7 @@ import UIKit
|
|||||||
"OSCBACK"
|
"OSCBACK"
|
||||||
]
|
]
|
||||||
|
|
||||||
@objc public static let touchPadCmds: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD", "MOUSEPAD", "DPAD", "TRACKBALL", "WASDPAD", "ARROWPAD"]
|
@objc public static let touchPadCmds: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD", "DS4TOUCH", "MOUSEPAD", "DPAD", "TRACKBALL", "WASDPAD", "ARROWPAD"]
|
||||||
@objc public static let stickTouchPads: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD"]
|
@objc public static let stickTouchPads: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD"]
|
||||||
@objc public static let nonVectorStickPads: [String] = ["LSPAD", "RSPAD"]
|
@objc public static let nonVectorStickPads: [String] = ["LSPAD", "RSPAD"]
|
||||||
@objc public static let specialOverlayButtonCmds: [String] = ["SETTINGS"]
|
@objc public static let specialOverlayButtonCmds: [String] = ["SETTINGS"]
|
||||||
|
|||||||
@@ -142,6 +142,10 @@ import UIKit
|
|||||||
private var capturedTouches: NSMutableSet
|
private var capturedTouches: NSMutableSet
|
||||||
private let noTouch: UITouch = UITouch()
|
private let noTouch: UITouch = UITouch()
|
||||||
|
|
||||||
|
//controller touch pad
|
||||||
|
private var pointerIdPool: Set<UInt32>
|
||||||
|
private var pointerIdDict: Dictionary<ObjectIdentifier, UInt32>
|
||||||
|
private var activePointerIds: Set<UInt32>
|
||||||
|
|
||||||
// whole button press down visual effect
|
// whole button press down visual effect
|
||||||
@objc public let buttonDownVisualEffectLayer = CAShapeLayer()
|
@objc public let buttonDownVisualEffectLayer = CAShapeLayer()
|
||||||
@@ -189,6 +193,8 @@ import UIKit
|
|||||||
self.comboButtonStrings = ["OSCL3"]
|
self.comboButtonStrings = ["OSCL3"]
|
||||||
case "RSPAD", "RSVPAD":
|
case "RSPAD", "RSVPAD":
|
||||||
self.comboButtonStrings = ["OSCR3"]
|
self.comboButtonStrings = ["OSCR3"]
|
||||||
|
case "DS4TOUCH":
|
||||||
|
self.comboButtonStrings = ["DS4TOUCH"]
|
||||||
default: break
|
default: break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,6 +239,12 @@ import UIKit
|
|||||||
self.sensitivityFactorX = 1.0
|
self.sensitivityFactorX = 1.0
|
||||||
self.sensitivityFactorY = 1.0
|
self.sensitivityFactorY = 1.0
|
||||||
self.capturedTouches = NSMutableSet()
|
self.capturedTouches = NSMutableSet()
|
||||||
|
self.pointerIdDict = [:]
|
||||||
|
self.pointerIdPool = []
|
||||||
|
for i in 0...10 { // iPadOS supports up to 11 finger touches
|
||||||
|
self.pointerIdPool.insert(UInt32(i))
|
||||||
|
}
|
||||||
|
self.activePointerIds = []
|
||||||
super.init(frame: .zero)
|
super.init(frame: .zero)
|
||||||
|
|
||||||
upIndicator = createLrudDirectionLayer()
|
upIndicator = createLrudDirectionLayer()
|
||||||
@@ -1125,6 +1137,11 @@ import UIKit
|
|||||||
self.sendComboButtonsUpEvent(comboStrings: self.comboButtonStrings)
|
self.sendComboButtonsUpEvent(comboStrings: self.comboButtonStrings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case "DS4TOUCH":
|
||||||
|
if quickDoubleTapDetected {
|
||||||
|
self.l3r3Indicator = self.createAndShowl3r3Indicator()
|
||||||
|
self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -1145,20 +1162,9 @@ import UIKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
if self.widgetType == WidgetTypeEnum.touchPad && self.touchPadString == "DS4TOUCH" {
|
||||||
if !self.buttonString.isEmpty {
|
self.handleControllerTouchesDown(touches: touches)
|
||||||
// if there's no "+" in the keystring, treat it as a regular button:
|
|
||||||
if CommandManager.oscButtonMappings.keys.contains(self.cmdString) {
|
|
||||||
self.sendOscButtonDownEvent(keyString: self.cmdString)
|
|
||||||
}
|
|
||||||
if CommandManager.keyboardButtonMappings.keys.contains(self.cmdString) {
|
|
||||||
LiSendLiSendKeyboardEvent(CommandManager.keyboardButtonMappings[self.cmdString]!,Int8(KEY_ACTION_DOWN), 0)
|
|
||||||
}
|
|
||||||
if CommandManager.mouseButtonMappings.keys.contains(self.cmdString) {
|
|
||||||
LiSendMouseButtonEvent(CChar(BUTTON_ACTION_PRESS), Int32(CommandManager.mouseButtonMappings[self.cmdString]!))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// this will also deal with button events
|
// this will also deal with button events
|
||||||
if self.widgetType == WidgetTypeEnum.button && !self.comboButtonStrings.isEmpty {
|
if self.widgetType == WidgetTypeEnum.button && !self.comboButtonStrings.isEmpty {
|
||||||
@@ -1204,6 +1210,42 @@ import UIKit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func handleControllerTouchesDown(touches: Set<UITouch>) {
|
||||||
|
for touch in touches{
|
||||||
|
let availablePointerIds = pointerIdPool.subtracting(activePointerIds)
|
||||||
|
if let pointerId = availablePointerIds.first {
|
||||||
|
pointerIdDict[ObjectIdentifier(touch)] = pointerId
|
||||||
|
let coordX = touch.location(in: self).x/self.bounds.width
|
||||||
|
let coordY = touch.location(in: self).y/self.bounds.height
|
||||||
|
LiSendControllerTouchEvent(0, UInt8(LI_TOUCH_EVENT_DOWN), pointerId, Float(coordX), Float(coordY), 1)
|
||||||
|
activePointerIds.insert(pointerId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleControllerTouchesMove(touches: Set<UITouch>) {
|
||||||
|
for touch in touches{
|
||||||
|
if let pointerId = pointerIdDict[ObjectIdentifier(touch)] {
|
||||||
|
let coordX = touch.location(in: self).x/self.bounds.width
|
||||||
|
let coordY = touch.location(in: self).y/self.bounds.height
|
||||||
|
LiSendControllerTouchEvent(0, UInt8(LI_TOUCH_EVENT_MOVE), pointerId, Float(coordX), Float(coordY), 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func handleControllerTouchesUp(touches: Set<UITouch>) {
|
||||||
|
for touch in touches{
|
||||||
|
if let pointerId = pointerIdDict[ObjectIdentifier(touch)] {
|
||||||
|
let coordX = touch.location(in: self).x/self.bounds.width
|
||||||
|
let coordY = touch.location(in: self).y/self.bounds.height
|
||||||
|
LiSendControllerTouchEvent(0, UInt8(LI_TOUCH_EVENT_UP), pointerId, Float(coordX), Float(coordY), 1)
|
||||||
|
activePointerIds.remove(pointerId)
|
||||||
|
pointerIdDict.removeValue(forKey: ObjectIdentifier(touch))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private func handleButtonSlidingUp(touches: Set<UITouch>) {
|
private func handleButtonSlidingUp(touches: Set<UITouch>) {
|
||||||
for touch in touches {
|
for touch in touches {
|
||||||
for subview in self.superview?.subviews ?? [] {
|
for subview in self.superview?.subviews ?? [] {
|
||||||
@@ -1296,7 +1338,6 @@ import UIKit
|
|||||||
|
|
||||||
private func handleTouchPadMoveEvent (_ touches: Set<UITouch>, with event: UIEvent?){
|
private func handleTouchPadMoveEvent (_ touches: Set<UITouch>, with event: UIEvent?){
|
||||||
if touches.count == 1{ // don't use event.alltouches.count here, it will counts all touches
|
if touches.count == 1{ // don't use event.alltouches.count here, it will counts all touches
|
||||||
|
|
||||||
switch self.touchPadString{
|
switch self.touchPadString{
|
||||||
case "MOUSEPAD":
|
case "MOUSEPAD":
|
||||||
DispatchQueue.global(qos: .userInteractive).async {
|
DispatchQueue.global(qos: .userInteractive).async {
|
||||||
@@ -1341,6 +1382,9 @@ import UIKit
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if self.widgetType == WidgetTypeEnum.touchPad && self.touchPadString == "DS4TOUCH" {
|
||||||
|
self.handleControllerTouchesMove(touches: touches)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
@@ -1421,6 +1465,8 @@ import UIKit
|
|||||||
self.onScreenControls.releaseControllerButton(RIGHT_FLAG)
|
self.onScreenControls.releaseControllerButton(RIGHT_FLAG)
|
||||||
self.onScreenControls.releaseControllerButton(UP_FLAG)
|
self.onScreenControls.releaseControllerButton(UP_FLAG)
|
||||||
self.onScreenControls.releaseControllerButton(DOWN_FLAG)
|
self.onScreenControls.releaseControllerButton(DOWN_FLAG)
|
||||||
|
case "DS4TOUCH":
|
||||||
|
self.handleControllerTouchesUp(touches: touches)
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user