-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcrosshair.c
265 lines (196 loc) · 6.36 KB
/
crosshair.c
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
-------------------------------------------------------------------------
OBJECT NAME: crosshair.c
FULL NAME: CrossHair Tracking
ENTRY POINTS: CanvasMotion()
STATIC FNS: TrackTimeSeries()
TrackXY()
DESCRIPTION: Cross hair tracking.
REFERENCES: none
REFERENCED BY: XtMainLoop()
COPYRIGHT: University Corporation for Atmospheric Research, 1999-2022
-------------------------------------------------------------------------
*/
#include "define.h"
static int saveX = 0, saveY = 0;
static Display *dpy;
static Window win;
static GC gc;
static char tStr[3][20];
static void TrackTimeSeries(int, int), TrackXY(int, int);
/* -------------------------------------------------------------------- */
void CanvasMotion(Widget w, XtPointer client, XmDrawingAreaCallbackStruct *evt)
{
XMotionEvent *xm = (XMotionEvent *)evt;
dpy = mainPlot[0].dpy;
win = XtWindow(mainPlot[0].canvas);
gc = mainPlot[0].gc;
/* The color that works ok on Solaris doesn't work so good under Linux.
* This should eventually be put in some defaults file along with colors.
* Similar code is in zoom.c.
*/
#ifdef SVR4
XSetForeground(dpy, gc, GetColor(2));
#else
XSetForeground(dpy, gc, GetColor(3));
#endif
XSetFont(dpy, gc, mainPlot[0].fontInfo[4]->fid);
XSetFunction(dpy, gc, GXxor);
switch (PlotType)
{
case TIME_SERIES:
TrackTimeSeries(xm->x, xm->y);
break;
case XY_PLOT:
TrackXY(xm->x, xm->y);
break;
}
XSetFunction(dpy, gc, GXcopy);
} /* END CANVASMOTION */
/* -------------------------------------------------------------------- */
static void TrackTimeSeries(int x, int y)
{
size_t i;
PLOT_INFO *plot = NULL;
float yDiff;
struct axisInfo *axis;
if (saveX) /* Erase previous lines. */
{
XDrawLine(dpy, win, gc, mainPlot[0].x.LV, saveY, mainPlot[0].x.RV, saveY);
for (i = 0; i < NumberOfPanels; ++i)
XDrawLine(dpy, win, gc, saveX, mainPlot[i].x.TH, saveX, mainPlot[i].x.BH);
XDrawString(dpy, win, gc, saveX+10, saveY+30, tStr[0], strlen(tStr[0]));
XDrawString(dpy, win, gc, saveX-50, saveY-10, tStr[1], strlen(tStr[1]));
}
/* Locate which panel the cursor is in.
*/
if (x >= mainPlot[0].x.LV && x <= mainPlot[0].x.RV)
for (i = 0; i < NumberOfPanels; ++i)
if (y >= mainPlot[i].x.TH && y <= mainPlot[i].x.BH)
plot = &mainPlot[i];
/* Bail out if we're outside all panels.
*/
if (!plot)
{
saveX = saveY = 0;
tStr[0][0] = tStr[1][0] = tStr[2][0] = '\0';
PointerCursor(mainPlot[0].canvas);
return;
}
CrossHairCursor(mainPlot[0].canvas);
/* Calculate engineering units.
*/
MakeTimeTicLabel(tStr[0], x - mainPlot[0].x.LV, mainPlot[0].x.HD);
XDrawString(dpy, win, gc, x+10, y+30, tStr[0], strlen(tStr[0]));
axis = &plot->Yaxis[whichSide()];
if (axis->logScale)
{
float yScale = plot->x.VD /
(log10(axis->max) - log10(axis->min));
if (axis->invertAxis)
yDiff = ((y - plot->x.TH) / yScale) + log10(axis->min);
else
yDiff = -(((y - plot->x.BH) / yScale) - log10(axis->min));
snprintf(tStr[1], 20, "%g", pow(10.0, yDiff));
}
else
{
yDiff = axis->max - axis->min;
if (axis->invertAxis)
yDiff *= (float)(y - plot->x.TH) / plot->x.VD;
else
yDiff *= (float)(plot->x.BH - y) / plot->x.VD;
snprintf(tStr[1], 20, "%g", axis->min + yDiff);
}
XDrawString(dpy, win, gc, x-50, y-10, tStr[1], strlen(tStr[1]));
/* Draw new lines and text.
*/
XDrawLine(dpy, win, gc, plot->x.LV, y, plot->x.RV, y);
for (i = 0; i < NumberOfPanels; ++i)
XDrawLine(dpy, win, gc, x, mainPlot[i].x.TH, x, mainPlot[i].x.BH);
saveX = x;
saveY = y;
} /* END TRACKTIMESERIES */
/* -------------------------------------------------------------------- */
static void TrackXY(int x, int y)
{
size_t i;
PLOT_INFO *plot = NULL;
float xDiff, yDiff;
struct axisInfo *axis;
if (saveX) /* Erase previous lines. */
{
XDrawLine(dpy, win, gc, saveX, xyyPlot[0].x.TH, saveX, xyyPlot[0].x.BH);
for (i = 0; i < NumberOfXYpanels; ++i)
XDrawLine(dpy, win, gc, xyyPlot[i].x.LV, saveY, xyyPlot[i].x.RV, saveY);
XDrawString(dpy, win, gc, saveX+10, saveY+30, tStr[0], strlen(tStr[0]));
XDrawString(dpy, win, gc, saveX-50, saveY-10, tStr[1], strlen(tStr[1]));
/* XDrawString(dpy, win, gc, saveX+10, saveY-10, tStr[2], strlen(tStr[2]));*/
}
/* Locate which panel the cursor is in.
*/
if (y >= xyyPlot[0].x.TH && y <= xyyPlot[0].x.BH)
for (i = 0; i < NumberOfXYpanels; ++i)
if (x >= xyyPlot[i].x.LV && x <= xyyPlot[i].x.RV)
plot = &xyyPlot[i];
/* Bail out if we're outside all panels.
*/
if (!plot)
{
saveX = saveY = 0;
tStr[0][0] = tStr[1][0] = tStr[2][0] = '\0';
PointerCursor(xyyPlot[0].canvas);
return;
}
CrossHairCursor(xyyPlot[0].canvas);
/* Calculate engineering units.
*/
axis = &plot->Xaxis;
if (axis->logScale)
{
float xScale = plot->x.HD / (log10(axis->max) - log10(axis->min));
if (axis->invertAxis)
xDiff = -(((x - plot->x.RV) / xScale) - log10(axis->min));
else
xDiff = ((x - plot->x.LV) / xScale) + log10(axis->min);
snprintf(tStr[0], 20, "%g", pow(10.0, xDiff));
}
else
{
xDiff = axis->max - axis->min;
if (axis->invertAxis)
xDiff *= (float)(x + plot->x.RV) / plot->x.HD;
else
xDiff *= (float)(x - plot->x.LV) / plot->x.HD;
snprintf(tStr[0], 20, "%g", axis->min + xDiff);
}
XDrawString(dpy, win, gc, x+10, y+30, tStr[0], strlen(tStr[0]));
axis = &plot->Yaxis[whichSide()];
if (axis->logScale)
{
float yScale = plot->x.VD / (log10(axis->max) - log10(axis->min));
if (axis->invertAxis)
yDiff = ((y - plot->x.TH) / yScale) + log10(axis->min);
else
yDiff = -(((y - plot->x.BH) / yScale) - log10(axis->min));
snprintf(tStr[1], 20, "%g", pow(10.0, yDiff));
}
else
{
yDiff = axis->max - axis->min;
if (axis->invertAxis)
yDiff *= (float)(y - plot->x.TH) / plot->x.VD;
else
yDiff *= (float)(plot->x.BH - y) / plot->x.VD;
snprintf(tStr[1], 20, "%g", axis->min + yDiff);
}
XDrawString(dpy, win, gc, x-50, y-10, tStr[1], strlen(tStr[1]));
/* Draw new lines and text.
*/
XDrawLine(dpy, win, gc, x, plot->x.TH, x, plot->x.BH);
for (i = 0; i < NumberOfXYpanels; ++i)
XDrawLine(dpy, win, gc, xyyPlot[i].x.LV, y, xyyPlot[i].x.RV, y);
saveX = x;
saveY = y;
} /* END TRACKXY */
/* END CROSSHAIR.C */