|
|
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("Curve", NULL, "Name of the tool that draws curves, i.e., the %s of the New %s operation.")
9: */
10:
11: @implementation Curve
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: [Curve setVersion:1];
20: return self;
21: }
22:
23: - (float)arrowAngle:(int)corner
24: /*
25: * Since our control points are at a 90 degree angle, we'll draw our arrows
26: * at 90 degree angles (however, this method breaks down a bit as the bounds
27: * get very skinny--perhaps a better one could be found).
28: */
29: {
30: if (gFlags.downhill) {
31: switch (corner) {
32: case UPPER_LEFT: return 180.0;
33: case LOWER_RIGHT: return - 90.0;
34: }
35: } else {
36: switch (corner) {
37: case UPPER_RIGHT: return 0.0;
38: case LOWER_LEFT: return -90.0;
39: }
40: }
41: return 0.0;
42: }
43:
44: - drawLine
45: /*
46: * Overridden from our superclass (Line).
47: * This is called from the draw method to actually do the drawing of the line,
48: * that way, we can inherit the arrow drawing, etc ...
49: */
50: {
51: if (gFlags.downhill) {
52: PSCurve(bounds.origin.x, bounds.origin.y + bounds.size.height,
53: bounds.origin.x + bounds.size.width,
54: bounds.origin.y + bounds.size.height,
55: bounds.origin.x + bounds.size.width,
56: bounds.origin.y + bounds.size.height,
57: bounds.origin.x + bounds.size.width, bounds.origin.y);
58: } else {
59: PSCurve(bounds.origin.x, bounds.origin.y,
60: bounds.origin.x,
61: bounds.origin.y + bounds.size.height,
62: bounds.origin.x,
63: bounds.origin.y + bounds.size.height,
64: bounds.origin.x + bounds.size.width,
65: bounds.origin.y + bounds.size.height);
66: }
67: return self;
68: }
69:
70: - (BOOL)hit:(const NXPoint *)p
71: /*
72: * Line only gets a hit if the mouse is within some tolerance of the line.
73: * Obviously that algorithm doesn't work for a curve. We could come up
74: * with the proper algorithm to only hit a curve if it is within a tolerance,
75: * but that would be complicated so we take the easy way out and just
76: * get a hit if it is anywhere in the bounds. It is unfortunate that we
77: * have to copy code from Graphic to accomplish this. Perhaps a better
78: * way exists?
79: */
80: {
81: return (!gFlags.locked && gFlags.active && NXMouseInRect(p, &bounds, NO));
82: }
83:
84: @end
85:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.