From 65629b5964cb7175538db6558e84ddc31845fc13 Mon Sep 17 00:00:00 2001
From: Miller Puckette <msp@ucsd.edu>
Date: Mon, 19 May 2008 14:15:21 -0700
Subject: [PATCH] working on GOP bug

---
 src/g_canvas.h |  2 +-
 src/g_editor.c | 58 +++++++++++++++++++++++++++++++-------------------
 src/g_graph.c  |  3 +--
 src/g_text.c   | 16 +++-----------
 src/m_class.c  |  1 -
 src/s_stuff.h  |  1 +
 6 files changed, 42 insertions(+), 39 deletions(-)

diff --git a/src/g_canvas.h b/src/g_canvas.h
index afb79cf83..c074ad5c1 100644
--- a/src/g_canvas.h
+++ b/src/g_canvas.h
@@ -353,6 +353,7 @@ EXTERN int gobj_click(t_gobj *x, struct _glist *glist,
 EXTERN void gobj_save(t_gobj *x, t_binbuf *b);
 EXTERN void gobj_properties(t_gobj *x, struct _glist *glist);
 EXTERN void gobj_save(t_gobj *x, t_binbuf *b);
+EXTERN int gobj_shouldvis(t_gobj *x, struct _glist *glist);
 
 /* -------------------- functions on glists --------------------- */
 EXTERN t_glist *glist_new( void);
@@ -414,7 +415,6 @@ EXTERN int text_xcoord(t_text *x, t_glist *glist);
 EXTERN int text_ycoord(t_text *x, t_glist *glist);
 EXTERN int text_xpix(t_text *x, t_glist *glist);
 EXTERN int text_ypix(t_text *x, t_glist *glist);
-EXTERN int text_shouldvis(t_text *x, t_glist *glist);
 
 /* -------------------- functions on rtexts ------------------------- */
 #define RTEXT_DOWN 1
diff --git a/src/g_editor.c b/src/g_editor.c
index a44d952a3..8f240f57b 100644
--- a/src/g_editor.c
+++ b/src/g_editor.c
@@ -61,28 +61,43 @@ void gobj_delete(t_gobj *x, t_glist *glist)
         (*x->g_pd->c_wb->w_deletefn)(x, glist);
 }
 
+int gobj_shouldvis(t_gobj *x, struct _glist *glist)
+{
+    t_object *ob;
+    if (!glist->gl_havewindow && glist->gl_isgraph && glist->gl_goprect &&
+        glist->gl_owner && (pd_class(&glist->gl_pd) != garray_class))
+    {
+        /* if we're graphing-on-parent and the object falls outside the
+        graph rectangle, don't draw it. */
+        int x1, y1, x2, y2, gx1, gy1, gx2, gy2, m;
+        gobj_getrect(&glist->gl_gobj, glist->gl_owner, &x1, &y1, &x2, &y2);
+        if (x1 > x2)
+            m = x1, x1 = x2, x2 = m;
+        if (y1 > y2)
+            m = y1, y1 = y2, y2 = m;
+        gobj_getrect(x, glist, &gx1, &gy1, &gx2, &gy2);
+        if (gx1 < x1 || gx1 > x2 || gx2 < x1 || gx2 > x2 ||
+            gy1 < y1 || gy1 > y2 || gy2 < y1 || gy2 > y2)
+                return (0);
+    }
+    if (ob = pd_checkobject(&x->g_pd))
+    {
+        /* return true if the text box should be drawn.  We don't show text
+        boxes inside graphs---except comments, if we're doing the new
+        (goprect) style. */
+        return (glist->gl_havewindow ||
+            (ob->te_pd != canvas_class &&
+                ob->te_pd->c_wb != &text_widgetbehavior) ||
+            (ob->te_pd == canvas_class && (((t_glist *)ob)->gl_isgraph)) ||
+            (glist->gl_goprect && (ob->te_type == T_TEXT)));
+    }
+    else return (1);
+}
+
 void gobj_vis(t_gobj *x, struct _glist *glist, int flag)
 {
-    if (x->g_pd->c_wb && x->g_pd->c_wb->w_visfn)
-    {
-        if (!glist->gl_havewindow && glist->gl_isgraph && glist->gl_goprect &&
-            glist->gl_owner && (pd_class(&glist->gl_pd) != garray_class))
-        {
-            /* if we're graphing-on-parent and the object falls outside the
-            graph rectangle, don't draw it. */
-            int x1, y1, x2, y2, gx1, gy1, gx2, gy2, m;
-            gobj_getrect(&glist->gl_gobj, glist->gl_owner, &x1, &y1, &x2, &y2);
-            if (x1 > x2)
-                m = x1, x1 = x2, x2 = m;
-            if (y1 > y2)
-                m = y1, y1 = y2, y2 = m;
-            gobj_getrect(x, glist, &gx1, &gy1, &gx2, &gy2);
-            if (gx1 < x1 || gx1 > x2 || gx2 < x1 || gx2 > x2 ||
-                gy1 < y1 || gy1 > y2 || gy2 < y1 || gy2 > y2)
-                    return;
-        }
+    if (x->g_pd->c_wb && x->g_pd->c_wb->w_visfn && gobj_shouldvis(x, glist))
         (*x->g_pd->c_wb->w_visfn)(x, glist, flag);
-    }
 }
 
 int gobj_click(t_gobj *x, struct _glist *glist,
@@ -765,9 +780,8 @@ int canvas_hitbox(t_canvas *x, t_gobj *y, int xpos, int ypos,
 {
     int x1, y1, x2, y2;
     t_text *ob;
-    if ((ob = pd_checkobject(&y->g_pd)) && 
-        !text_shouldvis(ob, x))
-            return (0);
+    if (!gobj_shouldvis(y, x))
+        return (0);
     gobj_getrect(y, x, &x1, &y1, &x2, &y2);
     if (xpos >= x1 && xpos <= x2 && ypos >= y1 && ypos <= y2)
     {
diff --git a/src/g_graph.c b/src/g_graph.c
index f4196def1..ce5580c2e 100644
--- a/src/g_graph.c
+++ b/src/g_graph.c
@@ -671,7 +671,6 @@ void glist_redraw(t_glist *x)
 
 /* --------------------------- widget behavior  ------------------- */
 
-extern t_widgetbehavior text_widgetbehavior;
 int garray_getname(t_garray *x, t_symbol **namep);
 
 
@@ -904,7 +903,7 @@ static void graph_getrect(t_gobj *z, t_glist *glist,
             hadwindow = x->gl_havewindow;
             x->gl_havewindow = 0;
             for (g = x->gl_list; g; g = g->g_next)
-                if ((!(ob = pd_checkobject(&g->g_pd))) || text_shouldvis(ob, x))
+                if (gobj_shouldvis(g, x))
             {
                     /* don't do this for arrays, just let them hang outside the
                     box. */
diff --git a/src/g_text.c b/src/g_text.c
index bbdb7729d..1d4559ecd 100644
--- a/src/g_text.c
+++ b/src/g_text.c
@@ -989,7 +989,7 @@ static void text_select(t_gobj *z, t_glist *glist, int state)
     t_text *x = (t_text *)z;
     t_rtext *y = glist_findrtext(glist, x);
     rtext_select(y, state);
-    if (glist_isvisible(glist) && text_shouldvis(x, glist))
+    if (glist_isvisible(glist) && gobj_shouldvis(&x->te_g, glist))
         sys_vgui(".x%lx.c itemconfigure %sR -fill %s\n", glist, 
             rtext_gettag(y), (state? "blue" : "black"));
 }
@@ -1007,22 +1007,12 @@ static void text_delete(t_gobj *z, t_glist *glist)
     canvas_deletelinesfor(glist, x);
 }
 
-    /* return true if the text box should be drawn.  We don't show text boxes
-    inside graphs---except comments, if we're doing the new (goprect) style. */
-int text_shouldvis(t_text *x, t_glist *glist)
-{
-    return (glist->gl_havewindow ||
-        (x->te_pd != canvas_class && x->te_pd->c_wb != &text_widgetbehavior) ||
-        (x->te_pd == canvas_class && (((t_glist *)x)->gl_isgraph)) ||
-        (glist->gl_goprect && (x->te_type == T_TEXT)));
-}
-
 static void text_vis(t_gobj *z, t_glist *glist, int vis)
 {
     t_text *x = (t_text *)z;
     if (vis)
     {
-        if (text_shouldvis(x, glist))
+        if (gobj_shouldvis(&x->te_g, glist))
         {
             t_rtext *y = glist_findrtext(glist, x);
             if (x->te_type == T_ATOM)
@@ -1035,7 +1025,7 @@ static void text_vis(t_gobj *z, t_glist *glist, int vis)
     else
     {
         t_rtext *y = glist_findrtext(glist, x);
-        if (text_shouldvis(x, glist))
+        if (gobj_shouldvis(&x->te_g, glist))
         {
             text_eraseborder(x, glist, rtext_gettag(y));
             rtext_erase(y);
diff --git a/src/m_class.c b/src/m_class.c
index ab0b86bed..da8b0e4f4 100644
--- a/src/m_class.c
+++ b/src/m_class.c
@@ -149,7 +149,6 @@ static void pd_defaultlist(t_pd *x, t_symbol *s, int argc, t_atom *argv)
     argument form, one for the multiple one; see select_setup() to find out
     how this is handled.  */
 
-extern t_widgetbehavior text_widgetbehavior;
 extern void text_save(t_gobj *z, t_binbuf *b);
 
 t_class *class_new(t_symbol *s, t_newmethod newmethod, t_method freemethod,
diff --git a/src/s_stuff.h b/src/s_stuff.h
index a1f9026c4..e53d3edc9 100644
--- a/src/s_stuff.h
+++ b/src/s_stuff.h
@@ -325,3 +325,4 @@ EXTERN void inmidi_polyaftertouch(int portno,
                                   int pitch,
                                   int value);
 /* } jsarlo */
+extern t_widgetbehavior text_widgetbehavior;
-- 
GitLab