// REFACTOR: this is a nice base for the Tool class //tools container / list, automatically managed when you create a new Tool(); var tool = {}; //class for tools class Tool { name = "AbstractTool"; isSelected = false; switchFunction = undefined; // Cursor and brush size cursorType = {}; cursor = undefined; cursorHTMLElement = undefined; // Useful coordinates startMousePos = {}; currMousePos = {}; prevMousePos = {}; endMousePos = {}; // HTML elements mainButton = undefined; brushPreview = document.getElementById("brush-preview"); // Tool tutorial toolTutorial = document.getElementById("tool-tutorial"); tutorialTimer = undefined; tutorialString = ""; constructor (name, options) { this.name = name; this.cursorType = options; this.mainButton = document.getElementById(name + "-button"); if (this.mainButton != undefined) { // Timer to show the tutorial Events.on("mouseenter", this.mainButton, function(){ this.setTutorial(); this.tutorialTimer = setTimeout(this.showTutorial.bind(this), 750) }.bind(this)); // Clear the callback if the user cancels the hovering Events.on("mouseleave", this.mainButton, function() { if (this.tutorialTimer != undefined) clearTimeout(this.tutorialTimer); this.tutorialTimer = undefined; this.hideTutorial(); }.bind(this)) this.hideTutorial(); } } showTutorial() { let tutorialRect = this.toolTutorial.getBoundingClientRect(); if ((this.mainButton.getBoundingClientRect().top - 48 + (tutorialRect.bottom - tutorialRect.top)) > window.innerHeight) { this.toolTutorial.style.top = window.innerHeight - 48 - (tutorialRect.bottom - tutorialRect.top) + "px"; } else { this.toolTutorial.style.top = this.mainButton.getBoundingClientRect().top - 48 + "px"; } this.toolTutorial.className = "fade-in"; } hideTutorial() { this.toolTutorial.className = "fade-out"; } resetTutorial() { this.tutorialString = ""; } setTutorial() { this.toolTutorial.innerHTML = this.tutorialString; } addTutorialKey(key, text) { this.tutorialString += '
  • ' + key + ' ' + text + '
  • '; } addTutorialText(key, text) { this.tutorialString += '
  • ' + key + ': ' + text + '
  • '; } addTutorialImg(imgPath) { this.tutorialString += ''; } addTutorialTitle(text) { this.tutorialString += "

    " + text + "