From 17fcf215a157bc609f62ab52ecc827816ea42f7d Mon Sep 17 00:00:00 2001 From: Ivica Ico Bukvic <ico@vt.edu> Date: Fri, 18 May 2012 22:50:57 -0400 Subject: [PATCH] *overhauled creation of abstractions from the menu (for the k12 project). *fixed bug where objects were selected via a mouse click based on their left-to-right rather than top-to-bottom position *fixed bug where undoing moving of a GOP object would incorrectly draw the object on top of other objects *fixed bug where nlets would show on top of other objects when highlighted --- src/g_canvas.c | 3 +++ src/g_editor.c | 38 +++++++++++++++----------------------- src/g_graph.c | 2 +- src/g_text.c | 26 ++++++++++++++++++++++++++ src/pd.tk | 4 +--- 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/g_canvas.c b/src/g_canvas.c index 717e0ebc2..3577157d1 100644 --- a/src/g_canvas.c +++ b/src/g_canvas.c @@ -1941,6 +1941,7 @@ void canvasgop__motionhook(t_scalehandle *sh,t_floatarg f1, t_floatarg f2) /* why are some of these "glist" and others "canvas"? */ extern void glist_text(t_glist *x, t_symbol *s, int argc, t_atom *argv); extern void canvas_obj(t_glist *gl, t_symbol *s, int argc, t_atom *argv); +extern void canvas_obj_abstraction_from_menu(t_glist *gl, t_symbol *s, int argc, t_atom *argv); extern void canvas_bng(t_glist *gl, t_symbol *s, int argc, t_atom *argv); extern void canvas_toggle(t_glist *gl, t_symbol *s, int argc, t_atom *argv); extern void canvas_vslider(t_glist *gl, t_symbol *s, int argc, t_atom *argv); @@ -1984,6 +1985,8 @@ void g_canvas_setup(void) /* -------------------------- objects ----------------------------- */ class_addmethod(canvas_class, (t_method)canvas_obj, gensym("obj"), A_GIMME, A_NULL); + class_addmethod(canvas_class, (t_method)canvas_obj_abstraction_from_menu, + gensym("obj_abstraction"), A_GIMME, A_NULL); class_addmethod(canvas_class, (t_method)canvas_msg, gensym("msg"), A_GIMME, A_NULL); class_addmethod(canvas_class, (t_method)canvas_floatatom, diff --git a/src/g_editor.c b/src/g_editor.c index 043023924..70336415b 100644 --- a/src/g_editor.c +++ b/src/g_editor.c @@ -22,7 +22,7 @@ char *class_gethelpdir(t_class *c); /* ------------------ forward declarations --------------- */ static void canvas_doclear(t_canvas *x); -static void glist_setlastxy(t_glist *gl, int xval, int yval); +void glist_setlastxy(t_glist *gl, int xval, int yval); static void glist_donewloadbangs(t_glist *x); static t_binbuf *canvas_docopy(t_canvas *x); static void canvas_dopaste(t_canvas *x, t_binbuf *b); @@ -1808,8 +1808,10 @@ static t_gobj *canvas_findhitbox(t_canvas *x, int xpos, int ypos, *x1p = -0x7fffffff; for (y = x->gl_list; y; y = y->g_next) { - if (canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2) - && (x1 > *x1p)) + if (canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2)) + //&& (x1 > *x1p)) + /* commented section looks for whichever is more to the right + which is wrong since we are looking for topmost object */ *x1p = x1, *y1p = y1, *x2p = x2, *y2p = y2, rval = y; } /* if there are at least two selected objects, we'd prefer @@ -2606,9 +2608,9 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, x, canvas_cnct_outlet_tag); - sys_vgui(".x%x.c raise %s\n", - x, - canvas_cnct_outlet_tag); + //sys_vgui(".x%x.c raise %s\n", + // x, + // canvas_cnct_outlet_tag); outlet_issignal = obj_issignaloutlet(ob,closest); if (tooltips) { objtooltip = 1; @@ -2660,9 +2662,9 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, x, canvas_cnct_inlet_tag); - sys_vgui(".x%x.c raise %s\n", - x, - canvas_cnct_inlet_tag); + //sys_vgui(".x%x.c raise %s\n", + // x, + // canvas_cnct_inlet_tag); inlet_issignal = obj_issignalinlet(ob,closest); if (tooltips) { objtooltip = 1; @@ -3058,9 +3060,9 @@ void canvas_doconnect(t_canvas *x, int xpos, int ypos, int which, int doit) sys_vgui(".x%x.c itemconfigure %s -outline $select_nlet_color -width $highlight_width\n", x, canvas_cnct_inlet_tag); - sys_vgui(".x%x.c raise %s\n", - x, - canvas_cnct_inlet_tag); + //sys_vgui(".x%x.c raise %s\n", + // x, + // canvas_cnct_inlet_tag); inlet_issignal = obj_issignalinlet(ob2, closest2); if (tooltips) { objtooltip = 1; @@ -4836,7 +4838,7 @@ void glist_getnextxy(t_glist *gl, int *xpix, int *ypix) else *xpix = *ypix = 40; } -static void glist_setlastxy(t_glist *gl, int xval, int yval) +void glist_setlastxy(t_glist *gl, int xval, int yval) { canvas_last_glist = gl; canvas_last_glist_x = xval; @@ -4907,13 +4909,6 @@ static void canvas_tip(t_canvas *x, t_symbol *s, int argc, t_atom *argv) } } -static void canvas_undo_add_from_tcl(t_canvas *x) { - canvas_editmode(x, 1.); - canvas_undo_add(glist_getcanvas(x), 9, "create", - (void *)canvas_undo_set_create(glist_getcanvas(x))); -} - - void g_editor_setup(void) { /* ------------------------ events ---------------------------------- */ @@ -4986,9 +4981,6 @@ void g_editor_setup(void) gensym("copyfromexternalbuffer"), A_GIMME, A_NULL); class_addmethod(canvas_class, (t_method)canvas_reset_copyfromexternalbuffer, gensym("reset_copyfromexternalbuffer"), A_NULL); - class_addmethod(canvas_class, (t_method)canvas_undo_add_from_tcl, - gensym("undo_add"), A_NULL); - /* -------------- connect method used in reading files ------------------ */ class_addmethod(canvas_class, (t_method)canvas_connect, gensym("connect"), A_FLOAT, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); diff --git a/src/g_graph.c b/src/g_graph.c index 1143efd1b..cc88f7ea2 100644 --- a/src/g_graph.c +++ b/src/g_graph.c @@ -1083,7 +1083,7 @@ static void graph_displace(t_gobj *z, t_glist *glist, int dx, int dy) glist_getcanvas(x->gl_owner), tag, dx, dy); sys_vgui(".x%lx.c move %sR %d %d\n", glist_getcanvas(x->gl_owner), tag, dx, dy);*/ - glist_redraw(x); + glist_redraw(glist_getcanvas(glist)); gobj_select(z, glist, 1); canvas_fixlinesfor(glist_getcanvas(glist), &x->gl_obj); } diff --git a/src/g_text.c b/src/g_text.c index e83fd5f32..63cca65a6 100644 --- a/src/g_text.c +++ b/src/g_text.c @@ -254,6 +254,32 @@ void canvas_obj(t_glist *gl, t_symbol *s, int argc, t_atom *argv) } } +extern void glist_setlastxy(t_glist *gl, int xval, int yval); + +/* invoked from tcl/tk: abstraction_name x_offset y_offset */ +void canvas_obj_abstraction_from_menu(t_glist *gl, t_symbol *s, int argc, t_atom *argv) +{ + //fprintf(stderr,"canvas_abstraction_from_menu\n"); + t_text *x; + + t_binbuf *b = binbuf_new(); + binbuf_restore(b, 2, argv); + int connectme, xpix, ypix, indx, nobj; + canvas_howputnew(gl, &connectme, &xpix, &ypix, &indx, &nobj); + pd_vmess(&gl->gl_pd, gensym("editmode"), "i", 1); + canvas_objtext(gl, xpix+atom_getintarg(1, argc, argv), ypix+atom_getintarg(2, argc, argv), 1, b); + + if (connectme) { + canvas_connect(gl, indx, 0, nobj, 0); + } + else { + canvas_startmotion(glist_getcanvas(gl)); + } + canvas_undo_add(glist_getcanvas(gl), 9, "create", + (void *)canvas_undo_set_create(glist_getcanvas(gl))); + glist_setlastxy(glist_getcanvas(gl), xpix, ypix); +} + /* make an object box for an object that's already there. */ /* iemlib */ diff --git a/src/pd.tk b/src/pd.tk index 53b6417e0..f5424c861 100644 --- a/src/pd.tk +++ b/src/pd.tk @@ -2104,9 +2104,7 @@ proc put_K12_objects {name object} { global pointer_y_local if { $k12_mode == 1 } { - pd [concat $name dirty 1 \;] - pd [concat $name obj $pointer_x_local $pointer_y_local K12/$object \;] - pd [concat $name undo_add\;] + pd [concat $name obj_abstraction K12/$object 0 20 \;] } } -- GitLab