70 lines
1.9 KiB
C
70 lines
1.9 KiB
C
|
#include <stdio.h>
|
||
|
#include <math.h>
|
||
|
|
||
|
#include <hexagram/gauge.h>
|
||
|
#include <hexagram/speedo.h>
|
||
|
|
||
|
void hexagram_speedo_draw_face(cairo_t *cr,
|
||
|
double x,
|
||
|
double y,
|
||
|
double r) {
|
||
|
int i;
|
||
|
|
||
|
cairo_select_font_face(cr, "Helvetica",
|
||
|
CAIRO_FONT_SLANT_NORMAL,
|
||
|
CAIRO_FONT_WEIGHT_NORMAL);
|
||
|
|
||
|
cairo_set_font_size(cr, r * 0.125);
|
||
|
|
||
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||
|
cairo_arc(cr, x, y, r, 0, 2*M_PI);
|
||
|
cairo_stroke(cr);
|
||
|
|
||
|
/*
|
||
|
* Draw face numbers
|
||
|
*/
|
||
|
for (i=0; i<=180; i+=20) {
|
||
|
char text[5];
|
||
|
|
||
|
snprintf(text, 4, "%02d", i);
|
||
|
|
||
|
hexagram_gauge_draw_number(cr, x, y,
|
||
|
0.85 * r,
|
||
|
232 * (M_PI/180),
|
||
|
488 * (M_PI/180),
|
||
|
i / 180.0,
|
||
|
text);
|
||
|
}
|
||
|
|
||
|
for (i=0; i<=180; i+=2) {
|
||
|
hexagram_gauge_draw_mark(cr, x, y,
|
||
|
((i % 10)? 0.75: 0.7) * r,
|
||
|
0.8 * r,
|
||
|
232 * (M_PI/180),
|
||
|
488 * (M_PI/180),
|
||
|
i / 180.0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void hexagram_speedo_draw_needle(cairo_t *cr,
|
||
|
double x,
|
||
|
double y,
|
||
|
double r,
|
||
|
double kph) {
|
||
|
if (kph > 290) {
|
||
|
kph = 290;
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
* Draw a tiny boi circle
|
||
|
*/
|
||
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||
|
cairo_arc(cr, x, y, 0.08 * r, 0, 2*M_PI);
|
||
|
cairo_stroke(cr);
|
||
|
|
||
|
hexagram_gauge_draw_needle(cr, x, y, 0.8 * r,
|
||
|
232 * (M_PI/180),
|
||
|
488 * (M_PI/180),
|
||
|
kph / 290);
|
||
|
}
|