mirror of
https://github.com/lospec/pixel-editor.git
synced 2023-08-10 21:12:51 +03:00
Working on line tool
This commit is contained in:
@ -50,6 +50,9 @@ function KeyPress(e) {
|
||||
case 52: case 80:
|
||||
tool.pan.switchTo();
|
||||
break;
|
||||
case 76:
|
||||
tool.line.switchTo();
|
||||
break;
|
||||
//zoom - 5
|
||||
case 53:
|
||||
tool.zoom.switchTo();
|
||||
|
21
js/_line.js
Normal file
21
js/_line.js
Normal file
@ -0,0 +1,21 @@
|
||||
function diagLine(lastMouseClickPos, zoom, cursorLocation) {
|
||||
|
||||
let x0 = Math.floor(lastMouseClickPos[0]/zoom);
|
||||
let y0 = Math.floor(lastMouseClickPos[1]/zoom);
|
||||
let x1 = Math.floor(cursorLocation[0]/zoom);
|
||||
let y1 = Math.floor(cursorLocation[1]/zoom);
|
||||
|
||||
let dx = Math.abs(x1-x0);
|
||||
let dy = Math.abs(y1-y0);
|
||||
let sx = (x0 < x1 ? 1 : -1);
|
||||
let sy = (y0 < y1 ? 1 : -1);
|
||||
let err = dx-dy;
|
||||
|
||||
const brushSize = 1;
|
||||
|
||||
|
||||
if (currentTool.name !== 'line') return;
|
||||
|
||||
currentLayer.context.fillRect(x0-Math.floor(brushSize/2), y0-Math.floor(brushSize/2), brushSize, brushSize);
|
||||
|
||||
}
|
@ -346,6 +346,14 @@ function draw (mouseEvent) {
|
||||
updateMovePreview(getCursorPosition(mouseEvent));
|
||||
}
|
||||
}
|
||||
else if (currentTool.name === "line") {
|
||||
if (dragging) {
|
||||
if (mouseEvent.target.className == 'drawingCanvas' || mouseEvent.target.className == 'drawingCanvas') {
|
||||
diagLine(lastMouseClickPos, zoom, cursorLocation);
|
||||
}
|
||||
}
|
||||
currentLayer.updateLayerPreview();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,33 +75,14 @@ on('click',"eyedropper-button", function(){
|
||||
tool.eyedropper.switchTo();
|
||||
}, false);
|
||||
|
||||
//zoom tool button
|
||||
on('click',"zoom-button", function(){
|
||||
tool.zoom.switchTo();
|
||||
}, false);
|
||||
|
||||
//zoom in button
|
||||
on('click','zoom-in-button', function(){
|
||||
//changeZoom('in',[window.innerWidth/2-canvas.offsetLeft,window.innerHeight/2-canvas.offsetTop]);
|
||||
changeZoom('in', [canvasSize[0] * zoom / 2, canvasSize[1] * zoom / 2]);
|
||||
|
||||
for (let i=1; i<layers.length; i++) {
|
||||
layers[i].copyData(layers[0]);
|
||||
}
|
||||
}, false);
|
||||
|
||||
//zoom out button
|
||||
on('click','zoom-out-button', function(){
|
||||
changeZoom('out',[canvasSize[0]*zoom/2,canvasSize[1]*zoom/2]);
|
||||
|
||||
for (let i=1; i<layers.length; i++) {
|
||||
layers[i].copyData(layers[0]);
|
||||
}
|
||||
}, false);
|
||||
|
||||
//rectangular selection button
|
||||
on('click', "rectselect-button", function(){
|
||||
tool.rectselect.switchTo();
|
||||
}, false);
|
||||
|
||||
//line
|
||||
on('click',"line-button", function(){
|
||||
tool.line.switchTo();
|
||||
}, false);
|
||||
|
||||
/*global on */
|
||||
|
@ -41,6 +41,7 @@
|
||||
//=include _drawLine.js
|
||||
//=include _getCursorPosition.js
|
||||
//=include _fill.js
|
||||
//=include _line.js
|
||||
//=include _history.js
|
||||
//=include _deleteColor.js
|
||||
//=include _replaceAllOfColor.js
|
||||
|
4
js/tools/_line.js
Normal file
4
js/tools/_line.js
Normal file
@ -0,0 +1,4 @@
|
||||
new Tool('line', {
|
||||
cursor: 'crosshair',
|
||||
brushPreview: true,
|
||||
});
|
Reference in New Issue
Block a user