adjustable onScreenButtonView alpha(transparency)

This commit is contained in:
TrueZhuangjia committed 2024-10-14 15:10:53 +08:00
1 parent 113aaa1b81
commit 8999fd625d
11 files changed
+136 -33

No files matched your search

@@ -286,6 +286,7 @@ static NSMutableDictionary *onScreenButtonViewsDict;
buttonState.timestamp = buttonView.timestamp;
buttonState.widthFactor = buttonView.widthFactor;
buttonState.heightFactor = buttonView.heightFactor;
buttonState.backgroundAlpha = buttonView.backgroundAlpha;
NSData *buttonStateEncoded = [NSKeyedArchiver archivedDataWithRootObject:buttonState requiringSecureCoding:YES error:nil];
[buttonStatesEncoded addObject: buttonStateEncoded];
}];
@@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) CGFloat widthFactor; // for OnScreenButtonView
@property (nonatomic, assign) CGFloat heightFactor; // for OnScreenButtonView
@property (nonatomic, assign) CGFloat oscLayerSizeFactor; // for OnScreenController CALayer
@property (nonatomic, assign) CGFloat backgroundAlpha; // for OnScreenController CALayer
// @property (nonatomic, assign) BOOL hasValidPosition;
@@ -36,6 +36,7 @@
[encoder encodeFloat:self.widthFactor forKey:@"widthFactor"];
[encoder encodeFloat:self.heightFactor forKey:@"heightFactor"];
[encoder encodeFloat:self.oscLayerSizeFactor forKey:@"oscLayerSizeFactor"];
[encoder encodeFloat:self.backgroundAlpha forKey:@"backgroundAlpha"];
}
- (id) initWithCoder:(NSCoder*)decoder {
@@ -49,6 +50,7 @@
self.widthFactor = [decoder decodeFloatForKey:@"widthFactor"];
self.heightFactor = [decoder decodeFloatForKey:@"heightFactor"];
self.oscLayerSizeFactor = [decoder decodeFloatForKey:@"oscLayerSizeFactor"];
self.backgroundAlpha = [decoder decodeFloatForKey:@"backgroundAlpha"];
}
return self;
}
+31 -5
View File
@@ -18,21 +18,24 @@ import UIKit
@objc public var pressed: Bool
@objc public var widthFactor: CGFloat
@objc public var heightFactor: CGFloat
@objc public var backgroundAlpha: CGFloat
private let label: UILabel
private let originalBackgroundColor: UIColor
// private let originalBackgroundColor: UIColor
private var storedLocation: CGPoint = .zero
private let minimumBorderAlpha: CGFloat = 0.19
@objc init(keyString: String, keyLabel: String) {
self.keyString = keyString
self.keyLabel = keyLabel
self.label = UILabel()
self.originalBackgroundColor = UIColor(white: 0.2, alpha: 0.7)
// self.originalBackgroundColor = UIColor(white: 0.2, alpha: 0.7)
self.timestamp = 0
self.pressed = false
self.widthFactor = 1.0
self.heightFactor = 1.0
self.backgroundAlpha = 0.5
super.init(frame: .zero)
setupView()
}
@@ -52,6 +55,23 @@ import UIKit
OnScreenButtonView.editMode = enabled
}
@objc public func adjustButtonTransparency(alpha: CGFloat){
if(alpha != 0){
self.backgroundAlpha = alpha
}
else{
self.backgroundAlpha = 0.5
}
var borderAlpha = 1.5 * self.backgroundAlpha
if(borderAlpha < minimumBorderAlpha){
borderAlpha = minimumBorderAlpha
}
self.backgroundColor = UIColor(white: 0.2, alpha: self.backgroundAlpha)
self.layer.borderColor = UIColor(white: 0.2, alpha: borderAlpha).cgColor
}
@objc public func resizeButtonView(){
guard let superview = superview else { return }
@@ -83,6 +103,8 @@ import UIKit
setupView()
}
@objc public func setupView() {
label.text = self.keyLabel
label.font = UIFont.boldSystemFont(ofSize: 19)
@@ -97,17 +119,21 @@ import UIKit
label.translatesAutoresizingMaskIntoConstraints = false // enable auto alignment for the label
self.translatesAutoresizingMaskIntoConstraints = true // this is mandatory to prevent unexpected key view location change
self.layer.borderColor = UIColor(white: 0.2, alpha: 0.86).cgColor
var borderAlpha = 1.5 * self.backgroundAlpha
if(borderAlpha < minimumBorderAlpha){
borderAlpha = minimumBorderAlpha
}
// if(self.backgroundAlpha * )
self.layer.borderColor = UIColor(white: 0.2, alpha: borderAlpha).cgColor
self.layer.borderWidth = 1
self.layer.cornerRadius = 20
self.backgroundColor = UIColor(white: 0.2, alpha: 0.57)
self.backgroundColor = UIColor(white: 0.2, alpha: self.backgroundAlpha)
self.layer.shadowColor = UIColor.clear.cgColor
self.layer.shadowRadius = 8
self.layer.shadowOpacity = 0.5
addSubview(label)
NSLayoutConstraint.activate([
//self.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width * 0.088),
//self.heightAnchor.constraint(equalToConstant: UIScreen.main.bounds.height * 0.1),
+1 -1
View File
@@ -39,7 +39,7 @@
- (void) reloadOnScreenControlsWith:(ControllerSupport*)controllerSupport
andConfig:(StreamConfiguration*)streamConfig;
- (void) clearOnScreenKeyboardButtons;
- (void) reloadOnScreenKeyboardButtons;
- (void) reloadOnScreenButtonViews;
- (CGSize) getVideoAreaSize;
- (CGPoint) adjustCoordinatesForVideoArea:(CGPoint)point;
+2 -1
View File
@@ -363,7 +363,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
}
}
- (void) reloadOnScreenKeyboardButtons{
- (void) reloadOnScreenButtonViews{
NSLog(@"reload on screen keyboard buttons here");
@@ -389,6 +389,7 @@ static const double X1_MOUSE_SPEED_DIVISOR = 2.5;
[self->streamFrameTopLayerView addSubview:buttonView]; // add keyboard button to the stream frame view. must add it to the target view before setting location.
[buttonView setLocationWithXOffset:buttonState.position.x yOffset:buttonState.position.y];
[buttonView resizeButtonView]; // resize must be called after relocation
[buttonView adjustButtonTransparencyWithAlpha:buttonState.backgroundAlpha];
}
}
}