From a7b3b7dd2515e6be1fc5a1e3c14f3bc9de84f3b7 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Wed, 28 Oct 2009 18:04:38 +0000 Subject: [PATCH] Made zoom work on Shift+mousewheel (fails in Opera), made zoom out work on Shift+click in zoom mode git-svn-id: http://svg-edit.googlecode.com/svn/trunk@884 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.js | 33 ++++++++++++++++++++++++++++++++- editor/svgcanvas.js | 6 ++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 9d30c108..bd501325 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -126,7 +126,6 @@ function svg_edit_setup() { var scrTop = bb.y * zoomlevel; var scrOffY = w_area.height()/2 - (bb.height * zoomlevel)/2; w_area[0].scrollTop = Math.max(0,scrTop - scrOffY) + Math.max(0,canvas_pos.top); - clickSelect(); } // updates the toolbar (colors, opacity, etc) based on the selected element @@ -1070,6 +1069,38 @@ function svg_edit_setup() { setPushButtons(); + $('#workarea').bind("mousewheel DOMMouseScroll", function(e){ + if(!e.shiftKey) return; + e.preventDefault(); + var off = $('#svgcanvas').offset(); + var zoom = svgCanvas.getZoom(); + var bbox = { + 'x': (e.pageX - off.left)/zoom, + 'y': (e.pageY - off.top)/zoom, + 'width': 0, + 'height': 0 + }; + + // Respond to mouse wheel in IE/Webkit/Opera. + // (It returns up/dn motion in multiples of 120) + if(e.wheelDelta) { + if (e.wheelDelta >= 120) { + bbox.factor = 2; + } else if (e.wheelDelta <= -120) { + bbox.factor = .5; + } + } else if(e.detail) { + if (e.detail > 0) { + bbox.factor = .5; + } else if (e.detail < 0) { + bbox.factor = 2; + } + } + + if(!bbox.factor) return; + zoomChanged(window, bbox); + }); + // switch modifier key in tooltips if mac // NOTE: This code is not used yet until I can figure out how to successfully bind ctrl/meta // in Opera and Chrome diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index d32f622e..f3d5cdec 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -2970,11 +2970,13 @@ function BatchCommand(text) { if (rubberBox != null) { rubberBox.setAttribute("display", "none"); } + var factor = evt.shiftKey?.5:2; call("zoomed", { 'x': Math.min(start_x,x), 'y': Math.min(start_y,y), 'width': Math.abs(x-start_x), - 'height': Math.abs(y-start_y) + 'height': Math.abs(y-start_y), + 'factor': factor }); return; case "fhpath": @@ -4097,7 +4099,7 @@ function BatchCommand(text) { if(typeof val == 'object') { bb = val; if(bb.width == 0 || bb.height == 0) { - canvas.setZoom(current_zoom * 2); + canvas.setZoom(current_zoom * bb.factor); return {'zoom': current_zoom, 'bbox': bb}; } return calcZoom(bb);