Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed added space changing color with palette #468

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/utils/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function handleDrawing(canvas, color, lineThickness, bgColor, brushStyle)
event.preventDefault();
startDrawing(event);
});

canvas.addEventListener('touchend', (event) => {
event.preventDefault();
stopDrawing();
Expand Down Expand Up @@ -220,18 +220,19 @@ export function increaseHeight(canvas, bgColor, thickness, color, brushStyle) {
// Redraw the portion of the drawing that fits in the new canvas size
ctx.putImageData(imageData, 0, 0);


// Update drawHistory to fit within new height
drawHistory = histArray.filter((point) => point.y <= newHeight);
handleUpdates(canvas, color, thickness, bgColor, brushStyle);

}

export function decreaseHeight(canvas, bgColor, thickness, color, brushStyle) {
const ctx = canvas.getContext("2d");
const histArray = [...drawHistory];
const MIN_HEIGHT=250;
const MIN_HEIGHT = 250;
// Calculate new height, reducing by 10% of the current height
let newHeight = canvas.height - canvas.height * 0.1;

// Ensure new height does not go below 1 pixel
if (newHeight < MIN_HEIGHT) {
newHeight = MIN_HEIGHT;
Expand All @@ -243,39 +244,39 @@ export function decreaseHeight(canvas, bgColor, thickness, color, brushStyle) {

// Resize the canvas
canvas.height = newHeight;

handleUpdates(canvas, color, thickness, bgColor, brushStyle);
// Redraw the portion of the drawing that fits in the new canvas size
ctx.putImageData(imageData, 0, 0);

// Update drawHistory to fit within new height
drawHistory = histArray.filter((point) => point.y <= newHeight);
handleUpdates(canvas, color, thickness, bgColor, brushStyle);

}

export function changeAspect(canvas, bgColor, thickness, color, brushStyle, hnum, wnum) {

const ctx = canvas.getContext("2d");
const histArray = [...drawHistory];
let newHeight, newWidth;

// Set new height
if(hnum== 100 && wnum==100){//default case
newWidth = window.innerWidth * 0.8;
if (hnum == 100 && wnum == 100) {//default case
newWidth = window.innerWidth * 0.8;
newHeight = window.innerHeight * 0.6;
}
else{
else {
//adjust wnum hnums of various options to adjust the size
newWidth = window.innerWidth * wnum/100;
newHeight = window.innerWidth * hnum/100;
}
newWidth = window.innerWidth * wnum / 100;
newHeight = window.innerWidth * hnum / 100;
}

// Save the current drawing and clear the canvas
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
clearCanvas(canvas, bgColor);

// Resize the canvas
canvas.height = newHeight;
canvas.width= newWidth;
canvas.width = newWidth;

// Redraw the portion of the drawing that fits in the new canvas size
ctx.putImageData(imageData, 0, 0);
Expand All @@ -292,6 +293,7 @@ export function handleUpdates(canvas, color, lineThickness, bgColor, brushStyle)
ctx.strokeStyle = `${color}`;
canvas.style.backgroundColor = bgColor;
ctx.fillStyle = bgColor;
ctx.fillRect(0, 0, canvas.width, canvas.height);
setBrushStyle(ctx, brushStyle);
console.log("update called");
}