|
|
1.1 root 1: #import "draw.h"
2:
3: /*
4: * This line is just a stub to get genstrings to generate
5: * a .strings file entry for the name of this type of Graphic.
6: * The name is used in the Undo New <Whatever> menu item.
7: *
8: * NXLocalString("Circle", NULL, "Name of the tool that draws ovals, i.e., the %s of the New %s operation.")
9: */
10:
11: @implementation Circle : Graphic
12:
13: + initialize
14: /*
15: * This bumps the class version so that we can compatibly read
16: * old Graphic objects out of an archive.
17: */
18: {
19: [Circle setVersion:1];
20: return self;
21: }
22:
23: - (Graphic *)colorAcceptorAt:(const NXPoint *)point
24: /*
25: * An oval accepts a dropped color if the drop occurs
26: * within the bounds of the circle itself.
27: */
28: {
29: if ([self hit:point]) return self;
30: return nil;
31: }
32:
33: - (float)naturalAspectRatio
34: /*
35: * The natural aspect ratio of an oval is 1.0 (a circle).
36: */
37: {
38: return 1.0;
39: }
40:
41: - draw
42: {
43: if (bounds.size.width < 1.0 || bounds.size.height < 1.0) return self;
44:
45: if ([self fill]) {
46: PSgsave();
47: [self setFillColor];
48: PSFilledOval(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
49: PSgrestore();
50: }
51: if (!gFlags.nooutline) {
52: [self setLineColor];
53: PSFramedOval(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height);
54: }
55:
56: return self;
57: }
58:
59: - (BOOL)hit:(const NXPoint *)p
60: /*
61: * Hit only if inside the interior of the oval.
62: */
63: {
64: NXCoord x, y;
65: NXPoint center;
66: double angle, radius, diameter;
67:
68: if ([super hit:p]) {
69: center.x = bounds.origin.x + bounds.size.width / 2.0;
70: center.y = bounds.origin.y + bounds.size.height / 2.0;
71: diameter = MIN(bounds.size.width, bounds.size.height);
72: x = fabs(center.x - p->x) / (bounds.size.width / diameter);
73: y = fabs(center.y - p->y) / (bounds.size.height / diameter);
74: angle = atan2(y, x);
75: radius = diameter / 2.0;
76: return(x < radius * cos(angle) && y < radius * sin(angle));
77: } else {
78: return NO;
79: }
80: }
81:
82:
83: @end
84:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.