From 5fc30927a77e2d9f93ad9eec7c4108ec08d0cf46 Mon Sep 17 00:00:00 2001 From: Francesco <100066266+cranci1@users.noreply.github.com> Date: Sat, 17 May 2025 17:13:57 +0200 Subject: [PATCH] =?UTF-8?q?idk=20tf=20is=20this=20=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomPlayer/CustomPlayer.swift | 72 +++++++++---------- .../Helpers/SubtitleSettingsManager.swift | 3 +- .../SettingsSubViews/SettingsViewPlayer.swift | 38 +++++----- 3 files changed, 56 insertions(+), 57 deletions(-) diff --git a/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift b/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift index d6737d8..606ac7e 100644 --- a/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift +++ b/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift @@ -70,7 +70,8 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele var subtitleForegroundColor: String = "white" var subtitleBackgroundEnabled: Bool = true var subtitleFontSize: Double = 20.0 - var subtitleShadowRadius: Double = 1.0 + var subtitleOutlineWidth: Double = 1.0 + var subtitleOutlineColor: String = "black" var subtitlesLoader = VTTSubtitlesLoader() var subtitleStackView: UIStackView! var subtitleLabels: [UILabel] = [] @@ -1352,10 +1353,33 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele : .clear subtitleLabel.layer.cornerRadius = 5 subtitleLabel.clipsToBounds = true - subtitleLabel.layer.shadowColor = UIColor.black.cgColor - subtitleLabel.layer.shadowRadius = CGFloat(subtitleShadowRadius) - subtitleLabel.layer.shadowOpacity = 1.0 - subtitleLabel.layer.shadowOffset = .zero + + if subtitleOutlineWidth > 0 { + let textColor = subtitleUIColor() + let outlineColor = outlineUIColor() + let strokeTextAttributes = [ + NSAttributedString.Key.strokeColor: outlineColor, + NSAttributedString.Key.foregroundColor: textColor, + NSAttributedString.Key.strokeWidth: -CGFloat(subtitleOutlineWidth), + NSAttributedString.Key.font: UIFont.systemFont(ofSize: CGFloat(subtitleFontSize), weight: .bold) + ] as [NSAttributedString.Key : Any] + + if let text = subtitleLabel.text { + subtitleLabel.attributedText = NSAttributedString(string: text, attributes: strokeTextAttributes) + } + } + } + } + + private func outlineUIColor() -> UIColor { + switch subtitleOutlineColor { + case "black": return .black + case "white": return .white + case "yellow": return .yellow + case "green": return .green + case "blue": return .blue + case "red": return .red + default: return .black } } @@ -1729,19 +1753,16 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele UIView.animate(withDuration: 0.25) { self.blackCoverView.alpha = self.isDimmed ? 1.0 : 0.4 - // fade all controls (and lock button) in or out for v in self.controlsToHide { v.alpha = self.isDimmed ? 0 : 1 } self.dimButton.alpha = self.isDimmed ? 0 : 1 self.lockButton.alpha = self.isDimmed ? 0 : 1 - - // switch subtitle constraints just like toggleControls() + self.subtitleBottomToSafeAreaConstraint?.isActive = !self.isControlsVisible self.subtitleBottomToSliderConstraint?.isActive = self.isControlsVisible - + self.view.layoutIfNeeded() } - - // slide the dim-icon over + dimButtonToSlider.isActive = !isDimmed dimButtonToRight.isActive = isDimmed } @@ -2094,30 +2115,6 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele ] let fontSizeMenu = UIMenu(title: "Font Size", children: fontSizeActions) - let shadowActions = [ - UIAction(title: "None") { _ in - SubtitleSettingsManager.shared.update { settings in settings.shadowRadius = 0 } - self.loadSubtitleSettings() - self.updateSubtitleLabelAppearance() - }, - UIAction(title: "Low") { _ in - SubtitleSettingsManager.shared.update { settings in settings.shadowRadius = 1 } - self.loadSubtitleSettings() - self.updateSubtitleLabelAppearance() - }, - UIAction(title: "Medium") { _ in - SubtitleSettingsManager.shared.update { settings in settings.shadowRadius = 3 } - self.loadSubtitleSettings() - self.updateSubtitleLabelAppearance() - }, - UIAction(title: "High") { _ in - SubtitleSettingsManager.shared.update { settings in settings.shadowRadius = 6 } - self.loadSubtitleSettings() - self.updateSubtitleLabelAppearance() - } - ] - let shadowMenu = UIMenu(title: "Shadow Intensity", children: shadowActions) - let backgroundActions = [ UIAction(title: "Toggle") { _ in SubtitleSettingsManager.shared.update { settings in settings.backgroundEnabled.toggle() } @@ -2177,7 +2174,7 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele let delayMenu = UIMenu(title: "Subtitle Delay", children: delayActions + [resetDelayAction]) let subtitleOptionsMenu = UIMenu(title: "Subtitle Options", children: [ - subtitlesToggleAction, colorMenu, fontSizeMenu, shadowMenu, backgroundMenu, paddingMenu, delayMenu + subtitlesToggleAction, colorMenu, fontSizeMenu, backgroundMenu, paddingMenu, delayMenu ]) menuElements = [subtitleOptionsMenu] @@ -2256,7 +2253,8 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele let settings = SubtitleSettingsManager.shared.settings self.subtitleForegroundColor = settings.foregroundColor self.subtitleFontSize = settings.fontSize - self.subtitleShadowRadius = settings.shadowRadius + self.subtitleOutlineColor = settings.outlineColor + self.subtitleOutlineWidth = settings.outlineWidth self.subtitleBackgroundEnabled = settings.backgroundEnabled self.subtitleBottomPadding = settings.bottomPadding self.subtitleDelay = settings.subtitleDelay diff --git a/Sora/Utils/MediaPlayer/CustomPlayer/Helpers/SubtitleSettingsManager.swift b/Sora/Utils/MediaPlayer/CustomPlayer/Helpers/SubtitleSettingsManager.swift index 57e96b3..084b57a 100644 --- a/Sora/Utils/MediaPlayer/CustomPlayer/Helpers/SubtitleSettingsManager.swift +++ b/Sora/Utils/MediaPlayer/CustomPlayer/Helpers/SubtitleSettingsManager.swift @@ -10,7 +10,8 @@ import UIKit struct SubtitleSettings: Codable { var foregroundColor: String = "white" var fontSize: Double = 20.0 - var shadowRadius: Double = 1.0 + var outlineWidth: Double = 1.0 + var outlineColor: String = "white" var backgroundEnabled: Bool = true var bottomPadding: CGFloat = 20.0 var subtitleDelay: Double = 0.0 diff --git a/Sora/Views/SettingsView/SettingsSubViews/SettingsViewPlayer.swift b/Sora/Views/SettingsView/SettingsSubViews/SettingsViewPlayer.swift index 7bce329..4b95267 100644 --- a/Sora/Views/SettingsView/SettingsSubViews/SettingsViewPlayer.swift +++ b/Sora/Views/SettingsView/SettingsSubViews/SettingsViewPlayer.swift @@ -126,13 +126,13 @@ struct SettingsViewPlayer: View { struct SubtitleSettingsSection: View { @State private var foregroundColor: String = SubtitleSettingsManager.shared.settings.foregroundColor @State private var fontSize: Double = SubtitleSettingsManager.shared.settings.fontSize - @State private var shadowRadius: Double = SubtitleSettingsManager.shared.settings.shadowRadius + @State private var outlineWidth: Double = SubtitleSettingsManager.shared.settings.outlineWidth + @State private var outlineColor: String = SubtitleSettingsManager.shared.settings.outlineColor @State private var backgroundEnabled: Bool = SubtitleSettingsManager.shared.settings.backgroundEnabled @State private var bottomPadding: CGFloat = SubtitleSettingsManager.shared.settings.bottomPadding @State private var subtitleDelay: Double = SubtitleSettingsManager.shared.settings.subtitleDelay private let colors = ["white", "yellow", "green", "blue", "red", "purple"] - private let shadowOptions = [0, 1, 3, 6] var body: some View { Section(header: Text("Subtitle Settings")) { @@ -153,23 +153,6 @@ struct SubtitleSettingsSection: View { } } - HStack { - Text("Shadow") - Spacer() - Menu("\(Int(shadowRadius))") { - ForEach(shadowOptions, id: \.self) { option in - Button(action: { - shadowRadius = Double(option) - SubtitleSettingsManager.shared.update { settings in - settings.shadowRadius = Double(option) - } - }) { - Text("\(option)") - } - } - } - } - Toggle("Background Enabled", isOn: $backgroundEnabled) .tint(.accentColor) .onChange(of: backgroundEnabled) { newValue in @@ -189,6 +172,23 @@ struct SubtitleSettingsSection: View { } } + HStack { + Text("Outline Color") + Spacer() + Menu(outlineColor) { + ForEach(colors, id: \.self) { color in + Button(action: { + outlineColor = color + SubtitleSettingsManager.shared.update { settings in + settings.outlineColor = color + } + }) { + Text(color.capitalized) + } + } + } + } + HStack { Text("Bottom Padding:") Spacer()