forked from glebd/bwtoolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBWSplitViewInspectorAutosizingButtonCell.m
158 lines (133 loc) · 6.59 KB
/
BWSplitViewInspectorAutosizingButtonCell.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//
// BWSplitViewInspectorAutosizingButtonCell.m
// BWToolkit
//
// Created by Brandon Walkin (www.brandonwalkin.com)
// All code is provided under the New BSD license.
//
#import "BWSplitViewInspectorAutosizingButtonCell.h"
#import "BWSplitViewInspectorAutosizingView.h"
#import "NSColor+BWAdditions.h"
#import "NSImage+BWAdditions.h"
#import "NSApplication+BWAdditions.h"
#import "IBColor.h"
static NSColor *insetColor, *borderColor, *viewColor, *lineColor, *insetLineColor;
static NSImage *blueArrowStart, *blueArrowEnd, *redArrowStart, *redArrowEnd, *redArrowFill;
static float interiorInset = 7.0;
@implementation BWSplitViewInspectorAutosizingButtonCell
+ (void)initialize
{
insetColor = [IBColor customViewLightBorderColor];
borderColor = [IBColor customViewDarkBorderColor];
// Note: These two colors are reversed in IBColor in 10.5
if ([NSApplication bwIsOnLeopard])
viewColor = [IBColor containerCustomViewBackgroundColor];
else
viewColor = [IBColor childlessCustomViewBackgroundColor];
lineColor = [[NSColor colorWithCalibratedRed:124.0/255.0 green:139.0/255.0 blue:159.0/255.0 alpha:1.0] retain];
insetLineColor = [[[NSColor whiteColor] colorWithAlphaComponent:0.19] retain];
NSBundle *bundle = [NSBundle bundleForClass:[BWSplitViewInspectorAutosizingButtonCell class]];
blueArrowStart = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"Inspector-SplitViewArrowBlueLeft.tif"]];
blueArrowEnd = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"Inspector-SplitViewArrowBlueRight.tif"]];
redArrowStart = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"Inspector-SplitViewArrowRedLeft.tif"]];
redArrowFill = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"Inspector-SplitViewArrowRedFill.tif"]];
redArrowEnd = [[NSImage alloc] initWithContentsOfFile:[bundle pathForImageResource:@"Inspector-SplitViewArrowRedRight.tif"]];
}
- (void)drawBezelWithFrame:(NSRect)frame inView:(NSView *)controlView
{
[viewColor set];
NSRectFillUsingOperation(frame,NSCompositeSourceOver);
[insetColor bwDrawPixelThickLineAtPosition:1 withInset:0 inRect:frame inView:controlView horizontal:NO flip:NO];
[insetColor bwDrawPixelThickLineAtPosition:1 withInset:0 inRect:frame inView:controlView horizontal:NO flip:YES];
[insetColor bwDrawPixelThickLineAtPosition:1 withInset:0 inRect:frame inView:controlView horizontal:YES flip:YES];
[insetColor bwDrawPixelThickLineAtPosition:1 withInset:0 inRect:frame inView:controlView horizontal:YES flip:NO];
[borderColor bwDrawPixelThickLineAtPosition:0 withInset:0 inRect:frame inView:controlView horizontal:NO flip:NO];
[borderColor bwDrawPixelThickLineAtPosition:0 withInset:0 inRect:frame inView:controlView horizontal:NO flip:YES];
[borderColor bwDrawPixelThickLineAtPosition:0 withInset:0 inRect:frame inView:controlView horizontal:YES flip:YES];
[borderColor bwDrawPixelThickLineAtPosition:0 withInset:0 inRect:frame inView:controlView horizontal:YES flip:NO];
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
BOOL isVertical = [(BWSplitViewInspectorAutosizingView *)[controlView superview] isVertical];
NSImage *blueArrowStartCap, *blueArrowEndCap, *redArrowStartCap, *redArrowFillSlice, *redArrowEndCap;
if (isVertical)
{
blueArrowStartCap = blueArrowStart;
blueArrowEndCap = blueArrowEnd;
redArrowStartCap = redArrowStart;
redArrowFillSlice = redArrowFill;
redArrowEndCap = redArrowEnd;
[blueArrowStartCap setFlipped:YES];
[blueArrowEndCap setFlipped:YES];
}
else
{
blueArrowStartCap = [blueArrowStart bwRotateImage90DegreesClockwise:NO];
blueArrowEndCap = [blueArrowEnd bwRotateImage90DegreesClockwise:NO];
redArrowStartCap = [redArrowEnd bwRotateImage90DegreesClockwise:NO];
redArrowFillSlice = [redArrowFill bwRotateImage90DegreesClockwise:NO];
redArrowEndCap = [redArrowStart bwRotateImage90DegreesClockwise:NO];
}
float arrowHeight = [blueArrowStartCap size].height;
float arrowWidth = [blueArrowStartCap size].width;
NSRect arrowRect = NSZeroRect;
if (isVertical)
arrowRect = NSMakeRect(interiorInset, roundf(cellFrame.size.height / 2 - 0.5 * arrowHeight), roundf(cellFrame.size.width - interiorInset * 2), arrowHeight);
else
arrowRect = NSMakeRect(roundf(cellFrame.size.width / 2 - 0.5 * arrowWidth), interiorInset - 1, arrowWidth, roundf(cellFrame.size.height - (interiorInset - 1) * 2));
if ([self intValue] == 0)
{
NSPoint startArrowOrigin = arrowRect.origin;
NSPoint endArrowOrigin;
if (isVertical)
endArrowOrigin = NSMakePoint(NSMaxX(arrowRect) - arrowWidth, arrowRect.origin.y);
else
endArrowOrigin = NSMakePoint(arrowRect.origin.x,NSMaxY(arrowRect) - arrowHeight);
[blueArrowStartCap drawAtPoint:startArrowOrigin fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
[blueArrowEndCap drawAtPoint:endArrowOrigin fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
NSPoint startPoint, endPoint;
if (isVertical)
{
startPoint = NSMakePoint(arrowRect.origin.x + arrowWidth, arrowRect.origin.y + floorf(arrowHeight / 2) + 0.5);
endPoint = NSMakePoint(arrowRect.origin.x + arrowRect.size.width - arrowWidth, arrowRect.origin.y + floorf(arrowHeight / 2) + 0.5);
}
else
{
startPoint = NSMakePoint(arrowRect.origin.x + floorf(arrowWidth / 2) + 0.5, arrowRect.origin.y + arrowHeight);
endPoint = NSMakePoint(arrowRect.origin.x + floorf(arrowWidth / 2) + 0.5, NSMaxY(arrowRect) - arrowHeight);
}
CGFloat array[2] = {3.0, 1.0};
// Draw dashed line
NSBezierPath *dashedLine = [NSBezierPath bezierPath];
[dashedLine setLineWidth:1.0];
[dashedLine setLineDash:array count:2 phase:3.0];
[dashedLine moveToPoint:startPoint];
[dashedLine lineToPoint:endPoint];
[lineColor set];
[dashedLine stroke];
// Draw white dashed inset line
NSBezierPath *dashedInsetLine = [NSBezierPath bezierPath];
[dashedInsetLine setLineWidth:1.0];
[dashedInsetLine setLineDash:array count:2 phase:3.0];
if (isVertical)
{
[dashedInsetLine moveToPoint:NSMakePoint(startPoint.x, startPoint.y + 1)];
[dashedInsetLine lineToPoint:NSMakePoint(endPoint.x, endPoint.y + 1)];
}
else
{
[dashedInsetLine moveToPoint:NSMakePoint(startPoint.x + 1, startPoint.y)];
[dashedInsetLine lineToPoint:NSMakePoint(endPoint.x + 1, endPoint.y)];
}
[insetLineColor set];
[dashedInsetLine stroke];
}
else
{
if (isVertical)
NSDrawThreePartImage(arrowRect, redArrowStartCap, redArrowFillSlice, redArrowEndCap, NO, NSCompositeSourceOver, 1, YES);
else
NSDrawThreePartImage(arrowRect, redArrowStartCap, redArrowFillSlice, redArrowEndCap, YES, NSCompositeSourceOver, 1, YES);
}
}
@end