From 5cddd682ea61388ae71c1eaff381f0834bb2e020 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Mon, 20 Jul 2020 17:08:26 -0400
Subject: [PATCH] bring gobjs and canvases into focus for errors, add
 animations

---
 pd/nw/pdgui.js    | 30 ++++++++++++++++++++++++++++++
 pd/src/g_editor.c | 15 +++++++++++----
 2 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/pd/nw/pdgui.js b/pd/nw/pdgui.js
index 9ca168fb4..247bbfb78 100644
--- a/pd/nw/pdgui.js
+++ b/pd/nw/pdgui.js
@@ -2634,6 +2634,36 @@ function gui_gobj_deselect(cid, tag) {
     });
 }
 
+function gui_canvas_emphasize(cid) {
+    gui(cid).get_elem("patchsvg", function(e) {
+        // raise the window
+        gui_raise_window(cid);
+        // animate the background
+        e.animate([
+            {"backgroundColor": "white"},
+            {"backgroundColor": "#ff000099"},
+            {"backgroundColor": "white"}
+        ], { duration: 900, easing: "ease-in-out", iterations: 1 });
+    });
+}
+
+// bring a gobj into the viewport, plus do an animation to catch the
+// user's attention
+function gui_gobj_emphasize(cid, tag) {
+    gui(cid).get_gobj(tag, function(e) {
+        var border = e.querySelector(".border");
+        e.scrollIntoView();
+        // quick and dirty
+        if (border) {
+            border.animate([
+                 {fill: "white"},
+                 {fill: "#ff000099"},
+                 {fill: "white"}
+            ], { duration: 300, easing: "ease-in-out", iterations: 3});
+        }
+    });
+}
+
 // This adds a 0.5 offset to align to pixel grid, so it should
 // only be used to move gobjs to a new position.  (Should probably
 // be renamed to gobj_move to make this more obvious.)
diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c
index 320c61262..626b1384a 100644
--- a/pd/src/g_editor.c
+++ b/pd/src/g_editor.c
@@ -5828,6 +5828,13 @@ static void canvas_find_parent(t_canvas *x, t_floatarg f)
     }
 }
 
+    /* tell the gui to bring a gobj into view, possibly with an animation */
+static void gobj_emphasize(t_glist *g, t_gobj *x)
+{
+    t_rtext *y = glist_findrtext(g, (t_text *)x);
+    gui_vmess("gui_gobj_emphasize", "xs", g, rtext_gettag(y));
+}
+
 static int glist_dofinderror(t_glist *gl, void *error_object)
 {
     t_gobj *g;
@@ -5840,6 +5847,7 @@ static int glist_dofinderror(t_glist *gl, void *error_object)
             canvas_vis(glist_getcanvas(gl), 1);
             canvas_editmode(glist_getcanvas(gl), 1.);
             glist_select(gl, g);
+            gobj_emphasize(gl, g);
             return (1);
         }
         else if (g->g_pd == canvas_class)
@@ -5860,11 +5868,10 @@ void canvas_finderror(void *error_object)
         if ((void *)x == error_object)
         {
             /* If the error is associated with a toplevel canvas, we
-               do a quick-and-dirty unvis and vis to give some basic
-               visual feedback to the user */
+               we raise it to the top and do a quick-and-dirty background
+               animation for visual feedback to the user */
             glist_noselect(x);
-            canvas_vis(glist_getcanvas(x), 0);
-            canvas_vis(glist_getcanvas(x), 1);
+            gui_vmess("gui_canvas_emphasize", "x", glist_getcanvas(x));
             return;
         }
         if (glist_dofinderror(x, error_object))
-- 
GitLab