|
|
1.1 root 1: #include <CC/jerq.h>
2: #include "pot.pri"
3:
4: extern void circle(Bitmap *, Point, short, int);
5: extern void disc(Bitmap *, Point, short, int);
6:
7: #define P_H_STRING 0x8000
8: #define P_H_VALUE 0x4000
9:
10: Globepot.Globepot(Rectangle rect, short fl, short lat, short lon) : (rect, fl, lat)
11: {
12: w = lon;
13: ctop();
14: }
15:
16: Globepot.Globepot(Rectangle rect, short fl, short lat, short lon, Point sp, char *s) : (rect, fl, lat)
17: {
18: w = lon;
19: ctop();
20: flags |= P_H_STRING;
21: stroffset = sp;
22: str = s;
23: }
24:
25: Globepot.Globepot(Rectangle rect, short fl, short lat, short lon, Point vp) : (rect, fl, lat)
26: {
27: w = lon;
28: ctop();
29: flags |= P_H_VALUE;
30: valoffset = vp;
31: }
32:
33: Globepot.Globepot(Rectangle rect, short fl, short lat, short lon, Point vp, Point sp, char *s) : (rect, fl, lat)
34: {
35: w = lon;
36: ctop();
37: flags |= P_H_STRING|P_H_VALUE;
38: valoffset = vp;
39: stroffset = sp;
40: str = s;
41: }
42:
43: void
44: Globepot.resize(Rectangle rect)
45: {
46: r = rect;
47: calc();
48: ctop();
49: draw();
50: }
51:
52: void
53: Globepot.calc()
54: {
55: radius = min(r.c.x-r.o.x, r.c.y-r.o.y)/2;
56: offset = max(1, radius/4);
57: center = div(add(r.o, r.c), 2);
58: }
59:
60: #define blob (*(front? &disc:&circle))(&display, pt, 6, F_XOR)
61:
62: void
63: Globepot.draw()
64: {
65: Point a, b;
66: long black = 0xFFFFFFFF, dashed = 0xF0F0F0F0;
67:
68: circle(&display, center, radius, F_OR);
69: a = add(center, Pt(0, -radius));
70: b = add(center, Pt(0, radius));
71: elarc(&display, center, offset, radius, a, b, F_OR, black);
72: elarc(&display, center, offset, radius, b, a, F_OR, dashed);
73: a = add(center, Pt(-radius, 0));
74: b = add(center, Pt(radius, 0));
75: elarc(&display, center, radius, offset, a, b, F_OR, black);
76: elarc(&display, center, radius, offset, b, a, F_OR, dashed);
77: blob;
78: if(flags&P_H_STRING) string(&defont, str, &display, r.o+stroffset, F_OR);
79: if(flags&P_H_VALUE) prvals();
80: }
81:
82: void
83: Globepot.mod(int but)
84: {
85: Point p, lp;
86: int d, outside = 0;
87:
88: while(button(but))
89: {
90: p = mouse.xy-center;
91: d = max(1, sqrt(p.x*(long)p.x + p.y*(long)p.y));
92: if(outside)
93: {
94: if(d < radius-20)
95: outside = 0;
96: }
97: else
98: {
99: if(d > radius+20)
100: {
101: outside = 1;
102: blob;
103: front = !front;
104: blob;
105: }
106: }
107: if(d > radius)
108: {
109: p.x = muldiv(p.x, radius, d);
110: p.y = muldiv(p.y, radius, d);
111: }
112: p = add(p, center);
113: if(p != pt)
114: {
115: blob;
116: pt = p;
117: blob;
118: if(flags&P_H_VALUE) prvals();
119: ptoc();
120: if(flags&P_H_VALUE) prvals();
121: nap(2);
122: }
123: }
124: outside = 0;
125: }
126:
127: void
128: Globepot.setval(short lat, short lon)
129: {
130: blob;
131: if(flags&P_H_VALUE) prvals();
132: val = lat;
133: w = lon;
134: ctop();
135: if(flags&P_H_VALUE) prvals();
136: blob;
137: }
138:
139: #define FUDGE 12
140:
141: void
142: Globepot.ptoc()
143: {
144: Point p = sub(pt, center);
145: int q, sx, sy, fudge;
146:
147: q = sx = sqrt(radius*(long)radius - p.x*(long)p.x);
148: sy = sqrt(radius*(long)radius - p.y*(long)p.y);
149: fudge = muldiv(FUDGE, sy, radius);
150: if(front == 0) q = -q;
151: w = (450 - atan2(p.x, q) + fudge)%360;
152: fudge = muldiv(FUDGE, sx, radius);
153: val = atan2(sy, p.y);
154: val = (val > 90)? (360-val):-val;
155: if(front)
156: if(val+fudge > 90)
157: val = 180-val-fudge;
158: else
159: val += fudge;
160: else
161: if(val-fudge < -90)
162: val = -180-val+fudge;
163: else
164: val -= fudge;
165: }
166:
167: void
168: Globepot.ctop()
169: {
170: Point p;
171: int a, h, fudge;
172:
173: front = (w <= 90+FUDGE) || (w > 270+FUDGE);
174: calc();
175: fudge = FUDGE/2;
176: if(front)
177: if(val-fudge < -90)
178: a = -180-val+fudge;
179: else
180: a = val-fudge;
181: else
182: if(val+fudge > 90)
183: a = 180-val-fudge;
184: else
185: a = val+fudge;
186: a = (a < 0)? -a:(360-a);
187: p.y = muldiv(sin(a), radius, 1024);
188: h = muldiv(radius, cos(a), 1024);
189: p.x = muldiv(cos((450-w+fudge)%360), h, 1024);
190:
191: #define delta(z, rad) muldiv(FUDGE, sqrt(rad*(long)rad-z*(long)z), rad)
192:
193: p.x -= delta(p.y, radius);
194: p.y -= delta(p.x, h);
195: pt = add(center, p);
196: }
197:
198: void
199: Globepot.prvals()
200: {
201: char buf[128];
202:
203: sprintf(buf, "lat=%d long=%d", val, w);
204: string(&defont, buf, &display, add(r.o, valoffset), F_XOR);
205: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.