[vlc-commits] macosx: time fields: Cache alternative time representation
David Fuhrmann
git at videolan.org
Tue Apr 6 09:55:47 UTC 2021
vlc/vlc-3.0 | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Tue Apr 6 11:12:06 2021 +0200| [30ce9f876c9d56122e94450a4c988e45fea7b6cc] | committer: David Fuhrmann
macosx: time fields: Cache alternative time representation
This allows to toggle between remaining and elapsed
time at any time, also while the media is paused.
Close #25433
(backport of 497fc4216d776fc81d241578eaf9abd17dbeedcb)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=30ce9f876c9d56122e94450a4c988e45fea7b6cc
---
modules/gui/macosx/VLCControlsBarCommon.m | 12 +++++------
modules/gui/macosx/VLCFSPanelController.m | 18 +++++++----------
modules/gui/macosx/VLCTimeField.h | 3 +--
modules/gui/macosx/VLCTimeField.m | 33 +++++++++++++++++++++++++++++++
4 files changed, 47 insertions(+), 19 deletions(-)
diff --git a/modules/gui/macosx/VLCControlsBarCommon.m b/modules/gui/macosx/VLCControlsBarCommon.m
index 46f7026244..046824322f 100644
--- a/modules/gui/macosx/VLCControlsBarCommon.m
+++ b/modules/gui/macosx/VLCControlsBarCommon.m
@@ -319,14 +319,14 @@
p_input = pl_CurrentInput(getIntf());
if (p_input != NULL) {
vlc_value_t pos;
- NSString * o_time;
pos.f_float = f_updated / 10000.;
var_Set(p_input, "position", pos);
[self.timeSlider setFloatValue: f_updated];
- o_time = [[VLCStringUtility sharedInstance] getCurrentTimeAsString: p_input negative:[self.timeField timeRemaining]];
- [self.timeField setStringValue: o_time];
+ NSString *time = [[VLCStringUtility sharedInstance] getCurrentTimeAsString:p_input negative:NO];
+ NSString *remainingTime = [[VLCStringUtility sharedInstance] getCurrentTimeAsString:p_input negative:YES];
+ [self.timeField setTime:time withRemainingTime:remainingTime];
vlc_object_release(p_input);
}
}
@@ -372,9 +372,9 @@
[self.timeSlider setIndefinite:buffering];
}
- NSString *time = [[VLCStringUtility sharedInstance] getCurrentTimeAsString:p_input
- negative:[self.timeField timeRemaining]];
- [self.timeField setStringValue:time];
+ NSString *time = [[VLCStringUtility sharedInstance] getCurrentTimeAsString:p_input negative:NO];
+ NSString *remainingTime = [[VLCStringUtility sharedInstance] getCurrentTimeAsString:p_input negative:YES];
+ [self.timeField setTime:time withRemainingTime:remainingTime];
[self.timeField setNeedsDisplay:YES];
vlc_object_release(p_input);
diff --git a/modules/gui/macosx/VLCFSPanelController.m b/modules/gui/macosx/VLCFSPanelController.m
index 86294bcb96..036853db1a 100644
--- a/modules/gui/macosx/VLCFSPanelController.m
+++ b/modules/gui/macosx/VLCFSPanelController.m
@@ -285,17 +285,13 @@ static NSString *kAssociatedFullscreenRect = @"VLCFullscreenAssociatedWindowRect
} else {
[_remainingOrTotalTime setHidden:NO];
- NSString *totalTime;
-
- if ([_remainingOrTotalTime timeRemaining]) {
- mtime_t remaining = 0;
- if (dur > t)
- remaining = dur - t;
- totalTime = [NSString stringWithFormat:@"-%s", secstotimestr(psz_time, (remaining / 1000000))];
- } else {
- totalTime = toNSStr(secstotimestr(psz_time, (dur / 1000000)));
- }
- [_remainingOrTotalTime setStringValue:totalTime];
+ mtime_t remaining = 0;
+ if (dur > t)
+ remaining = dur - t;
+ NSString *remainingTime = [NSString stringWithFormat:@"-%s", secstotimestr(psz_time, (remaining / 1000000))];
+ NSString *totalTime = toNSStr(secstotimestr(psz_time, (dur / 1000000)));
+
+ [_remainingOrTotalTime setTime:totalTime withRemainingTime:remainingTime];
}
/* Update current position (left field) */
diff --git a/modules/gui/macosx/VLCTimeField.h b/modules/gui/macosx/VLCTimeField.h
index c6d81e6d6a..56a16c3645 100644
--- a/modules/gui/macosx/VLCTimeField.h
+++ b/modules/gui/macosx/VLCTimeField.h
@@ -33,8 +33,7 @@
@interface VLCTimeField : NSTextField
- at property (readonly) BOOL timeRemaining;
-
- (void)setRemainingIdentifier:(NSString *)o_string;
+- (void)setTime:(NSString *)time withRemainingTime:(NSString *)remainingTime;
@end
diff --git a/modules/gui/macosx/VLCTimeField.m b/modules/gui/macosx/VLCTimeField.m
index 91d515a3c6..14dbad548d 100644
--- a/modules/gui/macosx/VLCTimeField.m
+++ b/modules/gui/macosx/VLCTimeField.m
@@ -32,6 +32,9 @@
{
NSString *o_remaining_identifier;
BOOL b_time_remaining;
+
+ NSString *_cachedTime;
+ NSString *_remainingTime;
}
@end
@@ -67,11 +70,41 @@
} else {
b_time_remaining = !b_time_remaining;
}
+
+ [self updateTimeValue];
}
[[self nextResponder] mouseDown:ourEvent];
}
+- (void)setTime:(NSString *)time withRemainingTime:(NSString *)remainingTime
+{
+ _cachedTime = time;
+ _remainingTime = remainingTime;
+
+ [self updateTimeValue];
+}
+
+- (void)updateTimeValue
+{
+ if (!_cachedTime || !_remainingTime)
+ return;
+
+ if ([self timeRemaining]) {
+ [super setStringValue:_remainingTime];
+ } else {
+ [super setStringValue:_cachedTime];
+ }
+}
+
+- (void)setStringValue:(NSString *)stringValue
+{
+ [super setStringValue:stringValue];
+
+ _cachedTime = nil;
+ _remainingTime = nil;
+}
+
- (BOOL)timeRemaining
{
if (o_remaining_identifier)
More information about the vlc-commits
mailing list