From 98cefeae1fff8994c2abe0152e44137bb09d9f99 Mon Sep 17 00:00:00 2001
From: Ivica Ico Bukvic <ico@vt.edu>
Date: Thu, 8 Aug 2013 17:55:50 -0400
Subject: [PATCH] experimental implementation of disabling drawing outside the
 GOP array boundaries (currently disabled)

---
 pd/src/g_array.c    |  1 +
 pd/src/g_scalar.c   |  3 ++-
 pd/src/g_template.c | 31 ++++++++++++++++++++++---------
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/pd/src/g_array.c b/pd/src/g_array.c
index f2c25bb9c..0fb868ff6 100644
--- a/pd/src/g_array.c
+++ b/pd/src/g_array.c
@@ -719,6 +719,7 @@ static void array_motion(void *z, t_floatarg dx, t_floatarg dy)
                     (t_word *)(((char *)array_motion_wp) +
                         array_motion_elemsize * array_motion_lastx),
                             1);
+		// here we block scalar from exceeding the array GOP edges
 		if (graph) {
 			if (graph->gl_y1 > graph->gl_y2) {
 				if (newy > graph->gl_y1) newy = graph->gl_y1;
diff --git a/pd/src/g_scalar.c b/pd/src/g_scalar.c
index 7cba93154..f23444e99 100644
--- a/pd/src/g_scalar.c
+++ b/pd/src/g_scalar.c
@@ -266,6 +266,7 @@ static void scalar_select(t_gobj *z, t_glist *owner, int state)
 
 static void scalar_displace(t_gobj *z, t_glist *glist, int dx, int dy)
 {
+	//fprintf(stderr,"scalar_displace\n");
     t_scalar *x = (t_scalar *)z;
     t_symbol *templatesym = x->sc_template;
     t_template *template = template_findbyname(templatesym);
@@ -415,7 +416,7 @@ int scalar_doclick(t_word *data, t_template *template, t_scalar *sc,
     t_atom at[2];
     t_float basex = template_getfloat(template, gensym("x"), data, 0);
     t_float basey = template_getfloat(template, gensym("y"), data, 0);
-	//fprintf(stderr,"=================scalar_doclick %f %f %f %f\n", basex, basey, xloc, yloc);
+	//fprintf(stderr,"=================scalar_doclick %f %f %f %f %d\n", basex, basey, xloc, yloc, doit);
 
 	SETFLOAT(at, basex + xloc);
 	SETFLOAT(at+1, basey + yloc);
diff --git a/pd/src/g_template.c b/pd/src/g_template.c
index 4ab8cb9b0..d145cd4ac 100644
--- a/pd/src/g_template.c
+++ b/pd/src/g_template.c
@@ -1216,6 +1216,7 @@ static t_gpointer curve_motion_gpointer;
 
 static void curve_motion(void *z, t_floatarg dx, t_floatarg dy)
 {
+	//fprintf(stderr,"curve_motion\n");
     t_curve *x = (t_curve *)z;
     t_fielddesc *f = x->x_vec + curve_motion_field;
     t_atom at;
@@ -1679,6 +1680,7 @@ static void plot_vis(t_gobj *z, t_glist *glist,
 	}
 
 	//fprintf(stderr,"===============plot %lx glist %lx glist_getcanvas %lx plot->x_obj %lx plot->x_canvas %lx glist_getcanvas(plot->x_canvas) %lx\n", (t_int)x, (t_int)glist, (t_int)glist_getcanvas(glist), (t_int)&x->x_obj, (t_int)x->x_canvas, (t_int)x->x_canvas->gl_owner);
+	int draw_me = 1;	//used for experimental disabling of drawing outside GOP bounds
     int elemsize, yonset, wonset, xonset, i;
     t_canvas *elemtemplatecanvas;
     t_template *elemtemplate;
@@ -1747,16 +1749,27 @@ static void plot_vis(t_gobj *z, t_glist *glist,
                     minyval = yval;
                 if (i == nelem-1 || inextx != ixpix)
                 {
+					//fprintf(stderr,"%f %f %f %f %f\n", basey, minyval, maxyval,glist->gl_y2,glist->gl_y1);
+					// with the following experimental code we can prevent drawing outside the gop window (preferred but needs to be further tested)
+					/*if (glist->gl_y2 > glist->gl_y1) {
+						if (minyval >= glist->gl_y1 && maxyval <= glist->gl_y2) draw_me = 1;
+						else draw_me = 0; 
+					} else {
+						if (minyval >= glist->gl_y2 && maxyval <= glist->gl_y1) draw_me = 1;
+						else draw_me = 0; 
+					}
+					if (draw_me) {*/
 					//we subtract 1 from y to keep it in sync with the rest of the types of templates
-                    sys_vgui(
-".x%lx.c create rectangle %d %d %d %d -fill black -width 0  -tags {.x%lx.x%lx.plot%lx %lx}\n",
-                        glist_getcanvas(glist),
-                        ixpix, (int)glist_ytopixels(glist, 
-                            basey + fielddesc_cvttocoord(yfielddesc, minyval)) - 1,
-                        inextx, (int)(glist_ytopixels(glist, 
-                            basey + fielddesc_cvttocoord(yfielddesc, maxyval))
-                                + linewidth) - 1, glist_getcanvas(glist), glist,
-						 data, (t_int)tag);
+		               sys_vgui(
+	".x%lx.c create rectangle %d %d %d %d -fill black -width 0  -tags {.x%lx.x%lx.plot%lx %lx}\n",
+		                    glist_getcanvas(glist),
+		                    ixpix, (int)glist_ytopixels(glist, 
+		                        basey + fielddesc_cvttocoord(yfielddesc, minyval)) - 1,
+		                    inextx, (int)(glist_ytopixels(glist, 
+		                        basey + fielddesc_cvttocoord(yfielddesc, maxyval))
+		                            + linewidth) - 1, glist_getcanvas(glist), glist,
+							 data, (t_int)tag);
+					//} //part of experimental code above
                     ndrawn++;
                     minyval = 1e20;
                     maxyval = -1e20;
-- 
GitLab