Newer
Older
/* Copyright (c) 1997-2001 Miller Puckette and others.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
/* This file deals with the behavior of glists as either "text objects" or
"graphs" inside another glist. LATER move the inlet/outlet code of g_canvas.c
to this file... */
#include <stdlib.h>
#include "m_pd.h"
Ivica Bukvic
committed
#include "g_all_guis.h" /* for canvas handle freeing */
#include "s_stuff.h" /* for sys_hostfontsize */
#include <stdio.h>
#include <string.h>
Ivica Bukvic
committed
extern int array_joc;
int garray_joc(t_garray *x);
/* ---------------------- forward definitions ----------------- */
static void graph_vis(t_gobj *gr, t_glist *unused_glist, int vis);
Ivica Bukvic
committed
void graph_graphrect(t_gobj *z, t_glist *glist,
int *xp1, int *yp1, int *xp2, int *yp2);
static void graph_getrect(t_gobj *z, t_glist *glist,
int *xp1, int *yp1, int *xp2, int *yp2);
Ivica Ico Bukvic
committed
void graph_checkgop_rect(t_gobj *z, t_glist *glist,
int *xp1, int *yp1, int *xp2, int *yp2);
extern t_template *template_findbydrawcommand(t_gobj *g);
extern int do_not_redraw;
int gop_redraw = 0;
/* -------------------- maintaining the list -------------------- */
void canvas_drawredrect(t_canvas *x, int doit);
pokergaming
committed
int canvas_isgroup(t_canvas *x)
Ivica Bukvic
committed
{
/* t_binbuf *b = x->gl_obj.te_binbuf;
if (!b)
{
bug("canvas_isgroup");
Ivica Bukvic
committed
}
t_atom *argv = binbuf_getvec(x->gl_obj.te_binbuf);
if (argv[0].a_type == A_SYMBOL &&
argv[0].a_w.w_symbol == gensym("group"))
return 1;
else
return 0;
*/
if (x->gl_svg)
return 1;
else
return 0;
}
extern t_template *canvas_findtemplate(t_canvas *c);
extern t_canvas *canvas_templatecanvas_forgroup(t_canvas *c);
//fprintf(stderr,"glist_add %lx %d\n", (t_int)x, (x->gl_editor ? 1 : 0));
t_object *ob;
if (!x->gl_list) x->gl_list = y;
else
{
t_gobj *y2;
for (y2 = x->gl_list; y2->g_next; y2 = y2->g_next)
if (x->gl_editor && (ob = pd_checkobject(&y->g_pd)))
{
//let's now set up create undo
//glist_select(x, y);
//canvas_setundo(x, canvas_undo_create,
// canvas_undo_set_create(x, index), "create");
//glist_noselect(x);
}
if (x->gl_editor && x->gl_isgraph && !x->gl_goprect
&& pd_checkobject(&y->g_pd))
{
x->gl_goprect = 1;
canvas_drawredrect(x, 1);
}
if (glist_isvisible(x))
gobj_vis(y, x, 1);
if (class_isdrawcommand(y->g_pd))
{
t_template *tmpl = template_findbydrawcommand(y);
canvas_redrawallfortemplate(tmpl, 0);
}
Ivica Bukvic
committed
if (pd_class(&y->g_pd) == canvas_class &&
canvas_isgroup((t_canvas *)y))
{
t_canvas *templatecanvas =
canvas_templatecanvas_forgroup((t_canvas *)y);
t_template *tmpl = canvas_findtemplate(templatecanvas);
canvas_redrawallfortemplate(tmpl, 0);
Ivica Bukvic
committed
}
}
/* this is to protect against a hairy problem in which deleting
a sub-canvas might delete an inlet on a box, after the box had
been invisible-ized, so that we have to protect against redrawing it! */
int canvas_setdeleting(t_canvas *x, int flag)
{
int ret = x->gl_isdeleting;
x->gl_isdeleting = flag;
return (ret);
}
Ivica Bukvic
committed
/* check if canvas has an array and return 1, otherwise return 0
this is used to prevent creation of new objects in an array window */
int canvas_hasarray(t_canvas *x)
{
Ivica Bukvic
committed
t_gobj *g = x->gl_list;
int hasarray = 0;
Ivica Bukvic
committed
if (pd_class(&g->g_pd) == garray_class) hasarray = 1;
g = g->g_next;
}
return(hasarray);
}
/* JMZ: emit a closebang message */
void canvas_closebang(t_canvas *x);
/* delete an object from a glist and free it */
void glist_delete(t_glist *x, t_gobj *y)
{
Ivica Bukvic
committed
//fprintf(stderr,"glist_delete y=%lx x=%lx glist_getcanvas=%lx\n", y, x, glist_getcanvas(x));
if (x->gl_list)
{
//fprintf(stderr,"glist_delete YES\n");
t_gobj *g;
t_object *ob;
t_template *tmpl = NULL;
t_gotfn chkdsp = zgetfn(&y->g_pd, gensym("dsp"));
t_canvas *canvas = glist_getcanvas(x);
int drawcommand = class_isdrawcommand(y->g_pd);
int wasdeleting;
t_rtext *rt = NULL;
int late_rtext_free = 0;
if (pd_class(&y->g_pd) == canvas_class)
{
/* JMZ: send a closebang to the canvas */
canvas_closebang((t_canvas *)y);
pokergaming
committed
/* and this little hack so drawing commands can tell
if a [group] is deleting them (and thus suppress
their own redraws) */
((t_canvas *)y)->gl_unloading = 1;
/* if we are a group, let's call ourselves a drawcommand */
if (((t_canvas *)y)->gl_svg)
drawcommand = 1;
}
wasdeleting = canvas_setdeleting(canvas, 1);
if (x->gl_editor)
{
if (x->gl_editor->e_grab == y) x->gl_editor->e_grab = 0;
if (glist_isselected(x, y)) glist_deselect(x, y);
/* HACK -- we had phantom outlets not getting erased on the
screen because the canvas_setdeleting() mechanism is too
crude. LATER carefully set up rules for when the rtexts
should exist, so that they stay around until all the
steps of becoming invisible are done. In the meantime, just
zap the inlets and outlets here... */
if (pd_class(&y->g_pd) == canvas_class)
{
Ivica Bukvic
committed
if (glist_isvisible(x))
Ivica Bukvic
committed
t_glist *gl = (t_glist *)y;
if (gl->gl_isgraph)
{
char tag[80];
//sprintf(tag, "graph%lx", (t_int)gl);
//t_glist *yy = (t_glist *)y;
sprintf(tag, "%s",
rtext_gettag(glist_findrtext(x, &gl->gl_obj)));
glist_eraseiofor(x, &gl->gl_obj, tag);
text_eraseborder(&gl->gl_obj, x,
rtext_gettag(glist_findrtext(x, &gl->gl_obj)));
}
else
{
text_eraseborder(&gl->gl_obj, x,
rtext_gettag(glist_findrtext(x, &gl->gl_obj)));
Loading
Loading full blame...