on-screen widget tool icon compatibility

This commit is contained in:
TrueZhuanjia
2025-06-10 21:05:34 +08:00
parent 79a075e338
commit 5fd8a7c587
7 changed files with 152 additions and 41 deletions
+12 -6
View File
@@ -980,6 +980,7 @@ ICAgICAgICAgICAgICA
<state key="normal">
<color key="titleColor" red="0.34534250659999999" green="0.68327885720000003" blue="0.76859849690000004" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<imageReference key="image" image="trash.fill" catalog="system" symbolScale="large"/>
<preferredSymbolConfiguration key="preferredSymbolConfiguration" weight="bold"/>
</state>
<connections>
<action selector="trashCanTapped:" destination="xSZ-i2-Jts" eventType="touchUpInside" id="6s3-Wc-6us"/>
@@ -996,7 +997,7 @@ ICAgICAgICAgICAgICA
<state key="normal">
<color key="titleColor" red="0.34534250659999999" green="0.68327885720000003" blue="0.76859849690000004" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<color key="titleShadowColor" systemColor="systemTealColor"/>
<imageReference key="image" image="arrow.uturn.backward" catalog="system" symbolScale="large"/>
<imageReference key="image" image="arrow.uturn.backward" symbolScale="large"/>
</state>
<connections>
<action selector="undoTapped:" destination="xSZ-i2-Jts" eventType="touchUpInside" id="54z-kO-oCo"/>
@@ -1015,6 +1016,7 @@ ICAgICAgICAgICAgICA
<color key="titleColor" red="0.34534250659999999" green="0.68327885720000003" blue="0.76859849690000004" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<color key="titleShadowColor" systemColor="systemTealColor"/>
<imageReference key="image" image="square.and.arrow.down.fill" catalog="system" symbolScale="large"/>
<preferredSymbolConfiguration key="preferredSymbolConfiguration" weight="bold"/>
</state>
<connections>
<action selector="saveTapped:" destination="xSZ-i2-Jts" eventType="touchUpInside" id="bUV-Ja-Htd"/>
@@ -1034,6 +1036,7 @@ ICAgICAgICAgICAgICA
<state key="normal">
<color key="titleColor" red="0.34534250659999999" green="0.68327885720000003" blue="0.76859849690000004" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<imageReference key="image" image="tray.full.fill" catalog="system" symbolScale="large"/>
<preferredSymbolConfiguration key="preferredSymbolConfiguration" weight="bold"/>
</state>
<connections>
<action selector="loadTapped:" destination="xSZ-i2-Jts" eventType="touchUpInside" id="ZCn-S3-8em"/>
@@ -1055,12 +1058,13 @@ ICAgICAgICAgICAgICA
<state key="normal">
<color key="titleColor" red="0.34534250659404359" green="0.68327885717542713" blue="0.76859849691390991" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<imageReference key="image" image="plus.rectangle.fill.on.rectangle.fill" catalog="system" symbolScale="large"/>
<preferredSymbolConfiguration key="preferredSymbolConfiguration" weight="bold"/>
</state>
<connections>
<action selector="addTapped:" destination="xSZ-i2-Jts" eventType="touchUpInside" id="y4c-PU-rbS"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="R45-lM-YPl" userLabel="Edit">
<button autoresizesSubviews="NO" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="R45-lM-YPl" userLabel="Edit">
<rect key="frame" x="600" y="0.0" width="230" height="50"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="SpF-xI-pOI"/>
@@ -1069,8 +1073,9 @@ ICAgICAgICAgICAgICA
<color key="tintColor" systemColor="systemTealColor"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal">
<color key="titleColor" red="0.34534250659999999" green="0.68327885720000003" blue="0.76859849690000004" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<imageReference key="image" image="pencil.and.ellipsis.rectangle" catalog="system" symbolScale="large"/>
<color key="titleColor" systemColor="systemTealColor"/>
<color key="titleShadowColor" systemColor="systemTealColor"/>
<imageReference key="image" image="rectangle.and.pencil.and.ellipsis" symbolScale="large"/>
<preferredSymbolConfiguration key="preferredSymbolConfiguration" weight="heavy"/>
</state>
<connections>
@@ -1113,6 +1118,7 @@ ICAgICAgICAgICAgICA
<state key="normal">
<color key="titleColor" red="0.34534250659999999" green="0.68327885720000003" blue="0.76859849690000004" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
<imageReference key="image" image="arrow.left.square.fill" catalog="system" symbolScale="large"/>
<preferredSymbolConfiguration key="preferredSymbolConfiguration" weight="bold"/>
</state>
<connections>
<action selector="closeTapped:" destination="xSZ-i2-Jts" eventType="touchUpInside" id="sc6-Mq-rbQ"/>
@@ -1394,9 +1400,9 @@ ICAgICAgICAgICAgICA
<resources>
<image name="ChevronCompactUp" width="35" height="10"/>
<image name="arrow.left.square.fill" catalog="system" width="128" height="114"/>
<image name="arrow.uturn.backward" catalog="system" width="128" height="113"/>
<image name="pencil.and.ellipsis.rectangle" catalog="system" width="128" height="85"/>
<image name="arrow.uturn.backward" width="19.06089973449707" height="18.594499588012695"/>
<image name="plus.rectangle.fill.on.rectangle.fill" catalog="system" width="128" height="102"/>
<image name="rectangle.and.pencil.and.ellipsis" width="34.681900024414062" height="24.316600799560547"/>
<image name="square.and.arrow.down.fill" catalog="system" width="121" height="128"/>
<image name="trash.fill" catalog="system" width="117" height="128"/>
<image name="tray.full.fill" catalog="system" width="128" height="88"/>
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "arrow.uturn.backward.svg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Generator: Apple Native CoreSVG 341-->
<!DOCTYPE svg
PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 19.0609 18.5945">
<g>
<rect height="18.5945" opacity="0" width="19.0609" x="0" y="0"/>
<path d="M0 6.65839C0 6.9455 0.118749 7.23163 0.340428 7.4453L5.9543 12.9676C6.16074 13.182 6.45859 13.3008 6.71816 13.3008C7.35449 13.3008 7.77011 12.8684 7.77011 12.2639C7.77011 11.9449 7.64706 11.7154 7.46015 11.5223L4.94197 9.07695L2.06678 6.65664L4.94197 4.23184L7.46015 1.78475C7.64706 1.59159 7.77011 1.3621 7.77011 1.0414C7.77011 0.438669 7.35449 0.00625014 6.71816 0.00625014C6.45859 0.00625014 6.16074 0.124999 5.9543 0.339451L0.340428 5.86348C0.118749 6.07715 0 6.36328 0 6.65839ZM8.34922 17.5303C8.34922 18.1178 8.79395 18.5945 9.43476 18.5945L11.7785 18.5945C16.1367 18.5945 18.6996 16.0305 18.6996 12.1303C18.6996 8.25918 16.0789 5.58438 11.6469 5.58438L5.48338 5.58438L1.99784 5.74493C1.4955 5.76973 1.09238 6.14805 1.09238 6.65839C1.09238 7.16073 1.4955 7.53905 1.99784 7.56386L5.48338 7.7244L11.7072 7.7244C14.8527 7.7244 16.5807 9.50761 16.5807 12.0484C16.5807 14.599 14.8527 16.4643 11.7072 16.4643L9.43476 16.4643C8.79395 16.4643 8.34922 16.941 8.34922 17.5303Z" fill="white" fill-opacity="0.85"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "rectangle.and.pencil.and.ellipsis.svg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--Generator: Apple Native CoreSVG 341-->
<!DOCTYPE svg
PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 36.0056 24.9568">
<g>
<rect height="24.9568" opacity="0" width="36.0056" x="0" y="0"/>
<path d="M22.4493 8.98579L6.44943 8.98579C5.34773 8.98579 4.7305 9.61049 4.7305 10.7122L4.7305 17.287C4.7305 18.391 5.34773 19.0157 6.44943 19.0157L26.3953 19.0157C27.4993 19.0157 28.1067 18.391 28.1067 17.287L28.1067 12.5543L31.0713 9.57601C31.1139 9.86235 31.1338 10.1675 31.1338 10.4884L31.1338 17.5034C31.1338 20.4064 29.5072 22.033 26.6042 22.033L6.24053 22.033C3.33983 22.033 1.71085 20.4064 1.71085 17.5034L1.71085 10.4884C1.71085 7.58767 3.33983 5.96615 6.24053 5.96615L25.4749 5.96615Z" fill="white" fill-opacity="0.85"/>
<path d="M23.8762 14.3176L32.1906 5.998L30.0492 3.85654L21.7371 12.1761L20.8295 14.5412C20.6693 14.9827 21.1132 15.3566 21.4996 15.2113ZM32.9035 5.29257L33.8191 4.32711C34.3319 3.7695 34.4261 2.9615 33.896 2.41365L33.5302 2.04498C33.0788 1.58557 32.2455 1.69518 31.7149 2.22064L30.7644 3.15341Z" fill="white" fill-opacity="0.85"/>
<path d="M17.754 15.8646C18.6523 15.8646 19.3892 15.1352 19.3892 14.2368C19.3892 13.3385 18.6523 12.6091 17.754 12.6091C16.8557 12.6091 16.1263 13.3385 16.1263 14.2368C16.1263 15.1352 16.8557 15.8646 17.754 15.8646Z" fill="white" fill-opacity="0.85"/>
<path d="M13.1944 15.8646C14.0927 15.8646 14.8222 15.1352 14.8222 14.2368C14.8222 13.3385 14.0927 12.6091 13.1944 12.6091C12.2961 12.6091 11.5666 13.3385 11.5666 14.2368C11.5666 15.1352 12.2961 15.8646 13.1944 15.8646Z" fill="white" fill-opacity="0.85"/>
<path d="M8.63475 15.8646C9.53306 15.8646 10.2625 15.1352 10.2625 14.2368C10.2625 13.3385 9.53306 12.6091 8.63475 12.6091C7.73643 12.6091 7.00698 13.3385 7.00698 14.2368C7.00698 15.1352 7.73643 15.8646 8.63475 15.8646Z" fill="white" fill-opacity="0.85"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

+20 -3
View File
@@ -44,8 +44,11 @@ import UIKit
@objc public var latestTouchLocation: CGPoint
@objc public var selfViewOnTheRight: Bool = false
@objc public var shape: String = "default"
private var storedCenter: CGPoint = .zero // location from persisted data
@objc public var storedCenter: CGPoint = .zero // location from persisted data
@objc public var initialCenter: CGPoint = .zero // location from persisted data
@objc public var layoutChanges: [CGPoint] = []
private let appWindow: UIView
@@ -235,12 +238,23 @@ import UIKit
*/
storedCenter = position
center = storedCenter
initialCenter = storedCenter;
layoutChanges.append(initialCenter)
}
@objc public func enableRelocationMode(enabled: Bool){
OnScreenWidgetView.editMode = enabled
}
@objc public func undoRelocation(){
guard layoutChanges.count>1 else {return}
UIView.animate(withDuration: 0.2) {
self.center = self.layoutChanges[self.layoutChanges.count-2]
}
storedCenter = center
layoutChanges.removeLast()
}
@objc public func adjustTransparency(alpha: CGFloat){
if alpha != 0 {
self.backgroundAlpha = alpha
@@ -924,7 +938,6 @@ import UIKit
// Touch event handling
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.touchBegan = true
super.touchesBegan(touches, with: event)
self.isMultipleTouchEnabled = self.touchPadString == "MOUSEPAD" // only enable multi-touch in mousePad mode
@@ -1037,7 +1050,6 @@ import UIKit
latestTouchLocation = currentLocation
// center = currentLocation;
//NSLog("x coord: %f, y coord: %f", self.frame.origin.x, self.frame.origin.y)
storedCenter = center // Update initial center for next movement
if OnScreenWidgetView.editMode {
NotificationCenter.default.post(name: Notification.Name("OnScreenWidgetMovedByTouch"), object:self) // inform the layoutOnScreenControl to update guideLines for this widget view
}
@@ -1201,6 +1213,11 @@ import UIKit
}
if OnScreenWidgetView.editMode {
storedCenter = center // Update initial center for next movement
if center != layoutChanges.last {
layoutChanges.append(center)
}
guard let superview = superview else { return }
// Deactivate existing constraints if necessary
@@ -308,41 +308,51 @@
}
- (IBAction) undoTapped:(id)sender {
if ([self.layoutOSC.layoutChanges count] > 0) { // check if there are layout changes to roll back to
OnScreenButtonState *buttonState = [self.layoutOSC.layoutChanges lastObject]; // Get the 'OnScreenButtonState' object that contains the name, position, and visiblity state of the button the user last moved
CALayer *buttonLayer = [self.layoutOSC controllerLayerFromName:buttonState.name]; // get the on screen button layer that corresponds with the 'OnScreenButtonState' object that we retrieved above
/* Set the button's position and visiblity to what it was before the user last moved it */
buttonLayer.position = buttonState.position;
buttonLayer.hidden = buttonState.isHidden;
/* if user is showing or hiding dPad, then show or hide all four dPad button child layers as well since setting the 'hidden' property on the parent CALayer is not automatically setting the individual dPad child CALayers */
if ([buttonLayer.name isEqualToString:@"dPad"]) {
self.layoutOSC._upButton.hidden = buttonState.isHidden;
self.layoutOSC._rightButton.hidden = buttonState.isHidden;
self.layoutOSC._downButton.hidden = buttonState.isHidden;
self.layoutOSC._leftButton.hidden = buttonState.isHidden;
UIAlertController * nothingToUndoAlertController = [UIAlertController alertControllerWithTitle: [LocalizationHelper localizedStringForKey:@"Nothing to Undo"] message: [LocalizationHelper localizedStringForKey: @"There are no changes to undo"] preferredStyle:UIAlertControllerStyleAlert];
[nothingToUndoAlertController addAction:[UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Ok"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[nothingToUndoAlertController dismissViewControllerAnimated:NO completion:nil];
}]];
if(!widgetViewSelected){
if([self.layoutOSC.layoutChanges count] > 0) { // check if there are layout changes to roll back to
OnScreenButtonState *buttonState = [self.layoutOSC.layoutChanges lastObject]; // Get the 'OnScreenButtonState' object that contains the name, position, and visiblity state of the button the user last moved
CALayer *buttonLayer = [self.layoutOSC controllerLayerFromName:buttonState.name]; // get the on screen button layer that corresponds with the 'OnScreenButtonState' object that we retrieved above
/* Set the button's position and visiblity to what it was before the user last moved it */
buttonLayer.position = buttonState.position;
buttonLayer.hidden = buttonState.isHidden;
/* if user is showing or hiding dPad, then show or hide all four dPad button child layers as well since setting the 'hidden' property on the parent CALayer is not automatically setting the individual dPad child CALayers */
if ([buttonLayer.name isEqualToString:@"dPad"]) {
self.layoutOSC._upButton.hidden = buttonState.isHidden;
self.layoutOSC._rightButton.hidden = buttonState.isHidden;
self.layoutOSC._downButton.hidden = buttonState.isHidden;
self.layoutOSC._leftButton.hidden = buttonState.isHidden;
}
/* if user is showing or hiding the left or right analog sticks, then show or hide their corresponding inner analog stick child layers as well since setting the 'hidden' property on the parent analog stick doesn't automatically hide its child inner analog stick CALayer */
if ([buttonLayer.name isEqualToString:@"leftStickBackground"]) {
self.layoutOSC._leftStick.hidden = buttonState.isHidden;
}
if ([buttonLayer.name isEqualToString:@"rightStickBackground"]) {
self.layoutOSC._rightStick.hidden = buttonState.isHidden;
}
[self.layoutOSC.layoutChanges removeLastObject];
[self OSCLayoutChanged]; // will fade the undo button in or out depending on whether there are any further changes to undo
}
/* if user is showing or hiding the left or right analog sticks, then show or hide their corresponding inner analog stick child layers as well since setting the 'hidden' property on the parent analog stick doesn't automatically hide its child inner analog stick CALayer */
if ([buttonLayer.name isEqualToString:@"leftStickBackground"]) {
self.layoutOSC._leftStick.hidden = buttonState.isHidden;
else { // there are no changes to undo. let user know there are no changes to undo
[self presentViewController:nothingToUndoAlertController animated:YES completion:nil];
}
if ([buttonLayer.name isEqualToString:@"rightStickBackground"]) {
self.layoutOSC._rightStick.hidden = buttonState.isHidden;
}
[self.layoutOSC.layoutChanges removeLastObject];
[self OSCLayoutChanged]; // will fade the undo button in or out depending on whether there are any further changes to undo
}
else { // there are no changes to undo. let user know there are no changes to undo
UIAlertController * savedAlertController = [UIAlertController alertControllerWithTitle: [LocalizationHelper localizedStringForKey:@"Nothing to Undo"] message: [LocalizationHelper localizedStringForKey: @"There are no changes to undo"] preferredStyle:UIAlertControllerStyleAlert];
[savedAlertController addAction:[UIAlertAction actionWithTitle:[LocalizationHelper localizedStringForKey:@"Ok"] style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[savedAlertController dismissViewControllerAnimated:NO completion:nil];
}]];
[self presentViewController:savedAlertController animated:YES completion:nil];
else{
NSInteger recordChangesCount = selectedWidgetView.layoutChanges.count;
if(recordChangesCount>1) [selectedWidgetView undoRelocation];
else [self presentViewController:nothingToUndoAlertController animated:YES completion:nil];
self.undoButton.alpha = selectedWidgetView.layoutChanges.count>1 ? 1.0 : 0.3;
}
}
@@ -604,13 +614,20 @@
}
- (void)widgetViewTapped: (NSNotification *)notification{
//self.undoButton.alpha = selectedWidgetView.layoutChanges.count>1 && !CGPointEqualToPoint(selectedWidgetView.layoutChanges.lastObject.CGPointValue, selectedWidgetView.initialCenter)? 1.0 : 0.3;
// receive the selected widgetView obj passed from the notification
OnScreenWidgetView* widgetView = (OnScreenWidgetView* )notification.object;
[self->selectedWidgetView.stickBallLayer removeFromSuperlayer];
[self->selectedWidgetView.crossMarkLayer removeFromSuperlayer];
self->widgetViewSelected = true;
self->controllerLayerSelected = false;
self->selectedWidgetView = widgetView;
self.undoButton.alpha = selectedWidgetView.layoutChanges.count>1 ? 1.0 : 0.3;
[self.layoutOSC updateGuidelinesForOnScreenWidget:self->selectedWidgetView]; // shows guideline immediately when widget is tapped
// setup slider values
[self.widgetSizeSlider setValue: self->selectedWidgetView.widthFactor];
@@ -743,6 +760,8 @@
for (UIView *subview in view.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
button.imageView.image = [button.imageView.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
button.tintColor = [UIColor systemTealColor];
if(!button.imageView.image){
NSLog(@"missing image %d", button==_saveButton);
button.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
@@ -910,6 +929,7 @@
OnScreenWidgetView* widget = notification.object;
[self.view bringSubviewToFront:widget];
trashCanButton.tintColor = [self layerOverlapWithTrashcanButton:widget.layer] ? [UIColor redColor] : trashCanStoryBoardColor;
self.undoButton.alpha = 1.0;
}