Fix pencil size +/- buttons broken from upstream, apply brush preview snapping to

rectangle tool, fix pencil broken by merge
This commit is contained in:
Theo Cavignac
2020-04-12 11:39:37 +02:00
committed by Théo (Lattay) Cavignac
parent dd461da675
commit 05066d8cb1
3 changed files with 22 additions and 15 deletions

View File

@ -177,7 +177,7 @@ function draw (mouseEvent) {
if (currentTool == 'pencil') { if (currentTool == 'pencil') {
//move the brush preview //move the brush preview
setPreviewPosition(brushPreview, cursorLocation, brushSize); setPreviewPosition(brushPreview, cursorLocation, pencilSize);
//hide brush preview outside of canvas / canvas view //hide brush preview outside of canvas / canvas view
if (mouseEvent.target.className == 'drawingCanvas'|| mouseEvent.target.className == 'drawingCanvas') if (mouseEvent.target.className == 'drawingCanvas'|| mouseEvent.target.className == 'drawingCanvas')
@ -188,7 +188,11 @@ function draw (mouseEvent) {
//draw line to current pixel //draw line to current pixel
if (dragging) { if (dragging) {
if (mouseEvent.target.className == 'drawingCanvas' || mouseEvent.target.className == 'drawingCanvas') { if (mouseEvent.target.className == 'drawingCanvas' || mouseEvent.target.className == 'drawingCanvas') {
line(Math.floor(lastPos[0]/zoom),Math.floor(lastPos[1]/zoom),Math.floor(cursorLocation[0]/zoom),Math.floor(cursorLocation[1]/zoom)); line(
Math.floor(lastPos[0]/zoom), Math.floor(lastPos[1]/zoom),
Math.floor(cursorLocation[0]/zoom), Math.floor(cursorLocation[1]/zoom),
pencilSize
);
lastPos = cursorLocation; lastPos = cursorLocation;
} }
} }
@ -216,7 +220,11 @@ function draw (mouseEvent) {
//draw line to current pixel //draw line to current pixel
if (dragging) { if (dragging) {
if (mouseEvent.target.className == 'drawingCanvas' || mouseEvent.target.className == 'drawingCanvas') { if (mouseEvent.target.className == 'drawingCanvas' || mouseEvent.target.className == 'drawingCanvas') {
line(Math.floor(lastPos[0]/zoom),Math.floor(lastPos[1]/zoom),Math.floor(cursorLocation[0]/zoom),Math.floor(cursorLocation[1]/zoom), eraserSize); line(
Math.floor(lastPos[0]/zoom), Math.floor(lastPos[1]/zoom),
Math.floor(cursorLocation[0]/zoom), Math.floor(cursorLocation[1]/zoom),
eraserSize
);
lastPos = cursorLocation; lastPos = cursorLocation;
} }
} }
@ -224,8 +232,7 @@ function draw (mouseEvent) {
else if (currentTool == 'rectangle') else if (currentTool == 'rectangle')
{ {
//move the brush preview //move the brush preview
brushPreview.style.left = cursorLocation[0] + currentLayer.canvas.offsetLeft - rectangleSize * zoom / 2 + 'px'; setPreviewPosition(brushPreview, cursorLocation, rectangleSize)
brushPreview.style.top = cursorLocation[1] + currentLayer.canvas.offsetTop - rectangleSize * zoom / 2 + 'px';
//hide brush preview outside of canvas / canvas view //hide brush preview outside of canvas / canvas view
if (mouseEvent.target.className == 'drawingCanvas'|| mouseEvent.target.className == 'drawingCanvas') if (mouseEvent.target.className == 'drawingCanvas'|| mouseEvent.target.className == 'drawingCanvas')
@ -272,7 +279,7 @@ function draw (mouseEvent) {
var newBrushSize = prevBrushSize + brushSizeChange; var newBrushSize = prevBrushSize + brushSizeChange;
//set the brush to the new size as long as its bigger than 1 //set the brush to the new size as long as its bigger than 1
pencilSize = Math.max(1,newBrushSize); pencilSize = Math.max(1, newBrushSize);
//fix offset so the cursor stays centered //fix offset so the cursor stays centered
setPreviewPosition(brushPreview, cursorLocation, pencilSize); setPreviewPosition(brushPreview, cursorLocation, pencilSize);

View File

@ -20,8 +20,8 @@ function startRectDrawing(mouseEvent) {
// Saving the start coords of the rect // Saving the start coords of the rect
let cursorPos = getCursorPosition(mouseEvent); let cursorPos = getCursorPosition(mouseEvent);
startRectX = Math.round(cursorPos[0] / zoom) - 0.5; startRectX = Math.floor(cursorPos[0] / zoom) + 0.5;
startRectY = Math.round(cursorPos[1] / zoom) - 0.5; startRectY = Math.floor(cursorPos[1] / zoom) + 0.5;
drawRectangle(startRectX, startRectY); drawRectangle(startRectX, startRectY);
} }
@ -30,16 +30,16 @@ function updateRectDrawing(mouseEvent) {
let pos = getCursorPosition(mouseEvent); let pos = getCursorPosition(mouseEvent);
// Drawing the rect // Drawing the rect
drawRectangle(Math.round(pos[0] / zoom) + 0.5, Math.round(pos[1] / zoom) + 0.5); drawRectangle(Math.floor(pos[0] / zoom) + 0.5, Math.floor(pos[1] / zoom) + 0.5);
} }
function endRectDrawing(mouseEvent) { function endRectDrawing(mouseEvent) {
// Getting the end position // Getting the end position
let currentPos = getCursorPosition(mouseEvent); let cursorPos = getCursorPosition(mouseEvent);
let vfxContext = VFXCanvas.getContext('2d'); let vfxContext = VFXCanvas.getContext('2d');
endRectX = Math.round(currentPos[0] / zoom) + 0.5; endRectX = Math.floor(cursorPos[0] / zoom) + 0.5;
endRectY = Math.round(currentPos[1] / zoom) + 0.5; endRectY = Math.floor(cursorPos[1] / zoom) + 0.5;
// Inverting end and start (start must always be the top left corner) // Inverting end and start (start must always be the top left corner)
if (endRectX < startRectX) { if (endRectX < startRectX) {

View File

@ -5,13 +5,13 @@ on('click','pencil-button', function(){
//pencil bigger //pencil bigger
on('click','pencil-bigger-button', function(){ on('click','pencil-bigger-button', function(){
brushSize++; pencilSize++;
updateCursor(); updateCursor();
}, false); }, false);
//pencil smaller //pencil smaller
on('click','pencil-smaller-button', function(){ on('click','pencil-smaller-button', function(){
if(brushSize > 1) brushSize--; if(pencilSize > 1) pencilSize--;
updateCursor(); updateCursor();
}, false); }, false);