try to reduce directionPad on-screen widget performance cost
This commit is contained in:
@@ -116,6 +116,7 @@ import UIKit
|
||||
]
|
||||
|
||||
@objc public static let touchPadCmds: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD", "DS4TOUCH", "MOUSEPAD", "DPAD", "TRACKBALL", "WASDPAD", "ARROWPAD"]
|
||||
@objc public static let directionPads: [String] = ["DPAD", "WASDPAD", "ARROWPAD"]
|
||||
@objc public static let stickTouchPads: [String] = ["LSVPAD", "RSVPAD", "LSPAD", "RSPAD"]
|
||||
@objc public static let nonVectorStickPads: [String] = ["LSPAD", "RSPAD"]
|
||||
@objc public static let specialOverlayButtonCmds: [String] = ["SETTINGS"]
|
||||
|
||||
@@ -507,6 +507,7 @@ import UIKit
|
||||
center = storedCenter //anchor the center while resizing self
|
||||
|
||||
setupButtonDownVisualEffectLayer();
|
||||
if CommandManager.directionPads.contains(touchPadString) {setupLrudDirectionIndicatorlayers()}
|
||||
}
|
||||
|
||||
private func createAndShowl3r3Indicator() -> CAShapeLayer{
|
||||
@@ -680,17 +681,31 @@ import UIKit
|
||||
|
||||
//=====LRUD(left right up & down buttons) touchPad touch =========================================
|
||||
|
||||
private func createAndShowLrudBall(at point: CGPoint) -> CAShapeLayer {
|
||||
private func showLrudBall(at point: CGPoint) {
|
||||
// Create a circular path using UIBezierPath
|
||||
CATransaction.begin()
|
||||
CATransaction.setDisableActions(true)
|
||||
|
||||
let path = UIBezierPath(arcCenter: point, radius: 10, startAngle: 0, endAngle: 2 * .pi, clockwise: true)
|
||||
|
||||
// Create a CAShapeLayer
|
||||
lrudIndicatorBall.path = path.cgPath // Assign the circular path to the shape layer
|
||||
|
||||
lrudIndicatorBall.position = CGPointMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame))
|
||||
lrudIndicatorBall.isHidden = false;
|
||||
|
||||
CATransaction.commit()
|
||||
}
|
||||
|
||||
private func createLrudBall() -> CAShapeLayer {
|
||||
// Create a circular path using UIBezierPath
|
||||
let path = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: 10, startAngle: 0, endAngle: 2 * .pi, clockwise: true)
|
||||
|
||||
// Create a CAShapeLayer
|
||||
let ballLayer = CAShapeLayer()
|
||||
ballLayer.path = path.cgPath // Assign the circular path to the shape layer
|
||||
self.layer.superlayer?.addSublayer(ballLayer)
|
||||
|
||||
ballLayer.position = CGPointMake(CGRectGetMinX(self.frame), CGRectGetMinY(self.frame))
|
||||
|
||||
// Set the stroke color and width (border of the circle)
|
||||
ballLayer.strokeColor = stickBallColor
|
||||
ballLayer.lineWidth = 0
|
||||
@@ -698,6 +713,7 @@ import UIKit
|
||||
ballLayer.shadowRadius = 0;
|
||||
ballLayer.shadowOpacity = 0.8
|
||||
ballLayer.name = "lrudBall"
|
||||
ballLayer.isHidden = true
|
||||
|
||||
// Set the fill color (inside of the circle)
|
||||
ballLayer.fillColor = stickBallColor // Light fill with some transparency
|
||||
@@ -726,18 +742,15 @@ import UIKit
|
||||
|
||||
private func showLrudDirectionIndicator(with indicatorLayer:CAShapeLayer){
|
||||
// Add the border layer below the super layer
|
||||
self.layer.superlayer?.insertSublayer(indicatorLayer, below: self.layer)
|
||||
indicatorLayer.borderColor = voidlinkPurple
|
||||
|
||||
// show the indicator based on the touchBeganLocation
|
||||
let newPosition = CGPointMake(CGRectGetMinX(self.frame)+touchBeganLocation.x, CGRectGetMinY(self.frame)+touchBeganLocation.y)
|
||||
|
||||
if indicatorLayer.position != newPosition && vibrationOn {
|
||||
vibrationGenerator.prepare()
|
||||
vibrationGenerator.impactOccurred()
|
||||
// print("vibrationInstance: \(vibrationGenerator)")
|
||||
}
|
||||
|
||||
indicatorLayer.position = newPosition
|
||||
indicatorLayer.position = CGPointMake(CGRectGetMinX(self.frame)+touchBeganLocation.x, CGRectGetMinY(self.frame)+touchBeganLocation.y)
|
||||
|
||||
vibrationGenerator.prepare()
|
||||
vibrationGenerator.impactOccurred()
|
||||
print("vibrationInstance: \(vibrationGenerator)")
|
||||
|
||||
}
|
||||
|
||||
private func handleLrudTouchMove(){
|
||||
@@ -780,8 +793,8 @@ import UIKit
|
||||
}
|
||||
}
|
||||
else{
|
||||
self.upIndicator.removeFromSuperlayer()
|
||||
self.upIndicator.position = CGPointMake(0, 0)
|
||||
//self.upIndicator.removeFromSuperlayer()
|
||||
self.upIndicator.borderColor = UIColor.clear.cgColor
|
||||
switch touchPadString {
|
||||
case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["W"]!,Int8(KEY_ACTION_UP), 0)
|
||||
case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["UP_ARROW"]!,Int8(KEY_ACTION_UP), 0)
|
||||
@@ -799,8 +812,8 @@ import UIKit
|
||||
}
|
||||
}
|
||||
else{
|
||||
self.downIndicator.removeFromSuperlayer()
|
||||
self.downIndicator.position = CGPointMake(0, 0)
|
||||
// self.downIndicator.removeFromSuperlayer()
|
||||
self.downIndicator.borderColor = UIColor.clear.cgColor
|
||||
switch touchPadString {
|
||||
case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["S"]!,Int8(KEY_ACTION_UP), 0)
|
||||
case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["DOWN_ARROW"]!,Int8(KEY_ACTION_UP), 0)
|
||||
@@ -818,8 +831,8 @@ import UIKit
|
||||
}
|
||||
}
|
||||
else{
|
||||
self.leftIndicator.removeFromSuperlayer()
|
||||
self.leftIndicator.position = CGPointMake(0, 0)
|
||||
// self.leftIndicator.removeFromSuperlayer()
|
||||
self.leftIndicator.borderColor = UIColor.clear.cgColor
|
||||
switch touchPadString {
|
||||
case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["A"]!,Int8(KEY_ACTION_UP), 0)
|
||||
case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["LEFT_ARROW"]!,Int8(KEY_ACTION_UP), 0)
|
||||
@@ -837,8 +850,8 @@ import UIKit
|
||||
}
|
||||
}
|
||||
else{
|
||||
self.rightIndicator.removeFromSuperlayer()
|
||||
self.rightIndicator.position = CGPointMake(0, 0)
|
||||
// self.rightIndicator.removeFromSuperlayer()
|
||||
self.rightIndicator.borderColor = UIColor.clear.cgColor
|
||||
switch touchPadString {
|
||||
case "WASDPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["D"]!,Int8(KEY_ACTION_UP), 0)
|
||||
case "ARROWPAD": LiSendKeyboardEvent(CommandManager.keyboardButtonMappings["RIGHT_ARROW"]!,Int8(KEY_ACTION_UP), 0)
|
||||
@@ -949,6 +962,17 @@ import UIKit
|
||||
CATransaction.commit()
|
||||
}
|
||||
|
||||
private func setupLrudDirectionIndicatorlayers() {
|
||||
self.layer.superlayer?.insertSublayer(leftIndicator, below: self.layer);
|
||||
self.layer.superlayer?.insertSublayer(rightIndicator, below: self.layer);
|
||||
self.layer.superlayer?.insertSublayer(upIndicator, below: self.layer);
|
||||
self.layer.superlayer?.insertSublayer(downIndicator, below: self.layer);
|
||||
leftIndicator.borderColor = UIColor.clear.cgColor
|
||||
rightIndicator.borderColor = UIColor.clear.cgColor
|
||||
upIndicator.borderColor = UIColor.clear.cgColor
|
||||
downIndicator.borderColor = UIColor.clear.cgColor
|
||||
self.lrudIndicatorBall = self.createLrudBall()
|
||||
}
|
||||
|
||||
private func setupButtonDownVisualEffectLayer() {
|
||||
self.buttonDownVisualEffectWidth = 8
|
||||
@@ -1136,7 +1160,7 @@ import UIKit
|
||||
self.l3r3Indicator = self.createAndShowl3r3Indicator()
|
||||
self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)}
|
||||
case "DPAD", "WASDPAD", "ARROWPAD":
|
||||
if allCapturedTouchesCount == 1 {self.lrudIndicatorBall = createAndShowLrudBall(at: touchBeganLocation)}
|
||||
if allCapturedTouchesCount == 1 {showLrudBall(at: touchBeganLocation)}
|
||||
if quickDoubleTapDetected {
|
||||
self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)
|
||||
DispatchQueue.global(qos: .userInteractive).async {
|
||||
@@ -1398,6 +1422,9 @@ import UIKit
|
||||
self.touchBegan = false
|
||||
super.touchesEnded(touches, with: event)
|
||||
|
||||
CATransaction.begin()
|
||||
CATransaction.setDisableActions(true)
|
||||
|
||||
// for checking stationary touch points
|
||||
|
||||
if self.touchPadString != "MOUSEPAD" {quickDoubleTapDetected = false} //do not reset this flag here in mousePad mode
|
||||
@@ -1478,16 +1505,16 @@ import UIKit
|
||||
break
|
||||
}
|
||||
}
|
||||
self.l3r3Indicator.removeFromSuperlayer()
|
||||
self.upIndicator.removeFromSuperlayer()
|
||||
self.downIndicator.removeFromSuperlayer()
|
||||
self.leftIndicator.removeFromSuperlayer()
|
||||
self.rightIndicator.removeFromSuperlayer()
|
||||
// self.lrudIndicatorBall.removeFromSuperlayer()
|
||||
for subLayer in self.layer.superlayer?.sublayers ?? [] {
|
||||
if subLayer.name == "lrudBall" {subLayer.removeFromSuperlayer()}
|
||||
}
|
||||
|
||||
self.l3r3Indicator.borderColor = UIColor.clear.cgColor
|
||||
|
||||
if CommandManager.directionPads.contains(touchPadString){
|
||||
self.upIndicator.borderColor = UIColor.clear.cgColor
|
||||
self.downIndicator.borderColor = UIColor.clear.cgColor
|
||||
self.leftIndicator.borderColor = UIColor.clear.cgColor
|
||||
self.rightIndicator.borderColor = UIColor.clear.cgColor
|
||||
self.lrudIndicatorBall.isHidden = true
|
||||
}
|
||||
|
||||
if !OnScreenWidgetView.editMode && !self.cmdString.contains("+") && !self.comboButtonStrings.isEmpty { // if the command(keystring contains "+", it's a legacy multi-key command
|
||||
self.handleButtonSlidingUp(touches: touches)
|
||||
@@ -1505,6 +1532,8 @@ import UIKit
|
||||
}
|
||||
}
|
||||
|
||||
CATransaction.commit()
|
||||
|
||||
if OnScreenWidgetView.editMode {
|
||||
storedCenter = center // Update initial center for next movement
|
||||
if center != layoutChanges.last {
|
||||
@@ -1545,5 +1574,6 @@ import UIKit
|
||||
|
||||
self.handlebuttonUp()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -332,6 +332,7 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit);
|
||||
while (LiPollNextVideoFrame(&handle, &du)) {
|
||||
LiCompleteVideoFrame(handle, DrSubmitDecodeUnit(du));
|
||||
|
||||
/*
|
||||
// Calculate the actual display refresh rate
|
||||
double displayRefreshRate = 1 / (_displayLink.targetTimestamp - _displayLink.timestamp);
|
||||
|
||||
@@ -345,6 +346,7 @@ int DrSubmitDecodeUnit(PDECODE_UNIT decodeUnit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user