2013-01-30 19:38:54 +02:00
|
|
|
/*
|
|
|
|
* gui.c - Graphical output for ubb-la
|
|
|
|
*
|
|
|
|
* Written 2013 by Werner Almesberger
|
|
|
|
* Copyright 2013 Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2013-01-31 04:16:42 +02:00
|
|
|
#include <stdarg.h>
|
2013-01-30 19:38:54 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2013-01-31 07:50:01 +02:00
|
|
|
#include <alloca.h>
|
2013-01-30 19:38:54 +02:00
|
|
|
|
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_gfxPrimitives.h"
|
2013-01-31 04:16:42 +02:00
|
|
|
#include "SDL_gfxPrimitives_font.h"
|
2013-01-30 19:38:54 +02:00
|
|
|
|
|
|
|
#include "gui.h"
|
|
|
|
|
|
|
|
|
2013-01-31 02:25:47 +02:00
|
|
|
#if 0
|
|
|
|
#define DEBUG(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DEBUG(fmt, ...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2013-01-30 19:38:54 +02:00
|
|
|
#define XRES 320 /* canvas width */
|
|
|
|
#define YRES 240 /* canvas height */
|
|
|
|
|
2013-01-31 07:59:37 +02:00
|
|
|
|
|
|
|
/* ----- Colors ------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
2013-01-31 05:47:14 +02:00
|
|
|
#define TEXT_RGBA 0xffffffff /* general text */
|
2013-01-31 07:57:27 +02:00
|
|
|
#define UNIT_RGBA 0xb0e0ffff /* units */
|
2013-01-31 04:37:05 +02:00
|
|
|
#define MAP_BUF_RGBA 0x808080ff /* buffer in the map */
|
|
|
|
#define MAP_VIEW_RGBA 0xffffffff /* current view in the map */
|
2013-01-31 08:25:21 +02:00
|
|
|
#define CENTER_RGBA 0x5080ffff /* center marker */
|
2013-01-31 04:16:42 +02:00
|
|
|
#define LEVEL_RGBA 0xffff00ff /* constant level or single change */
|
|
|
|
#define BOUNCE_RGBA 0xff8080ff /* bouncing signal */
|
|
|
|
#define LABEL_RGBA 0xffffffff /* channel label */
|
2013-01-31 06:09:42 +02:00
|
|
|
#define DIV_RGBA 0x808080ff /* divisions */
|
2013-01-30 19:38:54 +02:00
|
|
|
|
2013-01-31 07:59:37 +02:00
|
|
|
|
|
|
|
/* ----- Layout ------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
2013-01-31 04:37:05 +02:00
|
|
|
#define XCENTER ((XRES+CH_XOFF)/2)
|
2013-01-31 06:11:18 +02:00
|
|
|
#define XWIDTH (XRES-CH_XOFF)
|
2013-01-31 04:37:05 +02:00
|
|
|
|
|
|
|
#define MAP_BUF_Y0 2
|
|
|
|
#define MAP_BUF_Y1 8
|
|
|
|
#define MAP_VIEW_Y0 0
|
|
|
|
#define MAP_VIEW_Y1 10
|
|
|
|
|
2013-01-31 08:25:21 +02:00
|
|
|
#define CENTER_W 8
|
|
|
|
#define CENTER_Y0 20
|
|
|
|
#define CENTER_Y1 24
|
|
|
|
|
2013-01-30 19:38:54 +02:00
|
|
|
#define CH_XOFF 30
|
|
|
|
#define CH_YOFF 30
|
|
|
|
#define CH_SKIP 16
|
|
|
|
#define CH_HEIGHT 8
|
|
|
|
|
2013-01-31 06:09:42 +02:00
|
|
|
#define DIV_X 32
|
|
|
|
#define DIV_Y 6
|
|
|
|
|
2013-01-31 01:35:30 +02:00
|
|
|
#define MAX_ZOOM 3
|
2013-01-30 19:38:54 +02:00
|
|
|
|
2013-01-31 08:15:33 +02:00
|
|
|
#define UNIT_GAP 2 /* space between number and unit */
|
|
|
|
|
2013-01-31 08:52:24 +02:00
|
|
|
#define POS_X 168
|
|
|
|
#define POS_Y (MEAS_DIV_Y-8-3)
|
|
|
|
|
|
|
|
#define MEAS_DIV_Y (FREQ_Y-3-1)
|
|
|
|
|
2013-01-31 05:47:14 +02:00
|
|
|
#define FREQ_X 0
|
2013-01-31 08:52:24 +02:00
|
|
|
#define FREQ_Y 222
|
2013-01-31 05:47:14 +02:00
|
|
|
#define INTERVAL_X 0
|
2013-01-31 08:52:24 +02:00
|
|
|
#define INTERVAL_Y (FREQ_Y+8+2)
|
2013-01-31 08:15:33 +02:00
|
|
|
#define DIV_SAMP_X (DIV_INT_X-8)
|
2013-01-31 06:21:56 +02:00
|
|
|
#define DIV_SAMP_Y FREQ_Y
|
|
|
|
#define DIV_INT_X 80
|
|
|
|
#define DIV_INT_Y INTERVAL_Y
|
2013-01-31 05:47:14 +02:00
|
|
|
|
2013-01-31 07:59:37 +02:00
|
|
|
|
|
|
|
/* ----- Miscellaneous definitions ----------------------------------------- */
|
|
|
|
|
|
|
|
|
2013-01-31 01:55:58 +02:00
|
|
|
#define REPEAT_DELAY_MS 300
|
|
|
|
#define REPEAT_INTERVAL_MS 30
|
2013-01-30 19:38:54 +02:00
|
|
|
|
|
|
|
static SDL_Surface *surf;
|
|
|
|
|
|
|
|
|
2013-01-31 03:07:31 +02:00
|
|
|
/* ----- SDL initialization and screen-wide functions ---------------------- */
|
|
|
|
|
|
|
|
|
2013-01-30 19:38:54 +02:00
|
|
|
void gui_init(void)
|
|
|
|
{
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
|
|
|
fprintf(stderr, "SDL_init: %s\n", SDL_GetError());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
atexit(SDL_Quit);
|
|
|
|
|
|
|
|
surf = SDL_SetVideoMode(XRES, YRES, 0, SDL_SWSURFACE);
|
|
|
|
if (!surf) {
|
|
|
|
fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-01-31 01:55:58 +02:00
|
|
|
|
|
|
|
SDL_EnableKeyRepeat(REPEAT_DELAY_MS, REPEAT_INTERVAL_MS);
|
2013-01-30 19:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void clear(void)
|
|
|
|
{
|
|
|
|
SDL_LockSurface(surf);
|
|
|
|
SDL_FillRect(surf, NULL, SDL_MapRGB(surf->format, 0, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 03:07:31 +02:00
|
|
|
static void update(void)
|
|
|
|
{
|
|
|
|
SDL_UnlockSurface(surf);
|
|
|
|
SDL_UpdateRect(surf, 0, 0, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 04:16:42 +02:00
|
|
|
/* ----- 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;
|
2013-01-31 06:45:42 +02:00
|
|
|
char *tmp, *s;
|
2013-01-31 04:16:42 +02:00
|
|
|
uint8_t *p;
|
2013-01-31 07:50:01 +02:00
|
|
|
int n, ix, iy;
|
2013-01-31 04:16:42 +02:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2013-01-31 07:50:01 +02:00
|
|
|
n = vsnprintf(NULL, 0, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
tmp = alloca(n+1);
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(tmp, n+1, fmt, ap);
|
2013-01-31 04:16:42 +02:00
|
|
|
va_end(ap);
|
|
|
|
|
2013-01-31 06:45:42 +02:00
|
|
|
for (s = tmp; *s; s++) {
|
2013-01-31 04:16:42 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 04:37:05 +02:00
|
|
|
/* ----- 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;
|
2013-01-31 09:03:31 +02:00
|
|
|
int x0, x1;
|
2013-01-31 04:37:05 +02:00
|
|
|
|
2013-01-31 06:11:18 +02:00
|
|
|
while (w >= XWIDTH/2) {
|
2013-01-31 04:37:05 +02:00
|
|
|
w >>= 1;
|
|
|
|
scale++;
|
|
|
|
}
|
|
|
|
boxColor(surf, XCENTER-(w >> 1), MAP_BUF_Y0,
|
|
|
|
XCENTER+(w >> 1), MAP_BUF_Y1, MAP_BUF_RGBA);
|
2013-01-31 09:03:31 +02:00
|
|
|
x0 = (s0-m+(XCENTER << scale)) >> scale;
|
|
|
|
x1 = x0+((s1-s0) >> scale);
|
|
|
|
rectangleColor(surf, x0, MAP_VIEW_Y0, x1, MAP_VIEW_Y1, MAP_VIEW_RGBA);
|
2013-01-31 04:37:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 03:07:31 +02:00
|
|
|
/* ----- Waveform elements ------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2013-01-30 19:38:54 +02:00
|
|
|
static inline int ch_y(int ch, int v)
|
|
|
|
{
|
|
|
|
return CH_YOFF+CH_SKIP*ch+(v ? 0 : CH_HEIGHT);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void bounce(int x, int ch)
|
|
|
|
{
|
|
|
|
vlineColor(surf, x, ch_y(ch, 0), ch_y(ch, 1), BOUNCE_RGBA);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void change(int x, int ch)
|
|
|
|
{
|
|
|
|
vlineColor(surf, x, ch_y(ch, 0), ch_y(ch, 1), LEVEL_RGBA);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 01:35:30 +02:00
|
|
|
static void level(int x0, int x1, int ch, int v)
|
2013-01-30 19:38:54 +02:00
|
|
|
{
|
2013-01-31 01:35:30 +02:00
|
|
|
if (x0 == x1)
|
|
|
|
pixelColor(surf, x0, ch_y(ch, v), LEVEL_RGBA);
|
|
|
|
else
|
|
|
|
hlineColor(surf, x0, x1, ch_y(ch, v), LEVEL_RGBA);
|
2013-01-30 19:38:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 03:07:31 +02:00
|
|
|
/* ----- Show (part of) a buffer ------------------------------------------- */
|
|
|
|
|
|
|
|
|
2013-01-31 01:35:30 +02:00
|
|
|
static void show_buffer_zoom_in(const uint8_t *buf, int skip, int nibbles,
|
|
|
|
int x0, int x1)
|
|
|
|
{
|
|
|
|
int f = (x1-x0)/(nibbles-skip);
|
|
|
|
int x, i, j;
|
|
|
|
int last[4] = { -1, -1, -1, -1};
|
|
|
|
uint8_t v, bit;
|
|
|
|
|
2013-01-31 02:25:47 +02:00
|
|
|
DEBUG("in: %d-%d (%d) Sa %d-%d (%d) pix %d f (%d)\n",
|
|
|
|
skip, nibbles, nibbles-skip, x0, x1, x1-x0, f, f*(nibbles-skip));
|
2013-01-31 01:35:30 +02:00
|
|
|
x = x0;
|
|
|
|
for (i = skip; i != nibbles; i++) {
|
|
|
|
v = (buf[i >> 1] >> 4*(~i & 1)) & 0xf;
|
|
|
|
for (j = 0; j != 4; j++) {
|
|
|
|
bit = (v >> j) & 1;
|
|
|
|
if (bit == last[j] || last[j] == -1) {
|
|
|
|
level(x, x+f-1, j, bit);
|
|
|
|
} else {
|
|
|
|
change(x, j);
|
|
|
|
level(x+1, x+f-1, j, bit);
|
|
|
|
}
|
|
|
|
last[j] = bit;
|
|
|
|
}
|
|
|
|
x += f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void show_buffer_zoom_out(const uint8_t *buf, int skip, int nibbles,
|
2013-01-30 19:38:54 +02:00
|
|
|
int x0, int x1)
|
|
|
|
{
|
2013-01-31 01:35:30 +02:00
|
|
|
int f = (nibbles-skip)/(x1-x0);
|
2013-01-30 19:38:54 +02:00
|
|
|
int x;
|
2013-01-31 01:35:30 +02:00
|
|
|
int i = skip, n, j;
|
2013-01-30 19:38:54 +02:00
|
|
|
int changes[4], last[4] = { -1, -1, -1, -1}, next[4];
|
|
|
|
uint8_t v, bit;
|
|
|
|
|
2013-01-31 02:25:47 +02:00
|
|
|
DEBUG("out: %d-%d (%d) Sa %d-%d (%d) pix %d f (%d)\n",
|
|
|
|
skip, nibbles, nibbles-skip, x0, x1, x1-x0, f, f*(x1-x0));
|
2013-01-31 01:35:30 +02:00
|
|
|
for (x = x0; x != x1; x++) {
|
|
|
|
n = i+f;
|
2013-01-30 19:38:54 +02:00
|
|
|
for (j = 0; j != 4; j++) {
|
|
|
|
next[j] = last[j];
|
|
|
|
changes[j] = 0;
|
|
|
|
}
|
|
|
|
while (i != n) {
|
|
|
|
v = (buf[i >> 1] >> 4*(~i & 1)) & 0xf;
|
|
|
|
for (j = 0; j != 4; j++) {
|
|
|
|
bit = (v >> j) & 1;
|
|
|
|
if (bit != next[j]) {
|
|
|
|
changes[j]++;
|
|
|
|
next[j] = bit;
|
|
|
|
}
|
|
|
|
}
|
2013-01-31 01:35:30 +02:00
|
|
|
i++;
|
2013-01-30 19:38:54 +02:00
|
|
|
}
|
|
|
|
for (j = 0; j != 4; j++) {
|
|
|
|
if (changes[j] > 1)
|
|
|
|
bounce(x, j);
|
|
|
|
else if (!changes[j] || last[j] == -1)
|
2013-01-31 01:35:30 +02:00
|
|
|
level(x, x, j, next[j]);
|
2013-01-30 19:38:54 +02:00
|
|
|
else
|
|
|
|
change(x, j);
|
|
|
|
last[j] = next[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 01:35:30 +02:00
|
|
|
static void show_buffer(const uint8_t *buf, int skip, int nibbles,
|
|
|
|
int x0, int x1, int zoom, int pos)
|
|
|
|
{
|
2013-01-31 04:37:05 +02:00
|
|
|
int xm, w, s, p0, p1;
|
2013-01-31 01:49:39 +02:00
|
|
|
int d, dp;
|
2013-01-31 01:35:30 +02:00
|
|
|
|
|
|
|
xm = (x0+x1) >> 1;
|
2013-01-31 01:49:39 +02:00
|
|
|
dp = pos-((nibbles+skip) >> 1);
|
2013-01-31 01:35:30 +02:00
|
|
|
if (zoom < 0) {
|
2013-01-31 04:37:05 +02:00
|
|
|
s = (x1-x0) << -zoom;
|
|
|
|
show_map(skip, nibbles, pos-s/2, pos+s/2);
|
2013-01-31 01:35:30 +02:00
|
|
|
w = (nibbles-skip) >> -zoom;
|
2013-01-31 01:49:39 +02:00
|
|
|
p0 = xm-(w >> 1)-(dp >> -zoom);
|
|
|
|
p1 = xm+((w+1) >> 1)-(dp >> -zoom);
|
2013-01-31 01:35:30 +02:00
|
|
|
if (p0 < x0) {
|
|
|
|
skip += (x0-p0) << -zoom;
|
|
|
|
p0 = x0;
|
|
|
|
}
|
|
|
|
if (p1 > x1) {
|
|
|
|
nibbles -= (p1-x1) << -zoom;
|
|
|
|
p1 = x1;
|
|
|
|
}
|
|
|
|
show_buffer_zoom_out(buf, skip, nibbles, p0, p1);
|
|
|
|
} else {
|
2013-01-31 04:37:05 +02:00
|
|
|
s = (x1-x0) >> zoom;
|
|
|
|
show_map(skip, nibbles, pos-s/2, pos+s/2);
|
2013-01-31 01:35:30 +02:00
|
|
|
w = (nibbles-skip) << zoom;
|
2013-01-31 01:49:39 +02:00
|
|
|
p0 = xm-(w >> 1)-(dp << zoom);
|
|
|
|
p1 = xm+((w+1) >> 1)-(dp << zoom);
|
2013-01-31 01:35:30 +02:00
|
|
|
if (p0 < x0) {
|
|
|
|
d = ((x0-p0)+(1 << zoom)-1) >> zoom;
|
|
|
|
skip += d;
|
|
|
|
p0 += d << zoom;
|
|
|
|
}
|
|
|
|
if (p1 > x1) {
|
|
|
|
d = ((p1-x1)+(1 << zoom)-1) >> zoom;
|
|
|
|
nibbles -= d;
|
|
|
|
p1 -= d << zoom;
|
|
|
|
}
|
|
|
|
show_buffer_zoom_in(buf, skip, nibbles, p0, p1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 05:47:14 +02:00
|
|
|
/* ----- Display the sample frequency -------------------------------------- */
|
|
|
|
|
|
|
|
|
2013-01-31 08:52:24 +02:00
|
|
|
static void si_text(int x, int y, double v, const char *unit, int digits)
|
2013-01-31 05:47:14 +02:00
|
|
|
{
|
|
|
|
const char *pfx;
|
|
|
|
|
|
|
|
if (v >= 1e6) {
|
|
|
|
v /= 1e6;
|
|
|
|
pfx = "M";
|
|
|
|
} else if (v >= 1e3) {
|
|
|
|
v /= 1e3;
|
|
|
|
pfx = "k";
|
|
|
|
} else if (v >= 1) {
|
|
|
|
pfx = " ";
|
|
|
|
} else if (v >= 1e-3) {
|
|
|
|
v *= 1e3;
|
|
|
|
pfx = "m";
|
|
|
|
} else if (v >= 1e-6) {
|
|
|
|
v *= 1e6;
|
|
|
|
pfx = "u";
|
|
|
|
} else {
|
|
|
|
v *= 1e9;
|
|
|
|
pfx = "n";
|
|
|
|
}
|
2013-01-31 08:52:24 +02:00
|
|
|
if (v >= 10 && digits == 3)
|
2013-01-31 07:57:27 +02:00
|
|
|
textf(x, y, TEXT_RGBA, "%3d", (int) (v+0.5));
|
2013-01-31 08:52:24 +02:00
|
|
|
else if (v >= 100 && digits == 4)
|
|
|
|
textf(x, y, TEXT_RGBA, "%4d", (int) (v+0.5));
|
|
|
|
else if (v >= 100)
|
|
|
|
textf(x, y, TEXT_RGBA, "%*.*f", digits, digits-4, v);
|
|
|
|
else if (v >= 10)
|
|
|
|
textf(x, y, TEXT_RGBA, "%*.*f", digits, digits-3, v);
|
2013-01-31 05:47:14 +02:00
|
|
|
else
|
2013-01-31 08:52:24 +02:00
|
|
|
textf(x, y, TEXT_RGBA, "%*.*f", digits, digits-2, v);
|
|
|
|
textf(x+digits*8+UNIT_GAP, y, UNIT_RGBA, "%s%s", pfx, unit);
|
2013-01-31 05:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 06:21:56 +02:00
|
|
|
static void show_freq(double freq, int zoom)
|
2013-01-31 05:47:14 +02:00
|
|
|
{
|
2013-01-31 06:21:56 +02:00
|
|
|
int div;
|
|
|
|
|
2013-01-31 08:52:24 +02:00
|
|
|
si_text(FREQ_X, FREQ_Y, freq, "Sa/s", 3);
|
|
|
|
si_text(INTERVAL_X, INTERVAL_Y, 1/freq, "s/Sa", 3);
|
2013-01-31 06:21:56 +02:00
|
|
|
div = (DIV_X >> MAX_ZOOM) << (MAX_ZOOM-zoom);
|
2013-01-31 07:57:27 +02:00
|
|
|
textf(DIV_SAMP_X, DIV_SAMP_Y, TEXT_RGBA, "%4d", div);
|
2013-01-31 08:15:33 +02:00
|
|
|
textf(DIV_SAMP_X+4*8+UNIT_GAP, DIV_SAMP_Y, UNIT_RGBA, "Sa/div", div);
|
2013-01-31 08:52:24 +02:00
|
|
|
si_text(DIV_INT_X, DIV_INT_Y, div/freq, "s/div", 3);
|
2013-01-31 05:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 06:09:42 +02:00
|
|
|
/* ----- Show a divisions -------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void show_divisions(void)
|
|
|
|
{
|
2013-01-31 06:11:18 +02:00
|
|
|
int n = XWIDTH/2/DIV_X;
|
2013-01-31 06:09:42 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = -n; i <= n; i++)
|
|
|
|
vlineColor(surf, XCENTER+i*DIV_X,
|
2013-01-31 08:25:21 +02:00
|
|
|
ch_y(0, 1)-DIV_Y, ch_y(3, 0)+DIV_Y,
|
|
|
|
i ? DIV_RGBA : CENTER_RGBA);
|
2013-01-31 06:09:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 03:07:31 +02:00
|
|
|
/* ----- Main event loop --------------------------------------------------- */
|
2013-01-30 19:38:54 +02:00
|
|
|
|
|
|
|
|
2013-01-31 02:08:25 +02:00
|
|
|
static int pos_step(int zoom)
|
|
|
|
{
|
|
|
|
return 1 << (MAX_ZOOM-zoom+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-31 05:47:14 +02:00
|
|
|
void gui(const uint8_t *buf, int skip, int nibbles, double freq)
|
2013-01-30 19:38:54 +02:00
|
|
|
{
|
|
|
|
SDL_Event event;
|
2013-01-31 01:35:30 +02:00
|
|
|
int pos = (skip+nibbles) >> 1;
|
|
|
|
int zoom; /* < 0: zoom out; 0: 1 pixel = 1 sample; > 1: zoom in */
|
|
|
|
int min_zoom = 0;
|
2013-01-31 04:16:42 +02:00
|
|
|
int i;
|
2013-01-30 19:38:54 +02:00
|
|
|
|
2013-01-31 06:11:18 +02:00
|
|
|
while (XWIDTH < (nibbles-skip) >> -min_zoom)
|
2013-01-31 01:35:30 +02:00
|
|
|
min_zoom--;
|
|
|
|
zoom = min_zoom;
|
2013-01-30 19:38:54 +02:00
|
|
|
while (1) {
|
|
|
|
clear();
|
2013-01-31 04:16:42 +02:00
|
|
|
for (i = 0; i != 4; i++)
|
|
|
|
textf(0, ch_y(i, 1), LABEL_RGBA, "CH%d", i);
|
2013-01-31 06:09:42 +02:00
|
|
|
show_divisions();
|
2013-01-31 08:25:21 +02:00
|
|
|
filledTrigonColor(surf, XCENTER, CENTER_Y1,
|
|
|
|
XCENTER-CENTER_W/2, CENTER_Y0,
|
|
|
|
XCENTER+CENTER_W/2, CENTER_Y0, CENTER_RGBA);
|
2013-01-31 01:35:30 +02:00
|
|
|
show_buffer(buf, skip, nibbles, CH_XOFF, XRES, zoom, pos);
|
2013-01-31 06:21:56 +02:00
|
|
|
show_freq(freq, zoom);
|
2013-01-31 08:52:24 +02:00
|
|
|
si_text(POS_X, POS_Y, pos/freq, "s", 7);
|
|
|
|
hlineColor(surf, 0, XRES-1, MEAS_DIV_Y, DIV_RGBA);
|
2013-01-30 19:38:54 +02:00
|
|
|
update();
|
|
|
|
|
2013-01-31 01:37:42 +02:00
|
|
|
while (1) {
|
2013-01-30 19:38:54 +02:00
|
|
|
SDL_WaitEvent(&event);
|
|
|
|
switch (event.type) {
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
switch (event.key.keysym.sym) {
|
|
|
|
case SDLK_UP:
|
|
|
|
if (zoom < MAX_ZOOM)
|
|
|
|
zoom++;
|
|
|
|
break;
|
|
|
|
case SDLK_DOWN:
|
2013-01-31 01:35:30 +02:00
|
|
|
if (zoom > min_zoom)
|
2013-01-30 19:38:54 +02:00
|
|
|
zoom--;
|
|
|
|
break;
|
2013-01-31 01:49:39 +02:00
|
|
|
case SDLK_LEFT:
|
2013-01-31 02:08:25 +02:00
|
|
|
pos -= pos_step(zoom);
|
|
|
|
if (pos < 0)
|
|
|
|
pos = 0;
|
2013-01-31 01:49:39 +02:00
|
|
|
break;
|
|
|
|
case SDLK_RIGHT:
|
2013-01-31 02:08:25 +02:00
|
|
|
pos += pos_step(zoom);
|
|
|
|
if (pos > nibbles-1)
|
|
|
|
pos = nibbles-1;
|
2013-01-31 01:49:39 +02:00
|
|
|
break;
|
2013-01-30 19:38:54 +02:00
|
|
|
case SDLK_RETURN:
|
|
|
|
case SDLK_q:
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
printf("%x\n", event.key.keysym.sym);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_QUIT:
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-31 01:37:42 +02:00
|
|
|
break;
|
2013-01-30 19:38:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|