forked from glebd/bwtoolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBWGradientBoxInspector.m
110 lines (90 loc) · 2.45 KB
/
BWGradientBoxInspector.m
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//
// BWGradientBoxInspector.m
// BWToolkit
//
// Created by Brandon Walkin (www.brandonwalkin.com)
// All code is provided under the New BSD license.
//
#import "BWGradientBoxInspector.h"
#import "NSEvent+BWAdditions.h"
#import "NSView+BWAdditions.h"
static float heightDelta = 33;
static float animationDuration = 0.1;
@interface BWGradientBoxInspector (BWGBIPrivate)
- (void)updateWellVisibility;
@end
@implementation BWGradientBoxInspector
@synthesize fillPopupSelection, gradientWell, colorWell, wellContainer;
- (void)awakeFromNib
{
[super awakeFromNib];
largeViewHeight = [[self view] frame].size.height;
smallViewHeight = largeViewHeight - heightDelta;
}
- (NSString *)viewNibName
{
return @"BWGradientBoxInspector";
}
- (void)refresh
{
[super refresh];
box = [[self inspectedObjects] objectAtIndex:0];
[self updateWellVisibility];
// Update the popup selections in case of an undo operation
if ([box hasGradient])
[self setFillPopupSelection:2];
else if ([box hasFillColor])
[self setFillPopupSelection:1];
else
[self setFillPopupSelection:0];
}
+ (BOOL)supportsMultipleObjectInspection
{
return NO;
}
- (void)setFillPopupSelection:(int)anInt
{
fillPopupSelection = anInt;
if (fillPopupSelection == 0)
{
[box setHasGradient:NO];
[box setHasFillColor:NO];
}
else if (fillPopupSelection == 1)
{
[box setHasGradient:NO];
[box setHasFillColor:YES];
[gradientWell setHidden:YES];
[colorWell setHidden:NO];
[colorWell setEnabled:YES];
}
else
{
[box setHasGradient:YES];
[box setHasFillColor:NO];
[gradientWell setHidden:NO];
[colorWell setHidden:YES];
[colorWell setEnabled:NO];
}
}
- (void)updateWellVisibility
{
BOOL willCollapse;
NSRect targetFrame = [[self view] frame];
float viewHeight = [[self view] frame].size.height;
if ((int)viewHeight == (int)largeViewHeight && ![box hasGradient] && ![box hasFillColor])
willCollapse = YES;
else if ((int)viewHeight == (int)smallViewHeight && ([box hasGradient] || [box hasFillColor]))
willCollapse = NO;
else
return;
targetFrame.size.height = willCollapse ? smallViewHeight : largeViewHeight;
float alpha = willCollapse ? 0 : 1;
float duration = [NSEvent bwShiftKeyIsDown] ? animationDuration * 10 : animationDuration;
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:duration];
[[wellContainer bwAnimator] setAlphaValue:alpha];
[[[self view] bwAnimator] setFrame:targetFrame];
[NSAnimationContext endGrouping];
}
@end