1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-16 21:57:30 +02:00

ubb-la/gui.c: display a small map of buffer and view

This commit is contained in:
Werner Almesberger 2013-01-30 23:37:05 -03:00
parent f99b62636f
commit e1be0f242b

View File

@ -35,10 +35,19 @@
#define XRES 320 /* canvas width */ #define XRES 320 /* canvas width */
#define YRES 240 /* canvas height */ #define YRES 240 /* canvas height */
#define MAP_BUF_RGBA 0x808080ff /* buffer in the map */
#define MAP_VIEW_RGBA 0xffffffff /* current view in the map */
#define LEVEL_RGBA 0xffff00ff /* constant level or single change */ #define LEVEL_RGBA 0xffff00ff /* constant level or single change */
#define BOUNCE_RGBA 0xff8080ff /* bouncing signal */ #define BOUNCE_RGBA 0xff8080ff /* bouncing signal */
#define LABEL_RGBA 0xffffffff /* channel label */ #define LABEL_RGBA 0xffffffff /* channel label */
#define XCENTER ((XRES+CH_XOFF)/2)
#define MAP_BUF_Y0 2
#define MAP_BUF_Y1 8
#define MAP_VIEW_Y0 0
#define MAP_VIEW_Y1 10
#define CH_XOFF 30 #define CH_XOFF 30
#define CH_YOFF 30 #define CH_YOFF 30
#define CH_SKIP 16 #define CH_SKIP 16
@ -122,6 +131,26 @@ static void textf(int x, int y, uint32_t color, const char *fmt, ...)
} }
/* ----- Map of buffer and view -------------------------------------------- */
static void show_map(int skip, int nibbles, int s0, int s1)
{
int w = nibbles-skip;
int m = (nibbles+skip) >> 1;
int scale = 0;
while (w >= (XRES-CH_XOFF)/2) {
w >>= 1;
scale++;
}
boxColor(surf, XCENTER-(w >> 1), MAP_BUF_Y0,
XCENTER+(w >> 1), MAP_BUF_Y1, MAP_BUF_RGBA);
rectangleColor(surf, (s0-m+(XCENTER << scale)) >> scale, MAP_VIEW_Y0,
(s1-m+(XCENTER << scale)) >> scale, MAP_VIEW_Y1, MAP_VIEW_RGBA);
}
/* ----- Waveform elements ------------------------------------------------- */ /* ----- Waveform elements ------------------------------------------------- */
@ -227,12 +256,14 @@ static void show_buffer_zoom_out(const uint8_t *buf, int skip, int nibbles,
static void show_buffer(const uint8_t *buf, int skip, int nibbles, static void show_buffer(const uint8_t *buf, int skip, int nibbles,
int x0, int x1, int zoom, int pos) int x0, int x1, int zoom, int pos)
{ {
int xm, w, p0, p1; int xm, w, s, p0, p1;
int d, dp; int d, dp;
xm = (x0+x1) >> 1; xm = (x0+x1) >> 1;
dp = pos-((nibbles+skip) >> 1); dp = pos-((nibbles+skip) >> 1);
if (zoom < 0) { if (zoom < 0) {
s = (x1-x0) << -zoom;
show_map(skip, nibbles, pos-s/2, pos+s/2);
w = (nibbles-skip) >> -zoom; w = (nibbles-skip) >> -zoom;
p0 = xm-(w >> 1)-(dp >> -zoom); p0 = xm-(w >> 1)-(dp >> -zoom);
p1 = xm+((w+1) >> 1)-(dp >> -zoom); p1 = xm+((w+1) >> 1)-(dp >> -zoom);
@ -246,6 +277,8 @@ static void show_buffer(const uint8_t *buf, int skip, int nibbles,
} }
show_buffer_zoom_out(buf, skip, nibbles, p0, p1); show_buffer_zoom_out(buf, skip, nibbles, p0, p1);
} else { } else {
s = (x1-x0) >> zoom;
show_map(skip, nibbles, pos-s/2, pos+s/2);
w = (nibbles-skip) << zoom; w = (nibbles-skip) << zoom;
p0 = xm-(w >> 1)-(dp << zoom); p0 = xm-(w >> 1)-(dp << zoom);
p1 = xm+((w+1) >> 1)-(dp << zoom); p1 = xm+((w+1) >> 1)-(dp << zoom);