-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #116 from 100mslive/1.5.0Release
1.5.0 Release
- Loading branch information
Showing
12 changed files
with
455 additions
and
60 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// BrightnessStripView.swift | ||
// Procreate | ||
// | ||
// Created by Pawan Dixit on 24/09/2022. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct BrightnessStripView: View { | ||
|
||
@Binding var controlValue: CGFloat | ||
let width: CGFloat | ||
@Binding var drawRefresh: Bool | ||
let onFinish: ((CGFloat)->Void)? | ||
|
||
var body: some View { | ||
|
||
let controlColor = Color(UIColor.init(hue: 0.0, saturation: 0.0, brightness: controlValue, alpha: 1.0)) | ||
|
||
PickerControlView(controlValue: $controlValue, drawRefresh: $drawRefresh, onFinish: onFinish, stripWidth: width, stripColors: extremeEndColors, circleColor: controlColor) | ||
} | ||
|
||
private var extremeEndColors: [Color] { | ||
[Color(UIColor.init(hue: 0.0, saturation: 0.0, brightness: 0, alpha: 1.0)), | ||
Color(UIColor.init(hue: 0.0, saturation: 0.0, brightness: 1, alpha: 1.0))] | ||
} | ||
} | ||
|
||
struct BrightnessStripView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
BrightnessStripView(controlValue: .constant(1), width: 600, drawRefresh: .constant(true), onFinish: nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// | ||
// ColorControlsView.swift | ||
// HMSSDKExample | ||
// | ||
// Created by Pawan Dixit on 1/9/24. | ||
// Copyright © 2024 100ms. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
import HMSSDK | ||
|
||
struct ColorControlsView: View { | ||
|
||
let videoFilterPlugin: HMSVideoFilterPlugin | ||
|
||
@Environment(\.presentationMode) var presentationMode | ||
|
||
@State var drawRefresh = false | ||
|
||
var body: some View { | ||
ZStack { | ||
VisualEffectView(effect: UIBlurEffect(style: .systemUltraThinMaterialDark)) | ||
.edgesIgnoringSafeArea(.all) | ||
.opacity(0.01) | ||
|
||
VStack(alignment: .center) { | ||
|
||
Button { | ||
videoFilterPlugin.brightness = HMSVideoFilterPlugin.defaultBrightness | ||
videoFilterPlugin.saturation = HMSVideoFilterPlugin.defaultSaturation | ||
videoFilterPlugin.hue = HMSVideoFilterPlugin.defaultHue | ||
videoFilterPlugin.sharpness = HMSVideoFilterPlugin.defaultSharpness | ||
videoFilterPlugin.redness = HMSVideoFilterPlugin.defaultRedness | ||
videoFilterPlugin.smoothness = HMSVideoFilterPlugin.defaultSmoothness | ||
|
||
drawRefresh.toggle() | ||
} label: { | ||
Text("Reset") | ||
} | ||
|
||
VStack(spacing: 5) { | ||
HueStripView(controlValue: Binding(get: { | ||
videoFilterPlugin.hue | ||
}, set: { | ||
videoFilterPlugin.hue = $0 | ||
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in | ||
}) | ||
Text("Hue") | ||
|
||
} | ||
|
||
VStack(spacing: 5) { | ||
SaturationStripView(controlValue: Binding(get: { | ||
videoFilterPlugin.saturation | ||
}, set: { | ||
videoFilterPlugin.saturation = $0 | ||
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in | ||
}) | ||
Text("Saturation") | ||
|
||
} | ||
|
||
VStack(spacing: 5) { | ||
BrightnessStripView(controlValue: Binding(get: { | ||
videoFilterPlugin.brightness | ||
}, set: { | ||
videoFilterPlugin.brightness = $0 | ||
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in | ||
}) | ||
Text("Brightness") | ||
|
||
} | ||
|
||
VStack(spacing: 5) { | ||
BrightnessStripView(controlValue: Binding(get: { | ||
videoFilterPlugin.sharpness | ||
}, set: { | ||
videoFilterPlugin.sharpness = $0 * 1 | ||
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in | ||
}) | ||
Text("Sharpness") | ||
|
||
} | ||
|
||
VStack(spacing: 5) { | ||
BrightnessStripView(controlValue: Binding(get: { | ||
videoFilterPlugin.redness - 1 | ||
}, set: { | ||
videoFilterPlugin.redness = 1 + $0 | ||
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in | ||
}) | ||
Text("Redness") | ||
|
||
} | ||
|
||
VStack(spacing: 5) { | ||
BrightnessStripView(controlValue: Binding(get: { | ||
videoFilterPlugin.smoothness | ||
}, set: { | ||
videoFilterPlugin.smoothness = $0 * 1 | ||
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in | ||
}) | ||
Text("Smoothness") | ||
|
||
} | ||
|
||
VStack(spacing: 5) { | ||
BrightnessStripView(controlValue: Binding(get: { | ||
videoFilterPlugin.exposure | ||
}, set: { | ||
videoFilterPlugin.exposure = $0 | ||
}), width: 300, drawRefresh: $drawRefresh, onFinish: {_ in | ||
}) | ||
Text("Exposure") | ||
|
||
} | ||
} | ||
.foregroundColor(.white) | ||
.padding() | ||
} | ||
.onTapGesture { | ||
presentationMode.wrappedValue.dismiss() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// HueStripView.swift | ||
// Procreate | ||
// | ||
// Created by Pawan Dixit on 24/09/2022. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct HueStripView: View { | ||
|
||
@Binding var controlValue: CGFloat | ||
let width: CGFloat | ||
@Binding var drawRefresh: Bool | ||
let onFinish: ((CGFloat)->Void)? | ||
|
||
private let gradientColors: [Color] = { | ||
let hueValues = Array(0...359).reversed() | ||
return hueValues.map { | ||
Color(UIColor(hue: CGFloat($0) / 359.0 , | ||
saturation: 1.0, | ||
brightness: 1.0, | ||
alpha: 1.0)) | ||
} | ||
}() | ||
|
||
var body: some View { | ||
|
||
let controlColor = Color(UIColor.init(hue: 1.0 - controlValue, saturation: 1.0, brightness: 1.0, alpha: 1.0)) | ||
|
||
PickerControlView(controlValue: $controlValue, drawRefresh: $drawRefresh, onFinish: onFinish, stripWidth: width, stripColors: gradientColors, circleColor: controlColor) | ||
} | ||
} | ||
|
||
struct HueStripView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
HueStripView(controlValue: .constant(1), width: 600, drawRefresh: .constant(true), onFinish: nil) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// | ||
// ColorPickerView.swift | ||
// Procreate | ||
// | ||
// Created by Pawan Dixit on 23/09/2022. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct PickerControlView: View { | ||
|
||
let precisionFactor = 50.0 | ||
|
||
// Params | ||
@Binding var controlValue: CGFloat | ||
@Binding var drawRefresh: Bool | ||
let onFinish: ((CGFloat)->Void)? | ||
|
||
let stripWidth: CGFloat | ||
let stripColors: [Color] | ||
let circleColor: Color | ||
|
||
// Gesture | ||
@State private var isDragging: Bool = false | ||
@State private var dragControlLocation: CGFloat = .zero | ||
@State private var dragOffset: CGSize = .zero | ||
|
||
// Gesture effects | ||
private var circleWidth: CGFloat { | ||
isDragging ? 35 : 15 | ||
} | ||
|
||
// Normalize gesture between 0 and stripWidth | ||
private func normalizedGestureLocation() -> CGFloat { | ||
var gestureLocation = dragControlLocation + dragOffset.width | ||
|
||
// Normalize with respect to strip width | ||
gestureLocation = max(0, gestureLocation) | ||
gestureLocation = min(gestureLocation, stripWidth) | ||
|
||
return gestureLocation | ||
} | ||
|
||
// Current control value based on current translation within the view | ||
private var currentControlValue: CGFloat { | ||
self.normalizedGestureLocation() / stripWidth | ||
} | ||
|
||
@State var lastTranslation = CGSize.zero | ||
|
||
var body: some View { | ||
|
||
let dragGesture = DragGesture() | ||
.onChanged({ (value) in | ||
|
||
let translation = CGSize(width: value.translation.width - lastTranslation.width, height: value.translation.height - lastTranslation.height) | ||
|
||
lastTranslation = value.translation | ||
|
||
// Use drag in y axis as precision factor for x axis movement | ||
let yDrag = max(1, abs(value.translation.height)/precisionFactor) | ||
dragOffset = CGSize(width: translation.width/yDrag, height: value.translation.height) | ||
|
||
controlValue = currentControlValue | ||
|
||
self.dragControlLocation += self.dragOffset.width | ||
self.dragControlLocation = max(0, self.dragControlLocation) | ||
self.dragControlLocation = min(self.dragControlLocation, stripWidth) | ||
|
||
self.dragOffset = .zero | ||
|
||
withAnimation { | ||
self.isDragging = true | ||
} | ||
}) | ||
.onEnded({ (value) in | ||
|
||
lastTranslation = .zero | ||
|
||
onFinish?(self.controlValue) | ||
|
||
withAnimation { | ||
|
||
self.isDragging = false | ||
} | ||
}) | ||
|
||
ZStack(alignment: .leading) { | ||
LinearGradient(gradient: Gradient(colors: stripColors), | ||
startPoint: .leading, | ||
endPoint: .trailing) | ||
.frame(width: stripWidth, height: 4) | ||
.cornerRadius(5) | ||
.shadow(radius: 8) | ||
|
||
Circle() | ||
.foregroundColor(self.circleColor) | ||
.frame(width: self.circleWidth, height: self.circleWidth, alignment: .center) | ||
.shadow(radius: 5) | ||
.offset(x: self.normalizedGestureLocation() - self.circleWidth / 2, y: 0.0) | ||
|
||
|
||
} | ||
.frame(width: stripWidth, height: 50) | ||
.padding(.horizontal) | ||
.contentShape(Rectangle()) | ||
.gesture(dragGesture) | ||
.onAppear() { | ||
dragControlLocation = controlValue * stripWidth | ||
} | ||
.onChange(of: drawRefresh) { newValue in | ||
dragControlLocation = controlValue * stripWidth | ||
} | ||
} | ||
} | ||
|
||
struct PickerControlView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
PickerControlView(controlValue: .constant(0.5), drawRefresh: .constant(false), onFinish: nil, stripWidth: 600, stripColors: [.white, .red], circleColor: .red) | ||
} | ||
} |
Oops, something went wrong.