87 lines
2.2 KiB
C
87 lines
2.2 KiB
C
#include <math.h>
|
|
|
|
#include <hexagram/gauge.h>
|
|
#include <hexagram/thermo.h>
|
|
|
|
#define RAD (M_PI / 180.0)
|
|
|
|
#define ANGLE_MIN (144.0 * RAD)
|
|
#define ANGLE_MAX (216.0 * RAD)
|
|
|
|
#define LEVEL_MIN 48
|
|
#define LEVEL_WARN 116
|
|
#define LEVEL_MAX 127
|
|
|
|
#define FONT_FACE "Muli"
|
|
|
|
static int draw_bg(hexagram_gauge *gauge, cairo_t *cr) {
|
|
hexagram_thermo *thermo = (hexagram_thermo *)gauge;
|
|
double incr;
|
|
int i;
|
|
|
|
if (hexagram_dial_draw_bg(&thermo->dial, cr) < 0) {
|
|
goto error_dial_draw_bg;
|
|
}
|
|
|
|
cairo_select_font_face(cr,
|
|
FONT_FACE,
|
|
CAIRO_FONT_SLANT_NORMAL,
|
|
CAIRO_FONT_WEIGHT_BOLD);
|
|
|
|
cairo_set_font_size(cr, thermo->dial.radius * 0.1);
|
|
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
hexagram_dial_draw_legend(&thermo->dial, cr, thermo->dial.min_value, "C");
|
|
|
|
cairo_set_source_rgb(cr, 1, 0, 0);
|
|
hexagram_dial_draw_legend(&thermo->dial, cr, thermo->dial.max_value, "H");
|
|
|
|
cairo_set_line_width(cr, 6.0);
|
|
|
|
incr = (thermo->dial.max_value - thermo->dial.min_value) / 8.0;
|
|
|
|
for (i=0; i<9; i++) {
|
|
double level = thermo->dial.min_value + i * incr;
|
|
|
|
if (level >= LEVEL_WARN) {
|
|
cairo_set_source_rgb(cr, 0.8, 0, 0);
|
|
} else {
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
}
|
|
|
|
hexagram_dial_draw_mark(&thermo->dial, cr, 0.83, 0.87, level);
|
|
|
|
level += incr;
|
|
}
|
|
|
|
return 0;
|
|
|
|
error_dial_draw_bg:
|
|
return -1;
|
|
}
|
|
|
|
int hexagram_thermo_init(hexagram_thermo *thermo,
|
|
double x,
|
|
double y,
|
|
double radius) {
|
|
if (hexagram_dial_init(&thermo->dial,
|
|
HEXAGRAM_DIAL_BOTTOM,
|
|
x,
|
|
y,
|
|
radius,
|
|
ANGLE_MIN,
|
|
ANGLE_MAX,
|
|
LEVEL_MIN,
|
|
LEVEL_MAX) < 0) {
|
|
goto error_dial_init;
|
|
}
|
|
|
|
thermo->dial.gauge.draw_bg = draw_bg;
|
|
thermo->dial.value = LEVEL_MIN;
|
|
thermo->level_warn = LEVEL_WARN;
|
|
|
|
return 0;
|
|
|
|
error_dial_init:
|
|
return -1;
|
|
}
|