ubb-la/gui.c |
10 | 10 | * (at your option) any later version. |
11 | 11 | */ |
12 | 12 | |
| 13 | #ifndef _GNU_SOURCE |
| 14 | #define _GNU_SOURCE /* for vasprintf */ |
| 15 | #endif |
| 16 | |
| 17 | #include <stdarg.h> |
13 | 18 | #include <stdint.h> |
14 | 19 | #include <stdlib.h> |
15 | 20 | |
16 | 21 | #include "SDL.h" |
17 | 22 | #include "SDL_gfxPrimitives.h" |
| 23 | #include "SDL_gfxPrimitives_font.h" |
18 | 24 | |
19 | 25 | #include "gui.h" |
20 | 26 | |
... | ... | |
29 | 35 | #define XRES 320 /* canvas width */ |
30 | 36 | #define YRES 240 /* canvas height */ |
31 | 37 | |
32 | | #define LEVEL_RGBA 0xffff00ff |
33 | | #define BOUNCE_RGBA 0xff8080ff |
| 38 | #define LEVEL_RGBA 0xffff00ff /* constant level or single change */ |
| 39 | #define BOUNCE_RGBA 0xff8080ff /* bouncing signal */ |
| 40 | #define LABEL_RGBA 0xffffffff /* channel label */ |
34 | 41 | |
35 | 42 | #define CH_XOFF 30 |
36 | 43 | #define CH_YOFF 30 |
... | ... | |
80 | 87 | } |
81 | 88 | |
82 | 89 | |
| 90 | /* ----- Text output ------------------------------------------------------- */ |
| 91 | |
| 92 | |
| 93 | /* |
| 94 | * stringColor from SDL_gfx fails for some reason. SDL_ttf is just too much |
| 95 | * compatibility trouble. So we do our own. |
| 96 | */ |
| 97 | |
| 98 | static void textf(int x, int y, uint32_t color, const char *fmt, ...) |
| 99 | { |
| 100 | va_list ap; |
| 101 | char *s; |
| 102 | uint8_t *p; |
| 103 | int ix, iy; |
| 104 | int res; |
| 105 | |
| 106 | va_start(ap, fmt); |
| 107 | res = vasprintf(&s, fmt, ap); |
| 108 | va_end(ap); |
| 109 | (void) res; |
| 110 | |
| 111 | while (*s) { |
| 112 | p = gfxPrimitivesFontdata+(*s << 3); |
| 113 | for (iy = 0; iy != 8; iy++) { |
| 114 | for (ix = 0; ix != 8; ix++) |
| 115 | if ((*p << ix) & 0x80) |
| 116 | pixelColor(surf, x+ix, y+iy, color); |
| 117 | p++; |
| 118 | } |
| 119 | x += 8; |
| 120 | s++; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | |
83 | 125 | /* ----- Waveform elements ------------------------------------------------- */ |
84 | 126 | |
85 | 127 | |
... | ... | |
237 | 279 | int pos = (skip+nibbles) >> 1; |
238 | 280 | int zoom; /* < 0: zoom out; 0: 1 pixel = 1 sample; > 1: zoom in */ |
239 | 281 | int min_zoom = 0; |
| 282 | int i; |
240 | 283 | |
241 | 284 | while (XRES-CH_XOFF < (nibbles-skip) >> -min_zoom) |
242 | 285 | min_zoom--; |
243 | 286 | zoom = min_zoom; |
244 | 287 | while (1) { |
245 | 288 | clear(); |
| 289 | for (i = 0; i != 4; i++) |
| 290 | textf(0, ch_y(i, 1), LABEL_RGBA, "CH%d", i); |
246 | 291 | show_buffer(buf, skip, nibbles, CH_XOFF, XRES, zoom, pos); |
247 | 292 | update(); |
248 | 293 | |