87 lines
2.3 KiB
C
87 lines
2.3 KiB
C
#include <math.h>
|
|
|
|
#include <hexagram/gauge.h>
|
|
#include <hexagram/thermo.h>
|
|
|
|
void hexagram_thermo_init(hexagram_thermo *thermo,
|
|
double x,
|
|
double y,
|
|
double radius,
|
|
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;
|
|
|
|
cairo_select_font_face(cr, "Helvetica",
|
|
CAIRO_FONT_SLANT_NORMAL,
|
|
CAIRO_FONT_WEIGHT_NORMAL);
|
|
|
|
cairo_set_font_size(cr, thermo->gauge.radius * 0.2);
|
|
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
|
|
cairo_arc(cr,
|
|
thermo->gauge.x,
|
|
thermo->gauge.y,
|
|
thermo->gauge.radius,
|
|
0,
|
|
2.0 * M_PI);
|
|
|
|
cairo_stroke(cr);
|
|
|
|
/*
|
|
* Draw face numbers
|
|
*/
|
|
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_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_move_to(cr,
|
|
thermo->gauge.x + 0.5 * thermo->gauge.radius,
|
|
thermo->gauge.y - 0.1 * thermo->gauge.radius);
|
|
|
|
cairo_show_text(cr, "260");
|
|
|
|
/*
|
|
* Draw gauge graduations
|
|
*/
|
|
for (i=0; i<=140; i+=7) {
|
|
if (i + 120 >= thermo->redline) {
|
|
cairo_set_source_rgb(cr, 1, 0, 0);
|
|
}
|
|
|
|
hexagram_gauge_draw_mark(&thermo->gauge,
|
|
cr,
|
|
(i % 35)? 0.8: 0.7,
|
|
0.90,
|
|
i / 140.0);
|
|
}
|
|
}
|
|
|
|
void hexagram_thermo_draw_needle(hexagram_thermo *thermo,
|
|
cairo_t *cr,
|
|
double temp) {
|
|
if (temp > 260) {
|
|
temp = 260;
|
|
}
|
|
|
|
hexagram_gauge_draw_needle(&thermo->gauge,
|
|
cr,
|
|
0.9,
|
|
temp / 260);
|
|
}
|