Commit f0916f85 authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

Fixed bug...

Fixed bug http://sourceforge.net/tracker/index.php?func=detail&aid=2457992&group_id=55736&atid=478070; hopefully also fixed incorrectly reported hit/selection boxes for nested structs (like the one reported in the previous bug report)
parent eb339ede
......@@ -835,11 +835,12 @@ int array_doclick(t_array *array, t_glist *glist, t_scalar *sc, t_array *ap,
array_getcoordinate(glist, (char *)(array->a_vec) + i * elemsize,
xonset, yonset, wonset, i, xloc, yloc, xinc,
xfield, yfield, wfield, &pxpix, &pypix, &pwpix);
//fprintf(stderr," array_getcoordinate %d: pxpix:%f pypix:%f pwpix:%f dx:%f dy:%f elemsize:%d yonset:%d wonset:%d xonset:%d xloc:%f yloc:%f xinc:%f\n", i, pxpix, pypix, pwpix, dx, dy, elemsize, yonset, wonset, xonset, xloc, yloc, xinc);
if (pwpix < 4)
pwpix = 4;
dx = pxpix - xpix;
if (dx < 0) dx = -dx;
if (dx > 8)
if (dx > 8) //this is the arbitrary radius away from the actual object's center
continue;
dy = pypix - ypix;
if (dy < 0) dy = -dy;
......@@ -856,15 +857,22 @@ int array_doclick(t_array *array, t_glist *glist, t_scalar *sc, t_array *ap,
if (dx + dy < best)
best = dx + dy;
}
//fprintf(stderr," 1st %f %f %f %f %f %d %d %d %d %d\n", pxpix, pypix, pwpix, dx, dy, elemsize, yonset, wonset, xonset, i);
}
if (best > 8)
if (best > 8) //this is the arbitrary radius away from the actual object's center
{
if (scalarvis != 0)
//fprintf(stderr," best > 8\n");
if (scalarvis != 0) {
//fprintf(stderr," array_doclick_element\n");
return (array_doclick_element(array, glist, sc, ap,
elemtemplatesym, linewidth, xloc, xinc, yloc,
xfield, yfield, wfield,
xpix, ypix, shift, alt, dbl, doit));
else return (0);
}
else {
//fprintf(stderr," return 0\n");
return (0);
}
}
best += 0.001; /* add truncation error margin */
for (i = 0; i < array->a_n; i += incr)
......@@ -889,13 +897,22 @@ int array_doclick(t_array *array, t_glist *glist, t_scalar *sc, t_array *ap,
dy = 100;
}
else dy2 = dy3 = 100;
//fprintf(stderr," 2nd %f %f %f %f %f %f %f %d %d %d %d %d\n", pxpix, pypix, pwpix, dx, dy, dy2, dy3, elemsize, yonset, wonset, xonset, i);
if (dx + dy <= best || dx + dy2 <= best || dx + dy3 <= best)
{
if (dy < dy2 && dy < dy3)
//fprintf(stderr, "got this far\n");
if (dy < dy2 && dy < dy3 || best < 1) {
array_motion_fatten = 0;
else if (dy2 < dy3)
//fprintf(stderr,"A\n");
}
else if (dy2 < dy3) {
array_motion_fatten = -1;
else array_motion_fatten = 1;
//fprintf(stderr,"B\n");
}
else {
array_motion_fatten = 1;
//fprintf(stderr,"C\n");
}
if (doit)
{
char *elem = (char *)array->a_vec;
......@@ -1026,6 +1043,7 @@ static void array_getrect(t_array *array, t_glist *glist,
y2 = pypix + pwpix;
}
}
//fprintf(stderr,"array_getrect %f %f %f %f\n", x1, y1, x2, y2);
*xp1 = x1;
*yp1 = y1;
*xp2 = x2;
......
......@@ -155,6 +155,7 @@ void scalar_getbasexy(t_scalar *x, t_float *basex, t_float *basey)
static void scalar_getrect(t_gobj *z, t_glist *owner,
int *xp1, int *yp1, int *xp2, int *yp2)
{
//fprintf(stderr,"scalar_getrect\n");
t_scalar *x = (t_scalar *)z;
t_template *template = template_findbyname(x->sc_template);
t_canvas *templatecanvas = template_findcanvas(template);
......@@ -184,11 +185,12 @@ static void scalar_getrect(t_gobj *z, t_glist *owner,
if (ny1 < y1) y1 = ny1;
if (nx2 > x2) x2 = nx2;
if (ny2 > y2) y2 = ny2;
//fprintf(stderr," ====scalar_getrect x1 %d y1 %d x2 %d y2 %d\n", x1, y1, x2, y2);
}
if (x2 < x1 || y2 < y1)
x1 = y1 = x2 = y2 = 0;
}
//fprintf(stderr,"scalar x1 %d y1 %d x2 %d y2 %d\n", x1, y1, x2, y2);
//fprintf(stderr,"FINAL scalar_getrect x1 %d y1 %d x2 %d y2 %d\n", x1, y1, x2, y2);
*xp1 = x1;
*yp1 = y1;
*xp2 = x2;
......@@ -249,8 +251,13 @@ static void scalar_select(t_gobj *z, t_glist *owner, int state)
sys_vgui(".x%lx.c dtag scalar%lx selected\n",
glist_getcanvas(owner), x);
if (templatecanvas) {
// get the universal tag for all nested objects
t_canvas *tag = owner;
while (tag->gl_owner) {
tag = tag->gl_owner;
}
sys_vgui(".x%lx.c dtag %lx selected\n",
glist_getcanvas(owner), x->sc_vec);
glist_getcanvas(owner), (t_int)tag);
}
}
//sys_vgui("pdtk_select_all_gop_widgets .x%lx %lx %d\n", glist_getcanvas(owner), owner, state);
......@@ -294,6 +301,7 @@ static void scalar_displace(t_gobj *z, t_glist *glist, int dx, int dy)
static void scalar_displace_withtag(t_gobj *z, t_glist *glist, int dx, int dy)
{
//fprintf(stderr,"scalar_displace_withtag %lx %d %d\n", (t_int)z, dx, dy);
t_scalar *x = (t_scalar *)z;
t_symbol *templatesym = x->sc_template;
t_template *template = template_findbyname(templatesym);
......@@ -407,19 +415,34 @@ 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);
SETFLOAT(at, basex + xloc);
SETFLOAT(at+1, basey + yloc);
if (doit)
//fprintf(stderr,"=================scalar_doclick %f %f %f %f\n", basex, basey, xloc, yloc);
SETFLOAT(at, basex + xloc);
SETFLOAT(at+1, basey + yloc);
if (doit) {
//fprintf(stderr," doit\n");
template_notifyforscalar(template, owner,
sc, gensym("click"), 2, at);
}
// if we are nested ignore xloc and yloc, otherwise nested objects get their hitbox miscalculated
if (xloc != 0.0 || yloc != 0.0) {
//fprintf(stderr,"ignoring\n");
basex = 0.0;
basey = 0.0;
}
for (y = templatecanvas->gl_list; y; y = y->g_next)
{
//fprintf(stderr,"looking for template... %f %f %f %f %lx %lx\n", basex, basey, xloc, yloc, (t_int)owner, (t_int)data);
t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
if (!wb) continue;
if (hit = (*wb->w_parentclickfn)(y, owner,
data, template, sc, ap, basex + xloc, basey + yloc,
xpix, ypix, shift, alt, dbl, doit))
return (hit);
if (hit = (*wb->w_parentclickfn)(y, owner,
data, template, sc, ap, basex + xloc, basey + yloc,
xpix, ypix, shift, alt, dbl, doit)) {
//fprintf(stderr," ...got it %f %f\n", basex + xloc, basey + yloc);
return (hit);
}
}
return (0);
}
......@@ -427,7 +450,7 @@ int scalar_doclick(t_word *data, t_template *template, t_scalar *sc,
static int scalar_click(t_gobj *z, struct _glist *owner,
int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
fprintf(stderr,"scalar_click\n");
//fprintf(stderr,"scalar_click %d %d\n", xpix, ypix);
t_scalar *x = (t_scalar *)z;
t_template *template = template_findbyname(x->sc_template);
return (scalar_doclick(x->sc_vec, template, x, 0,
......
......@@ -1067,7 +1067,9 @@ static void curve_getrect(t_gobj *z, t_glist *glist,
if (xloc > x2) x2 = xloc;
if (yloc < y1) y1 = yloc;
if (yloc > y2) y2 = yloc;
//fprintf(stderr," =====%d %d %d %d\n", x1, y1, x2, y2);
}
//fprintf(stderr,"FINAL curve_getrect %d %d %d %d\n", x1, y1, x2, y2);
*xp1 = x1;
*yp1 = y1;
*xp2 = x2;
......@@ -1251,6 +1253,7 @@ static int curve_click(t_gobj *z, t_glist *glist,
t_float basex, t_float basey,
int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
//fprintf(stderr,"curve_click %f %f %d %d %lx\n", basex, basey, xpix, ypix, (t_int)data);
t_curve *x = (t_curve *)z;
int i, n = x->x_npoints;
int bestn = -1;
......@@ -1552,6 +1555,7 @@ static void plot_getrect(t_gobj *z, t_glist *glist,
t_word *data, t_template *template, t_float basex, t_float basey,
int *xp1, int *yp1, int *xp2, int *yp2)
{
//fprintf(stderr,"plot_getrect\n");
t_plot *x = (t_plot *)z;
int elemsize, yonset, wonset, xonset;
t_canvas *elemtemplatecanvas;
......@@ -1576,12 +1580,14 @@ static void plot_getrect(t_gobj *z, t_glist *glist,
int incr = (array->a_n <= 2000 ? 1 : array->a_n / 1000);
for (i = 0, xsum = 0; i < array->a_n; i += incr)
{
//fprintf(stderr," <====plot_getrect %d %d %d %d\n", x1, y1, x2, y2);
t_float usexloc, useyloc;
t_gobj *y;
/* get the coords of the point proper */
array_getcoordinate(glist, (char *)(array->a_vec) + i * elemsize,
xonset, yonset, wonset, i, basex + xloc, basey + yloc, xinc,
xfielddesc, yfielddesc, wfielddesc, &xpix, &ypix, &wpix);
//fprintf(stderr," !!!!!!!!elemsize%d yonset%d wonset%d xonset%d i%d basex%f xloc%f basey%f yloc%f xinc%f xpix%f ypix%f wpix%f\n", elemsize, yonset, wonset, xonset, i, basex, xloc, basey, yloc, xinc, xpix, ypix, wpix);
if (xpix < x1)
x1 = xpix;
if (xpix > x2)
......@@ -1590,6 +1596,8 @@ static void plot_getrect(t_gobj *z, t_glist *glist,
y1 = ypix - wpix;
if (ypix + wpix > y2)
y2 = ypix + wpix;
//fprintf(stderr," /////plot_getrect %d %d %d %d\n", x1, y1, x2, y2);
if (scalarvis != 0)
{
......@@ -1598,14 +1606,15 @@ static void plot_getrect(t_gobj *z, t_glist *glist,
usexloc = basex + xloc + fielddesc_cvttocoord(xfielddesc,
*(t_float *)(((char *)(array->a_vec) + elemsize * i)
+ xonset));
else usexloc = basex + xsum, xsum += xinc;
else usexloc = x1; //usexloc = basex + xsum, xsum += xinc;
if (yonset >= 0)
yval = *(t_float *)(((char *)(array->a_vec) + elemsize * i)
+ yonset);
else yval = 0;
useyloc = basey + yloc + fielddesc_cvttocoord(yfielddesc, yval);
useyloc = (y1+y2)/2; //basey + yloc + fielddesc_cvttocoord(yfielddesc, yval);
for (y = elemtemplatecanvas->gl_list; y; y = y->g_next)
{
//fprintf(stderr,".-.-. usexloc %f useyloc %f (alt %f %f)\n", usexloc, useyloc, basex + xloc + fielddesc_cvttocoord(xfielddesc, *(t_float *)(((char *)(array->a_vec) + elemsize * i) + xonset)), *(t_float *)(((char *)(array->a_vec) + elemsize * i) + yonset));
int xx1, xx2, yy1, yy2;
t_parentwidgetbehavior *wb = pd_getparentwidget(&y->g_pd);
if (!wb) continue;
......@@ -1613,6 +1622,7 @@ static void plot_getrect(t_gobj *z, t_glist *glist,
(t_word *)((char *)(array->a_vec) + elemsize * i),
elemtemplate, usexloc, useyloc,
&xx1, &yy1, &xx2, &yy2);
//fprintf(stderr," .....plot_getrect %d %d %d %d\n", xx1, yy1, xx2, yy2);
if (xx1 < x1)
x1 = xx1;
if (yy1 < y1)
......@@ -1620,11 +1630,14 @@ static void plot_getrect(t_gobj *z, t_glist *glist,
if (xx2 > x2)
x2 = xx2;
if (yy2 > y2)
y2 = yy2;
y2 = yy2;
//fprintf(stderr," .....plot_getrect %d %d %d %d\n", x1, y1, x2, y2);
}
}
//fprintf(stderr," >====plot_getrect %d %d %d %d\n", x1, y1, x2, y2);
}
}
//fprintf(stderr,"FINAL plot_getrect %d %d %d %d\n", x1, y1, x2, y2);
*xp1 = x1;
*yp1 = y1;
......@@ -1942,6 +1955,7 @@ static int plot_click(t_gobj *z, t_glist *glist,
t_float basex, t_float basey,
int xpix, int ypix, int shift, int alt, int dbl, int doit)
{
//fprintf(stderr,"plot_click %lx %lx %f %f %d %d\n", (t_int)z, (t_int)glist, basex, basey, xpix, ypix);
t_plot *x = (t_plot *)z;
t_symbol *elemtemplatesym;
t_float linewidth, xloc, xinc, yloc, style, vis, scalarvis;
......@@ -1953,6 +1967,7 @@ static int plot_click(t_gobj *z, t_glist *glist,
&vis, &scalarvis,
&xfielddesc, &yfielddesc, &wfielddesc) && (vis != 0))
{
//fprintf(stderr," ->array_doclick\n");
return (array_doclick(array, glist, sc, ap,
elemtemplatesym,
linewidth, basex + xloc, xinc, basey + yloc, scalarvis,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment