From 0e9a308d6ccd76172b847e351db585e18e81d5c2 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 18 Aug 2016 17:13:36 -0300 Subject: [PATCH] eeshow/gui/: use underlay to draw a nice box for glabels --- eeshow/gui/common.h | 2 ++ eeshow/gui/glabel.c | 38 ++++++++++++++++++++++++++++++++++---- eeshow/gui/render.c | 5 ++++- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/eeshow/gui/common.h b/eeshow/gui/common.h index f175a5a..c8a3591 100644 --- a/eeshow/gui/common.h +++ b/eeshow/gui/common.h @@ -101,6 +101,8 @@ struct gui_ctx { }; +#define GLABEL_STACK_PADDING 5 + /* progress.c */ diff --git a/eeshow/gui/glabel.c b/eeshow/gui/glabel.c index 13f520b..dde7776 100644 --- a/eeshow/gui/glabel.c +++ b/eeshow/gui/glabel.c @@ -64,6 +64,7 @@ static void glabel_dest_click(void *user) void dehover_glabel(struct gui_ctx *ctx) { overlay_remove_all(&ctx->pop_overlays); + overlay_remove_all(&ctx->pop_underlays); redraw(ctx); } @@ -76,10 +77,10 @@ static void add_dest_overlay(struct gui_ctx *ctx, const char *label, .wmin = 100, .wmax = 100, .radius = 0, - .pad = 4, - .skip = -4, + .pad = 0, + .skip = 4, .fg = { 0.0, 0.0, 0.0, 1.0 }, - .bg = { 1.0, 0.8, 0.4, 0.8 }, + .bg = { 0.0, 0.0, 0.0, 0.0 }, .frame = { 1.0, 1.0, 1.0, 1.0 }, /* debugging */ .width = 0, }; @@ -97,11 +98,38 @@ static void add_dest_overlay(struct gui_ctx *ctx, const char *label, &ctx->aois, NULL, glabel_dest_click, sheet); overlay_text(over, "%d %s", n, sheet->sch->title); overlay_style(over, &style); - return; + break; } } +static void add_dest_frame(struct gui_ctx *ctx) +{ + int w, h; + + overlay_size_all(ctx->pop_overlays, + gtk_widget_get_pango_context(ctx->da), 0, 1, &w, &h); + + struct overlay_style style = { + .font = BOLD_FONT, + .wmin = w, + .hmin = h, + .radius = 0, + .pad = GLABEL_STACK_PADDING, + .skip = 0, + .fg = { 0.0, 0.0, 0.0, 1.0 }, + .bg = { 0.9, 0.9, 0.3, 0.8 }, + .frame = { 0.0, 0.0, 0.0, 1.0 }, /* debugging */ + .width = 1, + }; + struct overlay *over; + + over = overlay_add(&ctx->pop_underlays, NULL, NULL, NULL, NULL); + overlay_text_raw(over, ""); + overlay_style(over, &style); +} + + static bool hover_glabel(void *user, bool on) { struct glabel_aoi_ctx *aoi_ctx = user; @@ -121,8 +149,10 @@ static bool hover_glabel(void *user, bool on) aoi_dehover(); overlay_remove_all(&ctx->pop_overlays); + overlay_remove_all(&ctx->pop_underlays); for (sheet = ctx->new_hist->sheets; sheet; sheet = sheet->next) add_dest_overlay(ctx, aoi_ctx->obj->u.text.s, sheet, ++n); + add_dest_frame(ctx); eeschema_coord(ctx, bbox->x - curr_sheet->xmin, bbox->y - curr_sheet->ymin, diff --git a/eeshow/gui/render.c b/eeshow/gui/render.c index bbdcc94..ebdab4e 100644 --- a/eeshow/gui/render.c +++ b/eeshow/gui/render.c @@ -89,7 +89,10 @@ static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr, VCS_OVERLAYS_X, VCS_OVERLAYS_Y + (ctx->showing_history ? ctx->hist_y_offset : 0), 0, 1); - overlay_draw_all(ctx->pop_overlays, cr, ctx->pop_x, ctx->pop_y); + overlay_draw_all(ctx->pop_underlays, cr, ctx->pop_x, ctx->pop_y); + overlay_draw_all(ctx->pop_overlays, cr, + ctx->pop_x + sign1(ctx->pop_x) * GLABEL_STACK_PADDING, + ctx->pop_y + sign1(ctx->pop_y) * GLABEL_STACK_PADDING); return FALSE; }