*The Cheat flutters eyes, sounding very pleased*
This commit is contained in:
parent
cd9b07b8ac
commit
130c6cb0f0
5 changed files with 117 additions and 87 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <hexagram/can.h>
|
#include <hexagram/can.h>
|
||||||
#include <hexagram/window.h>
|
#include <hexagram/window.h>
|
||||||
#include <hexagram/gauge.h>
|
#include <hexagram/gauge.h>
|
||||||
|
#include <hexagram/tacho.h>
|
||||||
|
|
||||||
typedef struct _hexagram_cluster_state {
|
typedef struct _hexagram_cluster_state {
|
||||||
double rpm, rps, temp, fuel;
|
double rpm, rps, temp, fuel;
|
||||||
|
@ -18,84 +19,6 @@ static hexagram_cluster_state state = {
|
||||||
0, 0, 0, 0
|
0, 0, 0, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
static void draw_tachometer_needle(cairo_t *cr,
|
|
||||||
double x,
|
|
||||||
double y,
|
|
||||||
double r,
|
|
||||||
double rpm) {
|
|
||||||
if (rpm > 8000) {
|
|
||||||
rpm = 8000;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Draw a tiny boi circle
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void draw_tachometer(cairo_t *cr,
|
|
||||||
double x,
|
|
||||||
double y,
|
|
||||||
double r,
|
|
||||||
double redline) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
cairo_select_font_face(cr, "Helvetica",
|
|
||||||
CAIRO_FONT_SLANT_NORMAL,
|
|
||||||
CAIRO_FONT_WEIGHT_NORMAL);
|
|
||||||
|
|
||||||
cairo_set_font_size(cr, r * 0.125);
|
|
||||||
|
|
||||||
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
||||||
cairo_arc(cr, x, y, r, 0, 2*M_PI);
|
|
||||||
cairo_stroke(cr);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Draw face numbers
|
|
||||||
*/
|
|
||||||
for (i=0; i<=80; i+=10) {
|
|
||||||
char text[4];
|
|
||||||
|
|
||||||
snprintf(text, 3, "%02d", i);
|
|
||||||
|
|
||||||
hexagram_gauge_draw_number(cr, x, y,
|
|
||||||
0.85 * r,
|
|
||||||
232 * (M_PI/180),
|
|
||||||
488 * (M_PI/180),
|
|
||||||
i / 80.0,
|
|
||||||
text);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i=0; i<=80; i++) {
|
|
||||||
if (i * 100 >= redline) {
|
|
||||||
cairo_set_source_rgb(cr, 1, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i % 5 == 0) {
|
|
||||||
hexagram_gauge_draw_mark(cr, x, y,
|
|
||||||
0.7 * r,
|
|
||||||
0.8 * r,
|
|
||||||
232 * (M_PI/180),
|
|
||||||
488 * (M_PI/180),
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void draw_speedometer(cairo_t *cr,
|
static void draw_speedometer(cairo_t *cr,
|
||||||
double x,
|
double x,
|
||||||
double y,
|
double y,
|
||||||
|
@ -321,11 +244,11 @@ static void cluster_draw_bg(cairo_t *cr,
|
||||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
||||||
cairo_paint(cr);
|
cairo_paint(cr);
|
||||||
|
|
||||||
draw_tachometer(cr,
|
hexagram_tacho_draw_face(cr,
|
||||||
width * 0.2,
|
width * 0.2,
|
||||||
height * 0.5,
|
height * 0.5,
|
||||||
height * 0.4,
|
height * 0.4,
|
||||||
6500);
|
6500);
|
||||||
|
|
||||||
draw_speedometer(cr,
|
draw_speedometer(cr,
|
||||||
width * 0.8,
|
width * 0.8,
|
||||||
|
@ -386,10 +309,11 @@ static void cluster_draw(cairo_t *cr,
|
||||||
double y,
|
double y,
|
||||||
double width,
|
double width,
|
||||||
double height) {
|
double height) {
|
||||||
draw_tachometer_needle(cr, x + width * 0.2,
|
hexagram_tacho_draw_needle(cr,
|
||||||
|
x + width * 0.2,
|
||||||
y + height * 0.5,
|
y + height * 0.5,
|
||||||
height * 0.4,
|
height * 0.4,
|
||||||
state.rpm);
|
state.rpm);
|
||||||
|
|
||||||
draw_speedometer_needle(cr,
|
draw_speedometer_needle(cr,
|
||||||
width * 0.8,
|
width * 0.8,
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
#ifndef _HEXAGRAM_GAUGE_H
|
||||||
|
#define _HEXAGRAM_GAUGE_H
|
||||||
|
|
||||||
#include <cairo.h>
|
#include <cairo.h>
|
||||||
|
|
||||||
void hexagram_gauge_draw_needle(cairo_t *cr,
|
void hexagram_gauge_draw_needle(cairo_t *cr,
|
||||||
|
@ -25,3 +28,5 @@ void hexagram_gauge_draw_mark(cairo_t *cr,
|
||||||
double min_angle,
|
double min_angle,
|
||||||
double max_angle,
|
double max_angle,
|
||||||
double value);
|
double value);
|
||||||
|
|
||||||
|
#endif /* _HEXAGRAM_GAUGE_H */
|
||||||
|
|
18
include/hexagram/tacho.h
Normal file
18
include/hexagram/tacho.h
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#ifndef _HEXAGRAM_TACHO_H
|
||||||
|
#define _HEXAGRAM_TACHO_H
|
||||||
|
|
||||||
|
#include <cairo.h>
|
||||||
|
|
||||||
|
void hexagram_tacho_draw_face(cairo_t *cr,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
double r,
|
||||||
|
double redline);
|
||||||
|
|
||||||
|
void hexagram_tacho_draw_needle(cairo_t *cr,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
double r,
|
||||||
|
double rpm);
|
||||||
|
|
||||||
|
#endif /* _HEXAGRAM_TACHO_H */
|
|
@ -8,12 +8,12 @@ CFLAGS += -fPIC -I$(INCLUDE_PATH) $(shell pkg-config --cflags cairo x11)
|
||||||
LDFLAGS = $(shell pkg-config --libs cairo x11) -lXext
|
LDFLAGS = $(shell pkg-config --libs cairo x11) -lXext
|
||||||
|
|
||||||
HEADERS = dict.h hash.h can.h capture.h pcapng.h module.h window.h \
|
HEADERS = dict.h hash.h can.h capture.h pcapng.h module.h window.h \
|
||||||
gauge.h sim.h
|
gauge.h tacho.h sim.h
|
||||||
|
|
||||||
HEADERS_LOCAL = util.h
|
HEADERS_LOCAL = util.h
|
||||||
|
|
||||||
OBJS = dict.o hash.o can.o capture.o pcapng.o module.o window.o \
|
OBJS = dict.o hash.o can.o capture.o pcapng.o module.o window.o \
|
||||||
gauge.o sim.o
|
gauge.o tacho.o sim.o
|
||||||
|
|
||||||
VERSION_MAJOR = 0
|
VERSION_MAJOR = 0
|
||||||
VERSION_MINOR = 0.1
|
VERSION_MINOR = 0.1
|
||||||
|
|
83
src/tacho.c
Normal file
83
src/tacho.c
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <hexagram/gauge.h>
|
||||||
|
#include <hexagram/tacho.h>
|
||||||
|
|
||||||
|
void hexagram_tacho_draw_face(cairo_t *cr,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
double r,
|
||||||
|
double redline) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
cairo_select_font_face(cr, "Helvetica",
|
||||||
|
CAIRO_FONT_SLANT_NORMAL,
|
||||||
|
CAIRO_FONT_WEIGHT_NORMAL);
|
||||||
|
|
||||||
|
cairo_set_font_size(cr, r * 0.125);
|
||||||
|
|
||||||
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||||||
|
cairo_arc(cr, x, y, r, 0, 2*M_PI);
|
||||||
|
cairo_stroke(cr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draw face numbers
|
||||||
|
*/
|
||||||
|
for (i=0; i<=80; i+=10) {
|
||||||
|
char text[4];
|
||||||
|
|
||||||
|
snprintf(text, 3, "%02d", i);
|
||||||
|
|
||||||
|
hexagram_gauge_draw_number(cr, x, y,
|
||||||
|
0.85 * r,
|
||||||
|
232 * (M_PI/180),
|
||||||
|
488 * (M_PI/180),
|
||||||
|
i / 80.0,
|
||||||
|
text);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i<=80; i++) {
|
||||||
|
if (i * 100 >= redline) {
|
||||||
|
cairo_set_source_rgb(cr, 1, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i % 5 == 0) {
|
||||||
|
hexagram_gauge_draw_mark(cr, x, y,
|
||||||
|
0.7 * r,
|
||||||
|
0.8 * r,
|
||||||
|
232 * (M_PI/180),
|
||||||
|
488 * (M_PI/180),
|
||||||
|
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,
|
||||||
|
double x,
|
||||||
|
double y,
|
||||||
|
double r,
|
||||||
|
double rpm) {
|
||||||
|
if (rpm > 8000) {
|
||||||
|
rpm = 8000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draw a tiny boi circle
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue