Skip to content

Commit

Permalink
Use DurationDisplayTextField instead of TextField for leftLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
uiryuu committed Jun 12, 2020
1 parent c88c5cf commit cd791c7
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 27 deletions.
2 changes: 1 addition & 1 deletion iina/Base.lproj/Localizable.strings
Expand Up @@ -275,5 +275,5 @@
"touchbar.play_pause" = "Play / Pause";
"touchbar.seek" = "Seek";
"touchbar.time" = "Time Position";
"touchbar.remainingOrTotalTime" = "Remaining Time / Total Time";
"touchbar.remainingTimeOrTotalDuration" = "Remaining Time / Total Duration";
"touchbar.toggle_pip" = "Toggle Picture-in-Picture";
14 changes: 7 additions & 7 deletions iina/Base.lproj/MainWindowController.xib
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16096" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16097" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16096"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16097"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -29,7 +29,7 @@
<outlet property="fragVolumeView" destination="N3B-DL-XOA" id="4VW-Wa-AD7"/>
<outlet property="leftArrowButton" destination="10x-bg-xlj" id="HOT-Yl-7aO"/>
<outlet property="leftArrowLabel" destination="Yg9-Sd-sWy" id="fps-VD-ZgC"/>
<outlet property="leftLabel" destination="NBD-MV-OuG" id="cCh-WT-abz"/>
<outlet property="leftLabel" destination="NBD-MV-OuG" id="0tU-eK-sbp"/>
<outlet property="muteButton" destination="2py-h1-0km" id="baB-6t-gO7"/>
<outlet property="oscBottomMainView" destination="Qmi-hb-0aM" id="PM5-Ic-nvt"/>
<outlet property="oscFloatingBottomView" destination="hb6-oe-rHm" id="ZKe-zm-evE"/>
Expand Down Expand Up @@ -67,7 +67,7 @@
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" tabbingMode="disallowed" id="F0z-JX-Cv5" customClass="MainWindow" customModule="IINA" customModuleProvider="target">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES" fullSizeContentView="YES"/>
<rect key="contentRect" x="196" y="240" width="640" height="400"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/>
<rect key="screenRect" x="0.0" y="0.0" width="3440" height="1417"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="640" height="400"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -384,7 +384,7 @@
<action selector="playSliderChanges:" target="-2" id="UBG-Ky-3rr"/>
</connections>
</slider>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" alphaValue="0.5" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NBD-MV-OuG" userLabel="Left Label">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" alphaValue="0.5" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="NBD-MV-OuG" userLabel="Left Label" customClass="DurationDisplayTextField" customModule="IINA" customModuleProvider="target">
<rect key="frame" x="0.0" y="5" width="50" height="14"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="46" id="CMl-dC-PCr"/>
Expand Down Expand Up @@ -595,8 +595,8 @@
</objects>
<resources>
<image name="mute" width="17" height="14"/>
<image name="ontop" width="16" height="16"/>
<image name="ontop_off" width="16" height="16"/>
<image name="ontop" width="16" height="14"/>
<image name="ontop_off" width="16" height="14"/>
<image name="pause" width="24" height="24"/>
<image name="play" width="24" height="24"/>
<image name="speed" width="24" height="24"/>
Expand Down
10 changes: 5 additions & 5 deletions iina/Base.lproj/MiniPlayerWindowController.xib
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="15705" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="16097" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="15705"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="16097"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -20,7 +20,7 @@
<outlet property="controlView" destination="cDR-8J-QI7" id="B1L-ru-Mnc"/>
<outlet property="controlViewTopConstraint" destination="sJO-Qa-tUh" id="iXu-0b-vwV"/>
<outlet property="defaultAlbumArt" destination="Psi-wJ-2SC" id="oeb-1Z-2ho"/>
<outlet property="leftLabel" destination="9EY-2T-Ebf" id="ICj-Tc-hjF"/>
<outlet property="leftLabel" destination="9EY-2T-Ebf" id="L1e-2I-Mbu"/>
<outlet property="mediaInfoView" destination="Zv7-H8-iOq" id="LrZ-za-HpC"/>
<outlet property="muteButton" destination="5Og-lg-qvH" id="9dA-7h-PGA"/>
<outlet property="playButton" destination="aC9-OK-a4x" id="3Ej-3P-qnY"/>
Expand All @@ -46,7 +46,7 @@
<windowCollectionBehavior key="collectionBehavior" fullScreenNone="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="240" width="300" height="72"/>
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1057"/>
<rect key="screenRect" x="0.0" y="0.0" width="3440" height="1417"/>
<value key="minSize" type="size" width="300" height="72"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="300" height="72"/>
Expand Down Expand Up @@ -86,7 +86,7 @@
<binding destination="-2" name="font" keyPath="monospacedFont" id="TM3-Ri-L7h"/>
</connections>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9EY-2T-Ebf">
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="9EY-2T-Ebf" customClass="DurationDisplayTextField" customModule="IINA" customModuleProvider="target">
<rect key="frame" x="4" y="9" width="36" height="11"/>
<constraints>
<constraint firstAttribute="width" constant="32" id="1iE-QR-s8H"/>
Expand Down
4 changes: 2 additions & 2 deletions iina/DurationDisplayTextField.swift
Expand Up @@ -18,8 +18,9 @@ class DurationDisplayTextField: NSTextField {

var mode: DisplayMode = .duration

/** Switches the display mode for the right label */
/** Switches the display mode between duration and remaining time */
func switchMode() {
guard mode != .current else { return }
switch mode {
case .duration:
mode = .remaining
Expand All @@ -30,7 +31,6 @@ class DurationDisplayTextField: NSTextField {


func updateText(with duration: VideoTime, given current: VideoTime) {

let stringValue: String
switch mode {
case .current:
Expand Down
14 changes: 8 additions & 6 deletions iina/PlayerWindowController.swift
Expand Up @@ -113,7 +113,7 @@ class PlayerWindowController: NSWindowController, NSWindowDelegate {
@IBOutlet weak var playButton: NSButton!
@IBOutlet weak var playSlider: NSSlider!
@IBOutlet weak var rightLabel: DurationDisplayTextField!
@IBOutlet weak var leftLabel: NSTextField!
@IBOutlet weak var leftLabel: DurationDisplayTextField!

/** Differentiate between single clicks and double clicks. */
internal var singleClickTimer: Timer?
Expand Down Expand Up @@ -165,7 +165,8 @@ class PlayerWindowController: NSWindowController, NSWindowDelegate {
addObserver(to: .default, forName: .iinaMediaTitleChanged, object: player) { [unowned self] _ in
self.updateTitle()
}


leftLabel.mode = .current
rightLabel.mode = Preference.bool(for: .showRemainingTime) ? .remaining : .duration

updateVolume()
Expand Down Expand Up @@ -426,14 +427,15 @@ class PlayerWindowController: NSWindowController, NSWindowDelegate {
guard let duration = player.info.videoDuration, let pos = player.info.videoPosition else {
Logger.fatal("video info not available")
}
let percentage = (pos.second / duration.second) * 100
leftLabel.stringValue = pos.stringRepresentation
rightLabel.updateText(with: duration, given: pos)
[leftLabel, rightLabel].forEach { $0.updateText(with: duration, given: pos) }
if #available(macOS 10.12.2, *) {
player.touchBarSupport.touchBarPosLabels.forEach { $0.updateText(with: duration, given: pos) }
}
if andProgressBar {
let percentage = (pos.second / duration.second) * 100
playSlider.doubleValue = percentage
if #available(macOS 10.12.2, *) {
player.touchBarSupport.touchBarPlaySlider?.setDoubleValueSafely(percentage)
player.touchBarSupport.touchBarPosLabels.forEach { $0.updateText(with: duration, given: pos) }
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions iina/TouchBarSupport.swift
Expand Up @@ -27,7 +27,7 @@ fileprivate extension NSTouchBarItem.Identifier {
static let rewind = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.rewind")
static let fastForward = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.forward")
static let time = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.time")
static let remainingOrTotalTime = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.remainingOrTotalTime")
static let remainingTimeOrTotalDuration = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.remainingTimeOrTotalDuration")
static let ahead15Sec = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.ahead15Sec")
static let back15Sec = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.back15Sec")
static let ahead30Sec = NSTouchBarItem.Identifier("\(Bundle.main.bundleIdentifier!).TouchBarItem.ahead30Sec")
Expand Down Expand Up @@ -62,8 +62,8 @@ class TouchBarSupport: NSObject, NSTouchBarDelegate {
let touchBar = NSTouchBar()
touchBar.delegate = self
touchBar.customizationIdentifier = .windowBar
touchBar.defaultItemIdentifiers = [.playPause, .time, .slider, .remainingOrTotalTime]
touchBar.customizationAllowedItemIdentifiers = [.playPause, .slider, .volumeUp, .volumeDown, .rewind, .fastForward, .time, .remainingOrTotalTime, .ahead15Sec, .ahead30Sec, .back15Sec, .back30Sec, .next, .prev, .togglePIP, .fixedSpaceLarge]
touchBar.defaultItemIdentifiers = [.playPause, .time, .slider, .remainingTimeOrTotalDuration]
touchBar.customizationAllowedItemIdentifiers = [.playPause, .slider, .volumeUp, .volumeDown, .rewind, .fastForward, .time, .remainingTimeOrTotalDuration, .ahead15Sec, .ahead30Sec, .back15Sec, .back30Sec, .next, .prev, .togglePIP, .fixedSpaceLarge]
return touchBar
}()

Expand Down Expand Up @@ -124,15 +124,15 @@ class TouchBarSupport: NSObject, NSTouchBarDelegate {
item.customizationLabel = NSLocalizedString("touchbar.time", comment: "Time Position")
return item

case .remainingOrTotalTime:
case .remainingTimeOrTotalDuration:
let item = NSCustomTouchBarItem(identifier: identifier)
let label = DurationDisplayTextField(labelWithString: "00:00")
label.alignment = .center
label.font = .monospacedDigitSystemFont(ofSize: 0, weight: .regular)
label.mode = Preference.bool(for: .touchbarShowRemainingTime) ? .remaining : .duration
self.touchBarPosLabels.append(label)
item.view = label
item.customizationLabel = NSLocalizedString("touchbar.remainingOrTotalTime", comment: "Show Remaining Time or Total Time")
item.customizationLabel = NSLocalizedString("touchbar.remainingTimeOrTotalDuration", comment: "Show Remaining Time or Total Duration")
return item

case .ahead15Sec,
Expand Down
2 changes: 1 addition & 1 deletion iina/en.lproj/Localizable.strings
Expand Up @@ -275,5 +275,5 @@
"touchbar.play_pause" = "Play / Pause";
"touchbar.seek" = "Seek";
"touchbar.time" = "Time Position";
"touchbar.remainingOrTotalTime" = "Remaining Time / Total Time";
"touchbar.remainingTimeOrTotalDuration" = "Remaining Time / Total Duration";
"touchbar.toggle_pip" = "Toggle Picture-in-Picture";

0 comments on commit cd791c7

Please sign in to comment.