forked from coo-ona/cooViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSAttributedString_Adding.m
82 lines (72 loc) · 1.8 KB
/
NSAttributedString_Adding.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
//
// NSAttributedString_Adding.m
// cooViewer
//
// Created by coo on 08/02/11.
// Copyright 2008 coo. All rights reserved.
//
#import "NSAttributedString_Adding.h"
#import "NSBezierPath_Adding.h"
@implementation NSAttributedString (Adding)
-(void)drawInRect:(NSRect)rect bg:(NSColor*)bg border:(NSColor*)border
{
if (bg || border) {
NSPoint temp = rect.origin;
temp.x+=1;
temp.y+=1;
int rad = [self size].height/2;
NSRect tempRect = NSMakeRect(temp.x,temp.y,rad+[self size].width+rad,[self size].height+1);
NSBezierPath *bezier = [NSBezierPath bezierPathWithRectWithDoubleArc:tempRect];
[bezier closePath];
if (bg) {
[bg set];
[bezier fill];
}
if (border) {
[border set];
[bezier stroke];
}
NSPoint tempPt = NSMakePoint(temp.x+rad,temp.y+1);
[self drawInRect:NSMakeRect(tempPt.x,tempPt.y,[self size].width,[self size].height)];
} else {
[self drawInRect:rect];
}
}
-(void)drawInRect:(NSRect)rect bg:(NSColor*)bg
{
[self drawInRect:rect bg:bg border:nil];
}
-(void)drawAtPoint:(NSPoint)pt bg:(NSColor*)bg border:(NSColor*)border
{
if (bg || border) {
NSPoint temp = pt;
temp.x+=1;
temp.y+=1;
int rad = [self size].height/2;
NSRect tempRect = NSMakeRect(temp.x,temp.y,rad+[self size].width+rad,[self size].height+1);
NSBezierPath *bezier = [NSBezierPath bezierPathWithRectWithDoubleArc:tempRect];
[bezier closePath];
if (bg) {
[bg set];
[bezier fill];
}
if (border) {
[border set];
[bezier stroke];
}
NSPoint tempPt = NSMakePoint(temp.x+rad,temp.y+1);
[self drawAtPoint:tempPt];
} else {
[self drawAtPoint:pt];
}
}
-(void)drawAtPoint:(NSPoint)pt bg:(NSColor*)bg
{
[self drawAtPoint:pt bg:bg border:nil];
}
-(NSSize)sizeWithBG
{
int rad = [self size].height/2;
return NSMakeSize(rad+[self size].width+rad+2,[self size].height+4);
}
@end