From 2b8f6b5603e4cf6651f01926b3e83a07a1055dee Mon Sep 17 00:00:00 2001 From: Max <m.giller.dev@gmail.com> Date: Fri, 9 Jul 2021 12:58:57 +0200 Subject: [PATCH] Added backgroundClick event to tools --- editor/js/editor.js | 8 ++++++++ editor/js/state.js | 5 +++++ editor/js/tools/tool.js | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/editor/js/editor.js b/editor/js/editor.js index 88b22de..c9b0694 100644 --- a/editor/js/editor.js +++ b/editor/js/editor.js @@ -33,6 +33,13 @@ function downloadJson() { window.location = link; } +function extractPositions(event) { + return { + graph: { x: event.layerX, y: event.layerY }, + window: { x: event.clientX, y: event.clientY }, + }; +} + function load() { const graphContainer = document.getElementById("2d-graph"); const width = graphContainer.offsetWidth; @@ -50,6 +57,7 @@ function load() { .linkDirectionalParticleWidth((link) => state.linkDirectionalParticleWidth(link) ) + .onBackgroundClick((event) => state.onBackgroundClick(event, extractPositions(event))) .nodeCanvasObjectMode((node) => state.nodeCanvasObjectMode(node)) .nodeCanvasObject((node, ctx) => state.nodeCanvasObject(node, ctx)) .onLinkClick((link) => state.onLinkClick(link)); diff --git a/editor/js/state.js b/editor/js/state.js index dc020c2..7f4bdd0 100644 --- a/editor/js/state.js +++ b/editor/js/state.js @@ -183,6 +183,11 @@ class State extends Tool { return this.isLinkHighlighted(link) ? LINK_PARTICLE_COUNT : 0; } + onBackgroundClick(event, positions) { + console.log(event); + this.tool.onBackgroundClick(event, positions); + } + redraw() { this.display.setSelectedTool(this.tool); this.display.setSelectedItem(this.selectedItem); diff --git a/editor/js/tools/tool.js b/editor/js/tools/tool.js index 1b58655..3cbce81 100644 --- a/editor/js/tools/tool.js +++ b/editor/js/tools/tool.js @@ -74,4 +74,12 @@ class Tool { ); } } + + onBackgroundClick(event, positions) { + if (this.warnings) { + console.warn( + 'Method "onBackgroundClick" not implemented.' + ); + } + } } -- GitLab