Make all dial elements fully scalable

This commit is contained in:
XANTRONIX Development 2024-01-19 23:55:55 -05:00
parent a3118f24e3
commit e10422907e
5 changed files with 24 additions and 12 deletions

View file

@ -6,13 +6,15 @@
#define RAD (M_PI / 180.0) #define RAD (M_PI / 180.0)
#define ANGLE_OFFSET (M_PI / 2.0) #define ANGLE_OFFSET (M_PI / 2.0)
#define DIAL_MAIN_BEZEL_WIDTH 16 #define DIAL_MAIN_BEZEL_WIDTH (16.0 / 240.0)
#define DIAL_RADIUS_LEGEND_MAIN 0.69 #define DIAL_RADIUS_LEGEND_MAIN 0.69
#define DIAL_RADIUS_LEGEND_BOTTOM 0.725 #define DIAL_RADIUS_LEGEND_BOTTOM 0.725
#define DIAL_RADIUS_NEEDLE_MAIN_MIN 0.51 #define DIAL_NEEDLE_WIDTH (8.0 / 240.0)
#define DIAL_RADIUS_NEEDLE_MAIN_MAX 0.89
#define DIAL_RADIUS_NEEDLE_MAIN_MIN 0.51
#define DIAL_RADIUS_NEEDLE_MAIN_MAX 0.89
#define DIAL_RADIUS_NEEDLE_BOTTOM_MIN 0.8 #define DIAL_RADIUS_NEEDLE_BOTTOM_MIN 0.8
#define DIAL_RADIUS_NEEDLE_BOTTOM_MAX 0.9 #define DIAL_RADIUS_NEEDLE_BOTTOM_MAX 0.9
@ -68,7 +70,7 @@ static int main_draw_bg(hexagram_gauge *gauge, cairo_t *cr) {
double arc[5] = { double arc[5] = {
dial->gauge.x, dial->gauge.x,
dial->gauge.y, dial->gauge.y,
dial->radius - DIAL_MAIN_BEZEL_WIDTH, dial->radius - (dial->radius * DIAL_MAIN_BEZEL_WIDTH),
0, 0,
2.0 * M_PI 2.0 * M_PI
}; };
@ -80,13 +82,13 @@ static int main_draw_bg(hexagram_gauge *gauge, cairo_t *cr) {
/* Gauge bezel */ /* Gauge bezel */
cairo_set_source(cr, dial->gradient); cairo_set_source(cr, dial->gradient);
cairo_set_line_width(cr, DIAL_MAIN_BEZEL_WIDTH); cairo_set_line_width(cr, dial->radius * DIAL_MAIN_BEZEL_WIDTH);
cairo_arc(cr, arc[0], arc[1], arc[2], arc[3], arc[4]); cairo_arc(cr, arc[0], arc[1], arc[2], arc[3], arc[4]);
cairo_stroke(cr); cairo_stroke(cr);
/* Gauge centre bezel */ /* Gauge centre bezel */
cairo_set_source_rgba(cr, 1, 1, 1, gauge->alpha); cairo_set_source_rgba(cr, 1, 1, 1, gauge->alpha);
cairo_set_line_width(cr, DIAL_MAIN_BEZEL_WIDTH / 3.0); cairo_set_line_width(cr, dial->radius * DIAL_MAIN_BEZEL_WIDTH / 3.0);
cairo_arc(cr, dial->gauge.x, dial->gauge.y, dial->radius / 2, 0, 2.0 * M_PI); cairo_arc(cr, dial->gauge.x, dial->gauge.y, dial->radius / 2, 0, 2.0 * M_PI);
cairo_stroke(cr); cairo_stroke(cr);
@ -117,7 +119,7 @@ static int main_draw_fg(hexagram_gauge *gauge, cairo_t *cr) {
static int bottom_draw_bg(hexagram_gauge *gauge, cairo_t *cr) { static int bottom_draw_bg(hexagram_gauge *gauge, cairo_t *cr) {
hexagram_dial *dial = (hexagram_dial *)gauge; hexagram_dial *dial = (hexagram_dial *)gauge;
cairo_set_line_width(cr, 24); cairo_set_line_width(cr, dial->radius * (24 / 240.0));
cairo_set_source_rgba(cr, 0.2, 0.2, 0.2, gauge->alpha); cairo_set_source_rgba(cr, 0.2, 0.2, 0.2, gauge->alpha);
cairo_arc(cr, cairo_arc(cr,
@ -281,7 +283,7 @@ int hexagram_dial_draw_needle(hexagram_dial *dial, cairo_t *cr, double value) {
} }
cairo_set_source_rgba(cr, 1, 0.4, 1, 0.75 * dial->gauge.alpha); cairo_set_source_rgba(cr, 1, 0.4, 1, 0.75 * dial->gauge.alpha);
cairo_set_line_width(cr, 8); cairo_set_line_width(cr, dial->radius * DIAL_NEEDLE_WIDTH);
cairo_move_to(cr, cairo_move_to(cr,
dial->gauge.x + min_radius * dial->radius * cos(angle), dial->gauge.x + min_radius * dial->radius * cos(angle),

View file

@ -4,6 +4,8 @@
#include <hexagram/gauge.h> #include <hexagram/gauge.h>
#include <hexagram/fuel.h> #include <hexagram/fuel.h>
#define MARK_WIDTH (6.0 / 240.0)
#define RAD (M_PI / 180.0) #define RAD (M_PI / 180.0)
#define LEVEL_MIN 0 #define LEVEL_MIN 0
@ -36,7 +38,7 @@ static int draw_bg(hexagram_gauge *gauge, cairo_t *cr) {
cairo_set_source_rgba(cr, 1, 1, 1, gauge->alpha); cairo_set_source_rgba(cr, 1, 1, 1, gauge->alpha);
hexagram_dial_draw_legend(&fuel->dial, cr, fuel->dial.max_value, "1"); hexagram_dial_draw_legend(&fuel->dial, cr, fuel->dial.max_value, "1");
cairo_set_line_width(cr, 6.0); cairo_set_line_width(cr, fuel->dial.radius * MARK_WIDTH);
for (level=0; level<=LEVEL_MAX; level++) { for (level=0; level<=LEVEL_MAX; level++) {
int large = 0; int large = 0;

View file

@ -6,6 +6,9 @@
#define SPEED_FACTOR_MPH 0.621371 #define SPEED_FACTOR_MPH 0.621371
#define MARK_WIDTH_LARGE (6.0 / 240.0)
#define MARK_WIDTH (2.0 / 240.0)
#define ANGLE_MIN 232.0 * (M_PI / 180.0) #define ANGLE_MIN 232.0 * (M_PI / 180.0)
#define ANGLE_MAX 488.0 * (M_PI / 180.0) #define ANGLE_MAX 488.0 * (M_PI / 180.0)
@ -64,7 +67,7 @@ static int draw_bg(hexagram_gauge *gauge, cairo_t *cr) {
for (speed=0; speed<=max; speed += 5) { for (speed=0; speed<=max; speed += 5) {
int large = speed % 10 == 0? 1: 0; int large = speed % 10 == 0? 1: 0;
cairo_set_line_width(cr, large? 6.0: 2.0); cairo_set_line_width(cr, speedo->dial.radius * (large? MARK_WIDTH_LARGE: MARK_WIDTH));
hexagram_dial_draw_mark(&speedo->dial, cr, (double)speed / factor, large); hexagram_dial_draw_mark(&speedo->dial, cr, (double)speed / factor, large);
} }

View file

@ -4,6 +4,9 @@
#include <hexagram/gauge.h> #include <hexagram/gauge.h>
#include <hexagram/tacho.h> #include <hexagram/tacho.h>
#define MARK_WIDTH_LARGE (6.0 / 240.0)
#define MARK_WIDTH (2.0 / 240.0)
#define ANGLE_MIN (232.0 * (M_PI / 180.0)) #define ANGLE_MIN (232.0 * (M_PI / 180.0))
#define ANGLE_MAX (488.0 * (M_PI / 180.0)) #define ANGLE_MAX (488.0 * (M_PI / 180.0))
@ -36,7 +39,7 @@ static int draw_bg(hexagram_gauge *gauge, cairo_t *cr) {
cairo_set_source_rgba(cr, 0.6, 0.1, 0.1, gauge->alpha); cairo_set_source_rgba(cr, 0.6, 0.1, 0.1, gauge->alpha);
} }
cairo_set_line_width(cr, large? 6.0: 2.0); cairo_set_line_width(cr, tacho->dial.radius * (large? MARK_WIDTH_LARGE: MARK_WIDTH));
hexagram_dial_draw_mark(&tacho->dial, cr, rpm, large); hexagram_dial_draw_mark(&tacho->dial, cr, rpm, large);
} }

View file

@ -3,6 +3,8 @@
#include <hexagram/gauge.h> #include <hexagram/gauge.h>
#include <hexagram/thermo.h> #include <hexagram/thermo.h>
#define MARK_WIDTH (6.0 / 240.0)
#define RAD (M_PI / 180.0) #define RAD (M_PI / 180.0)
#define ANGLE_MIN (144.0 * RAD) #define ANGLE_MIN (144.0 * RAD)
@ -36,7 +38,7 @@ static int draw_bg(hexagram_gauge *gauge, cairo_t *cr) {
cairo_set_source_rgba(cr, 1, 0, 0, gauge->alpha); cairo_set_source_rgba(cr, 1, 0, 0, gauge->alpha);
hexagram_dial_draw_legend(&thermo->dial, cr, thermo->dial.max_value, "H"); hexagram_dial_draw_legend(&thermo->dial, cr, thermo->dial.max_value, "H");
cairo_set_line_width(cr, 6.0); cairo_set_line_width(cr, thermo->dial.radius * MARK_WIDTH);
incr = (thermo->dial.max_value - thermo->dial.min_value) / 8.0; incr = (thermo->dial.max_value - thermo->dial.min_value) / 8.0;