1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2024-11-05 11:10:39 +02:00

ubb-la/gui.c: add user-defined zero reference (set/unset with space)

This commit is contained in:
Werner Almesberger 2013-02-01 00:34:02 -03:00
parent 5b050b4b36
commit b99c81409f

View File

@ -41,6 +41,7 @@
#define MAP_BUF_RGBA 0x808080ff /* buffer in the map */
#define MAP_VIEW_RGBA 0xffffffff /* current view in the map */
#define CENTER_RGBA 0x5080ffff /* center marker */
#define USER_REF_RGBA 0x00ff40ff /* user reference marker */
#define LEVEL_RGBA 0xffff00ff /* constant level or single change */
#define BOUNCE_RGBA 0xff8080ff /* bouncing signal */
#define LABEL_RGBA 0xffffffff /* channel label */
@ -60,7 +61,11 @@
#define CENTER_W 8
#define CENTER_Y0 20
#define CENTER_Y1 24
#define CENTER_Y1 (CENTER_Y0+4)
#define USER_REF_W 8
#define USER_REF_Y0 92
#define USER_REF_Y1 (USER_REF_Y0+4)
#define CH_XOFF 30
#define CH_YOFF 30
@ -74,8 +79,8 @@
#define UNIT_GAP 2 /* space between number and unit */
#define POS_T_X 176
#define POS_SAMP_X 264
#define POS_T_X 182
#define POS_SAMP_X 270
#define POS_Y (MEAS_DIV_Y-8-3)
#define MEAS_DIV_Y (FREQ_Y-3-1)
@ -89,6 +94,13 @@
#define DIV_INT_X 80
#define DIV_INT_Y INTERVAL_Y
#define USER_T_X POS_T_X
#define USER_T_Y FREQ_Y
#define USER_SAMP_X POS_SAMP_X
#define USER_SAMP_Y USER_T_Y
#define USER_FREQ_X POS_T_X
#define USER_FREQ_Y (USER_T_Y+8+2)
/* ----- Miscellaneous definitions ----------------------------------------- */
@ -97,6 +109,7 @@
#define REPEAT_INTERVAL_MS 30
static SDL_Surface *surf;
static int user_ref = -1;
/* ----- SDL initialization and screen-wide functions ---------------------- */
@ -294,14 +307,25 @@ static void show_buffer_zoom_out(const uint8_t *buf, int skip, int nibbles,
}
static void user_ref_marker(int x0, int x1, int x)
{
if (x < 0 || x > x1-x0)
return;
filledTrigonColor(surf, x0+x, USER_REF_Y0,
x0+x-USER_REF_W/2, USER_REF_Y1,
x0+x+USER_REF_W/2, USER_REF_Y1, USER_REF_RGBA);
}
static void show_buffer(const uint8_t *buf, int skip, int nibbles,
int x0, int x1, int zoom, int pos)
{
int xm, w, s, p0, p1;
int d, dp;
int d, dp, ref;
xm = (x0+x1) >> 1;
dp = pos-((nibbles-skip) >> 1);
ref = user_ref+skip;
DEBUG("show: %d-%d Sa; %d-%d pix; pos %d dp %d; xm %d xcenter %d\n",
skip, nibbles, x0, x1, pos, dp, xm, XCENTER);
if (zoom < 0) {
@ -319,6 +343,8 @@ static void show_buffer(const uint8_t *buf, int skip, int nibbles,
p1 = x1;
}
show_buffer_zoom_out(buf, skip, nibbles, p0, p1);
if (user_ref != -1)
user_ref_marker(p0, p1, (ref-skip) >> -zoom);
} else {
s = (x1-x0) >> zoom;
show_map(skip, nibbles, pos-s/2, pos+s/2);
@ -336,6 +362,8 @@ static void show_buffer(const uint8_t *buf, int skip, int nibbles,
p1 -= d << zoom;
}
show_buffer_zoom_in(buf, skip, nibbles, p0, p1);
if (user_ref != -1)
user_ref_marker(p0, p1, (ref-skip) << zoom);
}
}
@ -404,6 +432,20 @@ static void show_position(double freq, int pos)
}
static void show_user_ref(double freq, int pos, int user_ref)
{
si_text(USER_T_X, USER_T_Y, fabs(user_ref-pos)/freq, "s", 7);
textf(USER_SAMP_X,USER_SAMP_Y, TEXT_RGBA, "%4d",
pos > user_ref ? pos-user_ref : user_ref-pos);
textf(USER_SAMP_X+4*8+UNIT_GAP, USER_SAMP_Y, UNIT_RGBA, "Sa", div);
if (pos != user_ref)
si_text(USER_FREQ_X, USER_FREQ_Y,
freq/fabs(user_ref-pos), "Hz", 7);
}
/* ----- Show divisions ---------------------------------------------------- */
@ -450,6 +492,8 @@ void gui(const uint8_t *buf, int skip, int nibbles, double freq)
show_buffer(buf, skip, nibbles, CH_XOFF, XRES, zoom, pos);
show_freq(freq, zoom);
show_position(freq, pos);
if (user_ref != -1)
show_user_ref(freq, pos, user_ref);
update();
while (1) {
@ -475,6 +519,12 @@ void gui(const uint8_t *buf, int skip, int nibbles, double freq)
if (pos > nibbles-skip-1)
pos = nibbles-skip-1;
break;
case SDLK_SPACE:
if (pos == user_ref)
user_ref = -1;
else
user_ref = pos;
break;
case SDLK_RETURN:
case SDLK_q:
return;