-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFluidTabButton.m
116 lines (88 loc) · 2.12 KB
/
FluidTabButton.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
//
// FluidTabButton.m
// FluidApp
//
// Created by Michael Fortin on 09-12-05.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "FluidTabButton.h"
@implementation FluidTabButton
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
isLeftMost = NO;
isRightMost = NO;
}
return self;
}
- (void)makeLeftMost
{
isLeftMost = YES;
}
- (void)makeRightMost
{
isRightMost = YES;
}
- (void)drawRect:(NSRect)dirtyRect
{
NSRect rect = [self bounds];
rect.origin.x+=0.7f;
rect.origin.y+=0.7f;
NSMutableParagraphStyle *ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[ps setAlignment:NSCenterTextAlignment];
NSDictionary *fontBlack =
[NSDictionary dictionaryWithObjects:
[NSArray arrayWithObjects:[NSColor blackColor],[NSFont fontWithName:@"Arial" size:10],ps,nil]
forKeys:
[NSArray arrayWithObjects:NSForegroundColorAttributeName,NSFontAttributeName,NSParagraphStyleAttributeName,nil]];
if ([self state] == NSOnState)
{
rect.size.height+=0.5f;
}
else
{
rect.size.height-=1.4f;
}
if (!isLeftMost)
{
rect.origin.x-=0.7f;
rect.size.width+=0.7f;
}
if (!isRightMost)
{
rect.size.width+=0.7f;
}
rect.size.width -=2.5f;
NSBezierPath *bp = [NSBezierPath bezierPath];
[bp setLineWidth:1.0f];
NSPoint tmp = rect.origin;
tmp.x += 5.5f;
[bp moveToPoint:tmp];
tmp = rect.origin;
tmp.x += rect.size.width;
tmp.x += 1.0f;
NSPoint tmp2 = tmp;
tmp2.y += 1.0f;
[bp appendBezierPathWithArcFromPoint:tmp toPoint:tmp2 radius:5];
tmp.y += rect.size.height;
[bp lineToPoint:tmp];
tmp.x -= rect.size.width;
[bp lineToPoint:tmp];
tmp.y -= rect.size.height;
tmp2 = tmp;
tmp2.x += 1.0f;
[bp appendBezierPathWithArcFromPoint:tmp toPoint:tmp2 radius:5];
if ([self state] == NSOnState)
[[NSColor whiteColor] set];
else
[[NSColor lightGrayColor] set];
[bp fill];
[[NSColor darkGrayColor] set];
[bp stroke];
//[[self title] drawAtPoint:tmp withAttributes:fontBlack];
rect = [self bounds];
rect.origin.y += 3.0f;
[[self title] drawInRect:rect withAttributes:fontBlack];
[ps release];
}
@end