From 3e0ca7a68732890ddfdf635d614f83174875a9d7 Mon Sep 17 00:00:00 2001 From: Isaiah Odhner Date: Sat, 26 Oct 2019 13:35:14 -0400 Subject: [PATCH] Hide preview if you would be zooming out --- src/app.js | 2 +- src/tools.js | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/app.js b/src/app.js index f33a117..ba0dff1 100644 --- a/src/app.js +++ b/src/app.js @@ -442,7 +442,7 @@ $G.on("cut copy paste", function(e){ reset_file(); reset_colors(); reset_canvas(); // (with newly reset colors) -reset_magnification(); +set_magnification(1); storage.get({ width: default_canvas_width, diff --git a/src/tools.js b/src/tools.js index d0825f8..653cb19 100644 --- a/src/tools.js +++ b/src/tools.js @@ -325,10 +325,16 @@ tools = [{ deselect: true, passive: true, + getProspectiveMagnification: ()=> ( + magnification === 1 ? return_to_magnification : 1 + ), + drawPreviewAboveGrid: function(ctx, x, y, scaled_by_amount, grid_visible) { if(!pointer_active && !pointer_over_canvas){return;} - if(pointer_active) { return; } // TODO: fix flash / whatever - // TODO: hide if would be zooming out + if(pointer_active) { return; } + var prospective_magnification = this.getProspectiveMagnification(); + + if(prospective_magnification < magnification) { return; } // hide if would be zooming out var hairline_width = 1/scaled_by_amount; @@ -357,12 +363,13 @@ tools = [{ } }, pointerdown: function(ctx, x, y){ - if(magnification !== 1){ - reset_magnification(); - }else{ - var prev_magnification = magnification; - // TODO: dedupe update_helper_layer - set_magnification(return_to_magnification); + var prev_magnification = magnification; + var prospective_magnification = this.getProspectiveMagnification(); + + // TODO: dedupe update_helper_layer + set_magnification(prospective_magnification); + + if (prospective_magnification > prev_magnification) { var scroll_left = $canvas_area.scrollLeft(); var scroll_top = $canvas_area.scrollTop(); // TODO: size rectangle based on viewport, and get position actually right