diff --git a/app/public/img/move.svg b/app/public/img/move.svg new file mode 100755 index 0000000..b9ca6b7 --- /dev/null +++ b/app/public/img/move.svg @@ -0,0 +1,97 @@ + + diff --git a/app/public/js/configuration.json b/app/public/js/configuration.json index 4154417..8fd4974 100644 --- a/app/public/js/configuration.json +++ b/app/public/js/configuration.json @@ -8,6 +8,7 @@ "presets": { "default": [ { "name": "Select", "id": "select", "desc": "", "exportedVar": ["ToolSelect"], "scriptPath": "/js/tools/select.js", "iconPath": "/img/select.svg" }, + { "name": "Move", "id": "move", "desc": "", "exportedVar": ["ToolMove"], "scriptPath": "/js/tools/move.js", "iconPath": "/img/move.svg" }, { "name": "Back", "id": "back", "desc": "Move selection to the back", "exportedVar": ["ToolBack"], "scriptPath": "/js/tools/back.js", "iconPath": "/img/back.svg" }, { "name": "Backward", "id": "backward", "desc": "Move selection one step back", "exportedVar": ["ToolBackward"], "scriptPath": "/js/tools/backward.js", "iconPath": "/img/backward.svg" }, { "name": "Foreward", "id": "foreward", "desc": "Move selection on step front", "exportedVar": ["ToolForeward"], "scriptPath": "/js/tools/foreward.js", "iconPath": "/img/foreward.svg" }, diff --git a/app/public/js/microdraw.js b/app/public/js/microdraw.js index 6809fa9..231afc9 100644 --- a/app/public/js/microdraw.js +++ b/app/public/js/microdraw.js @@ -581,7 +581,11 @@ const Microdraw = (function () { if( !me.navEnabled ) { event.stopHandlers = true; - me.mouseDrag(event.originalEvent.layerX, event.originalEvent.layerY, event.delta.x, event.delta.y); + me.mouseDrag( + event.originalEvent.layerX, + event.originalEvent.layerY, + event.delta.x, + event.delta.y); } }, @@ -656,7 +660,9 @@ const Microdraw = (function () { me.handle.y += point.y-me.handle.point.y; me.handle.point = point; me.commitMouseUndo(); - } else if (me.tools[me.selectedTool] && me.tools[me.selectedTool].mouseDrag) { + } else if (me.tools[me.selectedTool] + && me.tools[me.selectedTool].mouseDrag + ) { me.tools[me.selectedTool].mouseDrag(point, dpoint); } paper.view.draw(); diff --git a/app/public/js/tools/move.js b/app/public/js/tools/move.js new file mode 100644 index 0000000..e7b05a9 --- /dev/null +++ b/app/public/js/tools/move.js @@ -0,0 +1,109 @@ +/* global Microdraw */ +/* global paper */ + + +window.ToolMove = {move: (function() { + const tool = { + + /** + * @function mouseDrag + * @param {object} point The point where you moved to (x,y) + * @param {object} dpoint The movement of the point + * @return {void} + */ + mouseDrag: function mouseDrag(point, dpoint) { + + // event.stopHandlers = true; + for( var reg of Microdraw.ImageInfo[Microdraw.currentImage].Regions ) { + if( reg.path.selected ) { + reg.path.position.x += dpoint.x; + reg.path.position.y += dpoint.y; + Microdraw.commitMouseUndo(); + } + } + }, + + _handleHitResultType: function (hitResult, point) { + if( hitResult.type === 'handle-in' ) { + Microdraw.handle = hitResult.segment.handleIn; + Microdraw.handle.point = point; + } else if( hitResult.type === 'handle-out' ) { + Microdraw.handle = hitResult.segment.handleOut; + Microdraw.handle.point = point; + } else if( hitResult.type === 'segment' ) { + Microdraw.handle = hitResult.segment.point; + Microdraw.handle.point = point; + } else if( hitResult.type === 'fill' ) { + if ({}.hasOwnProperty.call(hitResult.item, 'fontSize')) { + Microdraw.tools.textAnnotation.updateTextAnnotationPanel(hitResult.item); + } + } + }, + + _handleHit: function (hitResult, point) { + // let prevRegion = null; + let re; + + for( let i = 0; i < Microdraw.ImageInfo[Microdraw.currentImage].Regions.length; i += 1 ) { + if( Microdraw.ImageInfo[Microdraw.currentImage].Regions[i].path === hitResult.item ) { + re = Microdraw.ImageInfo[Microdraw.currentImage].Regions[i]; + } + } + + // select path + if( Microdraw.region && Microdraw.region !== re ) { + Microdraw.region.path.selected = false; + // prevRegion = Microdraw.region; + } + Microdraw.selectRegion(re); + + tool._handleHitResultType(hitResult, point); + }, + + /** + * @function mouseDown + * @param {object} point The point where you click (x,y) + * @returns {void} + */ + mouseDown: function mouseDown(point) { + Microdraw.mouseUndo = Microdraw.getUndo(); + Microdraw.handle = null; + + const hitResult = paper.project.hitTest(point, { + tolerance : Microdraw.tolerance/paper.view.zoom, + stroke: true, + segments: true, + fill: true, + handles: true + }); + + Microdraw.newRegionFlag = false; + if( hitResult ) { + tool._handleHit(hitResult, point); + } + + if( hitResult === null && Microdraw.region ) { + //deselect paths + Microdraw.region.path.selected = false; + Microdraw.region = null; + } + + + paper.view.draw(); + }, + + + /* + * @function click + * @desc Convert polygon path to bezier curve + * @param {string} prevTool The previous tool to which the selection goes back + * @returns {void} + */ + click: function click() { + Microdraw.navEnabled = false; + Microdraw.handle = null; + } + }; + + return tool; +}())}; diff --git a/app/public/js/tools/select.js b/app/public/js/tools/select.js index c0920f8..4dd1d55 100644 --- a/app/public/js/tools/select.js +++ b/app/public/js/tools/select.js @@ -11,15 +11,16 @@ window.ToolSelect = {select: (function() { * @param {object} dpoint The movement of the point * @return {void} */ - mouseDrag: function mouseDrag() { + mouseDrag: function mouseDrag(point, dpoint) { + // event.stopHandlers = true; - for( var reg of Microdraw.ImageInfo[Microdraw.currentImage].Regions ) { - if( reg.path.selected ) { - // reg.path.position.x += dpoint.x; - // reg.path.position.y += dpoint.y; - // Microdraw.commitMouseUndo(); - } - } + // for( var reg of Microdraw.ImageInfo[Microdraw.currentImage].Regions ) { + // if( reg.path.selected ) { + // reg.path.position.x += dpoint.x; + // reg.path.position.y += dpoint.y; + // Microdraw.commitMouseUndo(); + // } + // } }, _handleHitResultType: function (hitResult, point) { @@ -33,7 +34,9 @@ window.ToolSelect = {select: (function() { Microdraw.handle = hitResult.segment.point; Microdraw.handle.point = point; } else if( hitResult.type === 'fill' ) { - Microdraw.tools.textAnnotation.updateTextAnnotationPanel(hitResult.item); + if ({}.hasOwnProperty.call(hitResult.item, 'fontSize')) { + Microdraw.tools.textAnnotation.updateTextAnnotationPanel(hitResult.item); + } } }, diff --git a/app/views/partials/toolsFull.mustache b/app/views/partials/toolsFull.mustache index 9f766a1..667120e 100644 --- a/app/views/partials/toolsFull.mustache +++ b/app/views/partials/toolsFull.mustache @@ -54,19 +54,20 @@