#include #include #include #include void hexagram_speedo_init(hexagram_speedo *speedo, double x, double y, double radius) { hexagram_gauge_init(&speedo->gauge, x, y, radius, 232.0 * (M_PI / 180.0), 488.0 * (M_PI / 180.0)); } void hexagram_speedo_draw_face(hexagram_speedo *speedo, cairo_t *cr) { int i; cairo_select_font_face(cr, "Helvetica", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); cairo_set_font_size(cr, speedo->gauge.radius * 0.125); cairo_set_source_rgb(cr, 1, 1, 1); cairo_arc(cr, speedo->gauge.x, speedo->gauge.y, speedo->gauge.radius, 0, 2.0 * 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(&speedo->gauge, cr, 0.85, i / 180.0, text); } for (i=0; i<=180; i+=2) { hexagram_gauge_draw_mark(&speedo->gauge, cr, (i % 10)? 0.75: 0.7, 0.8, i / 180.0); } } void hexagram_speedo_draw_needle(hexagram_speedo *speedo, cairo_t *cr, double rps) { double kph = (2.00152 * rps * 3600) / 1000.0; if (kph < 0) { kph = 0; } else if (kph > 290) { kph = 290; } hexagram_gauge_draw_needle(&speedo->gauge, cr, 0.8, kph / HEXAGRAM_SPEEDO_MAX_KPH); }