Commit 63df5d82 authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

*Jonathan Wilkes' 2 patches addressing:

- nested plots display properly
- plot is vis'd and unvis'd properly when deleting plot or struct
- commented out ugly plot_displace hack-- multiple plots should work just fine
- separated out garray dependencies into class "old_plot".  This way the changes I made don't affect garrays.  _Very_ ugly hack, but it was pretty simple to implement and will be easy to remove later.
- no crashes when non-existent arrays are entered into a [struct] that has scalars hanging around
- template_cancreate ported from 0.45
- added a function to get the offending struct (to use with "Find last error").  Not using it yet, though.
+ For creating scalars using an object box:
- scalar must have initial "float x float y" fields, in that order.  This means you can't accidentally type the name of the hidden garray structs and create a scalar.  (Nor any other structs that only have a "y" field, etc.)
- broken object box returned if the struct has a bogus array template.  (Although currently I'm just refusing to create such a struct.)
parent 799ced4d
...@@ -151,7 +151,7 @@ static char garray_arraytemplatefile[] = "\ ...@@ -151,7 +151,7 @@ static char garray_arraytemplatefile[] = "\
#N canvas 0 0 458 153 10;\n\ #N canvas 0 0 458 153 10;\n\
#X obj 43 31 struct _float_array array z float float style\n\ #X obj 43 31 struct _float_array array z float float style\n\
float linewidth float color symbol fillcolor symbol outlinecolor;\n\ float linewidth float color symbol fillcolor symbol outlinecolor;\n\
#X obj 43 70 plot z color linewidth 0 0 1 style fillcolor outlinecolor;\n\ #X obj 43 70 old_plot z color linewidth 0 0 1 style fillcolor outlinecolor;\n\
"; ";
static char garray_floattemplatefile[] = "\ static char garray_floattemplatefile[] = "\
#N canvas 0 0 458 153 10;\n\ #N canvas 0 0 458 153 10;\n\
......
...@@ -1634,7 +1634,10 @@ static void glist_redrawall(t_template *template, t_glist *gl, int action) ...@@ -1634,7 +1634,10 @@ static void glist_redrawall(t_template *template, t_glist *gl, int action)
{ {
t_class *cl; t_class *cl;
if (vis && g->g_pd == scalar_class && if (vis && g->g_pd == scalar_class &&
template == template_findbyname(((t_scalar *)g)->sc_template)) ((template == template_findbyname(((t_scalar *)g)->sc_template))
|| template_has_elemtemplate(
template_findbyname(((t_scalar *)g)->sc_template),
template)))
{ {
if (action == 1) if (action == 1)
{ {
......
...@@ -629,6 +629,7 @@ EXTERN t_scalar *scalar_new(t_glist *owner, ...@@ -629,6 +629,7 @@ EXTERN t_scalar *scalar_new(t_glist *owner,
EXTERN void word_free(t_word *wp, t_template *tmpl); EXTERN void word_free(t_word *wp, t_template *tmpl);
EXTERN void scalar_getbasexy(t_scalar *x, t_float *basex, t_float *basey); EXTERN void scalar_getbasexy(t_scalar *x, t_float *basex, t_float *basey);
EXTERN void scalar_redraw(t_scalar *x, t_glist *glist); EXTERN void scalar_redraw(t_scalar *x, t_glist *glist);
EXTERN int template_has_elemtemplate(t_template *t, t_template *template);
/* ------helper routines for "garrays" and "plots" -------------- */ /* ------helper routines for "garrays" and "plots" -------------- */
EXTERN int array_doclick(t_array *array, t_glist *glist, t_scalar *sc, t_array *ap, EXTERN int array_doclick(t_array *array, t_glist *glist, t_scalar *sc, t_array *ap,
...@@ -666,6 +667,8 @@ EXTERN void template_setsymbol(t_template *x, t_symbol *fieldname, ...@@ -666,6 +667,8 @@ EXTERN void template_setsymbol(t_template *x, t_symbol *fieldname,
EXTERN t_template *gtemplate_get(t_gtemplate *x); EXTERN t_template *gtemplate_get(t_gtemplate *x);
EXTERN t_template *template_findbyname(t_symbol *s); EXTERN t_template *template_findbyname(t_symbol *s);
EXTERN int template_cancreate(t_template *template);
EXTERN int template_hasxy(t_template *template);
EXTERN t_canvas *template_findcanvas(t_template *tmpl); EXTERN t_canvas *template_findcanvas(t_template *tmpl);
EXTERN void template_notify(t_template *tmpl, EXTERN void template_notify(t_template *tmpl,
t_symbol *s, int argc, t_atom *argv); t_symbol *s, int argc, t_atom *argv);
......
...@@ -87,6 +87,74 @@ void word_free(t_word *wp, t_template *template) ...@@ -87,6 +87,74 @@ void word_free(t_word *wp, t_template *template)
} }
} }
/* some of this code is used in a function in g_canvas.c...
need to modularize it */
static t_object *template_getstruct(t_template *template)
{
if (template)
{
t_gobj *y;
t_canvas *c;
if (c = template_findcanvas(template))
{
t_symbol *s1 = gensym("struct");
for (y = c->gl_list; y; y = y->g_next)
{
t_object *ob = pd_checkobject(&y->g_pd);
t_atom *argv;
if (!ob || ob->te_type != T_OBJECT ||
binbuf_getnatom(ob->te_binbuf) < 2)
continue;
argv = binbuf_getvec(ob->te_binbuf);
if (argv[0].a_w.w_symbol != s1)
continue;
if (canvas_makebindsym(argv[1].a_w.w_symbol) == template->t_sym)
return (ob);
}
}
}
return (0);
}
int template_hasxy(t_template *template)
{
t_symbol *zz;
int xonset, yonset, xtype, ytype, gotx, goty;
if (!template)
{
error("struct: couldn't find template %s", template->t_sym->s_name);
return 0;
}
gotx = template_find_field(template, gensym("x"), &xonset, &xtype, &zz);
goty = template_find_field(template, gensym("y"), &yonset, &ytype, &zz);
if ((gotx && (xtype == DT_FLOAT)) &&
(goty && (ytype == DT_FLOAT)) &&
(xonset == 0) && (yonset == sizeof(t_word)))
{
return 1;
}
else
return 0;
}
int template_cancreate(t_template *template)
{
int i, type, nitems = template->t_n;
t_dataslot *datatypes = template->t_vec;
t_template *elemtemplate;
for (i = 0; i < nitems; i++, datatypes++)
if (datatypes->ds_type == DT_ARRAY &&
(!(elemtemplate = template_findbyname(datatypes->ds_arraytemplate))
|| !template_cancreate(elemtemplate)))
{
t_object *ob = template_getstruct(template);
pd_error(ob, "%s: no such template",
datatypes->ds_arraytemplate->s_name);
return (0);
}
return (1);
}
/* make a new scalar and add to the glist. We create a "gp" here which /* make a new scalar and add to the glist. We create a "gp" here which
will be used for array items to point back here. This gp doesn't do will be used for array items to point back here. This gp doesn't do
reference counting or "validation" updates though; the parent won't go away reference counting or "validation" updates though; the parent won't go away
...@@ -105,6 +173,8 @@ t_scalar *scalar_new(t_glist *owner, t_symbol *templatesym) ...@@ -105,6 +173,8 @@ t_scalar *scalar_new(t_glist *owner, t_symbol *templatesym)
error("scalar: couldn't find template %s", templatesym->s_name); error("scalar: couldn't find template %s", templatesym->s_name);
return (0); return (0);
} }
if (!template_cancreate(template))
return (0);
x = (t_scalar *)getbytes(sizeof(t_scalar) + x = (t_scalar *)getbytes(sizeof(t_scalar) +
(template->t_n - 1) * sizeof(*x->sc_vec)); (template->t_n - 1) * sizeof(*x->sc_vec));
x->sc_gobj.g_pd = scalar_class; x->sc_gobj.g_pd = scalar_class;
...@@ -147,6 +217,36 @@ void glist_scalar(t_glist *glist, ...@@ -147,6 +217,36 @@ void glist_scalar(t_glist *glist,
binbuf_free(b); binbuf_free(b);
} }
/* search template fields recursively to see if the template
depends on elemtemplate */
int template_has_elemtemplate(t_template *t, t_template *elemtemplate)
{
int returnval = 0;
if (t && elemtemplate)
{
int i;
t_dataslot *d = t->t_vec;
for (i = 0; i < t->t_n; i++, d++)
{
if (d->ds_type == DT_ARRAY)
{
if (d->ds_arraytemplate == elemtemplate->t_sym)
{
returnval = 1;
break;
}
else
{
returnval = template_has_elemtemplate(
template_findbyname(d->ds_arraytemplate),
elemtemplate);
}
}
}
}
return (returnval);
}
/* -------------------- widget behavior for scalar ------------ */ /* -------------------- widget behavior for scalar ------------ */
void scalar_getbasexy(t_scalar *x, t_float *basex, t_float *basey) void scalar_getbasexy(t_scalar *x, t_float *basex, t_float *basey)
{ {
...@@ -506,8 +606,11 @@ static void scalar_displace_withtag(t_gobj *z, t_glist *glist, int dx, int dy) ...@@ -506,8 +606,11 @@ static void scalar_displace_withtag(t_gobj *z, t_glist *glist, int dx, int dy)
behavior, so we don't use the hack for them. (Non-garray scalars behavior, so we don't use the hack for them. (Non-garray scalars
should follow that behavior too, but cannot atm for the reason given should follow that behavior too, but cannot atm for the reason given
in the comment above scalar_select...) in the comment above scalar_select...)
*/
Apparently this is no longer needed, so it is commented out. Once
we test it we should be able to delete it for good... */
/*
if (template->t_sym != gensym("_float_array")) if (template->t_sym != gensym("_float_array"))
{ {
t_gobj *y; t_gobj *y;
...@@ -520,6 +623,7 @@ static void scalar_displace_withtag(t_gobj *z, t_glist *glist, int dx, int dy) ...@@ -520,6 +623,7 @@ static void scalar_displace_withtag(t_gobj *z, t_glist *glist, int dx, int dy)
basex, basey, dx, dy); basex, basey, dx, dy);
} }
} }
*/
//scalar_redraw(x, glist); //scalar_redraw(x, glist);
} }
......
This diff is collapsed.
...@@ -137,7 +137,10 @@ static void canvas_objtext(t_glist *gl, int xpix, int ypix, ...@@ -137,7 +137,10 @@ static void canvas_objtext(t_glist *gl, int xpix, int ypix,
{ {
t_symbol *templatesym = t_symbol *templatesym =
canvas_makebindsym(atom_getsymbol(scalar_at)); canvas_makebindsym(atom_getsymbol(scalar_at));
if (template_findbyname(templatesym)) t_template *tmpl = template_findbyname(templatesym);
if (template_findbyname(templatesym) &&
template_cancreate(tmpl) &&
template_hasxy(tmpl))
{ {
//post("Hmm, found a scalar from struct %s... ", //post("Hmm, found a scalar from struct %s... ",
// templatesym->s_name); // templatesym->s_name);
......
...@@ -11,7 +11,7 @@ extern "C" { ...@@ -11,7 +11,7 @@ extern "C" {
#define PD_MAJOR_VERSION 0 #define PD_MAJOR_VERSION 0
#define PD_MINOR_VERSION 42 #define PD_MINOR_VERSION 42
#define PD_BUGFIX_VERSION 7 #define PD_BUGFIX_VERSION 7
#define PD_TEST_VERSION "20131117" #define PD_TEST_VERSION "20140319"
#define PDL2ORK #define PDL2ORK
/* old name for "MSW" flag -- we have to take it for the sake of many old /* old name for "MSW" flag -- we have to take it for the sake of many old
......
Markdown is supported
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