mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Added back brush with new tool system
This commit is contained in:
@@ -1,14 +1,69 @@
|
||||
const ToolManager = (() => {
|
||||
/** What it should do
|
||||
*
|
||||
* - Listen to mouse events
|
||||
* - Bind mouse events
|
||||
* - Call tool functions
|
||||
*
|
||||
*
|
||||
*/
|
||||
brush = new BrushTool("brush", {type: 'html'});
|
||||
currTool = brush;
|
||||
|
||||
Events.on("mouseup", window, onMouseUp);
|
||||
Events.on("mousemove", window, onMouseMove);
|
||||
Events.on("mousedown", window, onMouseDown);
|
||||
|
||||
function onMouseDown(mouseEvent) {
|
||||
if (!Startup.documentCreated())
|
||||
return;
|
||||
|
||||
let mousePos = Input.getCursorPosition(mouseEvent);
|
||||
console.log("here");
|
||||
switch(mouseEvent.which) {
|
||||
case 1:
|
||||
if (!Input.isDragging()) {
|
||||
currTool.onStart(mousePos);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
case 3:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseMove(mouseEvent) {
|
||||
if (!Startup.documentCreated())
|
||||
return;
|
||||
let mousePos = Input.getCursorPosition(mouseEvent);
|
||||
// Call the hover event
|
||||
currTool.onHover(mousePos, mouseEvent.target);
|
||||
|
||||
if (Input.isDragging()) {
|
||||
currTool.onDrag(mousePos, mouseEvent.target);
|
||||
}
|
||||
}
|
||||
|
||||
function onMouseUp(mouseEvent) {
|
||||
if (!Startup.documentCreated())
|
||||
return;
|
||||
let mousePos = Input.getCursorPosition(mouseEvent);
|
||||
|
||||
switch(mouseEvent.which) {
|
||||
case 0:
|
||||
if (Input.isDragging()) {
|
||||
currTool.onEnd(mousePos);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function currentTool() {
|
||||
return currTool;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
currentTool
|
||||
}
|
||||
})
|
||||
})();
|
||||
Reference in New Issue
Block a user