From eff0ad48600a22b4f475e230596599e28bbb4afe Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 9 Aug 2016 10:58:29 -0300 Subject: [PATCH] eeshow/gui.c (zoom_to_extents): abstract obtaining the sheet size --- eeshow/gui.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/eeshow/gui.c b/eeshow/gui.c index b062c56..a77b93a 100644 --- a/eeshow/gui.c +++ b/eeshow/gui.c @@ -319,18 +319,27 @@ static void zoom_out(struct gui_ctx *ctx, int x, int y) } -static void zoom_to_extents(struct gui_ctx *ctx) +static void curr_sheet_size(struct gui_ctx *ctx, int *w, int *h) { const struct gui_sheet *sheet = ctx->curr_sheet; - GtkAllocation alloc; - ctx->x = sheet->w / 2; - ctx->y = sheet->h / 2; + *w = sheet->w; + *h = sheet->h; +} + + +static void zoom_to_extents(struct gui_ctx *ctx) +{ + GtkAllocation alloc; + int w, h; + + curr_sheet_size(ctx, &w, &h); + ctx->x = w / 2; + ctx->y = h / 2; gtk_widget_get_allocation(ctx->da, &alloc); ctx->zoom = 0; - while (sheet->w >> ctx->zoom > alloc.width || - sheet->h >> ctx->zoom > alloc.height) + while (w >> ctx->zoom > alloc.width || h >> ctx->zoom > alloc.height) ctx->zoom++; redraw(ctx);