Skip to content

Commit

Permalink
Fixed regression in toggling subpatch gop redrect
Browse files Browse the repository at this point in the history
* It is supposed to toggle on and off depending on whether the subpatch has scalars only in it. It does this by also intelligently accounting for temporary text objects that are created and need to be filled by the scalar name before they are converted into a scalar class.

* There is one condition the original implementation failed to account for: creating a new text_object in an empty canvas which erroneously still resulted in the assumption that the subpatch consisted of only scalars.

* This patch fixes this special case.

* To test: create an empty subpatch and enable GOP, inside the subpatch create an empty object which will erase GOP until you make that object something concrete (e.g. print). With the patch, the GOP redrect will never dissappear (and it shouldn't).
  • Loading branch information
pd-l2ork committed Oct 9, 2020
1 parent 4d38f27 commit 2e4940e
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions pd/src/g_graph.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,18 @@ extern t_canvas *canvas_templatecanvas_forgroup(t_canvas *c);
/* [email protected] 2020-08-24:
check if canvas consists of only scalars and returns 2. if the canvas only
has the last object as a non-scalar (e.g. a new object has just been created,
then we return 1, otherwise return 0. this is used to prevent creation of new
objects in an GOP window that only has scalars inside it or scalars with one
newly created object that is yet to be typed into and therefore properly
instantiated */
then we return 1, otherwise return 0. this is used to determine whether the
GOP redrect should be drawn inside the GOP-enabled toplevel window, depending
whether it only has scalars inside it or scalars with one newly created object
that is yet to be typed into and therefore properly instantiated */
int canvas_has_scalars_only(t_canvas *x)
{
t_gobj *g = x->gl_list;
int hasonlyscalars = 2;
int hasonlyscalars = 0;
while (g)
{
//post("g...");
hasonlyscalars = 2;
if (pd_class(&g->g_pd) != scalar_class)
{
/*
Expand All @@ -85,25 +86,27 @@ int canvas_has_scalars_only(t_canvas *x)

/* [email protected] 2020-08-24:
if we have one more object or the last object is not newly
instantiated text object
to distinguish between a comment and a text object that is
yet to be instantiated we use:
instantiated text object to distinguish between a comment and
a text object that is yet to be instantiated we use:
1) comment is text_class and its te_type is T_TEXT
2) blank object one is typing into is text_class but is NOT T_TEXT
3) instantiated object is something other than text_class (unless)
it is a comment
3) instantiated object is something other than text_class (unless
it is a comment)
4) object that has failed to create is same as blank object
*/
if (g->g_next || (pd_class(&g->g_pd) != text_class || ((t_text *)g)->te_type == T_TEXT))
hasonlyscalars = 0;
// check if we are not the only object on the canvas, in which case we should still
// return 0 since we have no scalars inside the canvas
else if (g == x->gl_list && !g->g_next)
hasonlyscalars = 0;
else
hasonlyscalars = 1;
break;
}
//post("...scalar, comment, or uninitialized object=yes");
g = g->g_next;
}
//post("has scalars only=%d", hasonlyscalars);
return(hasonlyscalars);
}

Expand All @@ -128,7 +131,7 @@ void glist_update_redrect(t_glist *x)
}
else if (canvas_has_scalars_only(x) && x->gl_goprect)
{
x->gl_goprect = 0;
x->gl_goprect = 0;
canvas_drawredrect(x, 0);
}
}
Expand Down

0 comments on commit 2e4940e

Please sign in to comment.