From b81e3f36a9ce1dd978e7d79adb2eba53f8c40442 Mon Sep 17 00:00:00 2001 From: unsettledgames <47360416+unsettledgames@users.noreply.github.com> Date: Thu, 5 Mar 2020 13:34:29 +0100 Subject: [PATCH] Added correct cursor to move tool Added _move.js to handle the selection movement, added cursor managemente for that tool. Found a bug in the imagedata part, it is currently blank. --- js/_mouseEvents.js | 15 ++++++++++++++- js/_move.js | 6 +++++- js/_rectSelect.js | 44 ++++++++++++++++++++++++++++++++++++++++---- js/_updateCursor.js | 15 ++++++++++++--- 4 files changed, 71 insertions(+), 9 deletions(-) diff --git a/js/_mouseEvents.js b/js/_mouseEvents.js index 8e658e1..ff65a71 100644 --- a/js/_mouseEvents.js +++ b/js/_mouseEvents.js @@ -1,6 +1,9 @@ +var currentMouseEvent; //mousedown - start drawing window.addEventListener("mousedown", function (mouseEvent) { + // Saving the event in case something else needs it + currentMouseEvent = mouseEvent; //if no document has been created yet, or this is a dialog open if (!documentCreated || dialogueOpen) return; @@ -44,7 +47,9 @@ window.addEventListener("mousedown", function (mouseEvent) { //mouseup - end drawing window.addEventListener("mouseup", function (mouseEvent) { - + // Saving the event in case something else needs it + currentMouseEvent = mouseEvent; + closeMenu(); if (!documentCreated || dialogueOpen) return; @@ -125,6 +130,9 @@ window.addEventListener("mouseup", function (mouseEvent) { //mouse is moving on canvas window.addEventListener("mousemove", draw, false); function draw (mouseEvent) { + // Saving the event in case something else needs it + currentMouseEvent = mouseEvent; + var cursorLocation = getCursorPosition(mouseEvent); //if a document hasnt yet been created, exit this function @@ -247,6 +255,11 @@ function draw (mouseEvent) { updateRectSelection(mouseEvent); } } + else if (currentTool == 'moveselection') { + console.log("Aggiorno il cursore"); + updateCursor(); + updateMovePreview(); + } } //mousewheel scrroll diff --git a/js/_move.js b/js/_move.js index a08b30f..d970200 100644 --- a/js/_move.js +++ b/js/_move.js @@ -1 +1,5 @@ -var imageDataToMove; \ No newline at end of file +var imageDataToMove; + +function updateMovePreview() { + +} \ No newline at end of file diff --git a/js/_rectSelect.js b/js/_rectSelect.js index de1af64..e00e18a 100644 --- a/js/_rectSelect.js +++ b/js/_rectSelect.js @@ -1,6 +1,8 @@ var isRectSelecting = false; let startX; let startY; +let endX; +let endY; let workingLayer; let imageData; @@ -29,13 +31,24 @@ function updateRectSelection(mouseEvent) { function endRectSelection(mouseEvent) { // Getting the end position let currentPos = getCursorPosition(mouseEvent); - let x = currentPos[0] / zoom; - let y = currentPos[1] / zoom; + endX = currentPos[0] / zoom; + endY = currentPos[1] / zoom; // Putting the vfx layer behind everything isRectSelecting = false; // Getting the selected pixels - imageData = currentLayer.context.createImageData(x - startX, y - startY); + imageData = currentLayer.context.createImageData(endX - startX, endY - startY); + + // Selecting the move tool + currentTool = 'moveselection'; + currentToolTemp = currentTool; + // Updating the cursor + updateCursor(); + + // TODO: find out why the imagedata is blank + for (i=0; i