From c40ad06140a71312ddce04c4bb778ab10a8820d5 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Sun, 9 Jun 2019 13:49:59 -0500 Subject: [PATCH] Split speedometer out into separate files --- examples/cluster.c | 83 ++++++---------------------------------------- src/Makefile | 4 +-- 2 files changed, 12 insertions(+), 75 deletions(-) diff --git a/examples/cluster.c b/examples/cluster.c index 2f1c680..3f5b92a 100644 --- a/examples/cluster.c +++ b/examples/cluster.c @@ -10,6 +10,7 @@ #include #include #include +#include typedef struct _hexagram_cluster_state { double rpm, rps, temp, fuel; @@ -19,70 +20,6 @@ static hexagram_cluster_state state = { 0, 0, 0, 0 }; -static void draw_speedometer(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); - } -} - -static void draw_speedometer_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); -} - static void draw_thermometer(cairo_t *cr, double x, double y, @@ -250,10 +187,10 @@ static void cluster_draw_bg(cairo_t *cr, height * 0.4, 6500); - draw_speedometer(cr, - width * 0.8, - height * 0.5, - height * 0.4); + hexagram_speedo_draw_face(cr, + width * 0.8, + height * 0.5, + height * 0.4); draw_thermometer(cr, width * 0.43, @@ -315,11 +252,11 @@ static void cluster_draw(cairo_t *cr, height * 0.4, state.rpm); - draw_speedometer_needle(cr, - width * 0.8, - height * 0.5, - height * 0.4, - (2.032 * state.rps * 3600) / 1000.0); + hexagram_speedo_draw_needle(cr, + width * 0.8, + height * 0.5, + height * 0.4, + (2.032 * state.rps * 3600) / 1000.0); draw_thermometer_needle(cr, width * 0.43, diff --git a/src/Makefile b/src/Makefile index 1353851..e53da4e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,12 +8,12 @@ CFLAGS += -fPIC -I$(INCLUDE_PATH) $(shell pkg-config --cflags cairo x11) LDFLAGS = $(shell pkg-config --libs cairo x11) -lXext HEADERS = dict.h hash.h can.h capture.h pcapng.h module.h window.h \ - gauge.h tacho.h sim.h + gauge.h tacho.h speedo.h sim.h HEADERS_LOCAL = util.h OBJS = dict.o hash.o can.o capture.o pcapng.o module.o window.o \ - gauge.o tacho.o sim.o + gauge.o tacho.o speedo.o sim.o VERSION_MAJOR = 0 VERSION_MINOR = 0.1