ploot

plot images or real-time plain text from a .csv file
Log | Files | Refs | README

commit d962017f48ac3c15c670c154b9a7f951fe1dd82d
parent b46882e628eb24be3bd67c724a50edceb6687030
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 30 Apr 2018 16:01:27 +0200

draw strings

Diffstat:
Mffdraw.c | 16+++++++++++++---
Mffdraw.h | 1+
Mmain.c | 4+---
3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/ffdraw.c b/ffdraw.c @@ -22,10 +22,8 @@ void ffdraw_pixel(Canvas *can, Color col, int x, int y) { -/* Make it segfault early. * / x = MIN(can->w - 1, x); y = MIN(can->h - 1, y); -/ **/ memcpy(can->b + x + (can->h - 1 - y) * can->w, col, sizeof(*can->b)); } @@ -45,7 +43,7 @@ ffdraw_rectangle(Canvas *can, Color col, } /* - * Adapted from Bresenham's line algorithm and dcat's tplot. + * From Bresenham's line algorithm and dcat's tplot. */ void ffdraw_line(Canvas *can, Color col, @@ -96,6 +94,18 @@ ffdraw_char(Canvas *can, Color col, char c, Font *f, ffdraw_pixel(can, col, x + xf, y + yf); } +/* + * Draw a left aligned string without wrapping it. + */ +void +ffdraw_str(Canvas *can, Color col, char *s, Font *f, + int x, int y) +{ + for (; *s; x += f->w, s++) + ffdraw_char(can, col, *s, f, x, y); + +} + void ffdraw_fill(Canvas *can, Color col) { diff --git a/ffdraw.h b/ffdraw.h @@ -20,4 +20,5 @@ void ffdraw_pixel (Canvas *, Color, int, int); void ffdraw_rectangle(Canvas *, Color, int, int, int, int); void ffdraw_line (Canvas *, Color, int, int, int, int); void ffdraw_char (Canvas *, Color, char, Font *, int, int); +void ffdraw_str (Canvas *, Color, char *, Font *, int, int); void ffdraw_fill (Canvas *, Color); diff --git a/main.c b/main.c @@ -19,9 +19,7 @@ ffdraw(Canvas *can) ffdraw_fill(can, col1); ffdraw_line(can, col2, 49,1,9,79); - ffdraw_char(can, col2, '0' - 1, &font_14x6, 44, 50); - ffdraw_char(can, col2, '0' + 0, &font_14x6, 50, 50); - ffdraw_char(can, col2, '0' + 1, &font_14x6, 56, 50); + ffdraw_str(can, col2, "01234", &font_14x6, 44, 50); } int