[vlc-commits] macOS: Simplify Windows.m animations
Marvin Scholz
git at videolan.org
Thu Mar 16 11:14:23 CET 2017
vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Thu Mar 16 10:55:10 2017 +0100| [17cf96429e76dff0c103ca55958388a0f3011b0c] | committer: Marvin Scholz
macOS: Simplify Windows.m animations
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=17cf96429e76dff0c103ca55958388a0f3011b0c
---
modules/gui/macosx/Windows.h | 14 +----
modules/gui/macosx/Windows.m | 145 ++++++++++---------------------------------
modules/gui/macosx/misc.h | 9 ---
modules/gui/macosx/misc.m | 33 ----------
4 files changed, 37 insertions(+), 164 deletions(-)
diff --git a/modules/gui/macosx/Windows.h b/modules/gui/macosx/Windows.h
index 30a8f7f..e44052f 100644
--- a/modules/gui/macosx/Windows.h
+++ b/modules/gui/macosx/Windows.h
@@ -40,17 +40,9 @@
@property (nonatomic, readwrite) BOOL hasActiveVideo;
@property (nonatomic, readwrite) BOOL fullscreen;
-/* animate mode is only supported in >=10.4 */
-- (void)orderFront: (id)sender animate: (BOOL)animate;
-
-/* animate mode is only supported in >=10.4 */
-- (void)orderOut: (id)sender animate: (BOOL)animate;
-
-/* animate mode is only supported in >=10.4 */
-- (void)orderOut: (id)sender animate: (BOOL)animate callback:(NSInvocation *)callback;
-
-/* animate mode is only supported in >=10.4 */
-- (void)closeAndAnimate: (BOOL)animate;
+- (void)closeAndAnimate:(BOOL)animate;
+- (void)orderFront:(id)sender animate:(BOOL)animate;
+- (void)orderOut:(id)sender animate:(BOOL)animate;
- (VLCVoutView *)videoView;
diff --git a/modules/gui/macosx/Windows.m b/modules/gui/macosx/Windows.m
index 98f9558..6b9f005 100644
--- a/modules/gui/macosx/Windows.m
+++ b/modules/gui/macosx/Windows.m
@@ -41,12 +41,6 @@
BOOL b_isset_canBecomeKeyWindow;
BOOL b_canBecomeMainWindow;
BOOL b_isset_canBecomeMainWindow;
- NSViewAnimation *o_current_animation;
-
- /*
- * YES when all animations are over
- * for fullscreen window: always YES
- */
}
@end
@@ -91,136 +85,65 @@
return [super canBecomeMainWindow];
}
-- (void)closeAndAnimate: (BOOL)animate
+- (void)closeAndAnimate:(BOOL)animate
{
- NSInvocation *invoc;
-
+ // No animation, just close
if (!animate) {
[super close];
return;
}
- // TODO this callback stuff does not work and is not needed
- invoc = [[NSInvocation alloc] init];
- [invoc setSelector:@selector(close)];
- [invoc setTarget: self];
-
- if (![self isVisible] || [self alphaValue] == 0.0) {
- [super close];
- return;
- }
-
- [self orderOut: self animate: YES callback: invoc];
+ // Animate window alpha value
+ [self setAlphaValue:1.0];
+ __unsafe_unretained typeof(self) this = self;
+ [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
+ [[NSAnimationContext currentContext] setDuration:0.9];
+ [[this animator] setAlphaValue:0.0];
+ } completionHandler:^{
+ [this close];
+ }];
}
-- (void)orderOut: (id)sender animate: (BOOL)animate
+- (void)orderOut:(id)sender animate:(BOOL)animate
{
- NSInvocation *invoc = [[NSInvocation alloc] init];
- [invoc setSelector:@selector(orderOut:)];
- [invoc setTarget: self];
- [invoc setArgument:(__bridge void * __nonnull)sender atIndex:2];
- [self orderOut: sender animate: animate callback: invoc];
-}
-
-- (void)orderOut: (id)sender animate: (BOOL)animate callback:(NSInvocation *)callback
-{
- NSViewAnimation *anim;
- NSViewAnimation *current_anim;
- NSMutableDictionary *dict;
-
if (!animate) {
- [self orderOut: sender];
+ [super orderOut:sender];
return;
}
- dict = [[NSMutableDictionary alloc] initWithCapacity:2];
-
- [dict setObject:self forKey:NSViewAnimationTargetKey];
-
- [dict setObject:NSViewAnimationFadeOutEffect forKey:NSViewAnimationEffectKey];
- anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
-
- [anim setAnimationBlockingMode:NSAnimationNonblocking];
- [anim setDuration:0.9];
- [anim setFrameRate:30];
- [anim setUserInfo:(__bridge void *)callback];
- [anim setDelegate:self];
-
- @synchronized(self) {
- current_anim = self->o_current_animation;
-
- if (!([[[current_anim viewAnimations] firstObject] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeOutEffect && [current_anim isAnimating])) {
- if (current_anim) {
- [current_anim stopAnimation];
- [anim setCurrentProgress:1.0 - [current_anim currentProgress]];
- } else
- [anim setCurrentProgress:1.0 - [self alphaValue]];
- self->o_current_animation = anim;
- [anim startAnimation];
- }
+ if ([self alphaValue] == 0.0) {
+ [super orderOut:self];
+ return;
}
+ __unsafe_unretained typeof(self) this = self;
+ [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
+ [[NSAnimationContext currentContext] setDuration:0.5];
+ [[this animator] setAlphaValue:0.0];
+ } completionHandler:^{
+ [this orderOut:self];
+ }];
}
-- (void)orderFront: (id)sender animate: (BOOL)animate
+- (void)orderFront:(id)sender animate:(BOOL)animate
{
- NSViewAnimation *anim;
- NSViewAnimation *current_anim;
- NSMutableDictionary *dict;
-
if (!animate) {
- [super orderFront: sender];
- [self setAlphaValue: 1.0];
+ [super orderFront:sender];
+ [self setAlphaValue:1.0];
return;
}
if (![self isVisible]) {
- [self setAlphaValue: 0.0];
- [super orderFront: sender];
- }
- else if ([self alphaValue] == 1.0) {
- [super orderFront: self];
+ [self setAlphaValue:0.0];
+ [super orderFront:sender];
+ } else if ([self alphaValue] == 1.0) {
+ [super orderFront:self];
return;
}
- dict = [[NSMutableDictionary alloc] initWithCapacity:2];
-
- [dict setObject:self forKey:NSViewAnimationTargetKey];
-
- [dict setObject:NSViewAnimationFadeInEffect forKey:NSViewAnimationEffectKey];
- anim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObject:dict]];
-
- [anim setAnimationBlockingMode:NSAnimationNonblocking];
- [anim setDuration:0.5];
- [anim setFrameRate:30];
- [anim setDelegate:self];
-
- @synchronized(self) {
- current_anim = self->o_current_animation;
-
- if (!([[[current_anim viewAnimations] firstObject] objectForKey: NSViewAnimationEffectKey] == NSViewAnimationFadeInEffect && [current_anim isAnimating])) {
- if (current_anim) {
- [current_anim stopAnimation];
- [anim setCurrentProgress:1.0 - [current_anim currentProgress]];
- }
- else
- [anim setCurrentProgress:[self alphaValue]];
- self->o_current_animation = anim;
- [self orderFront: sender];
- [anim startAnimation];
- }
- }
-}
-
-- (void)animationDidEnd:(NSAnimation*)anim
-{
- if ([self alphaValue] <= 0.0) {
- NSInvocation * invoc;
- [super orderOut: nil];
- [self setAlphaValue: 1.0];
- if ((invoc = [anim userInfo])) {
- [invoc invoke];
- }
- }
+ [NSAnimationContext beginGrouping];
+ [[NSAnimationContext currentContext] setDuration:0.5];
+ [[self animator] setAlphaValue:1.0];
+ [NSAnimationContext endGrouping];
}
- (VLCVoutView *)videoView
diff --git a/modules/gui/macosx/misc.h b/modules/gui/macosx/misc.h
index 848c8eb..b0561b6 100644
--- a/modules/gui/macosx/misc.h
+++ b/modules/gui/macosx/misc.h
@@ -25,15 +25,6 @@
#import <Cocoa/Cocoa.h>
/*****************************************************************************
- * NSAnimation (VLCAddition)
- *****************************************************************************/
-
- at interface NSAnimation (VLCAdditions)
- at property (readwrite) void * userInfo;
-
- at end
-
-/*****************************************************************************
* NSScreen (VLCAdditions)
*
* Missing extension to NSScreen
diff --git a/modules/gui/macosx/misc.m b/modules/gui/macosx/misc.m
index 08d42f9..9e5c2a6 100644
--- a/modules/gui/macosx/misc.m
+++ b/modules/gui/macosx/misc.m
@@ -34,39 +34,6 @@
NSString *const VLCOpenTextFieldWasClicked = @"VLCOpenTextFieldWasClicked";
/*****************************************************************************
- * NSAnimation (VLCAdditions)
- *
- * Missing extension to NSAnimation
- *****************************************************************************/
-
- at implementation NSAnimation (VLCAdditions)
-/* fake class attributes */
-static NSMapTable *VLCAdditions_userInfo = NULL;
-
-+ (void)load
-{
- /* init our fake object attribute */
- VLCAdditions_userInfo = NSCreateMapTable(NSNonRetainedObjectMapKeyCallBacks, NSObjectMapValueCallBacks, 16);
-}
-
-#warning FIXME: Dealloc is replaced, this seems like a very bad idea.
-- (void)dealloc
-{
- NSMapRemove(VLCAdditions_userInfo, (__bridge const void * __nullable)(self));
-}
-
-- (void)setUserInfo: (void *)userInfo
-{
- NSMapInsert(VLCAdditions_userInfo, (__bridge const void * __nullable)(self), (void*)userInfo);
-}
-
-- (void *)userInfo
-{
- return NSMapGet(VLCAdditions_userInfo, (__bridge const void * __nullable)(self));
-}
- at end
-
-/*****************************************************************************
* NSScreen (VLCAdditions)
*
* Missing extension to NSScreen
More information about the vlc-commits
mailing list