📄 tachometer.c
字号:
radius_y = center_y - w->tachometer.internal_border; if ((center_x==0) || (center_y==0) || (radius_x<=0) || (radius_y<=0)) return; /* can't draw anything */ gc = w->tachometer.needle_GC; cur_theta1 = (double) (330 - (load * 3)) * PI / 180.0; cur_theta2 = (double) (330 - (load * 3) + 1) * PI / 180.0; cur_theta3 = (double) (330 - (load * 3) - 1) * PI / 180.0; cur_theta4 = (330.0 - ((double) load * 3.0) + 7.0) * PI / 180.0; cur_theta5 = (330.0 - ((double) load * 3.0) - 7.0) * PI / 180.0; points[0].x = sin(cur_theta1) * radius_x * 0.75 + center_x; points[0].y = cos(cur_theta1) * radius_y * 0.75 + center_y; points[1].x = sin(cur_theta2) * radius_x * 0.7 + center_x; points[1].y = cos(cur_theta2) * radius_y * 0.7 + center_y; points[2].x = sin(cur_theta4) * radius_x * 0.1 + center_x; points[2].y = cos(cur_theta4) * radius_y * 0.1 + center_y; points[3].x = sin(cur_theta5) * radius_x * 0.1 + center_x; points[3].y = cos(cur_theta5) * radius_y * 0.1 + center_y; points[4].x = sin(cur_theta3) * radius_x * 0.7 + center_x; points[4].y = cos(cur_theta3) * radius_y * 0.7 + center_y; points[5].x = points[0].x; points[5].y = points[0].y; XDrawLines(XtDisplay(w), XtWindow(w), gc, points, 6, CoordModeOrigin);}static void DrawNumbers( TachometerWidget w, int which, Cardinal x, Cardinal y){ /* Draw Numbers */ if (which == 10) { DrawSingleNumber(w, 1, (Cardinal) ((double) x * 0.9), y); DrawSingleNumber(w, 0, x, y); } else DrawSingleNumber(w, which, x, y);}static void DrawSingleNumber(TachometerWidget w, int which, Cardinal x, Cardinal y){ XSegment segments[7]; Cardinal nsegments, width, height; unsigned char count; width = (w->core.width / 2) - w->tachometer.internal_border; height = (w->core.height / 2) - w->tachometer.internal_border; if ((width <= 0) || (height <= 0)) return; for (count = 0, nsegments = 0; count < 7; count++) if (num_segment[which].digit[count] == 1) { segments[nsegments].x1 = (short) (x + ((double)offset[count].x1 * ((double)width / 200.0))); segments[nsegments].y1 = (short) (y + ((double)offset[count].y1 * ((double)height / 200.0))); segments[nsegments].x2 = (short) (x + ((double)offset[count].x2 * ((double)width / 200.0))); segments[nsegments].y2 = (short) (y + ((double)offset[count].y2 * ((double)height / 200.0))); nsegments++; } XDrawSegments(XtDisplay(w), XtWindow(w), w->tachometer.scale_GC, segments, nsegments);}static void DrawLabelString(TachometerWidget w){ XPoint points[5]; Cardinal ry; unsigned char char_count; unsigned char data_count; Cardinal center_x, center_y; Cardinal radius_x, radius_y; GC gc; gc = w->tachometer.scale_GC; center_x = w->core.width / 2; center_y = w->core.height / 2; radius_x = center_x - w->tachometer.internal_border; radius_y = center_y - w->tachometer.internal_border; if (!(center_x && center_y && (radius_x > 0) && (radius_y > 0))) return; ry = (double) radius_y * 0.35 + center_y; for (char_count = 0; char_count < 4; char_count++) { for (data_count = 0; data_count < char_data[char_count].nofline ; data_count++) { points[data_count].x = (double) (char_data[char_count].point_list[data_count].x) * (double) radius_x * 0.01 + center_x; points[data_count].y = (double) (char_data[char_count].point_list[data_count].y) * (double) radius_y * 0.01 + ry; } XDrawLines(XtDisplay(w), XtWindow(w), gc, points, char_data[char_count].nofline, CoordModeOrigin); }}static void MoveNeedle(TachometerWidget w, int new){ int step, old, loop; old = w->tachometer.value; if (new > 100) new = 100; if (old == new) return; else if (old < new) step = (w->tachometer.speed ? w->tachometer.speed : new - old); else step = (w->tachometer.speed ? -w->tachometer.speed : new - old); if (old < new) { for (loop = old; loop < new; loop += step) DrawNeedle(w, loop); for (loop = old + step; loop <= new; loop += step) DrawNeedle(w, loop); } else { for (loop = old; loop > new; loop += step) DrawNeedle(w, loop); for (loop = old + step; loop >= new; loop += step) DrawNeedle(w, loop); } if (loop != new + step) /* The final needle wasn't printed */ DrawNeedle(w, new); w->tachometer.value = new;}static void GetneedleGC(TachometerWidget ta){ XGCValues values; values.background = ta->core.background_pixel; values.foreground = ta->tachometer.needle ^ ta->core.background_pixel; values.function = GXxor; ta->tachometer.needle_GC = XtGetGC( (Widget)ta, (unsigned) GCFunction | GCBackground | GCForeground, &values);}static void GetscaleGC(TachometerWidget ta){ XGCValues values; values.foreground = ta->tachometer.scale; values.background = ta->core.background_pixel; ta->tachometer.scale_GC = XtGetGC( (Widget)ta, (unsigned) GCForeground | GCBackground, &values);}static void GetcircleGC(TachometerWidget ta){ XGCValues values; values.foreground = ta->tachometer.circle; values.background = ta->core.background_pixel; ta->tachometer.circle_GC = XtGetGC( (Widget)ta, (unsigned) GCForeground | GCBackground, &values);}static void GetbackgroundGC(TachometerWidget ta){ XGCValues values; values.foreground = ta->core.background_pixel; values.background = ta->core.background_pixel; ta->tachometer.background_GC = XtGetGC( (Widget)ta, (unsigned) GCForeground | GCBackground, &values);}static void Initialize(Widget request, Widget new){ TachometerWidget ta = (TachometerWidget) new; GetneedleGC(ta); GetcircleGC(ta); GetscaleGC(ta); GetbackgroundGC(ta); ta->tachometer.width = ta->tachometer.height = 0;} /* Initialize */static void Realize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes){ *valueMask |= CWBitGravity; attributes->bit_gravity = NorthWestGravity; (*superclass->core_class.realize) (w, valueMask, attributes);} /* Realize */static void Redisplay(Widget w, XEvent *event, Region region)/* Repaint the widget window */{ TachometerWidget ta = (TachometerWidget) w; if (event->xexpose.count == 0) DrawTachometer(ta);}static void Resize(Widget w){ TachometerWidget ta = (TachometerWidget) w; if ((ta->core.width == ta->tachometer.width) && (ta->core.height == ta->tachometer.height)) /* What resize? We don't see a resize! */ return; XClearWindow(XtDisplay(w), XtWindow(w)); if ((ta->core.width <= ta->tachometer.width) && (ta->core.height <= ta->tachometer.height)) /* Only redraw here if no expose events are going to be */ /* generated, i.e. if the window has not grown horizontally */ /* or vertically. */ DrawTachometer(ta); ta->tachometer.width = ta->core.width; ta->tachometer.height = ta->core.height;}static Boolean SetValues(Widget current, Widget request, Widget new)/* Set specified arguments into widget */{ Boolean back, changed = False; TachometerWidget curta = (TachometerWidget) current; TachometerWidget newta = (TachometerWidget) new; back = (curta->core.background_pixel != newta->core.background_pixel); if (back || (curta->tachometer.needle != newta->tachometer.needle)) { XtReleaseGC(new, newta->tachometer.needle_GC); GetneedleGC(newta); changed = True; } if (back || (curta->tachometer.scale != newta->tachometer.scale)) { XtReleaseGC(new, newta->tachometer.scale_GC); GetscaleGC(newta); changed = True; } if (back || (curta->tachometer.circle != newta->tachometer.circle)) { XtReleaseGC(new, newta->tachometer.circle_GC); GetcircleGC(newta); changed = True; } if (back) { XtReleaseGC(new, newta->tachometer.background_GC); GetbackgroundGC(newta); changed = True; } if (curta->tachometer.value != newta->tachometer.value) { MoveNeedle(newta, newta->tachometer.value); changed = True; } return(changed);}static void Destroy(Widget w){ TachometerWidget ta = (TachometerWidget) w; XtReleaseGC( w, ta->tachometer.needle_GC ); XtReleaseGC( w, ta->tachometer.circle_GC ); XtReleaseGC( w, ta->tachometer.scale_GC ); XtReleaseGC( w, ta->tachometer.background_GC );}/*************************************************************** * * Exported Procedures * ***************************************************************/int TachometerGetValue(Widget w){ TachometerWidget ta = (TachometerWidget) w; return(ta->tachometer.value);}int TachometerSetValue(Widget w, int i){ int old; TachometerWidget ta = (TachometerWidget) w; old = ta->tachometer.value; MoveNeedle(ta, i); return(old);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -