#include <stdio.h>#include <X11/IntrinsicP.h>#include <X11/StringDefs.h>#include <X11/Xaw3d/XawInit.h>#include <X11/Xaw3d/StripCharP.h>#include <X11/Xfuncs.h>Include dependency graph for StripChart.c:

Go to the source code of this file.
Defines | |
| #define | MS_PER_SEC 1000 |
| #define | offset(field) XtOffsetOf(StripChartRec, field) |
| #define | HEIGHT ( (unsigned int) w->core.height) |
Functions | |
| static void | Initialize () |
| static void | Destroy () |
| static void | Redisplay () |
| static void | MoveChart () |
| static void | SetPoints () |
| static Boolean | SetValues () |
| static int | repaint_window () |
| static void | draw_it () |
| static void | CreateGC (StripChartWidget w, unsigned int which) |
| static void | DestroyGC (StripChartWidget w, unsigned int which) |
| static void | Initialize (Widget greq, Widget gnew, ArgList args, Cardinal *num_args) |
| static void | Destroy (Widget gw) |
| static void | Redisplay (Widget gw, XEvent *event, Region region) |
| static void | draw_it (XtPointer client_data, XtIntervalId *id) |
| static int | repaint_window (Widget gw, int left, int width) |
| static void | MoveChart (StripChartWidget w, Boolean blit) |
| static Boolean | SetValues (Widget current, Widget request, Widget new, ArgList args, Cardinal *num_args) |
| static void | SetPoints (Widget widget) |
Variables | |
| static XtResource | resources [] |
| StripChartClassRec | stripChartClassRec |
| WidgetClass | stripChartWidgetClass = (WidgetClass) &stripChartClassRec |
| #define HEIGHT ( (unsigned int) w->core.height) |
Definition at line 526 of file StripChart.c.
| #define MS_PER_SEC 1000 |
| #define offset | ( | field | ) | XtOffsetOf(StripChartRec, field) |
Definition at line 62 of file StripChart.c.
| static void CreateGC | ( | StripChartWidget | w, | |
| unsigned int | which | |||
| ) | [static] |
Definition at line 154 of file StripChart.c.
References FOREGROUND, and HIGHLIGHT.
00157 { 00158 XGCValues myXGCV; 00159 00160 if (which & FOREGROUND) { 00161 myXGCV.foreground = w->strip_chart.fgpixel; 00162 w->strip_chart.fgGC = XtGetGC((Widget) w, GCForeground, &myXGCV); 00163 } 00164 00165 if (which & HIGHLIGHT) { 00166 myXGCV.foreground = w->strip_chart.hipixel; 00167 w->strip_chart.hiGC = XtGetGC((Widget) w, GCForeground, &myXGCV); 00168 } 00169 }
| static void Destroy | ( | Widget | gw | ) | [static] |
Definition at line 212 of file StripChart.c.
References ALL_GCS, DestroyGC(), and w.
00214 { 00215 StripChartWidget w = (StripChartWidget)gw; 00216 00217 if (w->strip_chart.update > 0) 00218 XtRemoveTimeOut (w->strip_chart.interval_id); 00219 if (w->strip_chart.points) 00220 XtFree((char *) w->strip_chart.points); 00221 DestroyGC(w, (unsigned int) ALL_GCS); 00222 }
Here is the call graph for this function:

| static void Destroy | ( | ) |
| static void DestroyGC | ( | StripChartWidget | w, | |
| unsigned int | which | |||
| ) | [static] |
Definition at line 179 of file StripChart.c.
References FOREGROUND, and HIGHLIGHT.
00182 { 00183 if (which & FOREGROUND) 00184 XtReleaseGC((Widget) w, w->strip_chart.fgGC); 00185 00186 if (which & HIGHLIGHT) 00187 XtReleaseGC((Widget) w, w->strip_chart.hiGC); 00188 }
| static void draw_it | ( | XtPointer | client_data, | |
| XtIntervalId * | id | |||
| ) | [static] |
Definition at line 260 of file StripChart.c.
References CoordModePrevious, draw_it(), FALSE, MoveChart(), MS_PER_SEC, NULL, repaint_window(), s, ThreeDClassPart::shadowdraw, _StripChartClassRec::threeD_class, TRUE, value, w, XDrawPoints(), XtNgetValue, and y.
00263 { 00264 StripChartWidget w = (StripChartWidget)client_data; 00265 StripChartWidgetClass swclass = (StripChartWidgetClass) XtClass ((Widget) w); 00266 Dimension s = w->threeD.shadow_width; 00267 double value; 00268 00269 if (w->strip_chart.update > 0) 00270 w->strip_chart.interval_id = 00271 XtAppAddTimeOut(XtWidgetToApplicationContext( (Widget) w), 00272 (unsigned long) w->strip_chart.update * MS_PER_SEC, 00273 draw_it, client_data); 00274 00275 if (w->strip_chart.interval >= (int)( w->core.width - 2 * s)) 00276 MoveChart( (StripChartWidget) w, TRUE); 00277 00278 /* Get the value, stash the point and draw corresponding line. */ 00279 00280 if (w->strip_chart.get_value == NULL) 00281 return; 00282 00283 XtCallCallbacks( (Widget)w, XtNgetValue, (XtPointer)&value ); 00284 00285 /* 00286 * Keep w->strip_chart.max_value up to date, and if this data 00287 * point is off the graph, change the scale to make it fit. 00288 */ 00289 00290 if (value > w->strip_chart.max_value) { 00291 w->strip_chart.max_value = value; 00292 if (XtIsRealized((Widget)w) && 00293 w->strip_chart.max_value > w->strip_chart.scale) { 00294 XClearWindow(XtDisplay ((Widget) w), XtWindow ((Widget) w)); 00295 w->strip_chart.interval = repaint_window((Widget)w, 0, (int) w->core.width - 2 * s); 00296 (*swclass->threeD_class.shadowdraw) ((Widget) w, 00297 (XEvent *)0, (Region)0, 00298 FALSE); 00299 } 00300 } 00301 00302 w->strip_chart.valuedata[w->strip_chart.interval] = value; 00303 if (XtIsRealized((Widget)w)) { 00304 int y = (int) (( w->core.height - 2 * s) 00305 - (int)(( w->core.height - 2 * s) * value) / w->strip_chart.scale); 00306 00307 XFillRectangle(XtDisplay((Widget) w), XtWindow((Widget) w), w->strip_chart.fgGC, 00308 w->strip_chart.interval + s, 00309 y + s, (unsigned int) 1, 00310 (w->core.height - 2 * s) - y); 00311 /* 00312 * Fill in the graph lines we just painted over. 00313 */ 00314 00315 if (w->strip_chart.points != NULL) { 00316 w->strip_chart.points[0].x = w->strip_chart.interval + s; 00317 XDrawPoints(XtDisplay(w), XtWindow(w), w->strip_chart.hiGC, 00318 w->strip_chart.points, w->strip_chart.scale, 00319 CoordModePrevious); 00320 } 00321 00322 XFlush(XtDisplay(w)); /* Flush output buffers */ 00323 } 00324 w->strip_chart.interval++; /* Next point */ 00325 } /* draw_it */
Here is the call graph for this function:

| static void draw_it | ( | ) | [static] |
| static void Initialize | ( | Widget | greq, | |
| Widget | gnew, | |||
| ArgList | args, | |||
| Cardinal * | num_args | |||
| ) | [static] |
Definition at line 191 of file StripChart.c.
References ALL_GCS, CreateGC(), draw_it(), MS_PER_SEC, NULL, SetPoints(), and w.
00195 { 00196 StripChartWidget w = (StripChartWidget)gnew; 00197 00198 if (w->strip_chart.update > 0) 00199 w->strip_chart.interval_id = 00200 XtAppAddTimeOut( XtWidgetToApplicationContext(gnew), 00201 (unsigned long) w->strip_chart.update * MS_PER_SEC, 00202 draw_it, (XtPointer) gnew); 00203 CreateGC(w, (unsigned int) ALL_GCS); 00204 00205 w->strip_chart.scale = w->strip_chart.min_scale; 00206 w->strip_chart.interval = 0; 00207 w->strip_chart.max_value = 0.0; 00208 w->strip_chart.points = NULL; 00209 SetPoints((Widget)w); 00210 }
Here is the call graph for this function:

| static void Initialize | ( | void | ) | [static] |
| static void MoveChart | ( | StripChartWidget | w, | |
| Boolean | blit | |||
| ) | [static] |
Definition at line 410 of file StripChart.c.
References DEFAULT_JUMP, i, j, left, repaint_window(), s, and void().
00413 { 00414 Dimension s = w->threeD.shadow_width; 00415 double old_max; 00416 int left, i, j; 00417 int next = w->strip_chart.interval; 00418 00419 if (!XtIsRealized((Widget) w)) return; 00420 00421 if (w->strip_chart.jump_val < 0) w->strip_chart.jump_val = DEFAULT_JUMP; 00422 if (w->strip_chart.jump_val == DEFAULT_JUMP) 00423 j = ( w->core.width - 2 * s) / 2; /* Half the window width. */ 00424 else { 00425 j = ( w->core.width - 2 * s) - w->strip_chart.jump_val; 00426 if (j < 0) j = 0; 00427 } 00428 00429 (void) memmove((char *)(w->strip_chart.valuedata), 00430 (char *)(w->strip_chart.valuedata + next - j), 00431 j * sizeof(double)); 00432 next = w->strip_chart.interval = j; 00433 00434 /* 00435 * Since we just lost some data, recompute the 00436 * w->strip_chart.max_value. 00437 */ 00438 00439 old_max = w->strip_chart.max_value; 00440 w->strip_chart.max_value = 0.0; 00441 for (i = 0; i < next; i++) { 00442 if (w->strip_chart.valuedata[i] > w->strip_chart.max_value) 00443 w->strip_chart.max_value = w->strip_chart.valuedata[i]; 00444 } 00445 00446 if (!blit) return; /* we are done... */ 00447 00448 if ( ((int) old_max) != ( (int) w->strip_chart.max_value) ) { 00449 XClearWindow(XtDisplay(w), XtWindow(w)); 00450 repaint_window((Widget)w, 0, w->core.width - 2 * s); 00451 return; 00452 } 00453 00454 XCopyArea(XtDisplay((Widget)w), XtWindow((Widget)w), XtWindow((Widget)w), 00455 w->strip_chart.hiGC, 00456 (int) ((w->strip_chart.jump_val == DEFAULT_JUMP) ? 00457 (j + s) : (w->strip_chart.jump_val + s)), s, 00458 (unsigned int) j, (unsigned int) ( w->core.height - 2 * s), 00459 s, s); 00460 00461 XClearArea(XtDisplay((Widget)w), XtWindow((Widget)w), 00462 (int) j + s, s, 00463 (unsigned int) ((w->strip_chart.jump_val == DEFAULT_JUMP) ? 00464 j : w->strip_chart.jump_val), 00465 (unsigned int) ( w->core.height - 2 * s), 00466 FALSE); 00467 00468 /* Draw graph reference lines */ 00469 left = j; 00470 for (i = 1; i < w->strip_chart.scale; i++) { 00471 j = i * ((w->core.height - 2 * s) / w->strip_chart.scale); 00472 XDrawLine(XtDisplay((Widget) w), XtWindow( (Widget) w), 00473 w->strip_chart.hiGC, 00474 left, j + s, ((int)w->core.width - s - 1), j + s); 00475 } 00476 return; 00477 }
Here is the call graph for this function:

| static void MoveChart | ( | ) |
| static void Redisplay | ( | Widget | gw, | |
| XEvent * | event, | |||
| Region | region | |||
| ) | [static] |
Definition at line 231 of file StripChart.c.
References FALSE, s, ThreeDClassPart::shadowdraw, _StripChartClassRec::threeD_class, void(), w, width, and x.
00235 { 00236 00237 StripChartWidget w = (StripChartWidget)gw; 00238 StripChartWidgetClass swclass = (StripChartWidgetClass) XtClass (gw); 00239 Dimension x, width, s = w->threeD.shadow_width; 00240 00241 (*swclass->threeD_class.shadowdraw) (gw, event, region, FALSE); 00242 00243 if (event->type == GraphicsExpose) { 00244 x = event->xgraphicsexpose.x; 00245 width = event->xgraphicsexpose.width; 00246 } else { 00247 x = event->xexpose.x; 00248 width = event->xexpose.width; 00249 } 00250 if (x > s) x -= s; /* respect shadow width, but don't become negative */ 00251 else x = 0; 00252 if (x + width > w->core.width - 2 * s) /* ditto for right boundary */ 00253 width = w->core.width - 2 * s - x; 00254 00255 (void) repaint_window (gw, x, width); 00256 }
Here is the call graph for this function:

| static void Redisplay | ( | ) |
Definition at line 338 of file StripChart.c.
References dpy, FALSE, i, j, s, scale, SetPoints(), ThreeDClassPart::shadowdraw, _StripChartClassRec::threeD_class, w, and y.
00341 { 00342 StripChartWidget w = (StripChartWidget) gw; 00343 Dimension s = w->threeD.shadow_width; 00344 StripChartWidgetClass swclass = (StripChartWidgetClass) XtClass ((Widget) w); 00345 int i, j; 00346 int next = w->strip_chart.interval; 00347 int scale = w->strip_chart.scale; 00348 int scalewidth = 0; 00349 00350 /* Compute the minimum scale required to graph the data, but don't go 00351 lower than min_scale. */ 00352 if (w->strip_chart.interval != 0 || scale <= (int)w->strip_chart.max_value) 00353 scale = ((int) (w->strip_chart.max_value)) + 1; 00354 if (scale < w->strip_chart.min_scale) 00355 scale = w->strip_chart.min_scale; 00356 00357 if (scale != w->strip_chart.scale) { 00358 w->strip_chart.scale = scale; 00359 left = 0; 00360 width = next; /* check this */ 00361 scalewidth = w->core.width - 2 * s; 00362 00363 SetPoints(gw); 00364 00365 if (XtIsRealized (gw)) { 00366 XClearWindow (XtDisplay (gw), XtWindow (gw)); 00367 (*swclass->threeD_class.shadowdraw) (gw, (XEvent *)0, (Region)0, FALSE); 00368 } 00369 00370 } 00371 00372 if (XtIsRealized(gw)) { 00373 Display *dpy = XtDisplay(gw); 00374 Window win = XtWindow(gw); 00375 00376 width += left - 1; 00377 if (!scalewidth) scalewidth = width; 00378 00379 if (next < (++width - s)) width = next + s; 00380 00381 /* Draw data point lines. */ 00382 for (i = left; i < width; i++) { 00383 int y = (int) (( w->core.height - 2 * s) - 00384 (int)(( w->core.height - 2 * s) * w->strip_chart.valuedata[i]) / 00385 w->strip_chart.scale); 00386 00387 XFillRectangle(dpy, win, w->strip_chart.fgGC, 00388 i + s, y + s, (unsigned int) 1, 00389 (unsigned int) (w->core.height - 2 * s - y )); 00390 } 00391 00392 /* Draw graph reference lines */ 00393 for (i = 1; i < w->strip_chart.scale; i++) { 00394 j = i * ((w->core.height - 2 * s) / w->strip_chart.scale); 00395 XDrawLine(dpy, win, w->strip_chart.hiGC, 00396 left + s, j + s, scalewidth + s, j + s); 00397 } 00398 } 00399 return(next); 00400 }
Here is the call graph for this function:

| static int repaint_window | ( | ) | [static] |
| static void SetPoints | ( | Widget | widget | ) | [static] |
Definition at line 529 of file StripChart.c.
References i, NULL, points, s, size, w, and x.
00531 { 00532 StripChartWidget w = (StripChartWidget) widget; 00533 Dimension s = w->threeD.shadow_width; 00534 XPoint * points; 00535 Cardinal size; 00536 int i; 00537 00538 if (w->strip_chart.scale <= 1) { /* no scale lines. */ 00539 XtFree ((char *) w->strip_chart.points); 00540 w->strip_chart.points = NULL; 00541 return; 00542 } 00543 00544 size = sizeof(XPoint) * (w->strip_chart.scale - 1); 00545 00546 points = (XPoint *) XtRealloc( (XtPointer) w->strip_chart.points, size); 00547 w->strip_chart.points = points; 00548 00549 /* Draw graph reference lines into clip mask */ 00550 00551 for (i = 1; i < w->strip_chart.scale; i++) { 00552 points[i - 1].x = 0; 00553 points[i - 1].y = ( short)(((double)w->core.height - 2.0 * (double) s) / (double) w->strip_chart.scale ); 00554 } 00555 points[0].y += (short)s; 00556 }
| static void SetPoints | ( | ) |
| static Boolean SetValues | ( | Widget | current, | |
| Widget | request, | |||
| Widget | new, | |||
| ArgList | args, | |||
| Cardinal * | num_args | |||
| ) | [static] |
Definition at line 480 of file StripChart.c.
References CreateGC(), DestroyGC(), draw_it(), FALSE, StripChartPart::fgpixel, FOREGROUND, HIGHLIGHT, StripChartPart::hipixel, StripChartPart::interval_id, MS_PER_SEC, NO_GCS, _StripChartRec::strip_chart, TRUE, StripChartPart::update, and w.
00484 { 00485 StripChartWidget old = (StripChartWidget)current; 00486 StripChartWidget w = (StripChartWidget)new; 00487 Boolean ret_val = FALSE; 00488 unsigned int new_gc = NO_GCS; 00489 00490 if (w->strip_chart.update != old->strip_chart.update) { 00491 if (old->strip_chart.update > 0) 00492 XtRemoveTimeOut (old->strip_chart.interval_id); 00493 if (w->strip_chart.update > 0) 00494 w->strip_chart.interval_id = 00495 XtAppAddTimeOut(XtWidgetToApplicationContext(new), 00496 (unsigned long) w->strip_chart.update * MS_PER_SEC, 00497 draw_it, (XtPointer)w); 00498 } 00499 00500 if ( w->strip_chart.min_scale > (int) ((w->strip_chart.max_value) + 1) ) 00501 ret_val = TRUE; 00502 00503 if ( w->strip_chart.fgpixel != old->strip_chart.fgpixel ) { 00504 new_gc |= FOREGROUND; 00505 ret_val = True; 00506 } 00507 00508 if ( w->strip_chart.hipixel != old->strip_chart.hipixel ) { 00509 new_gc |= HIGHLIGHT; 00510 ret_val = True; 00511 } 00512 00513 DestroyGC(old, new_gc); 00514 CreateGC(w, new_gc); 00515 00516 return( ret_val ); 00517 }
Here is the call graph for this function:

| static Boolean SetValues | ( | ) | [static] |
XtResource resources[] [static] |
Initial value:
{
{XtNwidth, XtCWidth, XtRDimension, sizeof(Dimension),
offset(core.width), XtRImmediate, (XtPointer) 120},
{XtNheight, XtCHeight, XtRDimension, sizeof(Dimension),
offset(core.height), XtRImmediate, (XtPointer) 120},
{XtNupdate, XtCInterval, XtRInt, sizeof(int),
offset(strip_chart.update), XtRImmediate, (XtPointer) 10},
{XtNminScale, XtCScale, XtRInt, sizeof(int),
offset(strip_chart.min_scale), XtRImmediate, (XtPointer) 1},
{XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
offset(strip_chart.fgpixel), XtRString, XtDefaultForeground},
{XtNhighlight, XtCForeground, XtRPixel, sizeof(Pixel),
offset(strip_chart.hipixel), XtRString, XtDefaultForeground},
{XtNgetValue, XtCCallback, XtRCallback, sizeof(XtPointer),
offset(strip_chart.get_value), XtRImmediate, (XtPointer) NULL},
{XtNjumpScroll, XtCJumpScroll, XtRInt, sizeof(int),
offset(strip_chart.jump_val), XtRImmediate, (XtPointer) DEFAULT_JUMP},
}
Definition at line 64 of file StripChart.c.
Definition at line 89 of file StripChart.c.
| WidgetClass stripChartWidgetClass = (WidgetClass) &stripChartClassRec |
Definition at line 136 of file StripChart.c.
1.5.1