Oh man, The Cheat. This is gonna be bro-awesome.

This commit is contained in:
XANTRONIX Development 2019-05-25 22:49:59 -05:00
parent 9f919f6575
commit 021102c67a
2 changed files with 86 additions and 64 deletions

View file

@ -18,7 +18,7 @@ $(EXAMPLES): %: %.c $(STATIC)
$(CC) $(CFLAGS) $< -o $@ $(STATIC) $(CC) $(CFLAGS) $< -o $@ $(STATIC)
cluster: cluster.c $(STATIC) cluster: cluster.c $(STATIC)
$(CC) $(CFLAGS) $< -o $@ $(STATIC) $(shell pkg-config --cflags --libs cairo x11) $(CC) $(CFLAGS) $< -o $@ $(STATIC) $(shell pkg-config --cflags --libs cairo x11) -lm
view: view.c $(STATIC) view: view.c $(STATIC)
$(CC) $(CFLAGS) $< -o $@ $(STATIC) -lncurses $(CC) $(CFLAGS) $< -o $@ $(STATIC) -lncurses

View file

@ -28,79 +28,102 @@ static void draw_needle(cairo_t *cr,
cairo_stroke(cr); cairo_stroke(cr);
} }
static void redraw(cairo_t *ctx) { static void draw_face_number(cairo_t *cr,
/* double x,
* Paint canvas black double y,
*/ double r,
cairo_set_source_rgb(ctx, 0, 0, 0); double min_angle,
cairo_paint(ctx); double max_angle,
double value,
const char *text) {
double angle = min_angle + ((max_angle - min_angle) * value) - 95;
/* cairo_set_source_rgb(cr, 1, 1, 1);
* Draw two identical circles
*/
cairo_set_source_rgb(ctx, 1, 1, 1);
cairo_arc(ctx, 208, 240, 192, 0, 360);
cairo_stroke(ctx);
/* cairo_move_to(cr,
* Draw a gauge needle x + r * cos((M_PI/180.0) * angle),
*/ y + r * sin((M_PI/180.0) * angle));
draw_needle(ctx, 208, 240, 176, 232, 502, 0.0);
/* cairo_save(cr);
* Draw another circle cairo_rotate(cr, (M_PI/180.0) * (angle + 95));
*/ cairo_show_text(cr, text);
cairo_set_source_rgb(ctx, 1, 1, 1); cairo_restore(cr);
cairo_arc(ctx, 816, 240, 192, 0, 360);
cairo_stroke(ctx);
/*
* Draw two smaller circles
*/
cairo_arc(ctx, 442, 368, 64, 0, 360 * (M_PI/180));
cairo_stroke(ctx);
cairo_arc(ctx, 582, 368, 64, 0, 360 * (M_PI/180));
cairo_stroke(ctx);
/*
* Draw a rectangle
*/
cairo_move_to(ctx, 432, 48);
cairo_line_to(ctx, 592, 48);
cairo_line_to(ctx, 592, 288);
cairo_line_to(ctx, 432, 288);
cairo_line_to(ctx, 432, 48);
cairo_set_source_rgb(ctx, 0.75, 0, 0);
cairo_fill(ctx);
cairo_move_to(ctx, 432, 48);
cairo_line_to(ctx, 592, 48);
cairo_line_to(ctx, 592, 288);
cairo_line_to(ctx, 432, 288);
cairo_line_to(ctx, 432, 48);
cairo_set_source_rgb(ctx, 1, 1, 1);
cairo_stroke(ctx);
} }
static void draw_text(cairo_t *cr) { static void redraw(cairo_t *cr) {
int i;
/*
* Set up text
*/
cairo_select_font_face(cr, "Helvetica", cairo_select_font_face(cr, "Helvetica",
CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL); CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(cr, 13); cairo_set_font_size(cr, 24);
cairo_move_to(cr, 208 + 192, 240); /*
cairo_save(cr); * Paint canvas black
cairo_rotate(cr, 45.0 * (M_PI/180)); */
cairo_show_text(cr, "10"); cairo_set_source_rgb(cr, 0, 0, 0);
cairo_restore(cr); cairo_paint(cr);
cairo_move_to(cr, 208, 240 + 192); /*
cairo_save(cr); * Draw two identical circles
cairo_rotate(cr, 90.0 * (M_PI/180)); */
cairo_show_text(cr, "20"); cairo_set_source_rgb(cr, 1, 1, 1);
cairo_restore(cr); cairo_arc(cr, 208, 240, 192, 0, 360);
cairo_stroke(cr);
/*
* Draw a face number
*/
for (i=0; i<=80; i+=10) {
char text[4];
snprintf(text, 3, "%02d", i);
draw_face_number(cr, 208, 240, 162, 232, 488, i / 80.0, text);
}
/*
* Draw a gauge needle
*/
draw_needle(cr, 208, 240, 148, 232, 488, 0.0);
/*
* Draw another circle
*/
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_arc(cr, 816, 240, 192, 0, 360);
cairo_stroke(cr);
/*
* Draw two smaller circles
*/
cairo_arc(cr, 442, 368, 64, 0, 360 * (M_PI/180));
cairo_stroke(cr);
cairo_arc(cr, 582, 368, 64, 0, 360 * (M_PI/180));
cairo_stroke(cr);
/*
* Draw a rectangle
*/
cairo_move_to(cr, 432, 48);
cairo_line_to(cr, 592, 48);
cairo_line_to(cr, 592, 288);
cairo_line_to(cr, 432, 288);
cairo_line_to(cr, 432, 48);
cairo_set_source_rgb(cr, 0.75, 0, 0);
cairo_fill(cr);
cairo_move_to(cr, 432, 48);
cairo_line_to(cr, 592, 48);
cairo_line_to(cr, 592, 288);
cairo_line_to(cr, 432, 288);
cairo_line_to(cr, 432, 48);
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_stroke(cr);
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -139,7 +162,6 @@ int main(int argc, char **argv) {
ctx = cairo_create(sfc); ctx = cairo_create(sfc);
redraw(ctx); redraw(ctx);
draw_text(ctx);
while (1) { while (1) {
XExposeEvent *expose; XExposeEvent *expose;