From f99b62636f4bb625eb45cafe422cf4b8318f93a3 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 30 Jan 2013 23:16:42 -0300 Subject: [PATCH] ubb-la/gui.c: label channels --- ubb-la/gui.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/ubb-la/gui.c b/ubb-la/gui.c index 9a94be7..bc8fb68 100644 --- a/ubb-la/gui.c +++ b/ubb-la/gui.c @@ -10,11 +10,17 @@ * (at your option) any later version. */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE /* for vasprintf */ +#endif + +#include #include #include #include "SDL.h" #include "SDL_gfxPrimitives.h" +#include "SDL_gfxPrimitives_font.h" #include "gui.h" @@ -29,8 +35,9 @@ #define XRES 320 /* canvas width */ #define YRES 240 /* canvas height */ -#define LEVEL_RGBA 0xffff00ff -#define BOUNCE_RGBA 0xff8080ff +#define LEVEL_RGBA 0xffff00ff /* constant level or single change */ +#define BOUNCE_RGBA 0xff8080ff /* bouncing signal */ +#define LABEL_RGBA 0xffffffff /* channel label */ #define CH_XOFF 30 #define CH_YOFF 30 @@ -80,6 +87,41 @@ static void update(void) } +/* ----- Text output ------------------------------------------------------- */ + + +/* + * stringColor from SDL_gfx fails for some reason. SDL_ttf is just too much + * compatibility trouble. So we do our own. + */ + +static void textf(int x, int y, uint32_t color, const char *fmt, ...) +{ + va_list ap; + char *s; + uint8_t *p; + int ix, iy; + int res; + + va_start(ap, fmt); + res = vasprintf(&s, fmt, ap); + va_end(ap); + (void) res; + + while (*s) { + p = gfxPrimitivesFontdata+(*s << 3); + for (iy = 0; iy != 8; iy++) { + for (ix = 0; ix != 8; ix++) + if ((*p << ix) & 0x80) + pixelColor(surf, x+ix, y+iy, color); + p++; + } + x += 8; + s++; + } +} + + /* ----- Waveform elements ------------------------------------------------- */ @@ -237,12 +279,15 @@ void gui(const uint8_t *buf, int skip, int nibbles) int pos = (skip+nibbles) >> 1; int zoom; /* < 0: zoom out; 0: 1 pixel = 1 sample; > 1: zoom in */ int min_zoom = 0; + int i; while (XRES-CH_XOFF < (nibbles-skip) >> -min_zoom) min_zoom--; zoom = min_zoom; while (1) { clear(); + for (i = 0; i != 4; i++) + textf(0, ch_y(i, 1), LABEL_RGBA, "CH%d", i); show_buffer(buf, skip, nibbles, CH_XOFF, XRES, zoom, pos); update();