Skip to content

Home Information - Your home, your data, organized.

Python

Added mouse wheel support for zoom'ing

Anthony Cassandra3208a872c658
diff --git a/src/hi/static/js/edit-svg-icon.js b/src/hi/static/js/edit-svg-icon.js
index 2d43c404..1bcf69e8 100644
--- a/src/hi/static/js/edit-svg-icon.js
+++ b/src/hi/static/js/edit-svg-icon.js
@@ -64,7 +64,7 @@
if ( ! Hi.isEditMode ) { return; }
handleMouseDown( event );
});
- $(document).on('mousemove', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
+ $(document).on('mousemove', function(event) {
if ( ! Hi.isEditMode ) { return; }
handleMouseMove( event );
});
@@ -72,6 +72,10 @@
if ( ! Hi.isEditMode ) { return; }
handleMouseUp( event );
});
+ $(document).on('wheel', function(event) {
+ if ( ! Hi.isEditMode ) { return; }
+ handleMouseWheel( event );
+ });
$(document).on('click', function(event) {
if ( ! Hi.isEditMode ) { return; }
handleClick( event );
@@ -80,6 +84,7 @@
if ( ! Hi.isEditMode ) { return; }
handleKeyDown( event );
});
+
});
function handleMouseDown( event ) {
@@ -185,6 +190,24 @@
gLastMousePosition = currentMousePosition;
}
+
+ function handleMouseWheel( event ) {
+ if ( gSvgIconDragData ) {
+ return;
+ }
+
+ if ( gSvgIconEditData ) {
+ const e = event.originalEvent;
+ const scaleFactor = e.deltaY < 0 ? 1.1 : 0.9;
+
+ console.log( `Scale factor = ${scaleFactor} [${gSvgIconEditData.isScaling}]` );
+ if ( gSvgIconActionState == SvgActionStateType.SCALE ) {
+ adjustIconScale( gSvgIconEditData.element, scaleFactor );
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ }
+ }
+ }
function handleClick( event ) {
if ( gIgnoreCLick ) {
diff --git a/src/hi/static/js/svg-location.js b/src/hi/static/js/svg-location.js
index 87a9033b..00a81c39 100644
--- a/src/hi/static/js/svg-location.js
+++ b/src/hi/static/js/svg-location.js
@@ -56,12 +56,15 @@
$(document).on('mousedown', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
handleMouseDown( event );
});
- $(document).on('mousemove', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
+ $(document).on('mousemove', function(event) {
handleMouseMove( event );
});
$(document).on('mouseup', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
handleMouseUp( event );
});
+ $(document).on('wheel', function(event) {
+ handleMouseWheel( event );
+ });
$(document).on('click', function(event) {
handleClick( event );
});
@@ -148,6 +151,21 @@
gLastMousePosition = currentMousePosition;
}
+ function handleMouseWheel( event ) {
+ if ( gSelectedLocationViewSvg && isEventInLocationArea( event )) {
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ abortScale();
+ abortRotation();
+ const e = event.originalEvent;
+ if ( e.deltaY < 0 ) {
+ zoomIn();
+ } else {
+ zoomOut();
+ }
+ }
+ }
+
function handleClick( event ) {
if ( gIgnoreCLick ) {
if ( Hi.DEBUG ) { console.log( `Ignoring click [${MODULE_NAME}]`, event ); }
@@ -169,6 +187,22 @@
if ( Hi.DEBUG ) { console.log( `Click skipped [${MODULE_NAME}]` ); }
}
+ function isEventInLocationArea( event ) {
+ if ( $(event.target).is('input, textarea') ) {
+ return false;
+ }
+
+ const targetArea = $(Hi.LOCATION_VIEW_AREA_SELECTOR);
+ const targetOffset = targetArea.offset();
+ const targetWidth = targetArea.outerWidth();
+ const targetHeight = targetArea.outerHeight();
+
+ return (( gLastMousePosition.x >= targetOffset.left )
+ && ( gLastMousePosition.x <= ( targetOffset.left + targetWidth ))
+ && ( gLastMousePosition.y >= targetOffset.top )
+ && ( gLastMousePosition.y <= ( targetOffset.top + targetHeight )));
+ }
+
function handleKeyDown( event ) {
if ( $(event.target).is('input, textarea') ) {
return;