From c6498a8cc1b5cfe5caf7f6a316683d1846830028 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 21 Aug 2016 22:31:52 -0300 Subject: [PATCH] eeshow/gui/: hover callback now indicates in which direction we left --- eeshow/gui/aoi.c | 11 +++++++---- eeshow/gui/aoi.h | 2 +- eeshow/gui/glabel.c | 4 ++-- eeshow/gui/history.c | 4 ++-- eeshow/gui/over.c | 5 +++-- eeshow/gui/over.h | 3 ++- eeshow/gui/sheet.c | 12 ++++++------ 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/eeshow/gui/aoi.c b/eeshow/gui/aoi.c index 45e3012..1ec5818 100644 --- a/eeshow/gui/aoi.c +++ b/eeshow/gui/aoi.c @@ -72,13 +72,16 @@ bool aoi_hover(struct aoi *const *aois, int x, int y) if (hovering) { if (in_aoi(hovering, x, y)) return 1; - hovering->hover(hovering->user, 0); + aoi = hovering; + aoi->hover(aoi->user, 0, + x < aoi->x ? -1 : x >= aoi->x + aoi->w ? 1 : 0, + y < aoi->y ? -1 : y >= aoi->y + aoi->h ? 1 : 0); hovering = NULL; } for (aoi = *aois; aoi; aoi = aoi->next) if (aoi->hover && in_aoi(aoi, x, y) && - aoi->hover(aoi->user, 1)) { + aoi->hover(aoi->user, 1, 0, 0)) { hovering = aoi; return 1; } @@ -130,7 +133,7 @@ void aoi_remove(struct aoi **aois, const struct aoi *aoi) { assert(aoi); if (hovering == aoi) { - aoi->hover(aoi->user, 0); + aoi->hover(aoi->user, 0, 0, 0); hovering = NULL; } while (*aois && *aois != aoi) @@ -144,6 +147,6 @@ void aoi_remove(struct aoi **aois, const struct aoi *aoi) void aoi_dehover(void) { if (hovering) - hovering->hover(hovering->user, 0); + hovering->hover(hovering->user, 0, 0, 0); hovering = NULL; } diff --git a/eeshow/gui/aoi.h b/eeshow/gui/aoi.h index 6ac9889..fb3a833 100644 --- a/eeshow/gui/aoi.h +++ b/eeshow/gui/aoi.h @@ -20,7 +20,7 @@ struct aoi { int x, y, w, h; /* activation box, eeschema coordinates */ /* points to hovered aoi, or NULL */ - bool (*hover)(void *user, bool on); + bool (*hover)(void *user, bool on, int dx, int dy); void (*click)(void *user); void *user; diff --git a/eeshow/gui/glabel.c b/eeshow/gui/glabel.c index 83936da..8d7586b 100644 --- a/eeshow/gui/glabel.c +++ b/eeshow/gui/glabel.c @@ -132,7 +132,7 @@ static void add_dest_overlay(struct gui_ctx *ctx, const char *label, } -static bool pop_hover(void *user, bool on) +static bool pop_hover(void *user, bool on, int dx, int dy) { struct gui_ctx *ctx = user; @@ -184,7 +184,7 @@ static void add_dest_frame(struct gui_ctx *ctx) } -static bool hover_glabel(void *user, bool on) +static bool hover_glabel(void *user, bool on, int dx, int dy) { struct glabel_aoi_ctx *aoi_ctx = user; struct gui_ctx *ctx = aoi_ctx->sheet->ctx; diff --git a/eeshow/gui/history.c b/eeshow/gui/history.c index e17b8c3..4deef17 100644 --- a/eeshow/gui/history.c +++ b/eeshow/gui/history.c @@ -82,7 +82,7 @@ static void set_history_style(struct gui_hist *h, bool current) } -static bool hover_history(void *user, bool on) +static bool hover_history(void *user, bool on, int dx, int dy) { struct gui_hist *h = user; struct gui_ctx *ctx = h->ctx; @@ -274,7 +274,7 @@ void show_history(struct gui_ctx *ctx, enum selecting sel) h = skip_history(ctx, h); h->over = overlay_add(&ctx->hist_overlays, &ctx->aois, hover_history, click_history, h); - hover_history(h, 0); + hover_history(h, 0, 0, 0); set_history_style(h, 0); } redraw(ctx); diff --git a/eeshow/gui/over.c b/eeshow/gui/over.c index 9bdec04..aede7c5 100644 --- a/eeshow/gui/over.c +++ b/eeshow/gui/over.c @@ -45,7 +45,7 @@ struct overlay { struct overlay_style style; struct aoi **aois; - bool (*hover)(void *user, bool on); + bool (*hover)(void *user, bool on, int dx, int dy); void (*click)(void *user); void *user; @@ -420,7 +420,8 @@ void overlay_size_all(const struct overlay *overlays, struct overlay *overlay_add(struct overlay **overlays, struct aoi **aois, - bool (*hover)(void *user, bool on), void (*click)(void *user), void *user) + bool (*hover)(void *user, bool on, int dx, int dy), + void (*click)(void *user), void *user) { struct overlay *over, *prev; struct overlay **anchor; diff --git a/eeshow/gui/over.h b/eeshow/gui/over.h index e77793c..f80e1f8 100644 --- a/eeshow/gui/over.h +++ b/eeshow/gui/over.h @@ -54,7 +54,8 @@ void overlay_size_all(const struct overlay *overlays, PangoContext *pango_context, bool dx, bool dy, int *w, int *h); struct overlay *overlay_add(struct overlay **overlays, struct aoi **aois, - bool (*hover)(void *user, bool on), void (*click)(void *user), void *user); + bool (*hover)(void *user, bool on, int dx, int dy), + void (*click)(void *user), void *user); void overlay_text_raw(struct overlay *over, const char *s); void overlay_text(struct overlay *over, const char *fmt, ...); diff --git a/eeshow/gui/sheet.c b/eeshow/gui/sheet.c index 841363e..a3687ac 100644 --- a/eeshow/gui/sheet.c +++ b/eeshow/gui/sheet.c @@ -123,7 +123,7 @@ static void zoom_to_extents(struct gui_ctx *ctx) /* ----- Revision selection overlays --------------------------------------- */ -static bool show_history_details(void *user, bool on) +static bool show_history_details(void *user, bool on, int dx, int dy) { struct gui_hist *h = user; struct gui_ctx *ctx = h->ctx; @@ -219,7 +219,7 @@ static void revision_overlays_diff(struct gui_ctx *ctx) if (ctx->diff_mode == diff_new) style.frame = RGBA(0, 0, 0, 1); overlay_style(new->over, &style); - show_history_details(new, 0); + show_history_details(new, 0, 0, 0); add_delta(ctx); @@ -229,7 +229,7 @@ static void revision_overlays_diff(struct gui_ctx *ctx) if (ctx->diff_mode == diff_old) style.frame = RGBA(0, 0, 0, 1); overlay_style(old->over, &style); - show_history_details(old, 0); + show_history_details(old, 0, 0, 0); } @@ -244,7 +244,7 @@ void do_revision_overlays(struct gui_ctx *ctx) &ctx->aois, show_history_details, show_history_cb, ctx->new_hist); overlay_style(ctx->new_hist->over, &overlay_style_default); - show_history_details(ctx->new_hist, 0); + show_history_details(ctx->new_hist, 0, 0, 0); add_delta(ctx); } @@ -263,7 +263,7 @@ static void close_subsheet(void *user) } -static bool hover_sheet(void *user, bool on) +static bool hover_sheet(void *user, bool on, int dx, int dy) { struct gui_sheet *sheet = user; struct gui_ctx *ctx = sheet->ctx; @@ -314,7 +314,7 @@ static void sheet_selector_recurse(struct gui_ctx *ctx, struct gui_sheet *sheet) sheet_selector_recurse(ctx, parent); sheet->over = overlay_add(&ctx->sheet_overlays, &ctx->aois, hover_sheet, close_subsheet, sheet); - hover_sheet(sheet, 0); + hover_sheet(sheet, 0, 0, 0); }