Fixed a crash when Core Image was available.
[ITKit.git] / ITBevelView.m
1 #import "ITBevelView.h"
2
3 @implementation ITBevelView
4
5 - (id)initWithFrame:(NSRect)frameRect {
6         if ((self = [super initWithFrame:frameRect])) {
7                 _bevelDepth = 5;
8                 [self setAutoresizesSubviews:NO];
9         }
10         return self;
11 }
12
13 - (id)initWithCoder:(NSCoder *)coder {
14         if ((self = [super initWithCoder:coder])) {
15                 _bevelDepth = 5;
16                 [self setAutoresizesSubviews:NO];
17         }
18         return self;
19 }
20
21 - (int)bevelDepth {
22         return _bevelDepth;
23 }
24
25 - (void)setBevelDepth:(int)newDepth {
26         _bevelDepth = newDepth;
27         [self setNeedsDisplay:YES];
28 }
29
30 - (void)drawRect:(NSRect)aRect {
31         NSRect frameRect = [self convertRect:[self frame] fromView:[self superview]];
32         NSRect innerRect = NSMakeRect((frameRect.origin.x + _bevelDepth), (frameRect.origin.y + _bevelDepth), (frameRect.size.width - (_bevelDepth * 2)), (frameRect.size.height - (_bevelDepth * 2)));
33
34         NSBezierPath *leftEdge = [NSBezierPath bezierPath];
35         NSBezierPath *topEdge = [NSBezierPath bezierPath];
36         NSBezierPath *rightEdge = [NSBezierPath bezierPath];
37         NSBezierPath *bottomEdge = [NSBezierPath bezierPath];
38
39         [[[self subviews] objectAtIndex:0] setFrame:innerRect];
40
41         [leftEdge moveToPoint:frameRect.origin];
42         [leftEdge lineToPoint:NSMakePoint(frameRect.origin.x, frameRect.size.height)];
43         [leftEdge lineToPoint:NSMakePoint((frameRect.origin.x + _bevelDepth), (frameRect.size.height - _bevelDepth))];
44         [leftEdge lineToPoint:NSMakePoint((frameRect.origin.x + _bevelDepth), (frameRect.origin.y + _bevelDepth))];
45
46         [topEdge moveToPoint:NSMakePoint(frameRect.origin.x, frameRect.size.height)];
47         [topEdge lineToPoint:NSMakePoint(frameRect.size.width, frameRect.size.height)];
48         [topEdge lineToPoint:NSMakePoint((frameRect.size.width - _bevelDepth), (frameRect.size.height - _bevelDepth))];
49         [topEdge lineToPoint:NSMakePoint((frameRect.origin.x + _bevelDepth), (frameRect.size.height - _bevelDepth))];
50
51         [rightEdge moveToPoint:NSMakePoint(frameRect.size.width, frameRect.origin.y)];
52         [rightEdge lineToPoint:NSMakePoint(frameRect.size.width, frameRect.size.height)];
53         [rightEdge lineToPoint:NSMakePoint((frameRect.size.width - _bevelDepth), (frameRect.size.height - _bevelDepth))];
54         [rightEdge lineToPoint:NSMakePoint((frameRect.size.width - _bevelDepth), _bevelDepth)];
55
56         [bottomEdge moveToPoint:frameRect.origin];
57         [bottomEdge lineToPoint:NSMakePoint(frameRect.size.width, frameRect.origin.y)];
58         [bottomEdge lineToPoint:NSMakePoint((frameRect.size.width - _bevelDepth), _bevelDepth)];
59         [bottomEdge lineToPoint:NSMakePoint((frameRect.origin.x + _bevelDepth), (frameRect.origin.y + _bevelDepth))];
60
61         [[NSColor colorWithCalibratedWhite:0.5 alpha:0.5] set];
62         [leftEdge fill];
63         [[NSColor colorWithCalibratedWhite:0.0 alpha:0.5] set];
64         [topEdge fill];
65         [[NSColor colorWithCalibratedWhite:0.5 alpha:0.5] set];
66         [rightEdge fill];
67         [[NSColor colorWithCalibratedWhite:1.0 alpha:0.6] set];
68         [bottomEdge fill];
69
70         [[[self subviews] objectAtIndex:0] setNeedsDisplay:YES];
71 }
72
73 - (BOOL)mouseDownCanMoveWindow {
74         return NO;
75 }
76
77 - (void)dealloc {
78         [super dealloc];
79 }
80
81 @end