whiteboard / static /js /tools.js
5m4ck3r's picture
Upload 11 files
d7508be verified
raw
history blame
1.26 kB
class DrawingTools {
constructor(canvas, ctx) {
this.canvas = canvas;
this.ctx = ctx;
this.color = '#000000';
this.brushSize = 2;
this.isEraser = false;
this.setupTools();
}
setupTools() {
const colorPicker = document.getElementById('colorPicker');
const brushSize = document.getElementById('brushSize');
const brushSizeLabel = document.getElementById('brushSizeLabel');
const eraserBtn = document.getElementById('eraserBtn');
colorPicker.addEventListener('input', (e) => {
this.color = e.target.value;
this.isEraser = false;
eraserBtn.classList.remove('active');
});
brushSize.addEventListener('input', (e) => {
this.brushSize = e.target.value;
brushSizeLabel.textContent = `${this.brushSize}px`;
});
eraserBtn.addEventListener('click', () => {
this.isEraser = !this.isEraser;
eraserBtn.classList.toggle('active');
});
}
applyToolSettings() {
if (this.isEraser) {
this.ctx.globalCompositeOperation = 'destination-out';
this.ctx.strokeStyle = 'rgba(0,0,0,1)';
} else {
this.ctx.globalCompositeOperation = 'source-over';
this.ctx.strokeStyle = this.color;
}
this.ctx.lineWidth = this.brushSize;
}
}