Date:2013-01-31 03:16:42 (11 years 1 month ago)
Author:Werner Almesberger
Commit:f99b62636f4bb625eb45cafe422cf4b8318f93a3
Message:ubb-la/gui.c: label channels

Files: ubb-la/gui.c (4 diffs)

Change Details

ubb-la/gui.c
1010 * (at your option) any later version.
1111 */
1212
13#ifndef _GNU_SOURCE
14#define _GNU_SOURCE /* for vasprintf */
15#endif
16
17#include <stdarg.h>
1318#include <stdint.h>
1419#include <stdlib.h>
1520
1621#include "SDL.h"
1722#include "SDL_gfxPrimitives.h"
23#include "SDL_gfxPrimitives_font.h"
1824
1925#include "gui.h"
2026
...... 
2935#define XRES 320 /* canvas width */
3036#define YRES 240 /* canvas height */
3137
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 */
3441
3542#define CH_XOFF 30
3643#define CH_YOFF 30
...... 
8087}
8188
8289
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
98static 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
83125/* ----- Waveform elements ------------------------------------------------- */
84126
85127
...... 
237279    int pos = (skip+nibbles) >> 1;
238280    int zoom; /* < 0: zoom out; 0: 1 pixel = 1 sample; > 1: zoom in */
239281    int min_zoom = 0;
282    int i;
240283
241284    while (XRES-CH_XOFF < (nibbles-skip) >> -min_zoom)
242285        min_zoom--;
243286    zoom = min_zoom;
244287    while (1) {
245288        clear();
289        for (i = 0; i != 4; i++)
290            textf(0, ch_y(i, 1), LABEL_RGBA, "CH%d", i);
246291        show_buffer(buf, skip, nibbles, CH_XOFF, XRES, zoom, pos);
247292        update();
248293

Archive Download the corresponding diff file

Branches:
master



interactive