Why not go for a massive refactor?

This commit is contained in:
XANTRONIX Development 2019-06-09 15:46:41 -05:00
parent 6689722b31
commit 0299922b88
15 changed files with 452 additions and 306 deletions

View file

@ -65,6 +65,7 @@ int main(int argc, char **argv) {
hexagram_can_if *can_if; hexagram_can_if *can_if;
hexagram_window *window; hexagram_window *window;
hexagram_cluster *cluster;
int fd, int fd,
width = 1024, width = 1024,
@ -89,6 +90,10 @@ int main(int argc, char **argv) {
return 1; return 1;
} }
if ((cluster = hexagram_cluster_new(width, height)) == NULL) {
return 1;
}
display = hexagram_window_display(window); display = hexagram_window_display(window);
fd = hexagram_can_if_fd(can_if); fd = hexagram_can_if_fd(can_if);
@ -102,7 +107,7 @@ int main(int argc, char **argv) {
/* /*
* Draw the background layer * Draw the background layer
*/ */
hexagram_cluster_draw_bg(bg, width, height); hexagram_cluster_draw_bg(cluster, bg);
/* /*
* Present the background layer * Present the background layer
@ -136,7 +141,7 @@ int main(int argc, char **argv) {
case MapNotify: case MapNotify:
case Expose: case Expose:
hexagram_window_refresh_bg(window); hexagram_window_refresh_bg(window);
hexagram_cluster_draw_fg(&state, fg, 0, 0, width, height); hexagram_cluster_draw_fg(cluster, fg, &state);
hexagram_window_swap_buffer(window); hexagram_window_swap_buffer(window);
break; break;
@ -171,7 +176,7 @@ int main(int argc, char **argv) {
if (now.tv_sec - last.tv_sec if (now.tv_sec - last.tv_sec
|| now.tv_usec - last.tv_usec > 16666) { || now.tv_usec - last.tv_usec > 16666) {
hexagram_window_refresh_bg(window); hexagram_window_refresh_bg(window);
hexagram_cluster_draw_fg(&state, fg, 0, 0, width, height); hexagram_cluster_draw_fg(cluster, fg, &state);
hexagram_window_swap_buffer(window); hexagram_window_swap_buffer(window);
(void)memcpy(&last, &now, sizeof(now)); (void)memcpy(&last, &now, sizeof(now));

View file

@ -3,19 +3,35 @@
#include <cairo.h> #include <cairo.h>
#include <hexagram/tacho.h>
#include <hexagram/speedo.h>
#include <hexagram/thermo.h>
#include <hexagram/fuel.h>
#include <hexagram/mfd.h>
typedef struct _hexagram_cluster_state { typedef struct _hexagram_cluster_state {
double rpm, rps, temp, fuel; double rpm, rps, temp, fuel;
} hexagram_cluster_state; } hexagram_cluster_state;
void hexagram_cluster_draw_bg(cairo_t *cr, typedef struct _hexagram_cluster {
hexagram_tacho tacho;
hexagram_speedo speedo;
hexagram_thermo thermo;
hexagram_fuel fuel;
hexagram_mfd mfd;
double width, double width,
height;
} hexagram_cluster;
hexagram_cluster *hexagram_cluster_new(double width,
double height); double height);
void hexagram_cluster_draw_fg(hexagram_cluster_state *state, void hexagram_cluster_draw_bg(hexagram_cluster *cluster,
cairo_t *cr);
void hexagram_cluster_draw_fg(hexagram_cluster *cluster,
cairo_t *cr, cairo_t *cr,
double x, hexagram_cluster_state *state);
double y,
double width,
double height);
#endif /* _HEXAGRAM_CLUSTER_H */ #endif /* _HEXAGRAM_CLUSTER_H */

View file

@ -1,16 +1,26 @@
#ifndef _HEXAGRAM_FUEL_H #ifndef _HEXAGRAM_FUEL_H
#define _HEXAGRAM_FUEL_H #define _HEXAGRAM_FUEL_H
void hexagram_fuel_draw_face(cairo_t *cr, #include <cairo.h>
#include <hexagram/gauge.h>
typedef struct _hexagram_fuel {
hexagram_gauge gauge;
double redline;
} hexagram_fuel;
void hexagram_fuel_init(hexagram_fuel *fuel,
double x, double x,
double y, double y,
double r, double radius,
double redline); double redline);
void hexagram_fuel_draw_needle(cairo_t *cr, void hexagram_fuel_draw_face(hexagram_fuel *fuel,
double x, cairo_t *cr);
double y,
double r, void hexagram_fuel_draw_needle(hexagram_fuel *fuel,
cairo_t *cr,
double level); double level);
#endif /* _HEXAGRAM_FUEL_H */ #endif /* _HEXAGRAM_FUEL_H */

View file

@ -3,30 +3,35 @@
#include <cairo.h> #include <cairo.h>
void hexagram_gauge_draw_needle(cairo_t *cr, typedef struct _hexagram_gauge {
double x, double x, y;
double y, double radius;
double r, double min_angle;
double min_angle, double max_angle;
double max_angle, } hexagram_gauge;
double value);
void hexagram_gauge_draw_number(cairo_t *cr, void hexagram_gauge_init(hexagram_gauge *gauge,
double x, double x,
double y, double y,
double r, double radius,
double min_angle, double min_angle,
double max_angle, double max_angle);
void hexagram_gauge_draw_number(hexagram_gauge *gauge,
cairo_t *cr,
double radius,
double value, double value,
const char *text); const char *text);
void hexagram_gauge_draw_mark(cairo_t *cr, void hexagram_gauge_draw_mark(hexagram_gauge *gauge,
double x, cairo_t *cr,
double y, double min_radius,
double min_r, double max_radius,
double max_r, double value);
double min_angle,
double max_angle, void hexagram_gauge_draw_needle(hexagram_gauge *gauge,
cairo_t *cr,
double radius,
double value); double value);
#endif /* _HEXAGRAM_GAUGE_H */ #endif /* _HEXAGRAM_GAUGE_H */

View file

@ -3,10 +3,20 @@
#include <cairo.h> #include <cairo.h>
void hexagram_mfd_draw(cairo_t *cr, typedef struct _hexagram_mfd {
double x, y;
double width,
height;
} hexagram_mfd;
void hexagram_mfd_init(hexagram_mfd *mfd,
double x, double x,
double y, double y,
double width, double width,
double height); double height);
void hexagram_mfd_draw(hexagram_mfd *mfd,
cairo_t *cr);
#endif /* _HEXAGRAM_MFD_H */ #endif /* _HEXAGRAM_MFD_H */

View file

@ -3,15 +3,22 @@
#include <cairo.h> #include <cairo.h>
void hexagram_speedo_draw_face(cairo_t *cr, #include <hexagram/gauge.h>
double x,
double y,
double r);
void hexagram_speedo_draw_needle(cairo_t *cr, typedef struct _hexagram_speedo {
hexagram_gauge gauge;
} hexagram_speedo;
void hexagram_speedo_init(hexagram_speedo *speedo,
double x, double x,
double y, double y,
double r, double radius);
void hexagram_speedo_draw_face(hexagram_speedo *speedo,
cairo_t *cr);
void hexagram_speedo_draw_needle(hexagram_speedo *speedo,
cairo_t *cr,
double kph); double kph);
#endif /* _HEXAGRAM_SPEEDO_H */ #endif /* _HEXAGRAM_SPEEDO_H */

View file

@ -3,16 +3,24 @@
#include <cairo.h> #include <cairo.h>
void hexagram_tacho_draw_face(cairo_t *cr, #include <hexagram/gauge.h>
typedef struct _hexagram_tacho {
hexagram_gauge gauge;
double redline;
} hexagram_tacho;
void hexagram_tacho_init(hexagram_tacho *tacho,
double x, double x,
double y, double y,
double r, double radius,
double redline); double redline);
void hexagram_tacho_draw_needle(cairo_t *cr, void hexagram_tacho_draw_face(hexagram_tacho *tacho,
double x, cairo_t *cr);
double y,
double r, void hexagram_tacho_draw_needle(hexagram_tacho *tacho,
cairo_t *cr,
double rpm); double rpm);
#endif /* _HEXAGRAM_TACHO_H */ #endif /* _HEXAGRAM_TACHO_H */

View file

@ -3,16 +3,24 @@
#include <cairo.h> #include <cairo.h>
void hexagram_thermo_draw_face(cairo_t *cr, #include <hexagram/gauge.h>
typedef struct _hexagram_thermo {
hexagram_gauge gauge;
double redline;
} hexagram_thermo;
void hexagram_thermo_init(hexagram_thermo *thermo,
double x, double x,
double y, double y,
double r, double radius,
double redline); double redline);
void hexagram_thermo_draw_needle(cairo_t *cr, void hexagram_thermo_draw_face(hexagram_thermo *thermo,
double x, cairo_t *cr);
double y,
double r, void hexagram_thermo_draw_needle(hexagram_thermo *thermo,
cairo_t *cr,
double temp); double temp);
#endif /* _HEXAGRAM_THERMO_H */ #endif /* _HEXAGRAM_THERMO_H */

View file

@ -1,76 +1,78 @@
#include <hexagram/tacho.h> #include <stdlib.h>
#include <hexagram/speedo.h>
#include <hexagram/thermo.h>
#include <hexagram/fuel.h>
#include <hexagram/mfd.h>
#include <hexagram/cluster.h> #include <hexagram/cluster.h>
void hexagram_cluster_draw_bg(cairo_t *cr, hexagram_cluster *hexagram_cluster_new(double width, double height) {
double width, hexagram_cluster *cluster;
double height) {
if ((cluster = malloc(sizeof(*cluster))) == NULL) {
goto error_malloc_cluster;
}
hexagram_tacho_init(&cluster->tacho,
width * 0.2,
height * 0.5,
height * 0.4,
6500.0);
hexagram_speedo_init(&cluster->speedo,
width * 0.8,
height * 0.5,
height * 0.4);
hexagram_thermo_init(&cluster->thermo,
width * 0.43,
height * 0.76,
height * 0.13,
240.0);
hexagram_fuel_init(&cluster->fuel,
width * 0.57,
height * 0.76,
height * 0.13,
0.125);
hexagram_mfd_init(&cluster->mfd,
width * 0.42,
height * 0.10,
width * 0.16,
height * 0.50);
cluster->width = width;
cluster->height = height;
return cluster;
error_malloc_cluster:
return NULL;
}
void hexagram_cluster_draw_bg(hexagram_cluster *cluster,
cairo_t *cr) {
/* /*
* Paint canvas black * Paint canvas black
*/ */
cairo_set_source_rgb(cr, 0, 0, 0); cairo_set_source_rgb(cr, 0, 0, 0);
cairo_paint(cr); cairo_paint(cr);
hexagram_tacho_draw_face(cr, hexagram_tacho_draw_face(&cluster->tacho, cr);
width * 0.2, hexagram_speedo_draw_face(&cluster->speedo, cr);
height * 0.5, hexagram_thermo_draw_face(&cluster->thermo, cr);
height * 0.4, hexagram_fuel_draw_face(&cluster->fuel, cr);
6500); hexagram_mfd_draw(&cluster->mfd, cr);
hexagram_speedo_draw_face(cr,
width * 0.8,
height * 0.5,
height * 0.4);
hexagram_thermo_draw_face(cr,
width * 0.43,
height * 0.76,
height * 0.13,
240.0);
hexagram_fuel_draw_face(cr,
width * 0.57,
height * 0.76,
height * 0.13,
0.125);
hexagram_mfd_draw(cr,
width * 0.42,
height * 0.1,
width * 0.16,
height * 0.5);
} }
void hexagram_cluster_draw_fg(hexagram_cluster_state *state, void hexagram_cluster_draw_fg(hexagram_cluster *cluster,
cairo_t *cr, cairo_t *cr,
double x, hexagram_cluster_state *state) {
double y, hexagram_tacho_draw_needle(&cluster->tacho, cr, state->rpm);
double width,
double height) {
hexagram_tacho_draw_needle(cr,
x + width * 0.2,
y + height * 0.5,
height * 0.4,
state->rpm);
hexagram_speedo_draw_needle(cr, hexagram_speedo_draw_needle(&cluster->speedo, cr,
width * 0.8,
height * 0.5,
height * 0.4,
(2.032 * state->rps * 3600) / 1000.0); (2.032 * state->rps * 3600) / 1000.0);
hexagram_thermo_draw_needle(cr, hexagram_thermo_draw_needle(&cluster->thermo, cr,
width * 0.43,
height * 0.76,
height * 0.13,
state->temp); state->temp);
hexagram_fuel_draw_needle(cr, hexagram_fuel_draw_needle(&cluster->fuel, cr,
width * 0.57,
height * 0.76,
height * 0.13,
state->fuel); state->fuel);
} }

View file

@ -3,50 +3,71 @@
#include <hexagram/gauge.h> #include <hexagram/gauge.h>
#include <hexagram/fuel.h> #include <hexagram/fuel.h>
void hexagram_fuel_draw_face(cairo_t *cr, void hexagram_fuel_init(hexagram_fuel *fuel,
double x, double x,
double y, double y,
double r, double radius,
double redline) { double redline) {
hexagram_gauge_init(&fuel->gauge, x, y, radius,
300.0 * (M_PI / 180.0),
420.0 * (M_PI / 180.0));
fuel->redline = redline;
}
void hexagram_fuel_draw_face(hexagram_fuel *fuel,
cairo_t *cr) {
int i; int i;
cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, r, 0, 2*M_PI); cairo_arc(cr,
fuel->gauge.x,
fuel->gauge.y,
fuel->gauge.radius,
0,
2.0 * M_PI);
cairo_stroke(cr); cairo_stroke(cr);
cairo_move_to(cr, x - 0.8 * r, y - 0.1 * r); cairo_move_to(cr,
fuel->gauge.x - 0.8 * fuel->gauge.radius,
fuel->gauge.y - 0.1 * fuel->gauge.radius);
cairo_show_text(cr, "0"); cairo_show_text(cr, "0");
cairo_move_to(cr, x - 0.15 * r, y - 0.5 * r); cairo_move_to(cr,
fuel->gauge.x - 0.15 * fuel->gauge.radius,
fuel->gauge.y - 0.50 * fuel->gauge.radius);
cairo_show_text(cr, "1/2"); cairo_show_text(cr, "1/2");
cairo_move_to(cr, x + 0.65 * r, y - 0.1 * r); cairo_move_to(cr,
fuel->gauge.x + 0.65 * fuel->gauge.radius,
fuel->gauge.y - 0.10 * fuel->gauge.radius);
cairo_show_text(cr, "1"); cairo_show_text(cr, "1");
/* /*
* Draw gauge graduations * Draw gauge graduations
*/ */
for (i=0; i<=16; i++) { for (i=0; i<=16; i++) {
if (i <= (16.0 * redline)) { if (i <= (16.0 * fuel->redline)) {
cairo_set_source_rgb(cr, 1, 0, 0); cairo_set_source_rgb(cr, 1, 0, 0);
} else { } else {
cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_source_rgb(cr, 1, 1, 1);
} }
hexagram_gauge_draw_mark(cr, x, y, hexagram_gauge_draw_mark(&fuel->gauge,
((i % 4)? 0.8: 0.7) * r, cr,
0.90 * r, (i % 4)? 0.8: 0.7,
300 * (M_PI/180), 0.9,
420 * (M_PI/180),
(double)i / 16.0); (double)i / 16.0);
} }
} }
void hexagram_fuel_draw_needle(cairo_t *cr, void hexagram_fuel_draw_needle(hexagram_fuel *fuel,
double x, cairo_t *cr,
double y,
double r,
double level) { double level) {
if (level > 1.0) { if (level > 1.0) {
level = 1.0; level = 1.0;
@ -56,12 +77,18 @@ void hexagram_fuel_draw_needle(cairo_t *cr,
* Draw a tiny boi circle * Draw a tiny boi circle
*/ */
cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, 0.08 * r, 0, 2*M_PI);
cairo_arc(cr,
fuel->gauge.x,
fuel->gauge.y,
fuel->gauge.radius * 0.08,
0,
2.0 * M_PI);
cairo_stroke(cr); cairo_stroke(cr);
hexagram_gauge_draw_needle(cr, x, y, 0.9 * r, hexagram_gauge_draw_needle(&fuel->gauge,
300 * (M_PI/180), cr,
420 * (M_PI/180), 0.9,
level / 1.0); level / 1.0);
} }

View file

@ -3,41 +3,49 @@
#include <hexagram/gauge.h> #include <hexagram/gauge.h>
void hexagram_gauge_draw_needle(cairo_t *cr, void hexagram_gauge_init(hexagram_gauge *gauge,
double x, double x,
double y, double y,
double r, double radius,
double min_angle, double min_angle,
double max_angle, double max_angle) {
double value) { gauge->x = x;
double angle = min_angle + ((max_angle - min_angle) * value) - (M_PI/2); gauge->y = y;
gauge->radius = radius;
cairo_move_to(cr, x, y); gauge->min_angle = min_angle;
gauge->max_angle = max_angle;
cairo_set_source_rgb(cr, 0, 0.25, 1.0);
cairo_line_to(cr,
x + r * cos(angle),
y + r * sin(angle));
cairo_stroke(cr);
} }
void hexagram_gauge_draw_number(cairo_t *cr, void hexagram_gauge_draw_number(hexagram_gauge *gauge,
double x, cairo_t *cr,
double y, double radius,
double r,
double min_angle,
double max_angle,
double value, double value,
const char *text) { const char *text) {
double angle = min_angle + ((max_angle - min_angle) * value) - 1.658; double angle = gauge->min_angle
+ ((gauge->max_angle - gauge->min_angle) * value) - 1.658;
/*
* Draw the gauge pivot
*/
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr,
gauge->x,
gauge->y,
gauge->radius * 0.08,
0,
2.0 * M_PI);
cairo_stroke(cr);
/*
* Draw the needle atop the gauge pivot
*/
cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_source_rgb(cr, 1, 1, 1);
cairo_move_to(cr, cairo_move_to(cr,
x + r * cos(angle), gauge->x + (radius * gauge->radius) * cos(angle),
y + r * sin(angle)); gauge->y + (radius * gauge->radius) * sin(angle));
cairo_save(cr); cairo_save(cr);
cairo_rotate(cr, angle + 1.658); cairo_rotate(cr, angle + 1.658);
@ -46,23 +54,39 @@ void hexagram_gauge_draw_number(cairo_t *cr,
cairo_restore(cr); cairo_restore(cr);
} }
void hexagram_gauge_draw_mark(cairo_t *cr, void hexagram_gauge_draw_mark(hexagram_gauge *gauge,
double x, cairo_t *cr,
double y, double min_radius,
double min_r, double max_radius,
double max_r,
double min_angle,
double max_angle,
double value) { double value) {
double angle = min_angle + ((max_angle - min_angle) * value) - (M_PI/2); double angle = gauge->min_angle
+ ((gauge->max_angle - gauge->min_angle) * value) - (M_PI / 2.0);
cairo_move_to(cr, cairo_move_to(cr,
x + min_r * cos(angle), gauge->x + (min_radius * gauge->radius) * cos(angle),
y + min_r * sin(angle)); gauge->y + (min_radius * gauge->radius) * sin(angle));
cairo_line_to(cr, cairo_line_to(cr,
x + max_r * cos(angle), gauge->x + (max_radius * gauge->radius) * cos(angle),
y + max_r * sin(angle)); gauge->y + (max_radius * gauge->radius) * sin(angle));
cairo_stroke(cr);
}
void hexagram_gauge_draw_needle(hexagram_gauge *gauge,
cairo_t *cr,
double radius,
double value) {
double angle = gauge->min_angle
+ ((gauge->max_angle - gauge->min_angle) * value) - (M_PI / 2.0);
cairo_move_to(cr, gauge->x, gauge->y);
cairo_set_source_rgb(cr, 0, 0.25, 1.0);
cairo_line_to(cr,
gauge->x + (radius * gauge->radius) * cos(angle),
gauge->y + (radius * gauge->radius) * sin(angle));
cairo_stroke(cr); cairo_stroke(cr);
} }

View file

@ -1,23 +1,31 @@
#include <hexagram/mfd.h> #include <hexagram/mfd.h>
void hexagram_mfd_draw(cairo_t *cr, void hexagram_mfd_init(hexagram_mfd *mfd,
double x, double x,
double y, double y,
double width, double width,
double height) { double height) {
mfd->x = x;
mfd->y = y;
mfd->width = width;
mfd->height = height;
}
void hexagram_mfd_draw(hexagram_mfd *mfd,
cairo_t *cr) {
cairo_set_source_rgb(cr, 0.75, 0, 0); cairo_set_source_rgb(cr, 0.75, 0, 0);
cairo_move_to(cr, x, y); cairo_move_to(cr, mfd->x, mfd->y);
cairo_line_to(cr, x + width, y); cairo_line_to(cr, mfd->x + mfd->width, mfd->y);
cairo_line_to(cr, x + width, y + height); cairo_line_to(cr, mfd->x + mfd->width, mfd->y + mfd->height);
cairo_line_to(cr, x, y + height); cairo_line_to(cr, mfd->x, mfd->y + mfd->height);
cairo_line_to(cr, x, y); cairo_line_to(cr, mfd->x, mfd->y);
cairo_fill(cr); cairo_fill(cr);
cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_source_rgb(cr, 1, 1, 1);
cairo_move_to(cr, x, y); cairo_move_to(cr, mfd->x, mfd->y);
cairo_line_to(cr, x + width, y); cairo_line_to(cr, mfd->x + mfd->width, mfd->y);
cairo_line_to(cr, x + width, y + height); cairo_line_to(cr, mfd->x + mfd->width, mfd->y + mfd->height);
cairo_line_to(cr, x, y + height); cairo_line_to(cr, mfd->x, mfd->y + mfd->height);
cairo_line_to(cr, x, y); cairo_line_to(cr, mfd->x, mfd->y);
cairo_stroke(cr); cairo_stroke(cr);
} }

View file

@ -4,20 +4,34 @@
#include <hexagram/gauge.h> #include <hexagram/gauge.h>
#include <hexagram/speedo.h> #include <hexagram/speedo.h>
void hexagram_speedo_draw_face(cairo_t *cr, void hexagram_speedo_init(hexagram_speedo *speedo,
double x, double x,
double y, double y,
double r) { 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; int i;
cairo_select_font_face(cr, "Helvetica", cairo_select_font_face(cr, "Helvetica",
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL); CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, r * 0.125); cairo_set_font_size(cr, speedo->gauge.radius * 0.125);
cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, r, 0, 2*M_PI);
cairo_arc(cr,
speedo->gauge.x,
speedo->gauge.y,
speedo->gauge.radius,
0,
2.0 * M_PI);
cairo_stroke(cr); cairo_stroke(cr);
/* /*
@ -28,42 +42,31 @@ void hexagram_speedo_draw_face(cairo_t *cr,
snprintf(text, 4, "%02d", i); snprintf(text, 4, "%02d", i);
hexagram_gauge_draw_number(cr, x, y, hexagram_gauge_draw_number(&speedo->gauge,
0.85 * r, cr,
232 * (M_PI/180), 0.85,
488 * (M_PI/180),
i / 180.0, i / 180.0,
text); text);
} }
for (i=0; i<=180; i+=2) { for (i=0; i<=180; i+=2) {
hexagram_gauge_draw_mark(cr, x, y, hexagram_gauge_draw_mark(&speedo->gauge,
((i % 10)? 0.75: 0.7) * r, cr,
0.8 * r, (i % 10)? 0.75: 0.7,
232 * (M_PI/180), 0.8,
488 * (M_PI/180),
i / 180.0); i / 180.0);
} }
} }
void hexagram_speedo_draw_needle(cairo_t *cr, void hexagram_speedo_draw_needle(hexagram_speedo *speedo,
double x, cairo_t *cr,
double y,
double r,
double kph) { double kph) {
if (kph > 290) { if (kph > 290) {
kph = 290; kph = 290;
} }
/* hexagram_gauge_draw_needle(&speedo->gauge,
* Draw a tiny boi circle cr,
*/ 0.8,
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); kph / 290);
} }

View file

@ -4,21 +4,40 @@
#include <hexagram/gauge.h> #include <hexagram/gauge.h>
#include <hexagram/tacho.h> #include <hexagram/tacho.h>
void hexagram_tacho_draw_face(cairo_t *cr, void hexagram_tacho_init(hexagram_tacho *tacho,
double x, double x,
double y, double y,
double r, double radius,
double redline) { double redline) {
hexagram_gauge_init(&tacho->gauge,
x,
y,
radius,
232.0 * (M_PI / 180.0),
488.0 * (M_PI / 180.0));
tacho->redline = redline;
}
void hexagram_tacho_draw_face(hexagram_tacho *tacho,
cairo_t *cr) {
int i; int i;
cairo_select_font_face(cr, "Helvetica", cairo_select_font_face(cr, "Helvetica",
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL); CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, r * 0.125); cairo_set_font_size(cr, tacho->gauge.radius * 0.125);
cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, r, 0, 2*M_PI);
cairo_arc(cr,
tacho->gauge.x,
tacho->gauge.y,
tacho->gauge.radius,
0,
2.0 * M_PI);
cairo_stroke(cr); cairo_stroke(cr);
/* /*
@ -29,55 +48,35 @@ void hexagram_tacho_draw_face(cairo_t *cr,
snprintf(text, 3, "%02d", i); snprintf(text, 3, "%02d", i);
hexagram_gauge_draw_number(cr, x, y, hexagram_gauge_draw_number(&tacho->gauge,
0.85 * r, cr,
232 * (M_PI/180), 0.85,
488 * (M_PI/180),
i / 80.0, i / 80.0,
text); text);
} }
for (i=0; i<=80; i++) { for (i=0; i<=80; i++) {
if (i * 100 >= redline) { if (i * 100 >= tacho->redline) {
cairo_set_source_rgb(cr, 1, 0, 0); cairo_set_source_rgb(cr, 1, 0, 0);
} }
if (i % 5 == 0) { hexagram_gauge_draw_mark(&tacho->gauge,
hexagram_gauge_draw_mark(cr, x, y, cr,
0.7 * r, i % 5? 0.75: 0.7,
0.8 * r, 0.8,
232 * (M_PI/180),
488 * (M_PI/180),
i / 80.0); 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, void hexagram_tacho_draw_needle(hexagram_tacho *tacho,
double x, cairo_t *cr,
double y,
double r,
double rpm) { double rpm) {
if (rpm > 8000) { if (rpm > 8000) {
rpm = 8000; rpm = 8000;
} }
/* hexagram_gauge_draw_needle(&tacho->gauge,
* Draw a tiny boi circle cr,
*/ 0.8,
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); rpm / 8000);
} }

View file

@ -3,71 +3,85 @@
#include <hexagram/gauge.h> #include <hexagram/gauge.h>
#include <hexagram/thermo.h> #include <hexagram/thermo.h>
void hexagram_thermo_draw_face(cairo_t *cr, void hexagram_thermo_init(hexagram_thermo *thermo,
double x, double x,
double y, double y,
double r, double radius,
double redline) { double redline) {
hexagram_gauge_init(&thermo->gauge, x, y, radius,
300.0 * (M_PI / 180.0),
420.0 * (M_PI / 180.0));
thermo->redline = redline;
}
void hexagram_thermo_draw_face(hexagram_thermo *thermo,
cairo_t *cr) {
int i; int i;
cairo_select_font_face(cr, "Helvetica", cairo_select_font_face(cr, "Helvetica",
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL); CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, r * 0.2); cairo_set_font_size(cr, thermo->gauge.radius * 0.2);
cairo_set_source_rgb(cr, 1, 1, 1); cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, x, y, r, 0, 2*M_PI);
cairo_arc(cr,
thermo->gauge.x,
thermo->gauge.y,
thermo->gauge.radius,
0,
2.0 * M_PI);
cairo_stroke(cr); cairo_stroke(cr);
/* /*
* Draw face numbers * Draw face numbers
*/ */
cairo_move_to(cr, x - 0.8 * r, y - 0.1 * r); cairo_move_to(cr,
thermo->gauge.x - 0.8 * thermo->gauge.radius,
thermo->gauge.y - 0.1 * thermo->gauge.radius);
cairo_show_text(cr, "120"); cairo_show_text(cr, "120");
cairo_move_to(cr, x - 0.15 * r, y - 0.5 * r); cairo_move_to(cr,
thermo->gauge.x - 0.15 * thermo->gauge.radius,
thermo->gauge.y - 0.5 * thermo->gauge.radius);
cairo_show_text(cr, "190"); cairo_show_text(cr, "190");
cairo_move_to(cr, x + 0.5 * r, y - 0.1 * r); cairo_move_to(cr,
thermo->gauge.x + 0.5 * thermo->gauge.radius,
thermo->gauge.y - 0.1 * thermo->gauge.radius);
cairo_show_text(cr, "260"); cairo_show_text(cr, "260");
/* /*
* Draw gauge graduations * Draw gauge graduations
*/ */
for (i=0; i<=140; i+=7) { for (i=0; i<=140; i+=7) {
if (i + 120 >= redline) { if (i + 120 >= thermo->redline) {
cairo_set_source_rgb(cr, 1, 0, 0); cairo_set_source_rgb(cr, 1, 0, 0);
} }
hexagram_gauge_draw_mark(cr, x, y, hexagram_gauge_draw_mark(&thermo->gauge,
((i % 35)? 0.8: 0.7) * r, cr,
0.90 * r, (i % 35)? 0.8: 0.7,
300 * (M_PI/180), 0.90,
420 * (M_PI/180),
i / 140.0); i / 140.0);
} }
} }
void hexagram_thermo_draw_needle(cairo_t *cr, void hexagram_thermo_draw_needle(hexagram_thermo *thermo,
double x, cairo_t *cr,
double y,
double r,
double temp) { double temp) {
if (temp > 260) { if (temp > 260) {
temp = 260; temp = 260;
} }
/* hexagram_gauge_draw_needle(&thermo->gauge,
* Draw a tiny boi circle cr,
*/ 0.9,
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.9 * r,
300 * (M_PI/180),
420 * (M_PI/180),
temp / 260); temp / 260);
} }