mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Moved cursor in selection check to selection tool
This commit is contained in:
parent
69d7f12790
commit
b37d050af8
@ -6,6 +6,7 @@ var tool = {};
|
|||||||
class Tool {
|
class Tool {
|
||||||
name = "AbstractTool";
|
name = "AbstractTool";
|
||||||
isSelected = false;
|
isSelected = false;
|
||||||
|
switchFunction = undefined;
|
||||||
|
|
||||||
// Cursor and brush size
|
// Cursor and brush size
|
||||||
cursorType = {};
|
cursorType = {};
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
class LassoSelectionTool extends SelectionTool {
|
class LassoSelectionTool extends SelectionTool {
|
||||||
currentPixels = []
|
currentPixels = []
|
||||||
|
currSelection = {}
|
||||||
|
|
||||||
constructor (name, options, switchFunc, moveTool) {
|
constructor (name, options, switchFunc, moveTool) {
|
||||||
super(name, options, switchFunc, moveTool);
|
super(name, options, switchFunc, moveTool);
|
||||||
|
|
||||||
Events.on('click', this.mainButton, switchFunc, this);
|
Events.on('click', this.mainButton, switchFunc, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,4 +79,8 @@ class LassoSelectionTool extends SelectionTool {
|
|||||||
currFile.VFXLayer.context.fill();
|
currFile.VFXLayer.context.fill();
|
||||||
currFile.VFXLayer.context.closePath();
|
currFile.VFXLayer.context.closePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSelection() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -59,7 +59,7 @@ class MoveSelectionTool extends DrawingTool {
|
|||||||
onStart(mousePos, mouseTarget) {
|
onStart(mousePos, mouseTarget) {
|
||||||
super.onStart(mousePos, mouseTarget);
|
super.onStart(mousePos, mouseTarget);
|
||||||
|
|
||||||
if (!this.cursorInSelectedArea(mousePos) &&
|
if (!this.selectionTool.cursorInSelectedArea(mousePos) &&
|
||||||
!Util.isChildOfByClass(mouseTarget, "editor-top-menu")) {
|
!Util.isChildOfByClass(mouseTarget, "editor-top-menu")) {
|
||||||
this.endSelection();
|
this.endSelection();
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ class MoveSelectionTool extends DrawingTool {
|
|||||||
onHover(mousePos) {
|
onHover(mousePos) {
|
||||||
super.onHover(mousePos);
|
super.onHover(mousePos);
|
||||||
|
|
||||||
if (this.cursorInSelectedArea(mousePos)) {
|
if (this.selectionTool.cursorInSelectedArea(mousePos)) {
|
||||||
currFile.canvasView.style.cursor = 'move';
|
currFile.canvasView.style.cursor = 'move';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -109,20 +109,6 @@ class MoveSelectionTool extends DrawingTool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cursorInSelectedArea(cursorPos) {
|
|
||||||
// Getting the coordinates relatively to the canvas
|
|
||||||
let x = cursorPos[0] / currFile.zoom;
|
|
||||||
let y = cursorPos[1] / currFile.zoom;
|
|
||||||
|
|
||||||
if (this.currSelection.left <= x && x <= this.currSelection.right) {
|
|
||||||
if (y <= this.currSelection.bottom && y >= this.currSelection.top) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
endSelection() {
|
endSelection() {
|
||||||
if (this.currSelection == undefined)
|
if (this.currSelection == undefined)
|
||||||
return;
|
return;
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
class RectangularSelectionTool extends SelectionTool {
|
class RectangularSelectionTool extends SelectionTool {
|
||||||
switchFunc = undefined;
|
|
||||||
moveTool = undefined;
|
|
||||||
currSelection = {};
|
currSelection = {};
|
||||||
|
|
||||||
constructor (name, options, switchFunc, moveTool) {
|
constructor (name, options, switchFunc, moveTool) {
|
||||||
super(name, options, switchFunc);
|
super(name, options, switchFunc, moveTool);
|
||||||
|
|
||||||
this.switchFunc = switchFunc;
|
|
||||||
this.moveTool = moveTool;
|
|
||||||
Events.on('click', this.mainButton, switchFunc, this);
|
Events.on('click', this.mainButton, switchFunc, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,4 +204,18 @@ class RectangularSelectionTool extends SelectionTool {
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cursorInSelectedArea(cursorPos) {
|
||||||
|
// Getting the coordinates relatively to the canvas
|
||||||
|
let x = cursorPos[0] / currFile.zoom;
|
||||||
|
let y = cursorPos[1] / currFile.zoom;
|
||||||
|
|
||||||
|
if (this.currSelection.left <= x && x <= this.currSelection.right) {
|
||||||
|
if (y <= this.currSelection.bottom && y >= this.currSelection.top) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,9 +1,19 @@
|
|||||||
class SelectionTool extends Tool {
|
class SelectionTool extends Tool {
|
||||||
constructor(name, options, switchFunc) {
|
switchFunc = undefined;
|
||||||
super(name, options, switchFunc);
|
moveTool = undefined;
|
||||||
|
|
||||||
|
constructor(name, options, switchFunc, moveTool) {
|
||||||
|
super(name, options);
|
||||||
|
|
||||||
|
this.moveTool = moveTool;
|
||||||
|
this.switchFunc = switchFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
cutSelection() {}
|
cutSelection() {}
|
||||||
|
|
||||||
pasteSelection(){}
|
pasteSelection(){}
|
||||||
|
|
||||||
copySelection(){}
|
copySelection(){}
|
||||||
|
|
||||||
|
cursorInSelectedArea(){}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user