mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-27 17:05:20 +02:00
ubb-la/gui.c: label channels
This commit is contained in:
parent
444e0811bf
commit
f99b62636f
49
ubb-la/gui.c
49
ubb-la/gui.c
@ -10,11 +10,17 @@
|
|||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
#define _GNU_SOURCE /* for vasprintf */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
#include "SDL_gfxPrimitives.h"
|
#include "SDL_gfxPrimitives.h"
|
||||||
|
#include "SDL_gfxPrimitives_font.h"
|
||||||
|
|
||||||
#include "gui.h"
|
#include "gui.h"
|
||||||
|
|
||||||
@ -29,8 +35,9 @@
|
|||||||
#define XRES 320 /* canvas width */
|
#define XRES 320 /* canvas width */
|
||||||
#define YRES 240 /* canvas height */
|
#define YRES 240 /* canvas height */
|
||||||
|
|
||||||
#define LEVEL_RGBA 0xffff00ff
|
#define LEVEL_RGBA 0xffff00ff /* constant level or single change */
|
||||||
#define BOUNCE_RGBA 0xff8080ff
|
#define BOUNCE_RGBA 0xff8080ff /* bouncing signal */
|
||||||
|
#define LABEL_RGBA 0xffffffff /* channel label */
|
||||||
|
|
||||||
#define CH_XOFF 30
|
#define CH_XOFF 30
|
||||||
#define CH_YOFF 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 ------------------------------------------------- */
|
/* ----- Waveform elements ------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
@ -237,12 +279,15 @@ void gui(const uint8_t *buf, int skip, int nibbles)
|
|||||||
int pos = (skip+nibbles) >> 1;
|
int pos = (skip+nibbles) >> 1;
|
||||||
int zoom; /* < 0: zoom out; 0: 1 pixel = 1 sample; > 1: zoom in */
|
int zoom; /* < 0: zoom out; 0: 1 pixel = 1 sample; > 1: zoom in */
|
||||||
int min_zoom = 0;
|
int min_zoom = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
while (XRES-CH_XOFF < (nibbles-skip) >> -min_zoom)
|
while (XRES-CH_XOFF < (nibbles-skip) >> -min_zoom)
|
||||||
min_zoom--;
|
min_zoom--;
|
||||||
zoom = min_zoom;
|
zoom = min_zoom;
|
||||||
while (1) {
|
while (1) {
|
||||||
clear();
|
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);
|
show_buffer(buf, skip, nibbles, CH_XOFF, XRES, zoom, pos);
|
||||||
update();
|
update();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user