diff --git a/examples/cluster.c b/examples/cluster.c index f8fc568..2f1c680 100644 --- a/examples/cluster.c +++ b/examples/cluster.c @@ -9,6 +9,7 @@ #include #include #include +#include typedef struct _hexagram_cluster_state { double rpm, rps, temp, fuel; @@ -18,84 +19,6 @@ static hexagram_cluster_state state = { 0, 0, 0, 0 }; -static void draw_tachometer_needle(cairo_t *cr, - double x, - double y, - double r, - double rpm) { - if (rpm > 8000) { - rpm = 8000; - } - - /* - * 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), - rpm / 8000); -} - -static void draw_tachometer(cairo_t *cr, - double x, - double y, - double r, - double redline) { - 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<=80; i+=10) { - char text[4]; - - snprintf(text, 3, "%02d", i); - - hexagram_gauge_draw_number(cr, x, y, - 0.85 * r, - 232 * (M_PI/180), - 488 * (M_PI/180), - i / 80.0, - text); - } - - for (i=0; i<=80; i++) { - if (i * 100 >= redline) { - cairo_set_source_rgb(cr, 1, 0, 0); - } - - if (i % 5 == 0) { - hexagram_gauge_draw_mark(cr, x, y, - 0.7 * r, - 0.8 * r, - 232 * (M_PI/180), - 488 * (M_PI/180), - i / 80.0); - } else { - hexagram_gauge_draw_mark(cr, x, y, - 0.75 * r, - 0.8 * r, - 232 * (M_PI/180), - 488 * (M_PI/180), - i / 80.0); - } - } -} - static void draw_speedometer(cairo_t *cr, double x, double y, @@ -321,11 +244,11 @@ static void cluster_draw_bg(cairo_t *cr, cairo_set_source_rgb(cr, 0, 0, 0); cairo_paint(cr); - draw_tachometer(cr, - width * 0.2, - height * 0.5, - height * 0.4, - 6500); + hexagram_tacho_draw_face(cr, + width * 0.2, + height * 0.5, + height * 0.4, + 6500); draw_speedometer(cr, width * 0.8, @@ -386,10 +309,11 @@ static void cluster_draw(cairo_t *cr, double y, double width, double height) { - draw_tachometer_needle(cr, x + width * 0.2, + hexagram_tacho_draw_needle(cr, + x + width * 0.2, y + height * 0.5, height * 0.4, - state.rpm); + state.rpm); draw_speedometer_needle(cr, width * 0.8, diff --git a/include/hexagram/gauge.h b/include/hexagram/gauge.h index 37f7700..10bc657 100644 --- a/include/hexagram/gauge.h +++ b/include/hexagram/gauge.h @@ -1,3 +1,6 @@ +#ifndef _HEXAGRAM_GAUGE_H +#define _HEXAGRAM_GAUGE_H + #include void hexagram_gauge_draw_needle(cairo_t *cr, @@ -25,3 +28,5 @@ void hexagram_gauge_draw_mark(cairo_t *cr, double min_angle, double max_angle, double value); + +#endif /* _HEXAGRAM_GAUGE_H */ diff --git a/include/hexagram/tacho.h b/include/hexagram/tacho.h new file mode 100644 index 0000000..4dbb7d3 --- /dev/null +++ b/include/hexagram/tacho.h @@ -0,0 +1,18 @@ +#ifndef _HEXAGRAM_TACHO_H +#define _HEXAGRAM_TACHO_H + +#include + +void hexagram_tacho_draw_face(cairo_t *cr, + double x, + double y, + double r, + double redline); + +void hexagram_tacho_draw_needle(cairo_t *cr, + double x, + double y, + double r, + double rpm); + +#endif /* _HEXAGRAM_TACHO_H */ diff --git a/src/Makefile b/src/Makefile index c1fb37a..1353851 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 sim.h + gauge.h tacho.h sim.h HEADERS_LOCAL = util.h OBJS = dict.o hash.o can.o capture.o pcapng.o module.o window.o \ - gauge.o sim.o + gauge.o tacho.o sim.o VERSION_MAJOR = 0 VERSION_MINOR = 0.1 diff --git a/src/tacho.c b/src/tacho.c new file mode 100644 index 0000000..c226e62 --- /dev/null +++ b/src/tacho.c @@ -0,0 +1,83 @@ +#include +#include + +#include +#include + +void hexagram_tacho_draw_face(cairo_t *cr, + double x, + double y, + double r, + double redline) { + 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<=80; i+=10) { + char text[4]; + + snprintf(text, 3, "%02d", i); + + hexagram_gauge_draw_number(cr, x, y, + 0.85 * r, + 232 * (M_PI/180), + 488 * (M_PI/180), + i / 80.0, + text); + } + + for (i=0; i<=80; i++) { + if (i * 100 >= redline) { + cairo_set_source_rgb(cr, 1, 0, 0); + } + + if (i % 5 == 0) { + hexagram_gauge_draw_mark(cr, x, y, + 0.7 * r, + 0.8 * r, + 232 * (M_PI/180), + 488 * (M_PI/180), + i / 80.0); + } else { + hexagram_gauge_draw_mark(cr, x, y, + 0.75 * r, + 0.8 * r, + 232 * (M_PI/180), + 488 * (M_PI/180), + i / 80.0); + } + } +} + +void hexagram_tacho_draw_needle(cairo_t *cr, + double x, + double y, + double r, + double rpm) { + if (rpm > 8000) { + rpm = 8000; + } + + /* + * 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), + rpm / 8000); +}