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
26 lines
1.0 KiB
function tools_switch(state, tool) { |
|
if (state.tools.active_element) { |
|
state.tools.active_element.classList.remove('active'); |
|
} |
|
|
|
state.tools.active = tool; |
|
state.tools.active_element = document.querySelector(`.tool[data-tool="${tool}"]`); |
|
state.tools.active_element.classList.add('active'); |
|
} |
|
|
|
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"]'); |
|
|
|
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)); |
|
}); |
|
|
|
tools_switch(state, 'pencil'); |
|
} |