From cb2b57ccc909d30810c4ebdfd2c6f8bbd54f5129 Mon Sep 17 00:00:00 2001
From: mgfcf <m.giller@tu-braunschweig.de>
Date: Tue, 12 Oct 2021 20:48:32 +0200
Subject: [PATCH] Added link rendering to tools

---
 editor/js/editor.js     |  2 ++
 editor/js/state.js      | 20 ++++++++++++++++++++
 editor/js/tools/tool.js | 12 ++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/editor/js/editor.js b/editor/js/editor.js
index 8473bf1..74e3e3d 100644
--- a/editor/js/editor.js
+++ b/editor/js/editor.js
@@ -65,6 +65,8 @@ function load() {
         )
         .nodeCanvasObjectMode((node) => state.nodeCanvasObjectMode(node))
         .nodeCanvasObject((node, ctx, globalScale) => state.nodeCanvasObject(node, ctx, globalScale))
+        .linkCanvasObjectMode((link) => state.linkCanvasObjectMode(link))
+        .linkCanvasObject((link, ctx, globalScale) => state.linkCanvasObject(link, ctx, globalScale))
         .onLinkClick((link) => state.onLinkClick(link));
 
     graph.onChangeCallbacks.push((data) => {
diff --git a/editor/js/state.js b/editor/js/state.js
index cbf44c4..2066357 100644
--- a/editor/js/state.js
+++ b/editor/js/state.js
@@ -198,6 +198,26 @@ export class State extends Tool {
         return "after";
     }
 
+    linkCanvasObjectMode(link) {
+        var toolValue = this.tool.linkCanvasObjectMode(link);
+
+        if (toolValue !== undefined) {
+            return toolValue;
+        }
+
+        return "after";
+    }
+
+    linkCanvasObject(link, ctx, globalScale) {
+        var toolValue = this.tool.linkCanvasObject(link, ctx);
+
+        if (toolValue !== undefined) {
+            return toolValue;
+        }
+        
+        return undefined;
+    }
+
     linkWidth(link) {
         var toolValue = this.tool.linkWidth(link);
 
diff --git a/editor/js/tools/tool.js b/editor/js/tools/tool.js
index 0c7b3ad..63ab117 100644
--- a/editor/js/tools/tool.js
+++ b/editor/js/tools/tool.js
@@ -93,6 +93,18 @@ export default class Tool {
         }
     }
 
+    linkCanvasObject(link, ctx, globalScale) {
+        if (this.warnings) {
+            console.warn('Method "linkCanvasObject" not implemented.');
+        }
+    }
+
+    linkCanvasObjectMode(link) {
+        if (this.warnings) {
+            console.warn('Method "linkCanvasObjectMode" not implemented.');
+        }
+    }
+
     nodePointerAreaPaint(node, color, ctx) {
         if (this.warnings) {
             console.warn('Method "nodePointerAreaPaint" not implemented.');
-- 
GitLab