From 2775b5cb8d7e33ea4677f0b747f017ff75dfe2ac Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 3 Aug 2016 10:05:01 -0300 Subject: [PATCH] eeshow/gui.c: add zoom in/out with + (or =) and - --- eeshow/gui.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/eeshow/gui.c b/eeshow/gui.c index 40d9260..7735584 100644 --- a/eeshow/gui.c +++ b/eeshow/gui.c @@ -35,6 +35,9 @@ struct gui_ctx { int w, h; int xmin, ymin; + int curr_x; /* last on-screen mouse position */ + int curr_y; + unsigned zoom; /* scale by 1.0 / (1 << zoom) */ int x, y; /* center, in eeschema coordinates */ @@ -167,6 +170,9 @@ static gboolean motion_notify_event(GtkWidget *widget, GdkEventMotion *event, struct gui_ctx *ctx = data; int x, y; + ctx->curr_x = event->x; + ctx->curr_y = event->y; + canvas_coord(ctx, event->x, event->y, &x, &y); // fprintf(stderr, "motion\n"); pan_update(ctx, event->x, event->y); @@ -219,8 +225,18 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event, static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event, gpointer data) { -fprintf(stderr, "key %d\n", event->keyval); + struct gui_ctx *ctx = data; + int x, y; + + canvas_coord(ctx, ctx->curr_x, ctx->curr_y, &x, &y); switch (event->keyval) { + case '+': + case '=': + zoom_in(ctx, x, y); + break; + case '-': + zoom_out(ctx, x, y); + break; case GDK_KEY_q: gtk_main_quit(); }