From 1e7dfdc331a0085f1d984063a195ca342a9f1b0c Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Wed, 27 Apr 2016 23:23:50 -0400
Subject: [PATCH] go ahead and create foreground path in GUI along with the
 background

---
 externals/miXed/cyclone/sickle/Scope.c |  5 +++++
 pd/nw/pdgui.js                         | 17 +++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/externals/miXed/cyclone/sickle/Scope.c b/externals/miXed/cyclone/sickle/Scope.c
index fdc382f33..8b6084d64 100644
--- a/externals/miXed/cyclone/sickle/Scope.c
+++ b/externals/miXed/cyclone/sickle/Scope.c
@@ -722,6 +722,11 @@ static void scope_drawbg(t_scope *x, t_canvas *cv,
 	sys_vgui(".x%x.c create line %d %f %d %f\
  -width %f -tags {%s %s}\n", cv, x1, yy, x2, yy,
 		 SCOPE_GRIDWIDTH, x->x_gridtag, x->x_tag);
+    /* Here we draw the background, _and_ we create the paths
+       for the foreground paths. The paths will get filled with
+       data in scope_drawfgxy, etc. This should be cheaper than
+       creating and destroying a bunch of DOM objects on every
+       redraw. */
     gui_vmess("gui_scope_draw_bg", "xxsiifff",
         glist_getcanvas(cv),
         x,
diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index 57cf02f29..43f43b9af 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -3053,14 +3053,18 @@ function gui_scope_draw_bg(cid, tag, bg_color, w, h, grid_width, dx, dy) {
         }),
         path,
         path_string = "",
+        foreground_path, // to be used for the foreground lines
         i, x, y, align_x, align_y;
+    // Path strings for the grid lines
+    // vertical lines...
     for (i = 0, x = dx; i < 7; i++, x += dx) {
         align_x = (x|0) === x ? x : Math.round(x);
-        path_string += ["M", 0, 0, align_x, 0, align_x, h].join(" ");
+        path_string += ["M", align_x, 0, "V", h].join(" ");
     }
+    // horizontal lines...
     for (i = 0, y = dy; i < 3; i++, y += dy) {
         align_y = (y|0) === y ? y : Math.round(y);
-        path_string += ["M", 0, 0, 0, align_y, w, align_y].join(" ");
+        path_string += ["M", 0, align_y, "H", w].join(" ");
     }
     path = create_item(cid, "path", {
         d: path_string,
@@ -3068,8 +3072,17 @@ function gui_scope_draw_bg(cid, tag, bg_color, w, h, grid_width, dx, dy) {
         stroke: "black",
         "stroke-width": grid_width,
     });
+    // We go ahead and create a path to be used in the foreground. We'll
+    // set the actual path data in the draw/redraw functions. Doing it this
+    // way will save us having to create and destroy DOM objects each time
+    // we redraw the foreground
+    foreground_path = create_item(cid, "path", {
+        fill: "none",
+        id: "fgxy"
+    });
     g.appendChild(bg);
     g.appendChild(path);
+    g.appendChild(foreground_path);
 }
 
 function add_popup(cid, popup) {
-- 
GitLab