diff --git a/editor/js/editor.js b/editor/js/editor.js index 88b22de5bc943deccb16db4cbb9cd2e3b6ec224d..c9b0694ee2a652b8070fcacbcfcba8cc49a1f79d 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 dc020c27adce29e3f81c9390d7d160becec92cd1..7f4bdd0cbee36bc99d20521fe6ed210a6ad15c9a 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 1b58655ce3ca4beb03f107b7312a5b24825f12e7..3cbce813ea45f57bc259851910246814dcf88759 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.' + ); + } + } }