86 lines
2.1 KiB
C
86 lines
2.1 KiB
C
#include <stdlib.h>
|
|
#include <math.h>
|
|
|
|
#include <hexagram/gauge.h>
|
|
#include <hexagram/fuel.h>
|
|
|
|
#define RAD (M_PI / 180.0)
|
|
|
|
#define LEVEL_MIN 0
|
|
#define LEVEL_WARN 2
|
|
#define LEVEL_MAX 15
|
|
|
|
#define ANGLE_MIN (144.0 * RAD)
|
|
#define ANGLE_MAX (216.0 * RAD)
|
|
|
|
#define FONT_FACE "Muli"
|
|
|
|
static int draw_bg(hexagram_gauge *gauge, cairo_t *cr) {
|
|
hexagram_fuel *fuel = (hexagram_fuel *)gauge;
|
|
int level;
|
|
|
|
if (hexagram_dial_draw_bg(&fuel->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, fuel->dial.radius * 0.1);
|
|
|
|
cairo_set_source_rgba(cr, 1, 0, 0, gauge->alpha);
|
|
hexagram_dial_draw_legend(&fuel->dial, cr, 0, "0");
|
|
|
|
cairo_set_source_rgba(cr, 1, 1, 1, gauge->alpha);
|
|
hexagram_dial_draw_legend(&fuel->dial, cr, fuel->dial.max_value, "1");
|
|
|
|
cairo_set_line_width(cr, 6.0);
|
|
|
|
for (level=0; level<=LEVEL_MAX; level++) {
|
|
int large = 0;
|
|
|
|
if (level < 2) {
|
|
cairo_set_source_rgba(cr, 1, 0, 0, gauge->alpha);
|
|
} else if (level < 4) {
|
|
large = 1;
|
|
cairo_set_source_rgba(cr, 1, 0, 0, gauge->alpha);
|
|
} else {
|
|
large = 1;
|
|
cairo_set_source_rgba(cr, 1, 1, 1, gauge->alpha);
|
|
}
|
|
|
|
hexagram_dial_draw_mark(&fuel->dial, cr, level, large);
|
|
}
|
|
|
|
return 0;
|
|
|
|
error_dial_draw_bg:
|
|
return -1;
|
|
}
|
|
|
|
int hexagram_fuel_init(hexagram_fuel *fuel,
|
|
double x,
|
|
double y,
|
|
double radius) {
|
|
if (hexagram_dial_init(&fuel->dial,
|
|
HEXAGRAM_DIAL_BOTTOM,
|
|
x,
|
|
y,
|
|
radius,
|
|
ANGLE_MIN,
|
|
ANGLE_MAX,
|
|
LEVEL_MIN,
|
|
LEVEL_MAX) < 0) {
|
|
goto error_dial_init;
|
|
}
|
|
|
|
fuel->dial.gauge.draw_bg = draw_bg;
|
|
fuel->dial.value = LEVEL_MIN;
|
|
|
|
return 0;
|
|
|
|
error_dial_init:
|
|
return -1;
|
|
}
|