Date:2013-02-01 04:34:02 (6 years 7 months ago)
Author:Werner Almesberger
Commit:b99c81409f094dabf19a63aa748afcff2425e822
Message:ubb-la/gui.c: add user-defined zero reference (set/unset with space)

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

Change Details

ubb-la/gui.c
4141#define MAP_BUF_RGBA 0x808080ff /* buffer in the map */
4242#define MAP_VIEW_RGBA 0xffffffff /* current view in the map */
4343#define CENTER_RGBA 0x5080ffff /* center marker */
44#define USER_REF_RGBA 0x00ff40ff /* user reference marker */
4445#define LEVEL_RGBA 0xffff00ff /* constant level or single change */
4546#define BOUNCE_RGBA 0xff8080ff /* bouncing signal */
4647#define LABEL_RGBA 0xffffffff /* channel label */
...... 
6061
6162#define CENTER_W 8
6263#define CENTER_Y0 20
63#define CENTER_Y1 24
64#define CENTER_Y1 (CENTER_Y0+4)
65
66#define USER_REF_W 8
67#define USER_REF_Y0 92
68#define USER_REF_Y1 (USER_REF_Y0+4)
6469
6570#define CH_XOFF 30
6671#define CH_YOFF 30
...... 
7479
7580#define UNIT_GAP 2 /* space between number and unit */
7681
77#define POS_T_X 176
78#define POS_SAMP_X 264
82#define POS_T_X 182
83#define POS_SAMP_X 270
7984#define POS_Y (MEAS_DIV_Y-8-3)
8085
8186#define MEAS_DIV_Y (FREQ_Y-3-1)
...... 
8994#define DIV_INT_X 80
9095#define DIV_INT_Y INTERVAL_Y
9196
97#define USER_T_X POS_T_X
98#define USER_T_Y FREQ_Y
99#define USER_SAMP_X POS_SAMP_X
100#define USER_SAMP_Y USER_T_Y
101#define USER_FREQ_X POS_T_X
102#define USER_FREQ_Y (USER_T_Y+8+2)
103
92104
93105/* ----- Miscellaneous definitions ----------------------------------------- */
94106
...... 
97109#define REPEAT_INTERVAL_MS 30
98110
99111static SDL_Surface *surf;
112static int user_ref = -1;
100113
101114
102115/* ----- SDL initialization and screen-wide functions ---------------------- */
...... 
294307}
295308
296309
310static void user_ref_marker(int x0, int x1, int x)
311{
312    if (x < 0 || x > x1-x0)
313        return;
314    filledTrigonColor(surf, x0+x, USER_REF_Y0,
315        x0+x-USER_REF_W/2, USER_REF_Y1,
316        x0+x+USER_REF_W/2, USER_REF_Y1, USER_REF_RGBA);
317}
318
319
297320static void show_buffer(const uint8_t *buf, int skip, int nibbles,
298321    int x0, int x1, int zoom, int pos)
299322{
300323    int xm, w, s, p0, p1;
301    int d, dp;
324    int d, dp, ref;
302325
303326    xm = (x0+x1) >> 1;
304327    dp = pos-((nibbles-skip) >> 1);
328    ref = user_ref+skip;
305329    DEBUG("show: %d-%d Sa; %d-%d pix; pos %d dp %d; xm %d xcenter %d\n",
306330        skip, nibbles, x0, x1, pos, dp, xm, XCENTER);
307331    if (zoom < 0) {
...... 
319343            p1 = x1;
320344        }
321345        show_buffer_zoom_out(buf, skip, nibbles, p0, p1);
346        if (user_ref != -1)
347            user_ref_marker(p0, p1, (ref-skip) >> -zoom);
322348    } else {
323349        s = (x1-x0) >> zoom;
324350        show_map(skip, nibbles, pos-s/2, pos+s/2);
...... 
336362            p1 -= d << zoom;
337363        }
338364        show_buffer_zoom_in(buf, skip, nibbles, p0, p1);
365        if (user_ref != -1)
366            user_ref_marker(p0, p1, (ref-skip) << zoom);
339367    }
340368}
341369
...... 
404432}
405433
406434
435static void show_user_ref(double freq, int pos, int user_ref)
436{
437    si_text(USER_T_X, USER_T_Y, fabs(user_ref-pos)/freq, "s", 7);
438
439    textf(USER_SAMP_X,USER_SAMP_Y, TEXT_RGBA, "%4d",
440        pos > user_ref ? pos-user_ref : user_ref-pos);
441    textf(USER_SAMP_X+4*8+UNIT_GAP, USER_SAMP_Y, UNIT_RGBA, "Sa", div);
442
443    if (pos != user_ref)
444        si_text(USER_FREQ_X, USER_FREQ_Y,
445            freq/fabs(user_ref-pos), "Hz", 7);
446}
447
448
407449/* ----- Show divisions ---------------------------------------------------- */
408450
409451
...... 
450492        show_buffer(buf, skip, nibbles, CH_XOFF, XRES, zoom, pos);
451493        show_freq(freq, zoom);
452494        show_position(freq, pos);
495        if (user_ref != -1)
496            show_user_ref(freq, pos, user_ref);
453497        update();
454498
455499        while (1) {
...... 
475519                    if (pos > nibbles-skip-1)
476520                        pos = nibbles-skip-1;
477521                    break;
522                case SDLK_SPACE:
523                    if (pos == user_ref)
524                        user_ref = -1;
525                    else
526                        user_ref = pos;
527                    break;
478528                case SDLK_RETURN:
479529                case SDLK_q:
480530                    return;

Archive Download the corresponding diff file

Branches:
master



interactive