From ad7edc8fb58a256881fd470801e80dbb425cc79f Mon Sep 17 00:00:00 2001 From: ritsuka Date: Fri, 22 Aug 2014 17:59:21 +0000 Subject: [PATCH] MacGui: fixed the preview controller HUD style on the next OS X release. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6347 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- macosx/English.lproj/PicturePreview.xib | 402 ++++++++++----------- macosx/HBHUDView.h | 15 + macosx/HBHUDView.m | 95 +++++ macosx/HBPreviewController.m | 92 ++++- macosx/HandBrake.xcodeproj/project.pbxproj | 6 + 5 files changed, 381 insertions(+), 229 deletions(-) create mode 100644 macosx/HBHUDView.h create mode 100644 macosx/HBHUDView.m diff --git a/macosx/English.lproj/PicturePreview.xib b/macosx/English.lproj/PicturePreview.xib index ac699b0f8..53c5a1a27 100644 --- a/macosx/English.lproj/PicturePreview.xib +++ b/macosx/English.lproj/PicturePreview.xib @@ -1,7 +1,7 @@ - + - + @@ -10,17 +10,17 @@ - + - + - + @@ -47,215 +47,197 @@ - - - + + + + + + + + + + + + + + + + + diff --git a/macosx/HBHUDView.h b/macosx/HBHUDView.h new file mode 100644 index 000000000..9cea11ac4 --- /dev/null +++ b/macosx/HBHUDView.h @@ -0,0 +1,15 @@ +// +// HBVisualEffectBox.h +// HandBrake +// +// Created by Toby on 21/08/14. +// +// + +#import + +/** + * The HBHUDView class implements simple views that can draw the background in the HUD style. + */ +@interface HBHUDView : NSView +@end diff --git a/macosx/HBHUDView.m b/macosx/HBHUDView.m new file mode 100644 index 000000000..769c5ba99 --- /dev/null +++ b/macosx/HBHUDView.m @@ -0,0 +1,95 @@ +// +// HBVisualEffectBox.m +// HandBrake +// +// Created by Toby on 21/08/14. +// +// + +#import "HBHUDView.h" + +@interface NSView (HBHUDViewExtension) + +- (void)setBlendingMode:(int)mode; +- (void)setMaterial:(int)material; +- (void)setState:(int)state; + +@end + +@implementation HBHUDView + +- (instancetype)init +{ + self = [super init]; + if (self) + { + [self setupOldStyleHUD]; + } + + return self; +} + ++ (void)setupNewStyleHUD:(NSView *)view +{ + [view setWantsLayer:YES]; + [view.layer setCornerRadius:4]; + + // Hardcode the values so we can + // compile it with the 10.9 sdk. + [view setBlendingMode:1]; + [view setMaterial:2]; + [view setState:1]; + + [view setAppearance:[NSAppearance appearanceNamed:@"NSAppearanceNameVibrantDark"]]; +} + +- (void)setupOldStyleHUD +{ + [self setWantsLayer:YES]; + [self.layer setCornerRadius:14]; + + // Black transparent background and white border + CGColorRef white = CGColorCreateGenericRGB(1.0, 1.0, 1.0, 0.9); + [self.layer setBorderColor:white]; + CFRelease(white); + [self.layer setBorderWidth:2]; + + CGColorRef black = CGColorCreateGenericRGB(0.0, 0.0, 0.0, 0.6); + [self.layer setBackgroundColor:black]; + CFRelease(black); +} + +- (instancetype)initWithFrame:(NSRect)frame +{ + if (NSClassFromString(@"NSVisualEffectView")) + { + // Return a NSVisualEffectView instance + self = [[NSClassFromString(@"NSVisualEffectView") alloc] initWithFrame:frame]; + if (self) + { + [HBHUDView setupNewStyleHUD:self]; + } + } + else + { + self = [super initWithFrame:frame]; + if (self) + { + [self setupOldStyleHUD]; + } + } + + return self; +} + +- (instancetype)initWithCoder:(NSCoder *)coder +{ + self = [super initWithCoder:coder]; + if (self) + { + [self setupOldStyleHUD]; + } + return self; +} + +@end \ No newline at end of file diff --git a/macosx/HBPreviewController.m b/macosx/HBPreviewController.m index d13254ddc..c92bc4e8f 100644 --- a/macosx/HBPreviewController.m +++ b/macosx/HBPreviewController.m @@ -56,10 +56,10 @@ #define BORDER_SIZE 2.0 // make min width and height of preview window large enough for hud -#define MIN_WIDTH 460.0 -#define MIN_HEIGHT 128.0 +#define MIN_WIDTH 480.0 +#define MIN_HEIGHT 360.0 -#define ANIMATION_DUR 0.2 +#define ANIMATION_DUR 0.15 typedef enum ViewMode : NSUInteger { ViewModePicturePreview, @@ -70,9 +70,9 @@ typedef enum ViewMode : NSUInteger { @interface HBPreviewController () { /* HUD boxes */ - IBOutlet NSBox * fPictureControlBox; - IBOutlet NSBox * fEncodingControlBox; - IBOutlet NSBox * fMoviePlaybackControlBox; + IBOutlet NSView * fPictureControlBox; + IBOutlet NSView * fEncodingControlBox; + IBOutlet NSView * fMoviePlaybackControlBox; IBOutlet NSSlider * fPictureSlider; IBOutlet NSTextField * fInfoField; @@ -185,9 +185,6 @@ typedef enum ViewMode : NSUInteger { /* Setup our layers for core animation */ [[[self window] contentView] setWantsLayer:YES]; - [fPictureControlBox setWantsLayer:YES]; - [fEncodingControlBox setWantsLayer:YES]; - [fMoviePlaybackControlBox setWantsLayer:YES]; self.backLayer = [CALayer layer]; [self.backLayer setBounds:CGRectMake(0.0, 0.0, MIN_WIDTH, MIN_HEIGHT)]; @@ -442,7 +439,15 @@ typedef enum ViewMode : NSUInteger { [[NSAnimationContext currentContext] setDuration:ANIMATION_DUR]; [boxes enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { - [[obj animator] setHidden:([indexes containsIndex:idx]) ? NO : YES]; + BOOL hide = [indexes containsIndex:idx] ? NO : YES; + if (hide) + { + [self hideHudWithAnimation:obj]; + } + else + { + [self showHudWithAnimation:obj]; + } }]; [NSAnimationContext endGrouping]; @@ -545,33 +550,81 @@ typedef enum ViewMode : NSUInteger { /* Since we are not encoding, verify which control hud to show * or hide based on aMovie ( aMovie indicates we need movie controls ) */ - NSBox *hudBoxToShow; + NSView *hud; if (self.currentViewMode == !ViewModeMoviePreview) // No movie loaded up { - hudBoxToShow = fPictureControlBox; + hud = fPictureControlBox; } else // We have a movie { - hudBoxToShow = fMoviePlaybackControlBox; + hud = fMoviePlaybackControlBox; } - if (NSPointInRect(mouseLoc, [hudBoxToShow frame])) + if (NSPointInRect(mouseLoc, [hud frame])) { - [[hudBoxToShow animator] setHidden: NO]; + [self showHudWithAnimation:hud]; [self stopHudTimer]; } else if (NSPointInRect(mouseLoc, [[[self window] contentView] frame])) { - [[hudBoxToShow animator] setHidden: NO]; + [self showHudWithAnimation:hud]; [self startHudTimer]; } else { - [[hudBoxToShow animator] setHidden: YES]; + [self hideHudWithAnimation:hud]; + [self stopHudTimer]; } } } +- (void)showHudWithAnimation:(NSView *)hud +{ + // The standard view animator doesn't play + // nicely with the Yosemite visual effects yet. + // So let's do the fade ourself. + if (hud.layer.opacity == 0 || [hud isHidden]) + { + [hud setHidden:NO]; + + [CATransaction begin]; + CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; + fadeInAnimation.fromValue = @(0.0); + fadeInAnimation.toValue = @(1.0); + fadeInAnimation.beginTime = 0.0; + fadeInAnimation.duration = ANIMATION_DUR; + + [hud.layer addAnimation:fadeInAnimation forKey:nil]; + [hud.layer setOpacity:1]; + + [CATransaction commit]; + } +} + +- (void)hideHudWithAnimation:(NSView *)hud +{ + if (hud.layer.opacity != 0) + { + [CATransaction begin]; + [CATransaction setCompletionBlock:^{ + if (hud.layer.opacity == 0) + { + [hud setHidden:YES]; + } + }]; + CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; + fadeInAnimation.fromValue = @([hud.layer.presentationLayer opacity]); + fadeInAnimation.toValue = @(0.0); + fadeInAnimation.beginTime = 0.0; + fadeInAnimation.duration = ANIMATION_DUR; + + [hud.layer addAnimation:fadeInAnimation forKey:nil]; + [hud.layer setOpacity:0]; + + [CATransaction commit]; + } +} + - (void) startHudTimer { if (self.hudTimer) @@ -596,8 +649,9 @@ typedef enum ViewMode : NSUInteger { /* Regardless which control box is active, after the timer * period we want either one to fade to hidden. */ - [[fPictureControlBox animator] setHidden: YES]; - [[fMoviePlaybackControlBox animator] setHidden: YES]; + [self hideHudWithAnimation:fPictureControlBox]; + [self hideHudWithAnimation:fMoviePlaybackControlBox]; + [self stopHudTimer]; } diff --git a/macosx/HandBrake.xcodeproj/project.pbxproj b/macosx/HandBrake.xcodeproj/project.pbxproj index e49b41683..4676704df 100644 --- a/macosx/HandBrake.xcodeproj/project.pbxproj +++ b/macosx/HandBrake.xcodeproj/project.pbxproj @@ -129,6 +129,7 @@ A9AA447A1970664A00D7DEFC /* HBUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = A9AA44791970664A00D7DEFC /* HBUtilities.m */; }; A9BB0F2719A0ECE40079F1C1 /* HBHUDButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = A9BB0F2619A0ECE40079F1C1 /* HBHUDButtonCell.m */; }; A9C0DB85197E7B0000DF55B3 /* SubtitlesDefaults.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9C0DB83197E7B0000DF55B3 /* SubtitlesDefaults.xib */; }; + A9C9F88919A733FE00DC8923 /* HBHUDView.m in Sources */ = {isa = PBXBuildFile; fileRef = A9C9F88819A733FE00DC8923 /* HBHUDView.m */; }; A9CF25F11990D62C0023F727 /* Presets.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9CF25EF1990D62C0023F727 /* Presets.xib */; }; A9CF25F41990D64E0023F727 /* HBPreset.m in Sources */ = {isa = PBXBuildFile; fileRef = A9CF25F31990D64E0023F727 /* HBPreset.m */; }; A9CF25F71990D6820023F727 /* HBPresetsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = A9CF25F61990D6820023F727 /* HBPresetsViewController.m */; }; @@ -352,6 +353,8 @@ A9BB0F2519A0ECE40079F1C1 /* HBHUDButtonCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBHUDButtonCell.h; sourceTree = ""; }; A9BB0F2619A0ECE40079F1C1 /* HBHUDButtonCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBHUDButtonCell.m; sourceTree = ""; }; A9C0DB84197E7B0000DF55B3 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = SubtitlesDefaults.xib; sourceTree = ""; }; + A9C9F88719A733FE00DC8923 /* HBHUDView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBHUDView.h; sourceTree = ""; }; + A9C9F88819A733FE00DC8923 /* HBHUDView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBHUDView.m; sourceTree = ""; }; A9CF25F01990D62C0023F727 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = Presets.xib; sourceTree = ""; }; A9CF25F21990D64E0023F727 /* HBPreset.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBPreset.h; sourceTree = ""; }; A9CF25F31990D64E0023F727 /* HBPreset.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBPreset.m; sourceTree = ""; }; @@ -846,6 +849,8 @@ 273F209A14ADBE670021BE6D /* HBImageAndTextCell.m */, A9BB0F2519A0ECE40079F1C1 /* HBHUDButtonCell.h */, A9BB0F2619A0ECE40079F1C1 /* HBHUDButtonCell.m */, + A9C9F88719A733FE00DC8923 /* HBHUDView.h */, + A9C9F88819A733FE00DC8923 /* HBHUDView.m */, ); name = "UI Views"; sourceTree = ""; @@ -1065,6 +1070,7 @@ A9CF25F71990D6820023F727 /* HBPresetsViewController.m in Sources */, 273F20BE14ADC09F0021BE6D /* main.mm in Sources */, A91726E7197291BC00D1AFEF /* HBChapterTitlesController.m in Sources */, + A9C9F88919A733FE00DC8923 /* HBHUDView.m in Sources */, A932E26F198833920047D13E /* HBAudioDefaultsController.m in Sources */, 46AB433515F98A2B009C0961 /* DockTextField.m in Sources */, A9D488A51996270300E9B1BA /* HBTreeNode.m in Sources */, -- 2.40.0