DAMN YOU PROJECT BUILDER FOR IMPORTING ONLY FOUNDATION!!!
[ITKit.git] / ITBevelView.m
1 #import "ITBevelView.h"
2
3
4 @implementation ITBevelView
5
6
7 /*************************************************************************/
8 #pragma mark -
9 #pragma mark INITIALIZATION METHODS
10 /*************************************************************************/
11
12 - (id)initWithFrame:(NSRect)frameRect
13 {
14     if ( (self = [super initWithFrame:frameRect]) ) {
15         _bevelDepth = 5;
16         [self setAutoresizesSubviews:NO];
17     }
18     
19     return self;
20 }
21
22 - (id)initWithCoder:(NSCoder *)coder
23 {
24     if ( ( self = [super initWithCoder:coder] ) ) {
25         _bevelDepth = 5;
26         [self setAutoresizesSubviews:NO];
27     }
28
29     return self;
30 }
31
32
33 /*************************************************************************/
34 #pragma mark -
35 #pragma mark ACCESSOR METHODS
36 /*************************************************************************/
37
38 - (int)bevelDepth
39 {
40     return _bevelDepth;
41 }
42
43 - (void)setBevelDepth:(int)newDepth
44 {
45     _bevelDepth = newDepth;
46     [self setNeedsDisplay:YES];
47 }
48
49
50 /*************************************************************************/
51 #pragma mark -
52 #pragma mark INSTANCE METHODS
53 /*************************************************************************/
54
55 - (void)drawRect:(NSRect)aRect
56 {
57     NSRect frameRect = [self convertRect:[self frame] fromView:[self superview]];
58     NSRect innerRect = NSMakeRect( (frameRect.origin.x + _bevelDepth),
59                                    (frameRect.origin.y + _bevelDepth),
60                                    (frameRect.size.width  - (_bevelDepth * 2)),
61                                    (frameRect.size.height - (_bevelDepth * 2)) );
62
63     NSBezierPath *leftEdge   = [NSBezierPath bezierPath];
64     NSBezierPath *topEdge    = [NSBezierPath bezierPath];
65     NSBezierPath *rightEdge  = [NSBezierPath bezierPath];
66     NSBezierPath *bottomEdge = [NSBezierPath bezierPath];
67
68     [[[self subviews] objectAtIndex:0] setFrame:innerRect];
69     
70     [leftEdge moveToPoint:frameRect.origin];
71     [leftEdge lineToPoint:NSMakePoint(frameRect.origin.x, frameRect.size.height)];
72     [leftEdge lineToPoint:NSMakePoint( (frameRect.origin.x + _bevelDepth), (frameRect.size.height - _bevelDepth) )];
73     [leftEdge lineToPoint:NSMakePoint( (frameRect.origin.x + _bevelDepth), (frameRect.origin.y + _bevelDepth) )];
74
75     [topEdge moveToPoint:NSMakePoint(frameRect.origin.x, frameRect.size.height)];
76     [topEdge lineToPoint:NSMakePoint(frameRect.size.width, frameRect.size.height)];
77     [topEdge lineToPoint:NSMakePoint( (frameRect.size.width - _bevelDepth), (frameRect.size.height - _bevelDepth) )];
78     [topEdge lineToPoint:NSMakePoint( (frameRect.origin.x + _bevelDepth), (frameRect.size.height - _bevelDepth) )];
79
80     [rightEdge moveToPoint:NSMakePoint(frameRect.size.width, frameRect.origin.y)];
81     [rightEdge lineToPoint:NSMakePoint(frameRect.size.width, frameRect.size.height)];
82     [rightEdge lineToPoint:NSMakePoint( (frameRect.size.width - _bevelDepth), (frameRect.size.height - _bevelDepth) )];
83     [rightEdge lineToPoint:NSMakePoint( (frameRect.size.width - _bevelDepth), (_bevelDepth) )];
84
85     [bottomEdge moveToPoint:frameRect.origin];
86     [bottomEdge lineToPoint:NSMakePoint(frameRect.size.width, frameRect.origin.y)];
87     [bottomEdge lineToPoint:NSMakePoint( (frameRect.size.width - _bevelDepth), (_bevelDepth) )];
88     [bottomEdge lineToPoint:NSMakePoint( (frameRect.origin.x + _bevelDepth), (frameRect.origin.y + _bevelDepth) )];
89
90     [[NSColor colorWithCalibratedWhite:0.5 alpha:0.5] set];
91     [leftEdge fill];
92     [[NSColor colorWithCalibratedWhite:0.0 alpha:0.5] set];
93     [topEdge fill];
94     [[NSColor colorWithCalibratedWhite:0.5 alpha:0.5] set];
95     [rightEdge fill];
96     [[NSColor colorWithCalibratedWhite:1.0 alpha:0.6] set];
97     [bottomEdge fill];
98
99     [[[self subviews] objectAtIndex:0] setNeedsDisplay:YES];
100 }
101
102 - (BOOL)mouseDownCanMoveWindow
103 {
104     return NO;
105 }
106
107
108 /*************************************************************************/
109 #pragma mark -
110 #pragma mark DEALLOCATION METHOD
111 /*************************************************************************/
112
113 - (void)dealloc
114 {
115         [super dealloc];
116 }
117
118
119 @end