You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
1.0 KiB

2 years ago
function tools_switch(state, tool) {
if (state.tools.active_element) {
state.tools.active_element.classList.remove('active');
}
2 years ago
state.tools.active = tool;
state.tools.active_element = document.querySelector(`.tool[data-tool="${tool}"]`);
state.tools.active_element.classList.add('active');
}
2 years ago
function init_tools(state, context) {
const pencil = document.querySelector('.tool[data-tool="pencil"]');
const ruler = document.querySelector('.tool[data-tool="ruler"]');
const eraser = document.querySelector('.tool[data-tool="eraser"]');
const undo = document.querySelector('.tool[data-tool="undo"]');
2 years ago
pencil.addEventListener('click', () => tools_switch(state, 'pencil'));
ruler.addEventListener('click', () => tools_switch(state, 'ruler'));
eraser.addEventListener('click', () => tools_switch(state, 'eraser'));
undo.addEventListener('click', () => {
pop_stroke(state, context);
window.requestAnimationFrame(() => draw(state, context));
});
2 years ago
tools_switch(state, 'pencil');
}