forked from adlr/formulatepro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPCheckmark.m
72 lines (60 loc) · 2.03 KB
/
FPCheckmark.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
//
// FPCheckmark.m
// FormulatePro
//
// Created by Andrew de los Reyes on 12/22/06.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import "FPCheckmark.h"
@implementation FPCheckmark
+ (NSString *)archivalClassName;
{
return @"Checkmark";
}
- (id)initInDocumentView:(FPDocumentView *)docView
{
self = [super initInDocumentView:docView];
if (self) {
_strokeWidth *= 2.0;
}
return self;
}
- (void)draw:(BOOL)selected
{
NSBezierPath *path = [NSBezierPath bezierPath];
[path setLineWidth:[self strokeWidth]];
[_strokeColor set];
[path moveToPoint:NSMakePoint(NSMinX([self bounds]),
NSMinY([self bounds]))];
[path lineToPoint:NSMakePoint(NSMaxX([self bounds]),
NSMaxY([self bounds]))];
[path moveToPoint:NSMakePoint(NSMinX([self bounds]),
NSMaxY([self bounds]))];
[path lineToPoint:NSMakePoint(NSMaxX([self bounds]),
NSMinY([self bounds]))];
[path stroke];
}
- (BOOL)placeWithEvent:(NSEvent *)theEvent
{
_bounds.size = NSMakeSize(10.0, 10.0);
_naturalBounds = _bounds;
for (;;) {
_page = [_docView pageForPointFromEvent:theEvent];
NSPoint point = [_docView pagePointForPointFromEvent:theEvent page:_page];
// invalidate old bounds
[_docView setNeedsDisplayInRect:
[_docView convertRect:[self safeBounds] fromPage:_page]];
_bounds.origin = NSMakePoint(point.x - NSWidth(_bounds) / 2,
point.y - NSHeight(_bounds) / 2);
// invalidate new bounds
[_docView setNeedsDisplayInRect:
[_docView convertRect:[self safeBounds] fromPage:_page]];
// get ready for next iteration of the loop, or break out of loop
theEvent = [[_docView window] nextEventMatchingMask:
(NSLeftMouseDraggedMask | NSLeftMouseUpMask)];
if ([theEvent type] == NSLeftMouseUp)
break;
}
return YES;
}
@end