downsized widget panel for iphone

This commit is contained in:
TrueZhuanjia committed 2025-06-20 00:35:02 +08:00
1 parent a5bbca55a2
commit 47bae92dd5
13 files changed
+462 -83

No files matched your search

@@ -241,7 +241,7 @@ static CGRect streamViewBounds;
- (bool) updateSelectedProfile:(NSMutableArray *) oscButtonLayers {
NSMutableArray* buttonStatesEncoded = [self convertOnScreenControllerAndButtonsToButtonStates:oscButtonLayers];
NSMutableArray* buttonStatesEncoded = [self convertOnScreenControllerAndWidgetsToButtonStates:oscButtonLayers];
if([self getIndexOfSelectedProfile]==0) return false;
OSCProfile *newProfile = [[OSCProfile alloc] initWithName:[self getSelectedProfile].name
buttonStates:buttonStatesEncoded isSelected:YES]; // create a new 'OSCProfile'. Set the array of encoded button states created above to the 'buttonStates' property of the new profile, along with a 'name'. Set 'isSelected' argument to YES which will set this saved profile as the one that will show up in the game stream view
@@ -258,7 +258,7 @@ static CGRect streamViewBounds;
- (void) saveProfileWithName:(NSString*)name andButtonLayers:(NSMutableArray *)oscButtonLayers {
NSMutableArray* buttonStatesEncoded = [self convertOnScreenControllerAndButtonsToButtonStates:oscButtonLayers];
NSMutableArray* buttonStatesEncoded = [self convertOnScreenControllerAndWidgetsToButtonStates:oscButtonLayers];
OSCProfile *newProfile = [[OSCProfile alloc] initWithName:name
buttonStates:buttonStatesEncoded isSelected:YES]; // create a new 'OSCProfile'. Set the array of encoded button states created above to the 'buttonStates' property of the new profile, along with a 'name'. Set 'isSelected' argument to YES which will set this saved profile as the one that will show up in the game stream view
/* set all saved OSCProfiles 'isSelected' property to NO since the new profile you're adding will be set as the selected profile */
@@ -308,7 +308,7 @@ static CGRect streamViewBounds;
return position;
}
- (NSMutableArray* ) convertOnScreenControllerAndButtonsToButtonStates:(NSMutableArray *) oscButtonLayers {
- (NSMutableArray* ) convertOnScreenControllerAndWidgetsToButtonStates:(NSMutableArray *) oscButtonLayers {
/* iterate through each OSC button the user sees on screen, create an 'OnScreenButtonState' object from each button, encode each object, and then add each object to an array */
/*
NSSet *validPositionButtonNames = [NSSet setWithObjects:
@@ -357,6 +357,7 @@ static CGRect streamViewBounds;
buttonState.heightFactor = widgetView.heightFactor;
buttonState.backgroundAlpha = widgetView.backgroundAlpha;
buttonState.borderWidth = widgetView.borderWidth;
buttonState.vibrationStyle = widgetView.vibrationStyle;
buttonState.sensitivityFactor = widgetView.sensitivityFactor;
buttonState.stickIndicatorOffset = widgetView.stickIndicatorOffset;
buttonState.widgetShape = widgetView.shape;
@@ -37,6 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) CGFloat oscLayerSizeFactor; // for OnScreenController CALayer
@property (nonatomic, assign) CGFloat backgroundAlpha; // for OnScreenController CALayer
@property (nonatomic, assign) uint8_t vibrationStyle; // for OnScreenController CALayer
// @property (nonatomic, assign) BOOL hasValidPosition;
@@ -33,6 +33,7 @@
[encoder encodeObject:self.name forKey:@"name"];
[encoder encodeObject:self.alias forKey:@"alias"];
[encoder encodeInt:self.buttonType forKey:@"buttonType"];
[encoder encodeInt:self.vibrationStyle forKey:@"vibrationStyle"];
[encoder encodeCGPoint:self.position forKey:@"position"];
[encoder encodeBool:self.isHidden forKey:@"isHidden"];
[encoder encodeFloat:self.widthFactor forKey:@"widthFactor"];
@@ -51,6 +52,7 @@
self.name = [decoder decodeObjectForKey:@"name"];
self.alias = [decoder decodeObjectForKey:@"alias"];
self.buttonType = [decoder decodeIntForKey:@"buttonType"];
self.vibrationStyle = [decoder decodeIntForKey:@"vibrationStyle"];
self.position = [decoder decodeCGPointForKey:@"position"];
self.isHidden = [decoder decodeBoolForKey:@"isHidden"];
self.widthFactor = [decoder decodeFloatForKey:@"widthFactor"];
+35 -7
View File
@@ -41,6 +41,7 @@ import UIKit
@objc public var heightFactor: CGFloat = 1.0
@objc public var borderWidth: CGFloat = 0.0
@objc public var backgroundAlpha: CGFloat = 0.5
@objc public var vibrationStyle: Int = 6
@objc public var latestTouchLocation: CGPoint
@objc public var selfViewOnTheRight: Bool = false
@objc public var shape: String = "default"
@@ -50,10 +51,9 @@ import UIKit
private let appWindow: UIView
private var vibrationGenerator = UIImpactFeedbackGenerator(style: .light)
private var vibrationOn: Bool = false
// for all touchPad or buttons hybrid with touchPads
@objc public var hasStickIndicator: Bool = false
@@ -124,6 +124,7 @@ import UIKit
@objc public let buttonDownVisualEffectLayer = CAShapeLayer()
private var buttonDownVisualEffectWidth: CGFloat
@objc init(cmdString: String, buttonLabel: String, shape:String) {
self.cmdString = cmdString
@@ -226,9 +227,25 @@ import UIKit
fatalError("init(coder:) has not been implemented")
}
// ======================================================================================================
@objc public func setVibration(style: Int) {
if #available(iOS 13.0, *) {
vibrationOn = style < UIImpactFeedbackGenerator.FeedbackStyle.rigid.rawValue + 1
} else {
vibrationOn = style < UIImpactFeedbackGenerator.FeedbackStyle.heavy.rawValue + 1
};
vibrationStyle = style;
if #available(iOS 13.0, *) {
print("rigid value \(UIImpactFeedbackGenerator.FeedbackStyle.rigid.rawValue)")
} else {
// Fallback on earlier versions
};
if vibrationOn {
vibrationGenerator = UIImpactFeedbackGenerator(style: UIImpactFeedbackGenerator.FeedbackStyle(rawValue: style) ?? UIImpactFeedbackGenerator.FeedbackStyle.light)
}
}
@objc public func setLocation(position: CGPoint) {
/*
NSLayoutConstraint.activate([
@@ -437,6 +454,12 @@ import UIKit
self.layer.superlayer?.addSublayer(indicatorBorder)
indicatorBorder.position = CGPointMake(CGRectGetMinX(self.frame)+touchBeganLocation.x, CGRectGetMinY(self.frame)+touchBeganLocation.y)
if vibrationOn {
vibrationGenerator.prepare()
vibrationGenerator.impactOccurred()
print("vibrationInstance: \(vibrationGenerator)")
}
return indicatorBorder
}
@@ -787,7 +810,7 @@ import UIKit
}
//==== wholeButtonPress visual effect=============================================
private func buttonDownVisualEffect() {
private func buttonDownEffect() {
// setupBorderLayer()
CATransaction.begin()
CATransaction.setDisableActions(true)
@@ -795,6 +818,11 @@ import UIKit
buttonDownVisualEffectLayer.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame)) // update position every time we press down the button
buttonDownVisualEffectLayer.borderWidth = self.buttonDownVisualEffectWidth // this will show the visual effect
buttonDownVisualEffectLayer.borderColor = moonlightPurple
if vibrationOn {
vibrationGenerator.prepare()
vibrationGenerator.impactOccurred()
print("vibrationInstance: \(vibrationGenerator)")
}
CATransaction.commit()
}
@@ -1019,7 +1047,7 @@ import UIKit
// this will also deal with button events
if self.widgetType == WidgetTypeEnum.button && !self.comboButtonStrings.isEmpty {
self.buttonDownVisualEffect()
self.buttonDownEffect()
self.sendComboButtonsDownEvent(comboStrings: self.comboButtonStrings)
}
@@ -1034,7 +1062,7 @@ import UIKit
}
// here is in edit mode:
else{
self.buttonDownVisualEffect()
self.buttonDownEffect()
NotificationCenter.default.post(name: Notification.Name("OnScreenWidgetViewSelected"),object: self) // inform layout tool controller to fetch button size factors. self will be passed as the object of the notification
}
}
+1
View File
@@ -411,6 +411,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
widgetView.widthFactor = buttonState.widthFactor;
widgetView.heightFactor = buttonState.heightFactor;
widgetView.borderWidth = buttonState.borderWidth;
[widgetView setVibrationWithStyle:buttonState.vibrationStyle];
widgetView.sensitivityFactor = buttonState.sensitivityFactor;
widgetView.stickIndicatorOffset = buttonState.stickIndicatorOffset;
widgetView.minStickOffset = buttonState.minStickOffset;