summaryrefslogtreecommitdiffstats
path: root/macosx/HBHUDView.m
blob: e7414ae57350ff9282a890e5e1f7e945af74ed1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
//  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 release];
        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