From 6ff7d6331270441e1926abdb0b1f7b4ff2a06ce9 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Fri, 19 Aug 2016 06:48:44 -0300 Subject: [PATCH] eeshow/gui/: highlight glabels --- eeshow/TODO | 3 +-- eeshow/gui/common.h | 1 + eeshow/gui/glabel.c | 2 +- eeshow/gui/gui.c | 2 ++ eeshow/gui/render.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/eeshow/TODO b/eeshow/TODO index 9605101..dac2c93 100644 --- a/eeshow/TODO +++ b/eeshow/TODO @@ -65,6 +65,5 @@ GUI/sheets: GUI/glabels: - maybe indicate how many times label is used on each sheet - maybe indicate how it is used -- highlight occurrences of label on current sheet -- also highlight after jumping - there can be "hanging" pop-ups, see comment in gui/glabel.c:hover_glabel +- should there be a way to remove glabel highlighing ? diff --git a/eeshow/gui/common.h b/eeshow/gui/common.h index 6f04f86..983d636 100644 --- a/eeshow/gui/common.h +++ b/eeshow/gui/common.h @@ -84,6 +84,7 @@ struct gui_ctx { int pop_x, pop_y; int pop_dx, pop_dy; const void *pop_origin; /* item that created this pop-up */ + const char *glabel; /* currenly highlighted glabel, or NULL */ struct aoi *aois; /* areas of interest; in canvas coord */ diff --git a/eeshow/gui/glabel.c b/eeshow/gui/glabel.c index 550340e..7243c86 100644 --- a/eeshow/gui/glabel.c +++ b/eeshow/gui/glabel.c @@ -201,12 +201,12 @@ static bool hover_glabel(void *user, bool on) dehover_glabel(ctx); } - GtkAllocation alloc; int sx, sy, ex, ey, mx, my; unsigned n = 0; struct gui_sheet *sheet; + ctx->glabel = aoi_ctx->obj->u.text.s; ctx->pop_origin = aoi_ctx; aoi_dehover(); diff --git a/eeshow/gui/gui.c b/eeshow/gui/gui.c index 024b4c3..a485c24 100644 --- a/eeshow/gui/gui.c +++ b/eeshow/gui/gui.c @@ -375,6 +375,8 @@ int gui(unsigned n_args, char **args, bool recurse, int limit) .hist_overlays = NULL, .pop_overlays = NULL, .pop_underlays = NULL, + .pop_origin = NULL, + .glabel = NULL, .aois = NULL, .old_hist = NULL, .hist_y_offset = 0, diff --git a/eeshow/gui/render.c b/eeshow/gui/render.c index ee54412..92b6cc0 100644 --- a/eeshow/gui/render.c +++ b/eeshow/gui/render.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -33,6 +34,8 @@ #define SHEET_OVERLAYS_X -10 #define SHEET_OVERLAYS_Y 10 +#define GLABEL_HIGHLIGHT_PAD 6 + /* ----- Helper functions -------------------------------------------------- */ @@ -43,6 +46,59 @@ void redraw(const struct gui_ctx *ctx) } +/* ----- Highlight glabel -------------------------------------------------- */ + + +/* + * cd, cx, cy are simplified versions of what cro.c uses. Since we don't + * support glabel highlighting in diff mode, we don't need the xe and ye offset + * components. + */ + +static inline int cd(int x, float scale) +{ + return x * scale; +} + +static inline int cx(int x, int xo, float scale) +{ + return xo + x * scale; +} + + +static inline int cy(int y, int yo, float scale) +{ + return yo + y * scale; +} + + +static void highlight_glabel(const struct gui_ctx *ctx, cairo_t *cr, + int x, int y, float f) +{ + const struct sch_obj *obj; + + if (!ctx->glabel) + return; + + for (obj = ctx->curr_sheet->sch->objs; obj; obj = obj->next) { + const struct dwg_bbox *bbox = &obj->u.text.bbox; + + if (obj->type != sch_obj_glabel) + continue; + if (strcmp(obj->u.text.s, ctx->glabel)) + continue; + + cairo_rectangle(cr, + cx(bbox->x, x, f) - GLABEL_HIGHLIGHT_PAD, + cy(bbox->y, y, f) - GLABEL_HIGHLIGHT_PAD, + cd(bbox->w, f) + 2 * GLABEL_HIGHLIGHT_PAD, + cd(bbox->h, f) + 2 * GLABEL_HIGHLIGHT_PAD); + cairo_set_source_rgb(cr, 1, 0.8, 1); + cairo_fill(cr); + } +} + + /* ----- Draw to screen ---------------------------------------------------- */ @@ -72,6 +128,7 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr, cro_canvas_prepare(cr); if (!ctx->old_hist) { + highlight_glabel(ctx, cr, x, y, f); cro_canvas_draw(sheet->gfx_ctx, cr, x, y, f); } else { #if 0