From aebe147ae46e27127faa5c9d777de6b9ab822cc9 Mon Sep 17 00:00:00 2001 From: "N.N." Date: Mon, 30 May 2005 09:29:26 +0000 Subject: toxy alpha18 and pddp alpha2 (see notes.txt for toxy, pddp and shared) svn path=/trunk/externals/miXed/; revision=3094 --- toxy/Makefile.objects | 3 +- toxy/build_counter | 4 +- toxy/notes.txt | 18 ++++ toxy/plustot.c | 180 +++++++++++++++++++++++++++++------- toxy/plustot.env.c | 10 +- toxy/plustot.h | 24 ++++- toxy/plustot.in.c | 12 ++- toxy/plustot.out.c | 13 ++- toxy/plustot.print.c | 13 ++- toxy/plustot.qlist.c | 12 ++- toxy/plustot.var.c | 12 ++- toxy/pluswidget.c | 249 ++++++++++++++++++++++++++++++++++++++++++++++++++ 12 files changed, 484 insertions(+), 66 deletions(-) create mode 100644 toxy/pluswidget.c (limited to 'toxy') diff --git a/toxy/Makefile.objects b/toxy/Makefile.objects index 8139856..b0300f0 100644 --- a/toxy/Makefile.objects +++ b/toxy/Makefile.objects @@ -25,7 +25,8 @@ plustot.in.o \ plustot.var.o \ plustot.out.o \ plustot.qlist.o \ -plustot.print.o +plustot.print.o \ +pluswidget.o PLUSTOT_LIBS = $(TCL_LIB) diff --git a/toxy/build_counter b/toxy/build_counter index 53f4151..5b97c5e 100644 --- a/toxy/build_counter +++ b/toxy/build_counter @@ -1,7 +1,7 @@ #define TOXY_VERSION "0.1" #define TOXY_RELEASE "alpha" -#define TOXY_BUILD 17 +#define TOXY_BUILD 18 #if 0 -TOXY_SNAPSHOT = 0.1-alpha17 +TOXY_SNAPSHOT = 0.1-alpha18 #endif diff --git a/toxy/notes.txt b/toxy/notes.txt index 120f0db..10401a5 100644 --- a/toxy/notes.txt +++ b/toxy/notes.txt @@ -7,9 +7,27 @@ TODO for toxy . editor: break editorhook into separate properties, add them in single mode . find a way for "package require" to work out-of-the-box on windows * tow: canvas-wide and type-on-canvas-wide broadcasting + * plustot: + . do not evaluate if fresh, unless explicitly forced to (are side-effects + to be modal, requested with a flag, or triggered with a message?) + . creation time evaluation DONE for toxy +alpha18 + * plustot: + . adjusted to the new, stubified +bob handling + . +selectors registered as creation selectors, so that, e.g. "+in" is + a valid input form for "plustot +in" ("+tot +in" remains valid too) + . "save" callback changes every "+tot" selector to "plustot", + and every "+selector" to "plustot +selector" + . customized appearance: + - creation selector omitted if equals "plustot" or "+tot" + - text, border and i/o outline is brown, border is thicker, + inlets and outlets are lightgrey inside and taller + . mouse click interpreted as the message 'bang' + . accepting commands without arguments (beware: this is yet to be debugged) + alpha17 * widget: . first sketch of an editor widget (bpf), introducing a basic set of rules: diff --git a/toxy/plustot.c b/toxy/plustot.c index 1a738ef..31c2b0b 100644 --- a/toxy/plustot.c +++ b/toxy/plustot.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2003-2004 krzYszcz and others. +/* Copyright (c) 2003-2005 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ @@ -7,6 +7,7 @@ #include "g_canvas.h" #include "common/loud.h" #include "common/grow.h" +#include "unstable/forky.h" #include "hammer/file.h" #include "common/props.h" #include "toxy/scriptlet.h" @@ -33,7 +34,6 @@ # define PLUSDEBUG_DECRREFCOUNT(ob, fn) Tcl_DecrRefCount(ob) #endif -static t_symbol *plusps_tot; static t_symbol *plusps_env; static t_symbol *plusps_in; static t_symbol *plusps_var; @@ -42,6 +42,25 @@ static t_symbol *plusps_qlist; static t_symbol *plusps_print; static t_symbol *totps_query; +static void plussymbols_create(void) +{ + /* public */ + totps_plustot = gensym("plustot"); + plusps_tot = gensym("+tot"); + plusps_Ti = gensym("+Ti"); + plusps_To = gensym("+To"); + plusps_Tv = gensym("+Tv"); + + /* private */ + plusps_env = gensym("+env"); + plusps_in = gensym("+in"); + plusps_var = gensym("+var"); + plusps_out = gensym("+out"); + plusps_qlist = gensym("+qlist"); + plusps_print = gensym("+print"); + totps_query = gensym("query"); +} + static void plusloud_tcldirty(t_pd *caller, char *fnname) { loud_warning((caller == PLUSBOB_OWNER ? 0 : caller), "+tot", @@ -91,6 +110,28 @@ static t_plustype *plustin_basetype; static t_plustype *plustin_type; static t_plustin *plustin_default = 0; +static int plustin_testCmd(ClientData cd, Tcl_Interp *interp, + int objc, Tcl_Obj **objv) +{ + Tcl_Obj *result; + post("this is a test"); + if (objc != 2) + { + Tcl_WrongNumArgs(interp, 1, objv, "anyValue"); + return (TCL_ERROR); + } + + post("in refcount: %d", objv[1]->refCount); + result = Tcl_DuplicateObj(objv[1]); + post("out refcount: %d", result->refCount); + + if (result == NULL) + return (TCL_ERROR); + Tcl_SetObjResult(interp, result); + post("exit refcount: %d", result->refCount); + return (TCL_OK); +} + /* To be called from derived constructors or plustin's provider. */ t_plustin *plustin_create(t_plustype *tp, t_plusbob *parent, t_symbol *id) { @@ -106,6 +147,12 @@ t_plustin *plustin_create(t_plustype *tp, t_plusbob *parent, t_symbol *id) Tcl_Preserve(interp); if (Tcl_Init(interp) == TCL_ERROR) plusloud_tclerror(0, interp, "interpreter initialization failed"); + else + { + Tcl_CreateObjCommand(interp, "test::test", + (Tcl_ObjCmdProc*)plustin_testCmd, + (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); + } Tcl_Release(interp); } else loud_error(0, "failed attempt to create an interpreter"); @@ -318,15 +365,15 @@ Tcl_Obj *plustob_getvalue(t_plustob *tob) /* silent, if caller is empty */ t_plustin *plustag_tobtin(t_symbol *tag, t_pd *caller) { - return (plustag_validroot(tag, plusps_To, caller) - ? ((t_plustob *)tag)->tob_tin : 0); + t_plusbob *bob = plustag_validroot(tag, plusps_To, caller); + return (bob ? ((t_plustob *)bob)->tob_tin : 0); } /* silent, if caller is empty */ Tcl_Obj *plustag_tobvalue(t_symbol *tag, t_pd *caller) { - return (plustag_validroot(tag, plusps_To, caller) - ? ((t_plustob *)tag)->tob_value : 0); + t_plusbob *bob = plustag_validroot(tag, plusps_To, caller); + return (bob ? ((t_plustob *)bob)->tob_value : 0); } /* silent, if caller is empty */ @@ -408,9 +455,10 @@ Tcl_Obj *plustob_setsymbol(t_plustob *tob, t_symbol *s) { if (plustag_isvalid(s, 0)) { - if (plustag_validroot(s, plusps_To, PLUSBOB_OWNER)) + t_plusbob *bob; + if (bob = plustag_validroot(s, plusps_To, PLUSBOB_OWNER)) { - t_plustob *from = (t_plustob *)s; + t_plustob *from = (t_plustob *)bob; return (plustob_set(tob, from->tob_tin, from->tob_value)); } else return (0); @@ -962,7 +1010,7 @@ typedef struct _plusproxy typedef struct _plustot { - t_object x_ob; + t_plusobject x_plusobject; t_glist *x_glist; t_plustob *x_tob; /* interpreter's result (after invocation) */ t_scriptlet *x_script; @@ -1343,7 +1391,8 @@ static int plustot_makeproxies(t_plustot *x) x->x_proxies[i] = plusproxy_new((t_pd *)x, i, x->x_tob->tob_tin); for (i = 1; i < x->x_nproxies; i++) - inlet_new((t_object *)x, (t_pd *)x->x_proxies[i], 0, 0); + plusinlet_new(&x->x_plusobject, + (t_pd *)x->x_proxies[i], 0, 0); x->x_mainproxy = x->x_proxies[0]; /* second pass: traverse non-empty slots, create variables */ plustot_parsevariables(x, interp, @@ -1780,6 +1829,36 @@ static void plustot_tot(t_plustot *x, t_symbol *s, int ac, t_atom *av) } } +static void plustot_save(t_gobj *z, t_binbuf *bb) +{ + t_text *t = (t_text *)z; + t_binbuf *inbb = t->te_binbuf; + int ac = binbuf_getnatom(inbb); + t_atom *av = binbuf_getvec(inbb); + binbuf_addv(bb, "ssii", gensym("#X"), gensym("obj"), + (int)t->te_xpix, (int)t->te_ypix); + if (ac && av->a_type == A_SYMBOL) + { + t_symbol *s = av->a_w.w_symbol; + if (s != totps_plustot) + { + t_atom at; + SETSYMBOL(&at, totps_plustot); + binbuf_add(bb, 1, &at); + if (s == plusps_tot && ac > 1) + { + inbb = binbuf_new(); + binbuf_add(inbb, ac - 1, av + 1); + } + } + } + else loudbug_bug("plustot_save"); + binbuf_addbinbuf(bb, inbb); + binbuf_addsemi(bb); + if (inbb != t->te_binbuf) + binbuf_free(inbb); +} + #ifdef PLUSTOT_DEBUG static void plustot_debug(t_plustot *x) { @@ -1821,6 +1900,7 @@ static void plustot_free(t_plustot *x) freebytes(x->x_proxies, x->x_nproxies * sizeof(*x->x_proxies)); } if (x->x_script) scriptlet_free(x->x_script); + plusobject_free(&x->x_plusobject); } static void *plustot_new(t_symbol *s, int ac, t_atom *av) @@ -1832,10 +1912,15 @@ static void *plustot_new(t_symbol *s, int ac, t_atom *av) t_plustin *tin = 0; t_plustob *tob = 0; t_scriptlet *script = scriptlet_new(0, 0, 0, 0, glist, 0); - if (ac && av->a_type == A_SYMBOL) + if (s != plusps_tot && s != totps_plustot && s != &s_) + cmdname = s; + else if (ac && av->a_type == A_SYMBOL) { cmdname = av->a_w.w_symbol; ac--; av++; + } + if (cmdname) + { if (*cmdname->s_name == '+') { if (cmdname == plusps_env) @@ -1856,7 +1941,10 @@ static void *plustot_new(t_symbol *s, int ac, t_atom *av) return (0); } } +#if 0 + /* FIXME forgot where this constraint came from, debug carefully... */ if (ac) +#endif { ctail = plusstring_fromatoms(ac, av, script); plusstring_preserve(ctail); @@ -1865,7 +1953,7 @@ static void *plustot_new(t_symbol *s, int ac, t_atom *av) if ((tin = plustin_glistprovide(glist, PLUSTIN_GLIST_ANY, 0)) && (tob = plustob_new(tin, 0))) { - x = (t_plustot *)pd_new(plustot_class); + x = (t_plustot *)plusobject_new(plustot_class, cmdname, ac, av); /* tin already preserved (plustob_new() did it) */ plusbob_preserve((t_plusbob *)tob); plusbob_setowner((t_plusbob *)tob, (t_pd *)x); @@ -1933,7 +2021,7 @@ static void *plustot_new(t_symbol *s, int ac, t_atom *av) } } } - outlet_new((t_object *)x, &s_symbol); + plusoutlet_new(&x->x_plusobject, &s_symbol); } else { @@ -1950,16 +2038,56 @@ static void *plustot_new(t_symbol *s, int ac, t_atom *av) return (x); } +void plusobject_widgetfree(t_plusobject *po); +void plusobject_widgetcreate(t_plusobject *po, t_symbol *s, int ac, t_atom *av); +void plusclass_widgetsetup(t_class *c); + +void plusobject_free(t_plusobject *po) +{ + plusobject_widgetfree(po); +} + +t_plusobject *plusobject_new(t_class *c, t_symbol *s, int ac, t_atom *av) +{ + t_plusobject *po = (t_plusobject *)pd_new(c); + po->po_ninlets = 1; + po->po_noutlets = 0; + plusobject_widgetcreate(po, s, ac, av); + return (po); +} + +t_inlet *plusinlet_new(t_plusobject *po, t_pd *dest, + t_symbol *s1, t_symbol *s2) +{ + po->po_ninlets++; + return (inlet_new((t_object *)po, dest, s1, s2)); +} + +t_outlet *plusoutlet_new(t_plusobject *po, t_symbol *s) +{ + po->po_noutlets++; + return (outlet_new((t_object *)po, s)); +} + +void plusclass_inherit(t_class *c, t_symbol *s) +{ + class_addcreator((t_newmethod)plustot_new, s, A_GIMME, 0); + forky_setsavefn(c, plustot_save); + plusclass_widgetsetup(c); +} + void plustot_setup(void) { post("beware! this is plustot %s, %s %s build...", TOXY_VERSION, loud_ordinal(TOXY_BUILD), TOXY_RELEASE); - plustot_class = class_new(gensym("+tot"), + plussymbols_create(); + + plustot_class = class_new(totps_plustot, (t_newmethod)plustot_new, (t_method)plustot_free, sizeof(t_plustot), 0, A_GIMME, 0); - class_addcreator((t_newmethod)plustot_new, - gensym("plustot"), A_GIMME, 0); + plusclass_inherit(plustot_class, plusps_tot); + class_addbang(plustot_class, plustot_bang); class_addfloat(plustot_class, plustot_float); class_addsymbol(plustot_class, plustot_symbol); @@ -1974,10 +2102,6 @@ void plustot_setup(void) gensym("tot"), A_GIMME, 0); class_addmethod(plustot_class, (t_method)plustot_tot, gensym("query"), A_GIMME, 0); -#ifdef PLUSTOT_DEBUG - class_addmethod(plustot_class, (t_method)plustot_debug, - gensym("debug"), 0); -#endif plusproxy_class = class_new(gensym("+tot proxy"), 0, (t_method)plusproxy_free, @@ -1985,23 +2109,14 @@ void plustot_setup(void) class_addfloat(plusproxy_class, plusproxy_float); class_addsymbol(plusproxy_class, plusproxy_symbol); class_addlist(plusproxy_class, plusproxy_list); + #ifdef PLUSTOT_DEBUG + class_addmethod(plustot_class, (t_method)plustot_debug, + gensym("debug"), 0); class_addmethod(plusproxy_class, (t_method)plusproxy_debug, gensym("debug"), 0); #endif - plusps_tot = gensym("+tot"); - plusps_env = gensym("+env"); - plusps_in = gensym("+in"); - plusps_var = gensym("+var"); - plusps_out = gensym("+out"); - plusps_qlist = gensym("+qlist"); - plusps_print = gensym("+print"); - plusps_Ti = gensym("+Ti"); - plusps_To = gensym("+To"); - plusps_Tv = gensym("+Tv"); - totps_query = gensym("query"); - plustin_basetype = plusenv_setup(); plustin_type = plustype_new(plustin_basetype, plusps_Ti, sizeof(t_plustin), @@ -2013,7 +2128,6 @@ void plustot_setup(void) plusvar_type = plustype_new(plustob_type, plusps_Tv, sizeof(t_plusvar), (t_plustypefn)plusvar_delete, 0, 0, 0); - plustot_env_setup(); plustot_in_setup(); plustot_var_setup(); diff --git a/toxy/plustot.env.c b/toxy/plustot.env.c index e0e08f3..23ec82f 100644 --- a/toxy/plustot.env.c +++ b/toxy/plustot.env.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2003 krzYszcz and others. +/* Copyright (c) 2003-2005 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ @@ -19,7 +19,7 @@ typedef struct _plustot_env { - t_object x_ob; + t_plusobject x_plusobject; t_plustin *x_tin; t_glist *x_glist; t_hammerfile *x_filehandle; @@ -97,6 +97,7 @@ static void plustot_env_free(t_plustot_env *x) plusbob_detachchildren((t_plusbob *)x->x_tin, (t_plusbob *)tin); plusbob_release((t_plusbob *)x->x_tin); hammerfile_free(x->x_filehandle); + plusobject_free(&x->x_plusobject); } void *plustot_env_new(t_symbol *s, int ac, t_atom *av) @@ -110,11 +111,11 @@ void *plustot_env_new(t_symbol *s, int ac, t_atom *av) || (tin = plustin_glistprovide(gl, PLUSTIN_GLIST_THIS, 1))) { int warned = 0; - x = (t_plustot_env *)pd_new(plustot_env_class); + x = (t_plustot_env *)plusobject_new(plustot_env_class, s, ac, av); x->x_tin = tin; plusbob_preserve((t_plusbob *)tin); x->x_glist = gl; - outlet_new((t_object *)x, &s_symbol); + plusoutlet_new(&x->x_plusobject, &s_symbol); if (deftin) /* true if both oldtin == 0 (we are first in this glist) and plustin_default != 0 (bobs exist already) */ @@ -143,6 +144,7 @@ void plustot_env_setup(void) plustot_env_class = class_new(gensym("+env"), 0, (t_method)plustot_env_free, sizeof(t_plustot_env), 0, 0); + plusclass_inherit(plustot_env_class, gensym("+env")); class_addbang(plustot_env_class, plustot_env_bang); class_addmethod(plustot_env_class, (t_method)plustot_env_source, gensym("source"), A_DEFSYM, 0); diff --git a/toxy/plustot.h b/toxy/plustot.h index ad72d29..509e100 100644 --- a/toxy/plustot.h +++ b/toxy/plustot.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2003-2004 krzYszcz and others. +/* Copyright (c) 2003-2005 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ @@ -23,6 +23,19 @@ EXTERN_STRUCT _plustob; EXTERN_STRUCT _plusvar; #define t_plusvar struct _plusvar +EXTERN_STRUCT _pluswidget; +#define t_pluswidget struct _pluswidget + +typedef struct _plusobject +{ + t_object po_ob; + t_pluswidget *po_widget; + int po_ninlets; + int po_noutlets; +} t_plusobject; + +t_symbol *totps_plustot; +t_symbol *plusps_tot; t_symbol *plusps_Ti; t_symbol *plusps_To; t_symbol *plusps_Tv; @@ -47,9 +60,11 @@ t_plustob *plustob_new(t_plustin *tin, Tcl_Obj *ob); void plustob_setifshared(t_plustob *tob, t_plusifsharedfn ifsharedfn); int plustob_isshared(t_plustob *tob); Tcl_Obj *plustob_getvalue(t_plustob *tob); + t_plustin *plustag_tobtin(t_symbol *s, t_pd *caller); Tcl_Obj *plustag_tobvalue(t_symbol *s, t_pd *caller); Tcl_Obj *plusatom_tobvalue(t_atom *ap, t_pd *caller); + Tcl_Obj *plustob_set(t_plustob *tob, t_plustin *tin, Tcl_Obj *ob); Tcl_Obj *plustob_setfloat(t_plustob *tob, t_float f); Tcl_Obj *plustob_setsymbol(t_plustob *tob, t_symbol *s); @@ -68,6 +83,13 @@ Tcl_Obj *plusvar_setfloat(t_plusvar *var, t_float f, int doit); Tcl_Obj *plusvar_setsymbol(t_plusvar *var, t_symbol *s, int doit); Tcl_Obj *plusvar_setlist(t_plusvar *var, int ac, t_atom *av, int doit); +void plusobject_free(t_plusobject *po); +t_plusobject *plusobject_new(t_class *c, t_symbol *s, int ac, t_atom *av); +t_inlet *plusinlet_new(t_plusobject *po, t_pd *dest, + t_symbol *s1, t_symbol *s2); +t_outlet *plusoutlet_new(t_plusobject *po, t_symbol *s); +void plusclass_inherit(t_class *c, t_symbol *s); + void plustot_env_setup(void); void plustot_in_setup(void); void plustot_var_setup(void); diff --git a/toxy/plustot.in.c b/toxy/plustot.in.c index 206b8b0..3cb3b6c 100644 --- a/toxy/plustot.in.c +++ b/toxy/plustot.in.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2003 krzYszcz and others. +/* Copyright (c) 2003-2005 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ @@ -15,7 +15,7 @@ typedef struct _plusproxy_in typedef struct _plustot_in { - t_object x_ob; + t_plusobject x_plusobject; t_glist *x_glist; t_plustob *x_tob; t_plusproxy_in *x_proxy; @@ -75,6 +75,7 @@ static void plustot_in_free(t_plustot_in *x) { plusbob_release((t_plusbob *)x->x_tob); if (x->x_proxy) pd_free((t_pd *)x->x_proxy); + plusobject_free(&x->x_plusobject); } void *plustot_in_new(t_symbol *s, int ac, t_atom *av) @@ -86,15 +87,15 @@ void *plustot_in_new(t_symbol *s, int ac, t_atom *av) if ((tin = plustin_glistprovide(glist, PLUSTIN_GLIST_ANY, 0)) && (tob = plustob_new(tin, 0))) { - x = (t_plustot_in *)pd_new(plustot_in_class); + x = (t_plustot_in *)plusobject_new(plustot_in_class, s, ac, av); plusbob_preserve((t_plusbob *)tob); plusbob_setowner((t_plusbob *)tob, (t_pd *)x); plustob_setlist(tob, ac, av); x->x_glist = glist; x->x_tob = tob; x->x_proxy = plusproxy_in_new((t_pd *)x); - inlet_new((t_object *)x, (t_pd *)x->x_proxy, 0, 0); - outlet_new((t_object *)x, &s_symbol); + plusinlet_new(&x->x_plusobject, (t_pd *)x->x_proxy, 0, 0); + plusoutlet_new(&x->x_plusobject, &s_symbol); } else { @@ -113,6 +114,7 @@ void plustot_in_setup(void) plustot_in_class = class_new(gensym("+in"), 0, (t_method)plustot_in_free, sizeof(t_plustot_in), 0, 0); + plusclass_inherit(plustot_in_class, gensym("+in")); class_addbang(plustot_in_class, plustot_in_bang); class_addfloat(plustot_in_class, plustot_in_float); class_addsymbol(plustot_in_class, plustot_in_symbol); diff --git a/toxy/plustot.out.c b/toxy/plustot.out.c index 9b70d55..564e907 100644 --- a/toxy/plustot.out.c +++ b/toxy/plustot.out.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2003 krzYszcz and others. +/* Copyright (c) 2003-2005 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ @@ -9,8 +9,8 @@ typedef struct _plustot_out { - t_object x_ob; - t_binbuf *x_bb; + t_plusobject x_plusobject; + t_binbuf *x_bb; } t_plustot_out; static t_class *plustot_out_class; @@ -52,13 +52,15 @@ static void plustot_out_symbol(t_plustot_out *x, t_symbol *s) static void plustot_out_free(t_plustot_out *x) { binbuf_free(x->x_bb); + plusobject_free(&x->x_plusobject); } void *plustot_out_new(t_symbol *s, int ac, t_atom *av) { - t_plustot_out *x = (t_plustot_out *)pd_new(plustot_out_class); + t_plustot_out *x = + (t_plustot_out *)plusobject_new(plustot_out_class, s, ac, av); x->x_bb = binbuf_new(); - outlet_new((t_object *)x, &s_anything); + plusoutlet_new(&x->x_plusobject, &s_anything); return (x); } @@ -67,5 +69,6 @@ void plustot_out_setup(void) plustot_out_class = class_new(gensym("+out"), 0, (t_method)plustot_out_free, sizeof(t_plustot_out), 0, 0); + plusclass_inherit(plustot_out_class, gensym("+out")); class_addsymbol(plustot_out_class, plustot_out_symbol); } diff --git a/toxy/plustot.print.c b/toxy/plustot.print.c index 0bd6357..889ded3 100644 --- a/toxy/plustot.print.c +++ b/toxy/plustot.print.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2003 krzYszcz and others. +/* Copyright (c) 2003-2005 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ @@ -9,9 +9,9 @@ typedef struct _plustot_print { - t_object x_ob; - t_symbol *x_label; - t_binbuf *x_bb; + t_plusobject x_plusobject; + t_symbol *x_label; + t_binbuf *x_bb; } t_plustot_print; static t_class *plustot_print_class; @@ -75,11 +75,13 @@ static void plustot_print_symbol(t_plustot_print *x, t_symbol *s) static void plustot_print_free(t_plustot_print *x) { binbuf_free(x->x_bb); + plusobject_free(&x->x_plusobject); } void *plustot_print_new(t_symbol *s, int ac, t_atom *av) { - t_plustot_print *x = (t_plustot_print *)pd_new(plustot_print_class); + t_plustot_print *x = + (t_plustot_print *)plusobject_new(plustot_print_class, s, ac, av); x->x_label = (ac && av->a_type == A_SYMBOL ? av->a_w.w_symbol : 0); x->x_bb = binbuf_new(); return (x); @@ -90,5 +92,6 @@ void plustot_print_setup(void) plustot_print_class = class_new(gensym("+print"), 0, (t_method)plustot_print_free, sizeof(t_plustot_print), 0, 0); + plusclass_inherit(plustot_print_class, gensym("+print")); class_addsymbol(plustot_print_class, plustot_print_symbol); } diff --git a/toxy/plustot.qlist.c b/toxy/plustot.qlist.c index e4787fd..4be5430 100644 --- a/toxy/plustot.qlist.c +++ b/toxy/plustot.qlist.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2003 krzYszcz and others. +/* Copyright (c) 2003-2005 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ @@ -29,7 +29,7 @@ typedef struct _plusproxy_qlist typedef struct _plustot_qlist { - t_object x_ob; + t_plusobject x_plusobject; t_glist *x_glist; t_plustob *x_tob; t_outlet *x_rightout; @@ -168,6 +168,7 @@ static void plustot_qlist_free(t_plustot_qlist *x) { plusbob_release((t_plusbob *)x->x_tob); if (x->x_proxy) pd_free((t_pd *)x->x_proxy); + plusobject_free(&x->x_plusobject); } void *plustot_qlist_new(t_symbol *s, int ac, t_atom *av) @@ -179,15 +180,15 @@ void *plustot_qlist_new(t_symbol *s, int ac, t_atom *av) if ((tin = plustin_glistprovide(glist, PLUSTIN_GLIST_ANY, 0)) && (tob = plustob_new(tin, 0))) { - x = (t_plustot_qlist *)pd_new(plustot_qlist_class); + x = (t_plustot_qlist *)plusobject_new(plustot_qlist_class, s, ac, av); plusbob_preserve((t_plusbob *)tob); plusbob_setowner((t_plusbob *)tob, (t_pd *)x); plustob_setlist(tob, ac, av); x->x_glist = glist; x->x_tob = tob; x->x_proxy = plusproxy_qlist_new(x); - inlet_new((t_object *)x, (t_pd *)x->x_proxy, 0, 0); - outlet_new((t_object *)x, &s_anything); + plusinlet_new(&x->x_plusobject, (t_pd *)x->x_proxy, 0, 0); + plusoutlet_new(&x->x_plusobject, &s_anything); x->x_rightout = outlet_new((t_object *)x, &s_symbol); } else @@ -207,6 +208,7 @@ void plustot_qlist_setup(void) plustot_qlist_class = class_new(gensym("+qlist"), 0, (t_method)plustot_qlist_free, sizeof(t_plustot_qlist), 0, 0); + plusclass_inherit(plustot_qlist_class, gensym("+qlist")); class_addbang(plustot_qlist_class, plustot_qlist_bang); plusproxy_qlist_class = class_new(gensym("+qlist proxy"), 0, 0, diff --git a/toxy/plustot.var.c b/toxy/plustot.var.c index a5f36a7..9cb2453 100644 --- a/toxy/plustot.var.c +++ b/toxy/plustot.var.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2003 krzYszcz and others. +/* Copyright (c) 2003-2005 krzYszcz and others. * For information on usage and redistribution, and for a DISCLAIMER OF ALL * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ @@ -15,7 +15,7 @@ typedef struct _plusproxy_var typedef struct _plustot_var { - t_object x_ob; + t_plusobject x_plusobject; t_glist *x_glist; t_plusvar *x_var; t_plusproxy_var *x_proxy; @@ -75,6 +75,7 @@ static void plustot_var_free(t_plustot_var *x) { plusbob_release((t_plusbob *)x->x_var); if (x->x_proxy) pd_free((t_pd *)x->x_proxy); + plusobject_free(&x->x_plusobject); } void *plustot_var_new(t_symbol *s, int ac, t_atom *av) @@ -87,15 +88,15 @@ void *plustot_var_new(t_symbol *s, int ac, t_atom *av) (tin = plustin_glistprovide(glist, PLUSTIN_GLIST_ANY, 0)) && (var = plusvar_new(av->a_w.w_symbol->s_name, 0, tin))) { - x = (t_plustot_var *)pd_new(plustot_var_class); + x = (t_plustot_var *)plusobject_new(plustot_var_class, s, ac, av); plusbob_preserve((t_plusbob *)var); plusbob_setowner((t_plusbob *)var, (t_pd *)x); plusvar_setlist(var, ac - 1, av + 1, 1); x->x_glist = glist; x->x_var = var; x->x_proxy = plusproxy_var_new((t_pd *)x); - inlet_new((t_object *)x, (t_pd *)x->x_proxy, 0, 0); - outlet_new((t_object *)x, &s_symbol); + plusinlet_new(&x->x_plusobject, (t_pd *)x->x_proxy, 0, 0); + plusoutlet_new(&x->x_plusobject, &s_symbol); } else { @@ -117,6 +118,7 @@ void plustot_var_setup(void) plustot_var_class = class_new(gensym("+var"), 0, (t_method)plustot_var_free, sizeof(t_plustot_var), 0, 0); + plusclass_inherit(plustot_var_class, gensym("+var")); class_addbang(plustot_var_class, plustot_var_bang); class_addfloat(plustot_var_class, plustot_var_float); class_addsymbol(plustot_var_class, plustot_var_symbol); diff --git a/toxy/pluswidget.c b/toxy/pluswidget.c new file mode 100644 index 0000000..050b2a1 --- /dev/null +++ b/toxy/pluswidget.c @@ -0,0 +1,249 @@ +/* Copyright (c) 2005 krzYszcz and others. + * For information on usage and redistribution, and for a DISCLAIMER OF ALL + * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */ + +/* This is a prototype of a custom object box. It might be replaced with + a new core object type, T_CUSTOM (te_type bitfield would have to be + extended then). */ + +#include +#include +#include "m_pd.h" +#include "g_canvas.h" +#include "common/loud.h" +#include "toxy/plusbob.h" +#include "plustot.h" + +#ifdef KRZYSZCZ +//#define PLUSWIDGET_DEBUG +#endif + +struct _pluswidget +{ + char *pw_vistext; /* binbuf_gettext()-style (no null termination) */ + int pw_vissize; + int pw_rtextactive; + int pw_ishit; +}; + +/* Code that might be merged back to g_text.c starts here: */ + +static void pluswidget_getrect(t_gobj *z, t_glist *glist, + int *xp1, int *yp1, int *xp2, int *yp2) +{ + t_pluswidget *pw = ((t_plusobject *)z)->po_widget; + int width, height; + float x1, y1, x2, y2; + if (glist->gl_editor && glist->gl_editor->e_rtext) + { + if (pw->pw_rtextactive) + { + t_rtext *y = glist_findrtext(glist, (t_text *)z); + width = rtext_width(y); + height = rtext_height(y); + } + else + { + int font = glist_getfont(glist); + width = pw->pw_vissize * sys_fontwidth(font) + 2; + height = sys_fontheight(font) + 4; /* 2-pixel top/bottom margins */ + } + } + else width = height = 10; + x1 = text_xpix((t_text *)z, glist); + y1 = text_ypix((t_text *)z, glist); + x2 = x1 + width; + y2 = y1 + height; + y1 += 1; + *xp1 = x1; + *yp1 = y1; + *xp2 = x2; + *yp2 = y2; +} + +static void pluswidget_drawiofor(t_glist *glist, t_plusobject *po, + int firsttime, + char *tag, int x1, int y1, int x2, int y2) +{ + int n, nplus, i, width = x2 - x1; + for (n = po->po_noutlets, nplus = (n == 1 ? 1 : n-1), i = 0; i < n; i++) + { + int onset = x1 + (width - IOWIDTH) * i / nplus; + if (firsttime) + sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %so%d\ + -outline brown -fill lightgrey\n", + glist_getcanvas(glist), + onset, y2 - 3, + onset + IOWIDTH, y2 + 2, + tag, i); + else + sys_vgui(".x%lx.c coords %so%d %d %d %d %d\n", + glist_getcanvas(glist), tag, i, + onset, y2 - 3, + onset + IOWIDTH, y2 + 2); + } + for (n = po->po_ninlets, nplus = (n == 1 ? 1 : n-1), i = 0; i < n; i++) + { + int onset = x1 + (width - IOWIDTH) * i / nplus; + if (firsttime) + sys_vgui(".x%lx.c create rectangle %d %d %d %d -tags %si%d\ + -outline brown -fill lightgrey\n", + glist_getcanvas(glist), + onset, y1 - 3, + onset + IOWIDTH, y1 + 2, + tag, i); + else + sys_vgui(".x%lx.c coords %si%d %d %d %d %d\n", + glist_getcanvas(glist), tag, i, + onset, y1 - 3, + onset + IOWIDTH, y1 + 2); + } +} + +static void pluswidget_drawborder(t_text *t, t_glist *glist, + char *tag, int firsttime) +{ + int x1, y1, x2, y2; + pluswidget_getrect(&t->te_g, glist, &x1, &y1, &x2, &y2); + if (firsttime) + sys_vgui(".x%lx.c create line\ + %d %d %d %d %d %d %d %d %d %d -width 2 -fill brown -tags %sR\n", + glist_getcanvas(glist), + x1, y1, x2, y1, x2, y2, x1, y2, x1, y1, tag); + else + sys_vgui(".x%lx.c coords %sR\ + %d %d %d %d %d %d %d %d %d %d\n", + glist_getcanvas(glist), tag, + x1, y1, x2, y1, x2, y2, x1, y2, x1, y1); + pluswidget_drawiofor(glist, (t_plusobject *)t, firsttime, + tag, x1, y1, x2, y2); +} + +static void pluswidget_displace(t_gobj *z, t_glist *glist, int dx, int dy) +{ + t_text *t = (t_text *)z; + t->te_xpix += dx; + t->te_ypix += dy; + if (glist_isvisible(glist)) + { + t_rtext *y = glist_findrtext(glist, t); + rtext_displace(y, dx, dy); + pluswidget_drawborder(t, glist, rtext_gettag(y), 0); + canvas_fixlinesfor(glist_getcanvas(glist), t); + } +} + +static void pluswidget_select(t_gobj *z, t_glist *glist, int state) +{ + t_pluswidget *pw = ((t_plusobject *)z)->po_widget; + t_rtext *y = glist_findrtext(glist, (t_text *)z); + rtext_select(y, state); + if (glist_isvisible(glist) && glist->gl_havewindow) + { + if (state) + sys_vgui(".x%lx.c itemconfigure %s -fill blue\n", + glist, rtext_gettag(y)); + else + sys_vgui(".x%lx.c itemconfigure %s -text {%.*s} -fill brown\n", + glist, rtext_gettag(y), pw->pw_vissize, pw->pw_vistext); + } +} + +static void pluswidget_activate(t_gobj *z, t_glist *glist, int state) +{ + t_pluswidget *pw = ((t_plusobject *)z)->po_widget; + t_rtext *y = glist_findrtext(glist, (t_text *)z); + rtext_activate(y, state); + pw->pw_rtextactive = state; + pluswidget_drawborder((t_text *)z, glist, rtext_gettag(y), 0); +} + +static void pluswidget_delete(t_gobj *z, t_glist *glist) +{ + canvas_deletelinesfor(glist, (t_text *)z); +} + +static void pluswidget_vis(t_gobj *z, t_glist *glist, int vis) +{ + t_pluswidget *pw = ((t_plusobject *)z)->po_widget; + if (vis) + { + if (glist->gl_havewindow) + { + t_rtext *y = glist_findrtext(glist, (t_text *)z); + pluswidget_drawborder((t_text *)z, glist, rtext_gettag(y), 1); + rtext_draw(y); + sys_vgui(".x%lx.c itemconfigure %s -text {%.*s} -fill brown\n", + glist, rtext_gettag(y), pw->pw_vissize, pw->pw_vistext); + } + } + else + { + if (glist->gl_havewindow) + { + t_rtext *y = glist_findrtext(glist, (t_text *)z); + text_eraseborder((t_text *)z, glist, rtext_gettag(y)); + rtext_erase(y); + } + } +} + +static int pluswidget_click(t_gobj *z, t_glist *glist, int xpix, int ypix, + int shift, int alt, int dbl, int doit) +{ + if (doit) + pd_bang((t_pd *)z); + return (1); +} + +static t_widgetbehavior pluswidget_widgetbehavior = +{ + pluswidget_getrect, + pluswidget_displace, + pluswidget_select, + pluswidget_activate, + pluswidget_delete, + pluswidget_vis, + pluswidget_click, +}; + +/* Code that might be merged back to g_text.c ends here. */ + +void plusobject_widgetfree(t_plusobject *po) +{ + t_pluswidget *pw = po->po_widget; + if (pw) + { + if (pw->pw_vistext) + freebytes(pw->pw_vistext, pw->pw_vissize); + freebytes(pw, sizeof(*pw)); + } +} + +void plusobject_widgetcreate(t_plusobject *po, t_symbol *s, int ac, t_atom *av) +{ + t_pluswidget *pw = getbytes(sizeof(*pw)); + t_binbuf *inbb = binbuf_new(); + if (!s || s == &s_) + s = plusps_tot; + po->po_widget = pw; + if ((s != totps_plustot && s != plusps_tot) || ac == 0) + { + t_atom at; + if (s == totps_plustot) + s = plusps_tot; + SETSYMBOL (&at, s); + binbuf_add(inbb, 1, &at); + } + if (ac > 0) + binbuf_add(inbb, ac, av); + binbuf_gettext(inbb, &pw->pw_vistext, &pw->pw_vissize); + binbuf_free(inbb); + pw->pw_rtextactive = 0; + pw->pw_ishit = 0; +} + +void plusclass_widgetsetup(t_class *c) +{ + class_setwidget(c, &pluswidget_widgetbehavior); +} -- cgit v1.2.1