From f0635ce4fd55b6db325c332a0265af09b2f6b2df Mon Sep 17 00:00:00 2001 From: Jonathan Wilkes <jancsika@yahoo.com> Date: Sat, 7 Jun 2014 18:02:15 -0400 Subject: [PATCH] reformatted g_editor.c to be legible --- pd/src/g_editor.c | 7569 +++++++++++++++++++++++++-------------------- 1 file changed, 4208 insertions(+), 3361 deletions(-) diff --git a/pd/src/g_editor.c b/pd/src/g_editor.c index 6a5ce1c3c..d75207c07 100644 --- a/pd/src/g_editor.c +++ b/pd/src/g_editor.c @@ -45,11 +45,14 @@ static void canvas_cut(t_canvas *x); static void canvas_undo(t_canvas *x); static int paste_xyoffset = 0; /* a counter of pastes to make x,y offsets */ //static void canvas_mouseup_gop(t_canvas *x, t_gobj *g); -static void canvas_done_popup(t_canvas *x, t_float which, t_float xpos, t_float ypos); -static void canvas_doarrange(t_canvas *x, t_float which, t_gobj *oldy, t_gobj *oldy_prev, t_gobj *oldy_next); +static void canvas_done_popup(t_canvas *x, t_float which, t_float xpos, + t_float ypos); +static void canvas_doarrange(t_canvas *x, t_float which, t_gobj *oldy, + t_gobj *oldy_prev, t_gobj *oldy_next); static void canvas_paste_xyoffset(t_canvas *x); void canvas_setgraph(t_glist *x, int flag, int nogoprect); -void canvas_mouseup(t_canvas *x, t_floatarg fxpos, t_floatarg fypos, t_floatarg fwhich); +void canvas_mouseup(t_canvas *x, t_floatarg fxpos, t_floatarg fypos, + t_floatarg fwhich); static int outlet_issignal = 0; static int inlet_issignal = 0; static int last_inlet_filter = 0; @@ -57,7 +60,7 @@ static int last_outlet_filter = 0; static int copyfromexternalbuffer = 0; static int tooltips = 0; static int objtooltip = 0; -static int screenx1; /* screen coordinates when doing copyfromexternalbuffer */ +static int screenx1; /* screen coordinates when doing copyfromexternalbuffer */ static int screeny1; static int screenx2; static int screeny2; @@ -67,21 +70,28 @@ static void canvas_dofont(t_canvas *x, t_floatarg font, t_floatarg xresize, extern void canvas_setbounds(t_canvas *x, int x1, int y1, int x2, int y2); int canvas_apply_restore_original_position(t_canvas *x, int orig_pos); extern void canvas_draw_gop_resize_hooks(t_canvas *x); -static void canvas_font(t_canvas *x, t_floatarg font, t_floatarg oldfont, t_floatarg resize, t_floatarg preview); +static void canvas_font(t_canvas *x, t_floatarg font, t_floatarg oldfont, + t_floatarg resize, t_floatarg preview); static void canvas_displaceselection(t_canvas *x, int dx, int dy); -void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos, t_floatarg fmod); -// for updating preset_node locations in case of operations that alter glist object locations (tofront/back, cut, delete, undo/redo cut/delete) +void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos, + t_floatarg fmod); +/* for updating preset_node locations in case of operations that alter + glist object locations (tofront/back, cut, delete, undo/redo cut/delete) */ extern void glob_preset_node_list_check_loc_and_update(void); // for preset_node extern t_class *text_class; int do_not_redraw = 0; // used to optimize redrawing -int old_displace = 0; // for legacy displaces within gop that are not visible to displaceselection +int old_displace = 0; // for legacy displaces within gop that are not + // visible to displaceselection -int connect_exception = 0; // used when autopatching to bypass check whether one is trying to connect signal with non-signal nlet - // since this is impossible to figure out when the newly created object is an empty one +/* used when autopatching to bypass check whether one is trying to + connect signal with non-signal nlet since this is impossible to + figure out when the newly created object is an empty one */ +int connect_exception = 0; -// used to test whether the shift is pressed and if so, handle various connection exceptions (e.g. multiconnect) +/* used to test whether the shift is pressed and if so, + handle various connection exceptions (e.g. multiconnect) */ int glob_lmclick = 0; int glob_shift = 0; int glob_ctrl = 0; @@ -103,9 +113,9 @@ static t_canvas *c_selection; /* iemgui uses black inlets and outlets while default objects use gray ones add here more as necessary */ -int gobj_filter_highlight_behavior(t_text *y) { - - return (y->te_iemgui); +int gobj_filter_highlight_behavior(t_text *y) +{ + return (y->te_iemgui); } /* ---------------- generic widget behavior ------------------------- */ @@ -150,9 +160,12 @@ void gobj_delete(t_gobj *x, t_glist *glist) int gobj_shouldvis(t_gobj *x, struct _glist *glist) { t_object *ob; - //fprintf(stderr,"shouldvis %d %d %d %d\n", glist->gl_havewindow, glist->gl_isgraph, glist->gl_goprect, glist->gl_owner != NULL); + //fprintf(stderr,"shouldvis %d %d %d %d\n", + // glist->gl_havewindow, glist->gl_isgraph, + // glist->gl_goprect, glist->gl_owner != NULL); if (!glist->gl_havewindow && glist->gl_isgraph && glist->gl_goprect && - glist->gl_owner && (pd_class(&x->g_pd) != scalar_class) && (pd_class(&x->g_pd) != garray_class)) + glist->gl_owner && (pd_class(&x->g_pd) != scalar_class) && + (pd_class(&x->g_pd) != garray_class)) { /* if we're graphing-on-parent and the object falls outside the graph rectangle, don't draw it. */ @@ -163,35 +176,40 @@ int gobj_shouldvis(t_gobj *x, struct _glist *glist) if (y1 > y2) m = y1, y1 = y2, y2 = m; gobj_getrect(x, glist, &gx1, &gy1, &gx2, &gy2); - //fprintf(stderr,"gobj_shouldvis gop: %d %d %d %d || object %d %d %d %d\n", x1, x2, y1, y2, gx1, gx2, gy1, gy2); + //fprintf(stderr, + // "gobj_shouldvis gop: %d %d %d %d || object %d %d %d %d\n", + // x1, x2, y1, y2, gx1, gx2, gy1, gy2); if (gx1 < x1 || gx1 > x2 || gx2 < x1 || gx2 > x2 || - gy1 < y1 || gy1 > y2 || gy2 < y1 || gy2 > y2) { - //fprintf(stderr,"does not fit within boundaries\n"); + gy1 < y1 || gy1 > y2 || gy2 < y1 || gy2 > y2) + { + //fprintf(stderr,"does not fit within boundaries\n"); return (0); - } - if (glist==glist_getcanvas(glist)) - sys_vgui(".x%lx.c raise all_cords\n", glist_getcanvas(glist)); + } + if (glist==glist_getcanvas(glist)) + sys_vgui(".x%lx.c raise all_cords\n", glist_getcanvas(glist)); } if (ob = pd_checkobject(&x->g_pd)) { /* return true if the text box should be drawn. We don't show text boxes inside graphs---except comments, if we're doing the new (goprect) style. */ - //fprintf(stderr,"pd_checkobject %lx\n", x); - /*fprintf(stderr,"pd_checkobject %d %d %d %d %d %d %d\n", - glist->gl_havewindow, + //fprintf(stderr,"pd_checkobject %lx\n", x); + /*fprintf(stderr,"pd_checkobject %d %d %d %d %d %d %d\n", + glist->gl_havewindow, (ob->te_pd != canvas_class ? 1:0), - (ob->te_pd->c_wb != &text_widgetbehavior ? 1:0), - (ob->te_pd == canvas_class ? 1:0), - ((t_glist *)ob)->gl_isgraph, + (ob->te_pd->c_wb != &text_widgetbehavior ? 1:0), + (ob->te_pd == canvas_class ? 1:0), + ((t_glist *)ob)->gl_isgraph, glist->gl_goprect, - (ob->te_type == T_TEXT ? 1:0));*/ - if (sys_k12_mode && x->g_pd == preset_hub_class) { - //fprintf(stderr,"glist_select do not select invised preset_hub in K12 mode\n"); - t_preset_hub *ph = (t_preset_hub *)x; - if (ph->ph_invis > 0) return(0); - } - /*fprintf(stderr,"checking %d\n", (glist->gl_havewindow || + (ob->te_type == T_TEXT ? 1:0));*/ + if (sys_k12_mode && x->g_pd == preset_hub_class) + { + //fprintf(stderr, "glist_select do not select invised preset_hub " + // "in K12 mode\n"); + t_preset_hub *ph = (t_preset_hub *)x; + if (ph->ph_invis > 0) return(0); + } + /*fprintf(stderr,"checking %d\n", (glist->gl_havewindow || (ob->te_pd != canvas_class && ob->te_pd->c_wb != &text_widgetbehavior) || (ob->te_pd == canvas_class && (((t_glist *)ob)->gl_isgraph)) || @@ -203,14 +221,14 @@ int gobj_shouldvis(t_gobj *x, struct _glist *glist) (glist->gl_goprect && (ob->te_type == T_TEXT))); } else { - //fprintf(stderr,"else return 1\n"); - return (1); - } + //fprintf(stderr,"else return 1\n"); + return (1); + } } void gobj_vis(t_gobj *x, struct _glist *glist, int flag) { - if (do_not_redraw) return; + if (do_not_redraw) return; if (x->g_pd->c_wb && x->g_pd->c_wb->w_visfn && gobj_shouldvis(x, glist)) (*x->g_pd->c_wb->w_visfn)(x, glist, flag); } @@ -227,124 +245,187 @@ int gobj_click(t_gobj *x, struct _glist *glist, /* ------------------------ managing the selection ----------------- */ // direction -1 = lower, 1 = raise -int canvas_restore_original_position(t_glist *x, t_gobj *y, const char* objtag, int dir) -{ - // we do this instead to save us costly redraw of the canvas - //fprintf(stderr,"canvas_restore_original_position %lx %lx %s %d\n", (t_int)x, (t_int)y, objtag, dir); - int ret = 0; - // we only do this if we are not embedded inside gop, otherwise when gop is done redrawing we - // will get properly repositioned by gop's call to restore original position - if (pd_class(&y->g_pd) != canvas_class || ((t_glist *)y)->gl_owner == x) { - t_object *ob = NULL; - t_rtext *yrnxt = NULL, *yr = NULL; - - if (y->g_next) { - ob = pd_checkobject(&y->g_next->g_pd); - } - if (ob) { - yrnxt = glist_findrtext(x, (t_text *)&ob->ob_g); - } - if (y) { - ob = pd_checkobject(&y->g_pd); - } else { - ret = 1; - } - if (ob) { - yr = glist_findrtext(x, (t_text *)&ob->ob_g); - } - if (ret != 1) { - if (dir == -1) { - if (x->gl_list == y) { - // we get here if we are supposed to go all the way to the bottom - if (objtag) - sys_vgui(".x%lx.c addtag arrange withtag %s\n", x, objtag); - else - sys_vgui(".x%lx.c addtag arrange withtag selected\n", x); - sys_vgui(".x%lx.c lower arrange\n", x); - if (objtag) - sys_vgui(".x%lx.c dtag %s arrange\n", x, objtag); - else - sys_vgui(".x%lx.c dtag selected arrange\n", x); - } else if (yrnxt) { - // lower into middle - if (objtag) - sys_vgui("pdtk_find_lowest_widget_withtag_and_arrange .x%lx.c %s %s %s\n", x, rtext_gettag(yrnxt), rtext_gettag(yr), objtag); - else { - sys_vgui(".x%lx.c addtag arrange withtag selected\n", x); - sys_vgui("pdtk_find_lowest_widget_withtag_and_arrange .x%lx.c %s %s 0\n", x, rtext_gettag(yrnxt), rtext_gettag(yr)); - } - } else { - // fall back to legacy redraw for objects that are not patchable - canvas_redraw(x); - ret = -1; - } - } else { - if (yrnxt) { - // raise into middle - if (objtag) - sys_vgui("pdtk_find_lowest_widget_withtag_and_arrange .x%lx.c %s %s %s\n", x, rtext_gettag(yrnxt), rtext_gettag(yr), objtag); - else { - sys_vgui(".x%lx.c addtag arrange withtag selected\n", x); - sys_vgui("pdtk_find_lowest_widget_withtag_and_arrange .x%lx.c %s %s 0\n", x, rtext_gettag(yrnxt), rtext_gettag(yr)); - } - } else if (y->g_next == NULL) { - // we get here if we are supposed to go all the way to the top - if (objtag) - sys_vgui(".x%lx.c addtag arrange withtag %s\n", x, objtag); - else - sys_vgui(".x%lx.c addtag arrange withtag selected\n", x); - sys_vgui(".x%lx.c raise arrange\n", x); - if (objtag) - sys_vgui(".x%lx.c dtag %s arrange\n", x, objtag); - else - sys_vgui(".x%lx.c dtag selected arrange\n", x); - sys_vgui(".x%lx.c raise all_cords\n", x); - } else { - // fall back to legacy redraw for objects that are not patchable - canvas_redraw(x); - ret = -1; - } - } - } - } - return(ret); +int canvas_restore_original_position(t_glist *x, t_gobj *y, const char* objtag, + int dir) +{ + /* we do this instead to save us costly redraw of the canvas */ + //fprintf(stderr,"canvas_restore_original_position %lx %lx %s %d\n", + // (t_int)x, (t_int)y, objtag, dir); + int ret = 0; + // we only do this if we are not embedded inside gop, otherwise + // when gop is done redrawing we will get properly repositioned + // by gop's call to restore original position + if (pd_class(&y->g_pd) != canvas_class || ((t_glist *)y)->gl_owner == x) + { + t_object *ob = NULL; + t_rtext *yrnxt = NULL, *yr = NULL; + + if (y->g_next) + { + ob = pd_checkobject(&y->g_next->g_pd); + } + if (ob) + { + yrnxt = glist_findrtext(x, (t_text *)&ob->ob_g); + } + if (y) + { + ob = pd_checkobject(&y->g_pd); + } + else + { + ret = 1; + } + if (ob) + { + yr = glist_findrtext(x, (t_text *)&ob->ob_g); + } + if (ret != 1) + { + if (dir == -1) + { + if (x->gl_list == y) + { + /* we get here if we are supposed to go all the way + to the bottom */ + if (objtag) + { + sys_vgui(".x%lx.c addtag arrange withtag %s\n", + x, objtag); + } + else + { + sys_vgui(".x%lx.c addtag arrange withtag selected\n", + x); + } + sys_vgui(".x%lx.c lower arrange\n", x); + if (objtag) + sys_vgui(".x%lx.c dtag %s arrange\n", x, objtag); + else + sys_vgui(".x%lx.c dtag selected arrange\n", x); + } + else if (yrnxt) + { + /* lower into middle */ + if (objtag) + { + sys_vgui("pdtk_find_lowest_widget_withtag_and_arrange " + ".x%lx.c %s %s %s\n", + x, rtext_gettag(yrnxt), rtext_gettag(yr), objtag); + } + else + { + sys_vgui(".x%lx.c addtag arrange withtag selected\n", + x); + sys_vgui("pdtk_find_lowest_widget_withtag_and_arrange " + ".x%lx.c %s %s 0\n", + x, rtext_gettag(yrnxt), rtext_gettag(yr)); + } + } + else + { + /* fall back to legacy redraw for objects + that are not patchable */ + canvas_redraw(x); + ret = -1; + } + } + else + { + if (yrnxt) + { + /* raise into middle */ + if (objtag) + { + sys_vgui("pdtk_find_lowest_widget_withtag_and_arrange " + ".x%lx.c %s %s %s\n", + x, rtext_gettag(yrnxt), rtext_gettag(yr), objtag); + } + else + { + sys_vgui(".x%lx.c addtag arrange withtag selected\n", + x); + sys_vgui("pdtk_find_lowest_widget_withtag_and_arrange " + ".x%lx.c %s %s 0\n", + x, rtext_gettag(yrnxt), rtext_gettag(yr)); + } + } + else if (y->g_next == NULL) + { + /* we get here if we are supposed to go all the way + to the top */ + if (objtag) + { + sys_vgui(".x%lx.c addtag arrange withtag %s\n", + x, objtag); + } + else + { + sys_vgui(".x%lx.c addtag arrange withtag selected\n", + x); + } + sys_vgui(".x%lx.c raise arrange\n", x); + if (objtag) + sys_vgui(".x%lx.c dtag %s arrange\n", x, objtag); + else + sys_vgui(".x%lx.c dtag selected arrange\n", x); + sys_vgui(".x%lx.c raise all_cords\n", x); + } + else + { + /* fall back to legacy redraw for objects + that are not patchable */ + canvas_redraw(x); + ret = -1; + } + } + } + } + return(ret); } void canvas_check_nlet_highlights(t_glist *x) { - if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) - { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_inlet_tag, - (last_inlet_filter ? "black" : (inlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (inlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } - x->gl_editor->canvas_cnct_inlet_tag[0] = 0; - //if (x->gl_editor->e_onmotion == MA_CONNECT) { - x->gl_editor->e_onmotion = MA_NONE; - canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); - //} - } - - if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0 && x->gl_editor->e_onmotion != MA_CONNECT) - { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_outlet_tag, - (last_outlet_filter ? "black" : (outlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (outlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } - x->gl_editor->canvas_cnct_outlet_tag[0] = 0; - //if (x->gl_editor->e_onmotion == MA_CONNECT) { - x->gl_editor->e_onmotion = MA_NONE; - canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); - //} - } + if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) + { + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", + x, x->gl_editor->canvas_cnct_inlet_tag, + (last_inlet_filter ? "black" : (inlet_issignal ? + "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), + (inlet_issignal ? + "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } + x->gl_editor->canvas_cnct_inlet_tag[0] = 0; + //if (x->gl_editor->e_onmotion == MA_CONNECT) { + x->gl_editor->e_onmotion = MA_NONE; + canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); + //} + } + + if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0 && + x->gl_editor->e_onmotion != MA_CONNECT) + { + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", + x, x->gl_editor->canvas_cnct_outlet_tag, + (last_outlet_filter ? "black" : (outlet_issignal ? + "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), + (outlet_issignal ? + "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } + x->gl_editor->canvas_cnct_outlet_tag[0] = 0; + //if (x->gl_editor->e_onmotion == MA_CONNECT) { + x->gl_editor->e_onmotion = MA_NONE; + canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); + //} + } } void glist_selectline(t_glist *x, t_outconnect *oc, int index1, @@ -363,8 +444,8 @@ void glist_selectline(t_glist *x, t_outconnect *oc, int index1, x, x->gl_editor->e_selectline_tag); sys_vgui(".x%lx.c addtag selected withtag l%lx\n", glist_getcanvas(x), x->gl_editor->e_selectline_tag); - c_selection = x; - canvas_draw_gop_resize_hooks(x); + c_selection = x; + canvas_draw_gop_resize_hooks(x); } } @@ -386,10 +467,12 @@ void glist_deselectline(t_glist *x) issignal = 0; sys_vgui(".x%lx.c itemconfigure l%lx -stroke %s\n", x, x->gl_editor->e_selectline_tag, - (issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")); + (issignal ? + "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")); sys_vgui(".x%lx.c dtag l%lx selected\n", - glist_getcanvas(x), glist_getcanvas(x)->gl_editor->e_selectline_tag); - canvas_draw_gop_resize_hooks(x); + glist_getcanvas(x), + glist_getcanvas(x)->gl_editor->e_selectline_tag); + canvas_draw_gop_resize_hooks(x); } } @@ -407,39 +490,45 @@ int glist_isselected(t_glist *x, t_gobj *y) /* call this for unselected objects only */ void glist_select(t_glist *x, t_gobj *y) { - //fprintf(stderr,"glist_select c_selection=%lx x=%lx\n", (t_int)c_selection, (t_int)x); + //fprintf(stderr,"glist_select c_selection=%lx x=%lx\n", + // (t_int)c_selection, (t_int)x); if (x->gl_editor) { - //fprintf(stderr,"have editor\n"); + //fprintf(stderr,"have editor\n"); #ifdef PDL2ORK - // exception: if we are in K12 mode and preset_hub is hidden, do not select it - if (sys_k12_mode && y->g_pd == preset_hub_class) { - //fprintf(stderr,"glist_select do not select invised preset_hub in K12 mode\n"); - t_preset_hub *ph = (t_preset_hub *)y; - if (ph->ph_invis > 0) return; - } + // exception: if we are in K12 mode and preset_hub is hidden, + // do not select it + if (sys_k12_mode && y->g_pd == preset_hub_class) + { + //fprintf(stderr,"glist_select do not select invised preset_hub + //in K12 mode\n"); + t_preset_hub *ph = (t_preset_hub *)y; + if (ph->ph_invis > 0) return; + } #endif - if (c_selection && c_selection != x) { - //fprintf(stderr,"deselecting\n"); - glist_noselect(c_selection); - } + if (c_selection && c_selection != x) + { + //fprintf(stderr,"deselecting\n"); + glist_noselect(c_selection); + } t_selection *sel = (t_selection *)getbytes(sizeof(*sel)); - if (x->gl_editor->e_selectedline) { - //fprintf(stderr,"deselecting line\n"); + if (x->gl_editor->e_selectedline) + { + //fprintf(stderr,"deselecting line\n"); glist_deselectline(x); - } + } /* LATER #ifdef out the following check */ if (glist_isselected(x, y)) bug("glist_select"); sel->sel_next = x->gl_editor->e_selection; sel->sel_what = y; x->gl_editor->e_selection = sel; gobj_select(y, x, 1); - c_selection = x; + c_selection = x; - sys_vgui("pdtk_canvas_update_edit_menu .x%lx 1\n", x); - canvas_draw_gop_resize_hooks(x); + sys_vgui("pdtk_canvas_update_edit_menu .x%lx 1\n", x); + canvas_draw_gop_resize_hooks(x); } - //fprintf(stderr,"select done\n"); + //fprintf(stderr,"select done\n"); } /* recursively deselect everything in a gobj "g", if it happens to be @@ -461,7 +550,7 @@ int glist_getindex(t_glist *x, t_gobj *y); /* call this for selected objects only */ void glist_deselect(t_glist *x, t_gobj *y) { - //fprintf(stderr, "deselect\n"); + //fprintf(stderr, "deselect\n"); int fixdsp = 0; static int reenter = 0; /* if (reenter) return; */ @@ -472,20 +561,20 @@ void glist_deselect(t_glist *x, t_gobj *y) t_rtext *fuddy = 0; t_rtext *z = 0; if (!glist_isselected(x, y)) bug("glist_deselect"); - // following information is for undo_apply - // we need info on the old object's position - // in the gl_list so that we can restore it - int pos = glist_getindex(glist_getcanvas(x), y); + // following information is for undo_apply + // we need info on the old object's position + // in the gl_list so that we can restore it + int pos = glist_getindex(glist_getcanvas(x), y); if (x->gl_editor->e_textedfor) { - //fprintf(stderr, "e_textedfor\n"); + //fprintf(stderr, "e_textedfor\n"); fuddy = glist_findrtext(x, (t_text *)y); if (x->gl_editor->e_textedfor == fuddy) { - //fprintf(stderr, "e_textedfor == fuddy\n"); + //fprintf(stderr, "e_textedfor == fuddy\n"); if (x->gl_editor->e_textdirty) { - //fprintf(stderr, "textdirty yes\n"); + //fprintf(stderr, "textdirty yes\n"); z = fuddy; canvas_stowconnections(glist_getcanvas(x)); glist_checkanddeselectall(x, y); @@ -515,13 +604,17 @@ void glist_deselect(t_glist *x, t_gobj *y) } } } - // if we have an invalid object even if the text hasn't changed, we should still try to recreate it - if (!z && fuddy && pd_class(&((t_text *)y)->te_pd) == text_class && ((t_text *)y)->te_type != T_TEXT) - z = fuddy; + // if we have an invalid object even if the text hasn't changed, + // we should still try to recreate it + if (!z && fuddy && pd_class(&((t_text *)y)->te_pd) == text_class && + ((t_text *)y)->te_type != T_TEXT) + { + z = fuddy; + } if (z) { - //fprintf(stderr, "setto\n"); + //fprintf(stderr, "setto\n"); char *buf; int bufsize; @@ -532,27 +625,28 @@ void glist_deselect(t_glist *x, t_gobj *y) } if (fixdsp) canvas_resume_dsp(1); - if (!x->gl_editor->e_selection) - sys_vgui("pdtk_canvas_update_edit_menu .x%lx 0\n", x); - canvas_draw_gop_resize_hooks(x); + if (!x->gl_editor->e_selection) + sys_vgui("pdtk_canvas_update_edit_menu .x%lx 0\n", x); + canvas_draw_gop_resize_hooks(x); } reenter = 0; } void glist_noselect(t_glist *x) { - //fprintf(stderr,"glist_noselect\n"); + //fprintf(stderr,"glist_noselect\n"); if (x->gl_editor) { - if (x->gl_editor->e_selection) { - while (x->gl_editor->e_selection) - glist_deselect(x, x->gl_editor->e_selection->sel_what); - } + if (x->gl_editor->e_selection) + { + while (x->gl_editor->e_selection) + glist_deselect(x, x->gl_editor->e_selection->sel_what); + } if (x->gl_editor->e_selectedline) glist_deselectline(x); - if (c_selection == x) - c_selection = NULL; - canvas_draw_gop_resize_hooks(x); + if (c_selection == x) + c_selection = NULL; + canvas_draw_gop_resize_hooks(x); } } @@ -565,31 +659,35 @@ void glist_selectall(t_glist *x) { t_gobj *y = x->gl_list; #ifdef PDL2ORK - // exception: if we are in K12 mode and preset_hub is hidden, do not select it - if (sys_k12_mode && y->g_pd == preset_hub_class) { - //fprintf(stderr,"glist_select do not select invised preset_hub in K12 mode\n"); - t_preset_hub *ph = (t_preset_hub *)y; - if (ph->ph_invis > 0) y = y->g_next; - } + // exception: if we are in K12 mode and preset_hub is hidden, + // do not select it + if (sys_k12_mode && y->g_pd == preset_hub_class) + { + //fprintf(stderr,"glist_select do not select " + // "invised preset_hub in K12 mode\n"); + t_preset_hub *ph = (t_preset_hub *)y; + if (ph->ph_invis > 0) y = y->g_next; + } #endif - if (y) { - t_selection *sel = (t_selection *)getbytes(sizeof(*sel)); - x->gl_editor->e_selection = sel; - sel->sel_what = y; - gobj_select(y, x, 1); - while (y = y->g_next) - { - t_selection *sel2 = (t_selection *)getbytes(sizeof(*sel2)); - sel->sel_next = sel2; - sel = sel2; - sel->sel_what = y; - gobj_select(y, x, 1); - } - sel->sel_next = 0; - c_selection = x; - } - } - canvas_draw_gop_resize_hooks(x); + if (y) + { + t_selection *sel = (t_selection *)getbytes(sizeof(*sel)); + x->gl_editor->e_selection = sel; + sel->sel_what = y; + gobj_select(y, x, 1); + while (y = y->g_next) + { + t_selection *sel2 = (t_selection *)getbytes(sizeof(*sel2)); + sel->sel_next = sel2; + sel = sel2; + sel->sel_what = y; + gobj_select(y, x, 1); + } + sel->sel_next = 0; + c_selection = x; + } + } + canvas_draw_gop_resize_hooks(x); } } @@ -640,14 +738,14 @@ const char *canvas_undo_name; void canvas_setundo(t_canvas *x, t_undofn undofn, void *buf, const char *name) { - //fprintf(stderr,"canvas_setundo %s\n", name); + //fprintf(stderr,"canvas_setundo %s\n", name); int hadone = 0; /* blow away the old undo information. In one special case the old undo info is re-used; if so we shouldn't free it here. */ if (canvas_undo_fn && canvas_undo_buf && (buf != canvas_undo_buf)) { - //fprintf(stderr,"hadone canvas_setundo\n"); + //fprintf(stderr,"hadone canvas_setundo\n"); (*canvas_undo_fn)(canvas_undo_canvas, canvas_undo_buf, UNDO_FREE); hadone = 1; } @@ -657,8 +755,8 @@ void canvas_setundo(t_canvas *x, t_undofn undofn, void *buf, canvas_undo_whatnext = UNDO_UNDO; canvas_undo_name = name; //if (x && glist_isvisible(x) && glist_istoplevel(x)) - if (x) - // enable undo in menu + if (x) + // enable undo in menu sys_vgui("pdtk_undomenu .x%lx %s no\n", x, name); else if (hadone) sys_vgui("pdtk_undomenu nobody no no\n"); @@ -674,7 +772,7 @@ void canvas_noundo(t_canvas *x) static void canvas_undo(t_canvas *x) { - //fprintf(stderr,"canvas_undo\n"); + //fprintf(stderr,"canvas_undo\n"); if (x != canvas_undo_canvas) bug("canvas_undo 1"); else if (canvas_undo_whatnext != UNDO_UNDO) @@ -687,13 +785,13 @@ static void canvas_undo(t_canvas *x) if (glist_isvisible(x) && glist_istoplevel(x)) sys_vgui("pdtk_undomenu .x%lx no %s\n", x, canvas_undo_name); canvas_undo_whatnext = UNDO_REDO; - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); } } static void canvas_redo(t_canvas *x) { - //fprintf(stderr,"canvas_redo\n"); + //fprintf(stderr,"canvas_redo\n"); if (x != canvas_undo_canvas) bug("canvas_redo 1"); else if (canvas_undo_whatnext != UNDO_REDO) @@ -706,7 +804,7 @@ static void canvas_redo(t_canvas *x) if (glist_isvisible(x) && glist_istoplevel(x)) sys_vgui("pdtk_undomenu .x%lx %s no\n", x, canvas_undo_name); canvas_undo_whatnext = UNDO_UNDO; - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); } } @@ -757,7 +855,7 @@ void *canvas_undo_set_disconnect(t_canvas *x, void canvas_disconnect(t_canvas *x, t_float index1, t_float outno, t_float index2, t_float inno) { - //fprintf(stderr,"canvas_disconnect\n"); + //fprintf(stderr,"canvas_disconnect\n"); t_linetraverser t; t_outconnect *oc; linetraverser_start(&t, x); @@ -770,20 +868,25 @@ void canvas_disconnect(t_canvas *x, { sys_vgui(".x%lx.c delete l%lx\n", x, oc); // jsarlo - if(x->gl_editor && x->gl_editor->gl_magic_glass) { - magicGlass_unbind(x->gl_editor->gl_magic_glass); - magicGlass_hide(x->gl_editor->gl_magic_glass); - } + if(x->gl_editor && x->gl_editor->gl_magic_glass) + { + magicGlass_unbind(x->gl_editor->gl_magic_glass); + magicGlass_hide(x->gl_editor->gl_magic_glass); + } // end jsarlo obj_disconnect(t.tr_ob, t.tr_outno, t.tr_ob2, t.tr_inno); - // if we are dealing with a preset_node, make sure to also disconnect its invisible return node - // we trust here that the object has been already connected to a valid object so we blindly - // disconnect first outlet with the first inlet (EXCEPTION: print object that cannot be connected back to) - if (pd_class(&t.tr_ob->ob_g.g_pd) == preset_node_class && pd_class(&t.tr_ob2->ob_g.g_pd) != print_class) { - //fprintf(stderr,"gotta disconnect hidden one too...\n"); - obj_disconnect(t.tr_ob2, 0, t.tr_ob, 0); - } + /* if we are dealing with a preset_node, make sure to also + disconnect its invisible return node. We trust here that + the object has been already connected to a valid object + so we blindly disconnect first outlet with the first inlet + (EXCEPTION: print object that cannot be connected back to) */ + if (pd_class(&t.tr_ob->ob_g.g_pd) == preset_node_class && + pd_class(&t.tr_ob2->ob_g.g_pd) != print_class) + { + //fprintf(stderr,"gotta disconnect hidden one too...\n"); + obj_disconnect(t.tr_ob2, 0, t.tr_ob, 0); + } break; } } @@ -821,9 +924,10 @@ typedef struct _undo_cut t_binbuf *u_reconnectbuf; /* connections into and out of object */ t_binbuf *u_redotextbuf; /* buffer to paste back for redo if TEXT */ int u_mode; /* from flags above */ - int n_obj; /* number of selected objects to be cut */ - int p_a[1]; /* array of original glist positions of selected objects */ - /* at least one object is selected, we dynamically resize it later */ + int n_obj; /* number of selected objects to be cut */ + int p_a[1]; /* array of original glist positions of selected objects. + At least one object is selected, we dynamically resize + it later */ } t_undo_cut; void *canvas_undo_set_cut(t_canvas *x, int mode) @@ -833,33 +937,34 @@ void *canvas_undo_set_cut(t_canvas *x, int mode) t_linetraverser t; t_outconnect *oc; int nnotsel= glist_selectionindex(x, 0, 0); - int nsel = glist_selectionindex(x, 0, 1); - buf = (t_undo_cut *)getbytes(sizeof(*buf) + sizeof(buf->p_a[0]) * (nsel - 1)); - buf->n_obj = nsel; + int nsel = glist_selectionindex(x, 0, 1); + buf = (t_undo_cut *)getbytes(sizeof(*buf) + + sizeof(buf->p_a[0]) * (nsel - 1)); + buf->n_obj = nsel; buf->u_mode = mode; buf->u_redotextbuf = 0; /* store connections into/out of the selection */ buf->u_reconnectbuf = binbuf_new(); linetraverser_start(&t, x); - //if (linetraverser_next(&t)) { - while (oc = linetraverser_next(&t)) - { - int issel1 = glist_isselected(x, &t.tr_ob->ob_g); - int issel2 = glist_isselected(x, &t.tr_ob2->ob_g); - if (issel1 != issel2) - { - binbuf_addv(buf->u_reconnectbuf, "ssiiii;", - gensym("#X"), gensym("connect"), - (issel1 ? nnotsel : 0) - + glist_selectionindex(x, &t.tr_ob->ob_g, issel1), - t.tr_outno, - (issel2 ? nnotsel : 0) + - glist_selectionindex(x, &t.tr_ob2->ob_g, issel2), - t.tr_inno); - } - } - //} + //if (linetraverser_next(&t)) { + while (oc = linetraverser_next(&t)) + { + int issel1 = glist_isselected(x, &t.tr_ob->ob_g); + int issel2 = glist_isselected(x, &t.tr_ob2->ob_g); + if (issel1 != issel2) + { + binbuf_addv(buf->u_reconnectbuf, "ssiiii;", + gensym("#X"), gensym("connect"), + (issel1 ? nnotsel : 0) + + glist_selectionindex(x, &t.tr_ob->ob_g, issel1), + t.tr_outno, + (issel2 ? nnotsel : 0) + + glist_selectionindex(x, &t.tr_ob2->ob_g, issel2), + t.tr_inno); + } + } + //} if (mode == UCUT_TEXT) { buf->u_objectbuf = canvas_docopy(x); @@ -873,47 +978,52 @@ void *canvas_undo_set_cut(t_canvas *x, int mode) buf->u_objectbuf = canvas_docopy(x); } - //instantiate num_obj and fill array of positions of selected objects - if (mode == UCUT_CUT || mode == UCUT_CLEAR) - { - int i = 0, j = 0; - if (x->gl_list) { - for (y = x->gl_list; y; y = y->g_next) - { - if (glist_isselected(x, y)) { - buf->p_a[i] = j; - i++; - } - j++; - } - } - //for (i = 0; i < buf->n_obj; i++) - // fprintf(stderr,"%d position = %d\n", i, buf->p_a[i]); - } + //instantiate num_obj and fill array of positions of selected objects + if (mode == UCUT_CUT || mode == UCUT_CLEAR) + { + int i = 0, j = 0; + if (x->gl_list) + { + for (y = x->gl_list; y; y = y->g_next) + { + if (glist_isselected(x, y)) + { + buf->p_a[i] = j; + i++; + } + j++; + } + } + //for (i = 0; i < buf->n_obj; i++) + // fprintf(stderr,"%d position = %d\n", i, buf->p_a[i]); + } return (buf); } void canvas_undo_cut(t_canvas *x, void *z, int action) { - //fprintf(stderr, "canvas_undo_cut canvas=%d buf=%d action=%d\n", (int)x, (int)z, action); + //fprintf(stderr, "canvas_undo_cut canvas=%d buf=%d action=%d\n", + // (int)x, (int)z, action); t_undo_cut *buf = z; int mode = buf->u_mode; if (action == UNDO_UNDO) { - do_not_redraw += 1; - //fprintf(stderr,"UNDO_UNDO\n"); - if (mode == UCUT_CUT) { - //fprintf(stderr, "UCUT_CUT\n"); + do_not_redraw += 1; + //fprintf(stderr,"UNDO_UNDO\n"); + if (mode == UCUT_CUT) + { + //fprintf(stderr, "UCUT_CUT\n"); canvas_dopaste(x, buf->u_objectbuf); - } - else if (mode == UCUT_CLEAR) { - //fprintf(stderr, "UCUT_CLEAR\n"); + } + else if (mode == UCUT_CLEAR) + { + //fprintf(stderr, "UCUT_CLEAR\n"); canvas_dopaste(x, buf->u_objectbuf); - } + } else if (mode == UCUT_TEXT) { - //fprintf(stderr, "UCUT_TEXT\n"); + //fprintf(stderr, "UCUT_TEXT\n"); t_gobj *y1, *y2; glist_noselect(x); for (y1 = x->gl_list; y2 = y1->g_next; y1 = y2) @@ -935,79 +1045,90 @@ void canvas_undo_cut(t_canvas *x, void *z, int action) binbuf_eval(buf->u_reconnectbuf, 0, 0, 0); pd_unbind(&x->gl_pd, gensym("#X")); - //now reposition objects to their original locations - if (mode == UCUT_CUT || mode == UCUT_CLEAR) { - //fprintf(stderr,"reordering\n"); - int i = 0; - int paste_pos = glist_getindex(x,0) - buf->n_obj; //location of the first newly pasted object - //fprintf(stderr,"paste_pos %d\n", paste_pos); - t_gobj *y_prev, *y, *y_next; - for (i = 0; i < buf->n_obj; i++) { - //first check if we are in the same position already - if (paste_pos+i != buf->p_a[i]) { - //fprintf(stderr,"not in the right place\n"); - y_prev = glist_nth(x, paste_pos-1+i); - y = glist_nth(x, paste_pos+i); - y_next = glist_nth(x, paste_pos+1+i); - //if the object is supposed to be first in the gl_list - if (buf->p_a[i] == 0) { - if (y_prev && y_next) { - y_prev->g_next = y_next; - } - else if (y_prev && !y_next) - y_prev->g_next = NULL; - //now put the moved object at the beginning of the cue - y->g_next = glist_nth(x, 0); - x->gl_list = y; - //LATER when objects are properly tagged lower y here - } - //if the object is supposed to be at the current end of gl_list - //can this ever happen??? - /*else if (!glist_nth(x,buf->p_a[i])) { - - }*/ - //if the object is supposed to be in the middle of gl_list - else { - if (y_prev && y_next) { - y_prev->g_next = y_next; - } - else if (y_prev && !y_next) { - y_prev->g_next = NULL; - } - //now put the moved object in its right place - y_prev = glist_nth(x, buf->p_a[i]-1); - y_next = glist_nth(x, buf->p_a[i]); - - y_prev->g_next = y; - y->g_next = y_next; - //LATER when objects are properly tagged lower y here - } - } - } - do_not_redraw -= 1; - //LATER disable redrawing here - canvas_redraw(x); - if (x->gl_owner && glist_isvisible(x->gl_owner)) { - gobj_vis((t_gobj *)x, x->gl_owner, 0); - gobj_vis((t_gobj *)x, x->gl_owner, 1); - } - glob_preset_node_list_check_loc_and_update(); - } + //now reposition objects to their original locations + if (mode == UCUT_CUT || mode == UCUT_CLEAR) + { + //fprintf(stderr,"reordering\n"); + int i = 0; + + /* location of the first newly pasted object */ + int paste_pos = glist_getindex(x,0) - buf->n_obj; + //fprintf(stderr,"paste_pos %d\n", paste_pos); + t_gobj *y_prev, *y, *y_next; + for (i = 0; i < buf->n_obj; i++) + { + //first check if we are in the same position already + if (paste_pos+i != buf->p_a[i]) + { + //fprintf(stderr,"not in the right place\n"); + y_prev = glist_nth(x, paste_pos-1+i); + y = glist_nth(x, paste_pos+i); + y_next = glist_nth(x, paste_pos+1+i); + //if the object is supposed to be first in the gl_list + if (buf->p_a[i] == 0) + { + if (y_prev && y_next) + { + y_prev->g_next = y_next; + } + else if (y_prev && !y_next) + y_prev->g_next = NULL; + //now put the moved object at the beginning of the cue + y->g_next = glist_nth(x, 0); + x->gl_list = y; + //LATER when objects are properly tagged lower y here + } + //if the object is supposed to be at the current end + //of gl_list-- can this ever happen??? + /*else if (!glist_nth(x,buf->p_a[i])) { + + }*/ + //if the object is supposed to be in the middle of gl_list + else { + if (y_prev && y_next) + { + y_prev->g_next = y_next; + } + else if (y_prev && !y_next) + { + y_prev->g_next = NULL; + } + //now put the moved object in its right place + y_prev = glist_nth(x, buf->p_a[i]-1); + y_next = glist_nth(x, buf->p_a[i]); + + y_prev->g_next = y; + y->g_next = y_next; + //LATER when objects are properly tagged lower y here + } + } + } + do_not_redraw -= 1; + //LATER disable redrawing here + canvas_redraw(x); + if (x->gl_owner && glist_isvisible(x->gl_owner)) + { + gobj_vis((t_gobj *)x, x->gl_owner, 0); + gobj_vis((t_gobj *)x, x->gl_owner, 1); + } + glob_preset_node_list_check_loc_and_update(); + } } else if (action == UNDO_REDO) { - //fprintf(stderr,"UNDO_REDO\n"); - if (mode == UCUT_CUT || mode == UCUT_CLEAR) { - //we can't just blindly do clear here when the user may have - //unselected things between undo and redo, so first let's select - //the right stuff - glist_noselect(x); - int i = 0; - for (i = 0; i < buf->n_obj; i++) - glist_select(x, glist_nth(x, buf->p_a[i])); + //fprintf(stderr,"UNDO_REDO\n"); + if (mode == UCUT_CUT || mode == UCUT_CLEAR) + { + //we can't just blindly do clear here when the user may have + //unselected things between undo and redo, so first let's select + //the right stuff + glist_noselect(x); + int i = 0; + for (i = 0; i < buf->n_obj; i++) + glist_select(x, glist_nth(x, buf->p_a[i])); canvas_doclear(x); - glob_preset_node_list_check_loc_and_update(); - } + glob_preset_node_list_check_loc_and_update(); + } else if (mode == UCUT_TEXT) { t_gobj *y1, *y2; @@ -1023,14 +1144,18 @@ void canvas_undo_cut(t_canvas *x, void *z, int action) } else if (action == UNDO_FREE) { - //fprintf(stderr,"UNDO_FREE\n"); + //fprintf(stderr,"UNDO_FREE\n"); if (buf->u_objectbuf) binbuf_free(buf->u_objectbuf); if (buf->u_reconnectbuf) binbuf_free(buf->u_reconnectbuf); if (buf->u_redotextbuf) binbuf_free(buf->u_redotextbuf); - if (buf != NULL) t_freebytes(buf, sizeof(*buf) + sizeof(buf->p_a[0]) * (buf->n_obj-1)); + if (buf != NULL) + { + t_freebytes(buf, sizeof(*buf) + + sizeof(buf->p_a[0]) * (buf->n_obj-1)); + } } } @@ -1088,42 +1213,42 @@ void *canvas_undo_set_move(t_canvas *x, int selected) void canvas_undo_move(t_canvas *x, void *z, int action) { t_undo_move *buf = z; - t_class *cl; - int resortin = 0, resortout = 0; + t_class *cl; + int resortin = 0, resortout = 0; if (action == UNDO_UNDO || action == UNDO_REDO) { int i; int x1=0, y1=0, x2=0, y2=0, newx=0, newy=0; t_gobj *y; - //do_not_redraw = 1; + //do_not_redraw = 1; for (i = 0; i < buf->u_n; i++) { y = glist_nth(x, buf->u_vec[i].e_index); - newx = buf->u_vec[i].e_xpix; - newy = buf->u_vec[i].e_ypix; + newx = buf->u_vec[i].e_xpix; + newy = buf->u_vec[i].e_ypix; if (y) { - glist_noselect(x); - glist_select(x, y); - gobj_getrect(y, x, &x1, &y1, &x2, &y2); - canvas_displaceselection(x, newx-x1, newy - y1); - buf->u_vec[i].e_xpix = x1; - buf->u_vec[i].e_ypix = y1; - cl = pd_class(&y->g_pd); - if (cl == vinlet_class) resortin = 1; - else if (cl == voutlet_class) resortout = 1; + glist_noselect(x); + glist_select(x, y); + gobj_getrect(y, x, &x1, &y1, &x2, &y2); + canvas_displaceselection(x, newx-x1, newy - y1); + buf->u_vec[i].e_xpix = x1; + buf->u_vec[i].e_ypix = y1; + cl = pd_class(&y->g_pd); + if (cl == vinlet_class) resortin = 1; + else if (cl == voutlet_class) resortout = 1; } } - glist_noselect(x); + glist_noselect(x); for (i = 0; i < buf->u_n; i++) { - y = glist_nth(x, buf->u_vec[i].e_index); - glist_select(x, y); - } - //do_not_redraw = 0; - //canvas_redraw(x); - if (resortin) canvas_resortinlets(x); - if (resortout) canvas_resortoutlets(x); + y = glist_nth(x, buf->u_vec[i].e_index); + glist_select(x, y); + } + //do_not_redraw = 0; + //canvas_redraw(x); + if (resortin) canvas_resortinlets(x); + if (resortout) canvas_resortoutlets(x); } else if (action == UNDO_FREE) { @@ -1136,25 +1261,34 @@ void canvas_undo_move(t_canvas *x, void *z, int action) typedef struct _undo_paste { - int u_index; /* index of first object pasted */ - int u_sel_index; /* index of object selected at the time the other object was pasted (for autopatching) */ - int u_offset; /* offset for duplicated items (since it differs when duplicated into same or different canvas */ - t_binbuf *u_objectbuf; /* here we store actual copied data */ + int u_index; /* index of first object pasted */ + int u_sel_index; /* index of object selected at the time the other + object was pasted (for autopatching) */ + int u_offset; /* offset for duplicated items (since it differs + when duplicated into same or different canvas */ + t_binbuf *u_objectbuf; /* here we store actual copied data */ } t_undo_paste; -void *canvas_undo_set_paste(t_canvas *x, int offset, int duplicate, int d_offset) +void *canvas_undo_set_paste(t_canvas *x, int offset, int duplicate, + int d_offset) { t_undo_paste *buf = (t_undo_paste *)getbytes(sizeof(*buf)); buf->u_index = glist_getindex(x, 0) - offset; //do we need offset at all? - if (!duplicate && x->gl_editor->e_selection && !x->gl_editor->e_selection->sel_next) { - //if only one object is selected which will warrant autopatching - buf->u_sel_index = glist_getindex(x, x->gl_editor->e_selection->sel_what); - //fprintf(stderr,"canvas_undo_set_paste selected object index %d\n", buf->u_sel_index); - } else { - buf->u_sel_index = -1; - } - buf->u_offset = d_offset; - buf->u_objectbuf = binbuf_duplicate(copy_binbuf); + if (!duplicate && x->gl_editor->e_selection && + !x->gl_editor->e_selection->sel_next) + { + //if only one object is selected which will warrant autopatching + buf->u_sel_index = glist_getindex(x, + x->gl_editor->e_selection->sel_what); + //fprintf(stderr,"canvas_undo_set_paste selected object index %d\n", + // buf->u_sel_index); + } + else + { + buf->u_sel_index = -1; + } + buf->u_offset = d_offset; + buf->u_objectbuf = binbuf_duplicate(copy_binbuf); return (buf); } @@ -1171,30 +1305,33 @@ void canvas_undo_paste(t_canvas *x, void *z, int action) } else if (action == UNDO_REDO) { - //if (buf->u_offset) - // do_not_redraw += 1; + //if (buf->u_offset) + // do_not_redraw += 1; t_selection *sel; - glist_noselect(x); - //if the pasted object is supposed to be autopatched - //then select the object it should be autopatched to - if (buf->u_sel_index > -1) { - //fprintf(stderr,"undo trying autopatch\n"); - glist_select(x, glist_nth(x, buf->u_sel_index)); - } + glist_noselect(x); + //if the pasted object is supposed to be autopatched + //then select the object it should be autopatched to + if (buf->u_sel_index > -1) + { + //fprintf(stderr,"undo trying autopatch\n"); + glist_select(x, glist_nth(x, buf->u_sel_index)); + } canvas_dopaste(x, buf->u_objectbuf); /* if it was "duplicate" have to re-enact the displacement. */ - if (buf->u_offset) { - //do_not_redraw -= 1; + if (buf->u_offset) + { + //do_not_redraw -= 1; //for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) // gobj_displace(sel->sel_what, x, 10, 10); - canvas_paste_xyoffset(x); - } + canvas_paste_xyoffset(x); + } } - else if (action == UNDO_FREE) { + else if (action == UNDO_FREE) + { if (buf->u_objectbuf) binbuf_free(buf->u_objectbuf); t_freebytes(buf, sizeof(*buf)); - } + } } /* recursively check for abstractions to reload as result of a save. @@ -1203,13 +1340,14 @@ void canvas_undo_paste(t_canvas *x, void *z, int action) static void glist_doreload(t_glist *gl, t_symbol *name, t_symbol *dir, t_gobj *except) { - //fprintf(stderr,"doreload\n"); + //fprintf(stderr,"doreload\n"); t_gobj *g; int i, nobj = glist_getindex(gl, 0); /* number of objects */ int hadwindow = gl->gl_havewindow; - int found = 0; - // to optimize redrawing we select all objects that need to be updated and redraw them together - // then we look for sub-patches that may have more of the same... + int found = 0; + // to optimize redrawing we select all objects that need to be updated + // and redraw them together. Then we look for sub-patches that may have + // more of the same... for (g = gl->gl_list, i = 0; g && i < nobj; i++) { if (g != except && pd_class(&g->g_pd) == canvas_class && @@ -1222,35 +1360,39 @@ static void glist_doreload(t_glist *gl, t_symbol *name, t_symbol *dir, replacement will be at the end of the list, so we don't do g = g->g_next in this case. */ int j = glist_getindex(gl, g); - //fprintf(stderr, "rebuildlicious %d\n", j); - if (!gl->gl_havewindow) { + //fprintf(stderr, "rebuildlicious %d\n", j); + if (!gl->gl_havewindow) + { canvas_vis(glist_getcanvas(gl), 1); - //fprintf(stderr,"calling canvas_vis\n"); - } - if (!found) { - glist_noselect(gl); - found = 1; - } + //fprintf(stderr,"calling canvas_vis\n"); + } + if (!found) + { + glist_noselect(gl); + found = 1; + } glist_select(gl, g); //canvas_setundo(gl, canvas_undo_cut, // canvas_undo_set_cut(gl, UCUT_CLEAR), "clear"); - //canvas_undo_add(gl, 3, "clear", canvas_undo_set_cut(gl, UCUT_CLEAR)); + //canvas_undo_add(gl, 3, "clear", + // canvas_undo_set_cut(gl, UCUT_CLEAR)); - //canvas_cut(gl); - //canvas_undo_undo(gl); - //glist_noselect(gl); + //canvas_cut(gl); + //canvas_undo_undo(gl); + //glist_noselect(gl); //g = glist_nth(gl, j+1); } - g = g->g_next; - } - if (found) { - canvas_cut(gl); - canvas_undo_undo(gl); - //canvas_undo_rebranch(gl); - glist_noselect(gl); - } + g = g->g_next; + } + if (found) + { + canvas_cut(gl); + canvas_undo_undo(gl); + //canvas_undo_rebranch(gl); + glist_noselect(gl); + } - // now look for sub-patches... + // now look for sub-patches... for (g = gl->gl_list, i = 0; g && i < nobj; i++) { if (g != except && pd_class(&g->g_pd) == canvas_class && @@ -1258,7 +1400,7 @@ static void glist_doreload(t_glist *gl, t_symbol *name, t_symbol *dir, (!canvas_isabstraction((t_canvas *)g) || ((t_canvas *)g)->gl_name != name || canvas_getdir((t_canvas *)g) != dir) - ) + ) glist_doreload((t_canvas *)g, name, dir, except); g = g->g_next; } @@ -1289,7 +1431,7 @@ typedef struct _undo_apply { t_binbuf *u_objectbuf; /* the object cleared or typed into */ t_binbuf *u_reconnectbuf; /* connections into and out of object */ - int u_index; /* index of the previous object */ + int u_index; /* index of the previous object */ } t_undo_apply; void *canvas_undo_set_apply(t_canvas *x, int n) @@ -1298,13 +1440,15 @@ void *canvas_undo_set_apply(t_canvas *x, int n) t_gobj *y, *obj; t_linetraverser t; t_outconnect *oc; - /* enable editor (in case it is disabled) and select the object we are working on */ - if (!x->gl_edit) - canvas_editmode(x, 1); - obj = glist_nth(x, n); - if (obj && !glist_isselected(x, obj)) - glist_select(x, obj); - int nnotsel= glist_selectionindex(x, 0, 0); /* get number of all items for the offset below */ + /* enable editor (in case it is disabled) and select the object + we are working on */ + if (!x->gl_edit) + canvas_editmode(x, 1); + obj = glist_nth(x, n); + if (obj && !glist_isselected(x, obj)) + glist_select(x, obj); + /* get number of all items for the offset below */ + int nnotsel= glist_selectionindex(x, 0, 0); buf = (t_undo_apply *)getbytes(sizeof(*buf)); /* store connections into/out of the selection */ @@ -1326,11 +1470,11 @@ void *canvas_undo_set_apply(t_canvas *x, int n) t.tr_inno); } } - /* copy object in its current state */ + /* copy object in its current state */ buf->u_objectbuf = canvas_docopy(x); - /* store index of the currently selected object */ - buf->u_index = n; + /* store index of the currently selected object */ + buf->u_index = n; return (buf); } @@ -1340,30 +1484,30 @@ void canvas_undo_apply(t_canvas *x, void *z, int action) t_undo_apply *buf = z; if (action == UNDO_UNDO || action == UNDO_REDO) { - /* find current instance */ - glist_noselect(x); - glist_select(x, glist_nth(x, buf->u_index)); + /* find current instance */ + glist_noselect(x); + glist_select(x, glist_nth(x, buf->u_index)); - /* copy it for the new undo/redo */ - t_binbuf *tmp = canvas_docopy(x); + /* copy it for the new undo/redo */ + t_binbuf *tmp = canvas_docopy(x); - /* delete current instance */ - canvas_doclear(x); + /* delete current instance */ + canvas_doclear(x); - /* replace it with previous instance */ + /* replace it with previous instance */ canvas_dopaste(x, buf->u_objectbuf); - /* change previous instance with current one */ - buf->u_objectbuf = tmp; + /* change previous instance with current one */ + buf->u_objectbuf = tmp; - /* connections should stay the same */ + /* connections should stay the same */ pd_bind(&x->gl_pd, gensym("#X")); binbuf_eval(buf->u_reconnectbuf, 0, 0, 0); pd_unbind(&x->gl_pd, gensym("#X")); - //now we need to reposition the object to its original place - if (canvas_apply_restore_original_position(x, buf->u_index)) - canvas_redraw(x); + //now we need to reposition the object to its original place + if (canvas_apply_restore_original_position(x, buf->u_index)) + canvas_redraw(x); } else if (action == UNDO_FREE) { @@ -1378,68 +1522,73 @@ void canvas_undo_apply(t_canvas *x, void *z, int action) //legacy wrapper void canvas_apply_setundo(t_canvas *x, t_gobj *y) { - canvas_undo_add(x, 6, "apply", canvas_undo_set_apply(x, glist_getindex(x,y))); + canvas_undo_add(x, 6, "apply", + canvas_undo_set_apply(x, glist_getindex(x,y))); } int canvas_apply_restore_original_position(t_canvas *x, int orig_pos) { - t_gobj *y, *y1, *y_prev, *y_next; - //get the last object - y = glist_nth(x, glist_getindex(x, 0) - 1); - if (glist_getindex(x, y) != orig_pos) { - //first make the object prior to the pasted one the end of the list - y_prev = glist_nth(x, glist_getindex(x, 0) - 2); - if (y_prev) - y_prev->g_next = NULL; - //if the object is supposed to be first in the gl_list - if (orig_pos == 0) { - y->g_next = glist_nth(x, 0); - x->gl_list = y; - } - //if the object is supposed to be in the middle of the gl_list - else { - y_prev = glist_nth(x, orig_pos-1); - y_next = y_prev->g_next; - y_prev->g_next = y; - y->g_next = y_next; - } - return(1); - } - return(0); + t_gobj *y, *y1, *y_prev, *y_next; + //get the last object + y = glist_nth(x, glist_getindex(x, 0) - 1); + if (glist_getindex(x, y) != orig_pos) + { + //first make the object prior to the pasted one the end of the list + y_prev = glist_nth(x, glist_getindex(x, 0) - 2); + if (y_prev) + y_prev->g_next = NULL; + //if the object is supposed to be first in the gl_list + if (orig_pos == 0) + { + y->g_next = glist_nth(x, 0); + x->gl_list = y; + } + //if the object is supposed to be in the middle of the gl_list + else { + y_prev = glist_nth(x, orig_pos-1); + y_next = y_prev->g_next; + y_prev->g_next = y; + y->g_next = y_next; + } + return(1); + } + return(0); } /* --------- 7. arrange (to front/back) ----------- */ typedef struct _undo_arrange { - int u_previndex; /* old index */ - int u_newindex; /* new index */ + int u_previndex; /* old index */ + int u_newindex; /* new index */ } t_undo_arrange; void *canvas_undo_set_arrange(t_canvas *x, t_gobj *obj, int newindex) { - // newindex tells us is the new index at the beginning (0) or the end (1) + // newindex tells us is the new index at the beginning (0) or the end (1) t_undo_arrange *buf; t_gobj *y; - /* enable editor (in case it is disabled) and select the object we are working on */ - if (!x->gl_edit) - canvas_editmode(x, 1); + /* enable editor (in case it is disabled) and select the object + we are working on */ + if (!x->gl_edit) + canvas_editmode(x, 1); - // select the object - if (!glist_isselected(x, obj)) - glist_select(x, obj); + // select the object + if (!glist_isselected(x, obj)) + glist_select(x, obj); buf = (t_undo_arrange *)getbytes(sizeof(*buf)); - // set the u_newindex appropriately - if (newindex == 0) buf->u_newindex = 0; - else buf->u_newindex = glist_getindex(x, 0) - 1; + // set the u_newindex appropriately + if (newindex == 0) buf->u_newindex = 0; + else buf->u_newindex = glist_getindex(x, 0) - 1; - /* store index of the currently selected object */ - buf->u_previndex = glist_getindex(x, obj); + /* store index of the currently selected object */ + buf->u_previndex = glist_getindex(x, obj); - //fprintf(stderr,"undo_set_arrange %d %d\n", buf->u_previndex, buf->u_newindex); + //fprintf(stderr,"undo_set_arrange %d %d\n", + // buf->u_previndex, buf->u_newindex); return (buf); } @@ -1447,109 +1596,114 @@ void *canvas_undo_set_arrange(t_canvas *x, t_gobj *obj, int newindex) void canvas_undo_arrange(t_canvas *x, void *z, int action) { t_undo_arrange *buf = z; - t_gobj *y=NULL, *prev=NULL, *next=NULL; + t_gobj *y=NULL, *prev=NULL, *next=NULL; - if (!x->gl_edit) - canvas_editmode(x, 1); + if (!x->gl_edit) + canvas_editmode(x, 1); if (action == UNDO_UNDO) { - // this is our object - y = glist_nth(x, buf->u_newindex); - - //fprintf(stderr,"canvas_undo_arrange UNDO_UNDO %d %d\n", buf->u_previndex, buf->u_newindex); - - /* select object */ - glist_noselect(x); - glist_select(x, y); - - if (buf->u_newindex) { - // if it is the last object - - // first previous object should point to nothing - prev = glist_nth(x, buf->u_newindex - 1); - prev->g_next = NULL; - - /* now we reuse vars for the following: - old index should be right before the object previndex - is pointing to as the object was moved to the end */ - - /* old position is not first */ - if (buf->u_previndex) { - prev = glist_nth(x, buf->u_previndex - 1); - next = prev->g_next; - - // now readjust pointers - prev->g_next = y; - y->g_next = next; - } - /* old position is first */ - else { - prev = NULL; - next = x->gl_list; - - // now readjust pointers - y->g_next = next; - x->gl_list = y; - } - - // and finally redraw canvas - //canvas_redraw(x); - // we do this instead to save us costly redraw of the canvas - canvas_restore_original_position(x, y, 0, -1); - - glob_preset_node_list_check_loc_and_update(); - } - else { - // if it is the first object - - /* old index should be right after the object previndex - is pointing to as the object was moved to the end */ - prev = glist_nth(x, buf->u_previndex); - - // next may be NULL and that is ok - next = prev->g_next; - - //first glist pointer needs to point to the second object - x->gl_list = y->g_next; - - //now readjust pointers - prev->g_next = y; - y->g_next = next; - - // and finally redraw canvas - //canvas_redraw(x); - // we do this instead to save us costly redraw of the canvas - canvas_restore_original_position(x, y, 0, 1); - glob_preset_node_list_check_loc_and_update(); - } - } - else if (action == UNDO_REDO) { - // find our object - y = glist_nth(x, buf->u_previndex); - - //fprintf(stderr,"canvas_undo_arrange UNDO_REDO %d %d\n", buf->u_previndex, buf->u_newindex); - - /* select object */ - glist_noselect(x); - glist_select(x, y); - - int action; - if (!buf->u_newindex) action = 4; - else action = 3; - - t_gobj *oldy_prev=NULL, *oldy_next=NULL; - - // if there is an object before ours (in other words our index is > 0) - if (glist_getindex(x,y)) - oldy_prev = glist_nth(x, buf->u_previndex - 1); - - // if there is an object after ours - if (y->g_next) - oldy_next = y->g_next; - - canvas_doarrange(x, action, y, oldy_prev, oldy_next); - } + // this is our object + y = glist_nth(x, buf->u_newindex); + + //fprintf(stderr,"canvas_undo_arrange UNDO_UNDO %d %d\n", + // buf->u_previndex, buf->u_newindex); + + /* select object */ + glist_noselect(x); + glist_select(x, y); + + if (buf->u_newindex) + { + // if it is the last object + + // first previous object should point to nothing + prev = glist_nth(x, buf->u_newindex - 1); + prev->g_next = NULL; + + /* now we reuse vars for the following: + old index should be right before the object previndex + is pointing to as the object was moved to the end */ + + /* old position is not first */ + if (buf->u_previndex) + { + prev = glist_nth(x, buf->u_previndex - 1); + next = prev->g_next; + + // now readjust pointers + prev->g_next = y; + y->g_next = next; + } + /* old position is first */ + else { + prev = NULL; + next = x->gl_list; + + // now readjust pointers + y->g_next = next; + x->gl_list = y; + } + + // and finally redraw canvas + //canvas_redraw(x); + // we do this instead to save us costly redraw of the canvas + canvas_restore_original_position(x, y, 0, -1); + + glob_preset_node_list_check_loc_and_update(); + } + else { + // if it is the first object + + /* old index should be right after the object previndex + is pointing to as the object was moved to the end */ + prev = glist_nth(x, buf->u_previndex); + + // next may be NULL and that is ok + next = prev->g_next; + + //first glist pointer needs to point to the second object + x->gl_list = y->g_next; + + //now readjust pointers + prev->g_next = y; + y->g_next = next; + + // and finally redraw canvas + //canvas_redraw(x); + // we do this instead to save us costly redraw of the canvas + canvas_restore_original_position(x, y, 0, 1); + glob_preset_node_list_check_loc_and_update(); + } + } + else if (action == UNDO_REDO) + { + // find our object + y = glist_nth(x, buf->u_previndex); + + //fprintf(stderr,"canvas_undo_arrange UNDO_REDO %d %d\n", + // buf->u_previndex, buf->u_newindex); + + /* select object */ + glist_noselect(x); + glist_select(x, y); + + int action; + if (!buf->u_newindex) action = 4; + else action = 3; + + t_gobj *oldy_prev=NULL, *oldy_next=NULL; + + // if there is an object before ours (in other words our index is > 0) + if (glist_getindex(x,y)) + oldy_prev = glist_nth(x, buf->u_previndex - 1); + + // if there is an object after ours + if (y->g_next) + oldy_next = y->g_next; + + canvas_doarrange(x, action, y, oldy_prev, oldy_next); + } else if (action == UNDO_FREE) { t_freebytes(buf, sizeof(*buf)); @@ -1558,7 +1712,8 @@ void canvas_undo_arrange(t_canvas *x, void *z, int action) void canvas_arrange_setundo(t_canvas *x, t_gobj *obj, int newindex) { - canvas_setundo(x, canvas_undo_arrange, canvas_undo_set_arrange(x, obj, newindex), "arrange"); + canvas_setundo(x, canvas_undo_arrange, + canvas_undo_set_arrange(x, obj, newindex), "arrange"); } /* --------- 8. apply on canvas ----------- */ @@ -1567,7 +1722,7 @@ typedef struct _undo_canvas_properties { int gl_pixwidth; /* width in pixels (on parent, if a graph) */ int gl_pixheight; - t_float gl_x1; /* bounding rectangle in our own coordinates */ + t_float gl_x1; /* bounding rectangle in our own coordinates */ t_float gl_y1; t_float gl_x2; t_float gl_y2; @@ -1575,40 +1730,42 @@ typedef struct _undo_canvas_properties int gl_screeny1; int gl_screenx2; int gl_screeny2; - int gl_xmargin; /* origin for GOP rectangle */ + int gl_xmargin; /* origin for GOP rectangle */ int gl_ymargin; - unsigned int gl_goprect:1; /* draw rectangle for graph-on-parent */ - unsigned int gl_isgraph:1; /* show as graph on parent */ - unsigned int gl_hidetext:1; /* hide object-name + args when doing graph on parent */ + unsigned int gl_goprect:1; /* draw rectangle for graph-on-parent */ + unsigned int gl_isgraph:1; /* show as graph on parent */ + unsigned int gl_hidetext:1; /* hide object-name + args when doing + graph on parent */ } t_undo_canvas_properties; //t_undo_canvas_properties global_buf; void *canvas_undo_set_canvas(t_canvas *x) { - /* enable editor (in case it is disabled) */ - //if (x->gl_havewindow && !x->gl_edit) - // canvas_editmode(x, 1); - - t_undo_canvas_properties *buf = (t_undo_canvas_properties *)getbytes(sizeof(*buf)); - - buf->gl_pixwidth = x->gl_pixwidth; - buf->gl_pixheight = x->gl_pixheight; - buf->gl_x1 = x->gl_x1; - buf->gl_y1 = x->gl_y1; - buf->gl_x2 = x->gl_x2; - buf->gl_y2 = x->gl_y2; - buf->gl_screenx1 = x->gl_screenx1; - buf->gl_screeny1 = x->gl_screeny1; - buf->gl_screenx2 = x->gl_screenx2; - buf->gl_screeny2 = x->gl_screeny2; - buf->gl_xmargin = x->gl_xmargin; - buf->gl_ymargin = x->gl_ymargin; - buf->gl_goprect = x->gl_goprect; - buf->gl_isgraph = x->gl_isgraph; - buf->gl_hidetext = x->gl_hidetext; - + /* enable editor (in case it is disabled) */ + //if (x->gl_havewindow && !x->gl_edit) + // canvas_editmode(x, 1); + + t_undo_canvas_properties *buf = + (t_undo_canvas_properties *)getbytes(sizeof(*buf)); + + buf->gl_pixwidth = x->gl_pixwidth; + buf->gl_pixheight = x->gl_pixheight; + buf->gl_x1 = x->gl_x1; + buf->gl_y1 = x->gl_y1; + buf->gl_x2 = x->gl_x2; + buf->gl_y2 = x->gl_y2; + buf->gl_screenx1 = x->gl_screenx1; + buf->gl_screeny1 = x->gl_screeny1; + buf->gl_screenx2 = x->gl_screenx2; + buf->gl_screeny2 = x->gl_screeny2; + buf->gl_xmargin = x->gl_xmargin; + buf->gl_ymargin = x->gl_ymargin; + buf->gl_goprect = x->gl_goprect; + buf->gl_isgraph = x->gl_isgraph; + buf->gl_hidetext = x->gl_hidetext; + return (buf); } @@ -1619,128 +1776,141 @@ void canvas_undo_canvas_apply(t_canvas *x, void *z, int action) t_undo_canvas_properties *buf = (t_undo_canvas_properties *)z; t_undo_canvas_properties tmp; - if (!x->gl_edit) - canvas_editmode(x, 1); - - if (action == UNDO_UNDO || action == UNDO_REDO) - { - //close properties window first - t_int properties = gfxstub_haveproperties((void *)x); - if (properties) { - //sys_vgui("destroy .gfxstub%lx\n", properties); - gfxstub_deleteforkey(x); - } - - //store current canvas values into temporary data holder - tmp.gl_pixwidth = x->gl_pixwidth; - tmp.gl_pixheight = x->gl_pixheight; - tmp.gl_x1 = x->gl_x1; - tmp.gl_y1 = x->gl_y1; - tmp.gl_x2 = x->gl_x2; - tmp.gl_y2 = x->gl_y2; - tmp.gl_screenx1 = x->gl_screenx1; - tmp.gl_screeny1 = x->gl_screeny1; - tmp.gl_screenx2 = x->gl_screenx2; - tmp.gl_screeny2 = x->gl_screeny2; - tmp.gl_xmargin = x->gl_xmargin; - tmp.gl_ymargin = x->gl_ymargin; - tmp.gl_goprect = x->gl_goprect; - tmp.gl_isgraph = x->gl_isgraph; - tmp.gl_hidetext = x->gl_hidetext; - - //change canvas values with the ones from the undo buffer - x->gl_pixwidth = buf->gl_pixwidth; - x->gl_pixheight = buf->gl_pixheight; - x->gl_x1 = buf->gl_x1; - x->gl_y1 = buf->gl_y1; - x->gl_x2 = buf->gl_x2; - x->gl_y2 = buf->gl_y2; - x->gl_screenx1 = buf->gl_screenx1; - x->gl_screeny1 = buf->gl_screeny1; - x->gl_screenx2 = buf->gl_screenx2; - x->gl_screeny2 = buf->gl_screeny2; - x->gl_xmargin = buf->gl_xmargin; - x->gl_ymargin = buf->gl_ymargin; - x->gl_goprect = buf->gl_goprect; - x->gl_isgraph = buf->gl_isgraph; - x->gl_hidetext = buf->gl_hidetext; - - //copy data values from the temporary data to the undo buffer - buf->gl_pixwidth = tmp.gl_pixwidth; - buf->gl_pixheight = tmp.gl_pixheight; - buf->gl_x1 = tmp.gl_x1; - buf->gl_y1 = tmp.gl_y1; - buf->gl_x2 = tmp.gl_x2; - buf->gl_y2 = tmp.gl_y2; - buf->gl_screenx1 = tmp.gl_screenx1; - buf->gl_screeny1 = tmp.gl_screeny1; - buf->gl_screenx2 = tmp.gl_screenx2; - buf->gl_screeny2 = tmp.gl_screeny2; - buf->gl_xmargin = tmp.gl_xmargin; - buf->gl_ymargin = tmp.gl_ymargin; - buf->gl_goprect = tmp.gl_goprect; - buf->gl_isgraph = tmp.gl_isgraph; - buf->gl_hidetext = tmp.gl_hidetext; - - //redraw - canvas_setgraph(x, x->gl_isgraph + 2*x->gl_hidetext, 0); - canvas_dirty(x, 1); - if (x->gl_havewindow) { - canvas_redraw(x); - } - if (x->gl_owner && glist_isvisible(x->gl_owner)) - { - glist_noselect(x); - gobj_vis(&x->gl_gobj, x->gl_owner, 0); - gobj_vis(&x->gl_gobj, x->gl_owner, 1); - canvas_redraw(x->gl_owner); - } - //update scrollbars when GOP potentially exceeds window size - t_canvas *canvas=(t_canvas *)glist_getcanvas(x); - - //if gop is being disabled go one level up - /*if (!x->gl_isgraph && x->gl_owner) { - canvas=canvas->gl_owner; - canvas_redraw(canvas); - }*/ - - //if properties window is open, update the properties with the previous window properties - /*t_int properties = gfxstub_haveproperties((void *)x); - if (properties) { - sys_vgui("pdtk_canvas_dialog_undo_update .gfxstub%lx %d %d\n", properties, x->gl_isgraph, x->gl_hidetext); - sys_vgui(".gfxstub%lx.xscale.entry delete 0 end\n", properties); - sys_vgui(".gfxstub%lx.xrange.entry1 insert 0 %d\n", properties, x->gl_x1); - sys_vgui(".gfxstub%lx.yrange.entry1 delete 0 end\n", properties); - sys_vgui(".gfxstub%lx.yrange.entry1 insert 0 %d\n", properties, x->gl_y1); - sys_vgui(".gfxstub%lx.xrange.entry2 delete 0 end\n", properties); - sys_vgui(".gfxstub%lx.xrange.entry2 insert 0 %d\n", properties, x->gl_x2); - sys_vgui(".gfxstub%lx.yrange.entry2 delete 0 end\n", properties); - sys_vgui(".gfxstub%lx.yrange.entry2 insert 0 %d\n", properties, x->gl_y2); - sys_vgui(".gfxstub%lx.xrange.entry3 delete 0 end\n", properties); - sys_vgui(".gfxstub%lx.xrange.entry3 insert 0 %d\n", properties, x->gl_pixwidth); - sys_vgui(".gfxstub%lx.yrange.entry3 delete 0 end\n", properties); - sys_vgui(".gfxstub%lx.yrange.entry3 insert 0 %d\n", properties, x->gl_pixheight); - sys_vgui(".gfxstub%lx.xrange.entry4 delete 0 end\n", properties); - sys_vgui(".gfxstub%lx.xrange.entry4 insert 0 %d\n", properties, x->gl_xmargin); - sys_vgui(".gfxstub%lx.yrange.entry4 delete 0 end\n", properties); - sys_vgui(".gfxstub%lx.yrange.entry4 insert 0 %d\n", properties, x->gl_ymargin); - }*/ - - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", (t_int)x); - if (canvas != x) - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", (t_int)canvas); - } + if (!x->gl_edit) + canvas_editmode(x, 1); + + if (action == UNDO_UNDO || action == UNDO_REDO) + { + //close properties window first + t_int properties = gfxstub_haveproperties((void *)x); + if (properties) + { + //sys_vgui("destroy .gfxstub%lx\n", properties); + gfxstub_deleteforkey(x); + } + + //store current canvas values into temporary data holder + tmp.gl_pixwidth = x->gl_pixwidth; + tmp.gl_pixheight = x->gl_pixheight; + tmp.gl_x1 = x->gl_x1; + tmp.gl_y1 = x->gl_y1; + tmp.gl_x2 = x->gl_x2; + tmp.gl_y2 = x->gl_y2; + tmp.gl_screenx1 = x->gl_screenx1; + tmp.gl_screeny1 = x->gl_screeny1; + tmp.gl_screenx2 = x->gl_screenx2; + tmp.gl_screeny2 = x->gl_screeny2; + tmp.gl_xmargin = x->gl_xmargin; + tmp.gl_ymargin = x->gl_ymargin; + tmp.gl_goprect = x->gl_goprect; + tmp.gl_isgraph = x->gl_isgraph; + tmp.gl_hidetext = x->gl_hidetext; + + //change canvas values with the ones from the undo buffer + x->gl_pixwidth = buf->gl_pixwidth; + x->gl_pixheight = buf->gl_pixheight; + x->gl_x1 = buf->gl_x1; + x->gl_y1 = buf->gl_y1; + x->gl_x2 = buf->gl_x2; + x->gl_y2 = buf->gl_y2; + x->gl_screenx1 = buf->gl_screenx1; + x->gl_screeny1 = buf->gl_screeny1; + x->gl_screenx2 = buf->gl_screenx2; + x->gl_screeny2 = buf->gl_screeny2; + x->gl_xmargin = buf->gl_xmargin; + x->gl_ymargin = buf->gl_ymargin; + x->gl_goprect = buf->gl_goprect; + x->gl_isgraph = buf->gl_isgraph; + x->gl_hidetext = buf->gl_hidetext; + + //copy data values from the temporary data to the undo buffer + buf->gl_pixwidth = tmp.gl_pixwidth; + buf->gl_pixheight = tmp.gl_pixheight; + buf->gl_x1 = tmp.gl_x1; + buf->gl_y1 = tmp.gl_y1; + buf->gl_x2 = tmp.gl_x2; + buf->gl_y2 = tmp.gl_y2; + buf->gl_screenx1 = tmp.gl_screenx1; + buf->gl_screeny1 = tmp.gl_screeny1; + buf->gl_screenx2 = tmp.gl_screenx2; + buf->gl_screeny2 = tmp.gl_screeny2; + buf->gl_xmargin = tmp.gl_xmargin; + buf->gl_ymargin = tmp.gl_ymargin; + buf->gl_goprect = tmp.gl_goprect; + buf->gl_isgraph = tmp.gl_isgraph; + buf->gl_hidetext = tmp.gl_hidetext; + + //redraw + canvas_setgraph(x, x->gl_isgraph + 2*x->gl_hidetext, 0); + canvas_dirty(x, 1); + if (x->gl_havewindow) + { + canvas_redraw(x); + } + if (x->gl_owner && glist_isvisible(x->gl_owner)) + { + glist_noselect(x); + gobj_vis(&x->gl_gobj, x->gl_owner, 0); + gobj_vis(&x->gl_gobj, x->gl_owner, 1); + canvas_redraw(x->gl_owner); + } + //update scrollbars when GOP potentially exceeds window size + t_canvas *canvas=(t_canvas *)glist_getcanvas(x); + + //if gop is being disabled go one level up + /*if (!x->gl_isgraph && x->gl_owner) { + canvas=canvas->gl_owner; + canvas_redraw(canvas); + }*/ + + //if properties window is open, + //update the properties with the previous window properties + /*t_int properties = gfxstub_haveproperties((void *)x); + if (properties) { + sys_vgui("pdtk_canvas_dialog_undo_update .gfxstub%lx %d %d\n", + properties, x->gl_isgraph, x->gl_hidetext); + sys_vgui(".gfxstub%lx.xscale.entry delete 0 end\n", properties); + sys_vgui(".gfxstub%lx.xrange.entry1 insert 0 %d\n", + properties, x->gl_x1); + sys_vgui(".gfxstub%lx.yrange.entry1 delete 0 end\n", properties); + sys_vgui(".gfxstub%lx.yrange.entry1 insert 0 %d\n", + properties, x->gl_y1); + sys_vgui(".gfxstub%lx.xrange.entry2 delete 0 end\n", properties); + sys_vgui(".gfxstub%lx.xrange.entry2 insert 0 %d\n", + properties, x->gl_x2); + sys_vgui(".gfxstub%lx.yrange.entry2 delete 0 end\n", properties); + sys_vgui(".gfxstub%lx.yrange.entry2 insert 0 %d\n", + properties, x->gl_y2); + sys_vgui(".gfxstub%lx.xrange.entry3 delete 0 end\n", properties); + sys_vgui(".gfxstub%lx.xrange.entry3 insert 0 %d\n", + properties, x->gl_pixwidth); + sys_vgui(".gfxstub%lx.yrange.entry3 delete 0 end\n", properties); + sys_vgui(".gfxstub%lx.yrange.entry3 insert 0 %d\n", + properties, x->gl_pixheight); + sys_vgui(".gfxstub%lx.xrange.entry4 delete 0 end\n", properties); + sys_vgui(".gfxstub%lx.xrange.entry4 insert 0 %d\n", + properties, x->gl_xmargin); + sys_vgui(".gfxstub%lx.yrange.entry4 delete 0 end\n", properties); + sys_vgui(".gfxstub%lx.yrange.entry4 insert 0 %d\n", + properties, x->gl_ymargin); + }*/ + + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", (t_int)x); + if (canvas != x) + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", (t_int)canvas); + } else if (action == UNDO_FREE) { - if (buf) - t_freebytes(buf, sizeof(*buf)); + if (buf) + t_freebytes(buf, sizeof(*buf)); } } void canvas_canvas_setundo(t_canvas *x) { - canvas_setundo(x, canvas_undo_canvas_apply, canvas_undo_set_canvas(x), "apply"); + canvas_setundo(x, canvas_undo_canvas_apply, + canvas_undo_set_canvas(x), "apply"); } /* --------- 9. create ----------- */ @@ -1749,7 +1919,7 @@ extern t_pd *newest; typedef struct _undo_create { - int u_index; /* index of the created object object */ + int u_index; /* index of the created object object */ t_binbuf *u_objectbuf; /* the object cleared or typed into */ t_binbuf *u_reconnectbuf; /* connections into and out of object */ } t_undo_create; @@ -1759,60 +1929,64 @@ void *canvas_undo_set_create(t_canvas *x) t_gobj *y; t_linetraverser t; t_outconnect *oc; - int issel1, issel2; + int issel1, issel2; t_undo_create *buf = (t_undo_create *)getbytes(sizeof(*buf)); buf->u_index = glist_getindex(x, 0) - 1; int nnotsel= glist_selectionindex(x, 0, 0); - //fprintf(stderr,"buf->u_index=%d nnotsel=%d\n", buf->u_index, nnotsel); + //fprintf(stderr,"buf->u_index=%d nnotsel=%d\n", buf->u_index, nnotsel); buf->u_objectbuf = binbuf_new(); - if (x->gl_list) { - for (y = x->gl_list; y; y = y->g_next) - { - //if (glist_isselected(x, y)) { - if (!y->g_next) { - //fprintf(stderr,"undo_set_create: gobj_save\n"); - gobj_save(y, buf->u_objectbuf); - break; - } - } - buf->u_reconnectbuf = binbuf_new(); - linetraverser_start(&t, x); - while (oc = linetraverser_next(&t)) - { - //int issel1 = glist_isselected(x, &t.tr_ob->ob_g); - //int issel2 = glist_isselected(x, &t.tr_ob2->ob_g); - issel1 = ( &t.tr_ob->ob_g == y ? 1 : 0); - issel2 = ( &t.tr_ob2->ob_g == y ? 1 : 0); - //fprintf(stderr,"undo_set_create linetraverser %d %d\n", issel1, issel2); - if (issel1 != issel2) - { - //fprintf(stderr,"undo_set_create store connection\n"); - binbuf_addv(buf->u_reconnectbuf, "ssiiii;", - gensym("#X"), gensym("connect"), - (issel1 ? nnotsel : 0) - + glist_selectionindex(x, &t.tr_ob->ob_g, issel1), - t.tr_outno, - (issel2 ? nnotsel : 0) + - glist_selectionindex(x, &t.tr_ob2->ob_g, issel2), - t.tr_inno); - /*char *text; - int lengthp; - binbuf_gettext(buf->u_reconnectbuf, &text, &lengthp); - fprintf(stderr,"%s\n", text);*/ - } - } - } - return (buf); -} - -void canvas_undo_create(t_canvas *x, void *z, int action) + if (x->gl_list) + { + for (y = x->gl_list; y; y = y->g_next) + { + //if (glist_isselected(x, y)) { + if (!y->g_next) + { + //fprintf(stderr,"undo_set_create: gobj_save\n"); + gobj_save(y, buf->u_objectbuf); + break; + } + } + buf->u_reconnectbuf = binbuf_new(); + linetraverser_start(&t, x); + while (oc = linetraverser_next(&t)) + { + //int issel1 = glist_isselected(x, &t.tr_ob->ob_g); + //int issel2 = glist_isselected(x, &t.tr_ob2->ob_g); + issel1 = ( &t.tr_ob->ob_g == y ? 1 : 0); + issel2 = ( &t.tr_ob2->ob_g == y ? 1 : 0); + //fprintf(stderr,"undo_set_create linetraverser %d %d\n", + // issel1, issel2); + if (issel1 != issel2) + { + //fprintf(stderr,"undo_set_create store connection\n"); + binbuf_addv(buf->u_reconnectbuf, "ssiiii;", + gensym("#X"), gensym("connect"), + (issel1 ? nnotsel : 0) + + glist_selectionindex(x, &t.tr_ob->ob_g, issel1), + t.tr_outno, + (issel2 ? nnotsel : 0) + + glist_selectionindex(x, &t.tr_ob2->ob_g, issel2), + t.tr_inno); + /*char *text; + int lengthp; + binbuf_gettext(buf->u_reconnectbuf, &text, &lengthp); + fprintf(stderr,"%s\n", text);*/ + } + } + } + return (buf); +} + +void canvas_undo_create(t_canvas *x, void *z, int action) { t_undo_create *buf = z; t_gobj *y; - //fprintf(stderr,"canvas = %lx buf->u_index = %d\n", (t_int)x, buf->u_index); + //fprintf(stderr,"canvas = %lx buf->u_index = %d\n", + // (t_int)x, buf->u_index); if (action == UNDO_UNDO) { @@ -1824,24 +1998,25 @@ void canvas_undo_create(t_canvas *x, void *z, int action) else if (action == UNDO_REDO) { pd_bind(&x->gl_pd, gensym("#X")); - binbuf_eval(buf->u_objectbuf, 0, 0, 0); - pd_unbind(&x->gl_pd, gensym("#X")); + binbuf_eval(buf->u_objectbuf, 0, 0, 0); + pd_unbind(&x->gl_pd, gensym("#X")); pd_bind(&x->gl_pd, gensym("#X")); - binbuf_eval(buf->u_reconnectbuf, 0, 0, 0); - pd_unbind(&x->gl_pd, gensym("#X")); + binbuf_eval(buf->u_reconnectbuf, 0, 0, 0); + pd_unbind(&x->gl_pd, gensym("#X")); if (newest && pd_class(newest) == canvas_class) - canvas_loadbang((t_canvas *)newest); + canvas_loadbang((t_canvas *)newest); y = glist_nth(x, buf->u_index); glist_select(x, y); } - else if (action == UNDO_FREE) { - binbuf_free(buf->u_objectbuf); - binbuf_free(buf->u_reconnectbuf); + else if (action == UNDO_FREE) + { + binbuf_free(buf->u_objectbuf); + binbuf_free(buf->u_reconnectbuf); t_freebytes(buf, sizeof(*buf)); - } + } } -/* --------- 10. recreate (called from text_setto after text has changed) ----------- */ +/* ------ 10. recreate (called from text_setto after text has changed) ------ */ //recreate uses t_undo_create struct @@ -1849,117 +2024,126 @@ void *canvas_undo_set_recreate(t_canvas *x, t_gobj *y, int pos) { t_linetraverser t; t_outconnect *oc; - int issel1, issel2; + int issel1, issel2; t_undo_create *buf = (t_undo_create *)getbytes(sizeof(*buf)); buf->u_index = pos; - int nnotsel= glist_selectionindex(x, 0, 0) - 1; // - 1 is a critical difference from the create - //fprintf(stderr,"buf->u_index=%d nnotsel=%d\n", buf->u_index, nnotsel); + int nnotsel= glist_selectionindex(x, 0, 0) - 1; // - 1 is a critical + // difference from + // the create + //fprintf(stderr,"buf->u_index=%d nnotsel=%d\n", buf->u_index, nnotsel); buf->u_objectbuf = binbuf_new(); - //y = glist_nth(x, buf->u_index); - //fprintf(stderr,"undo_set_create: gobj_save\n"); - gobj_save(y, buf->u_objectbuf); - - buf->u_reconnectbuf = binbuf_new(); - linetraverser_start(&t, x); - while (oc = linetraverser_next(&t)) - { - //int issel1 = glist_isselected(x, &t.tr_ob->ob_g); - //int issel2 = glist_isselected(x, &t.tr_ob2->ob_g); - issel1 = ( &t.tr_ob->ob_g == y ? 1 : 0); - issel2 = ( &t.tr_ob2->ob_g == y ? 1 : 0); - //fprintf(stderr,"undo_set_create linetraverser %d %d\n", issel1, issel2); - if (issel1 != issel2) - { - //fprintf(stderr,"undo_set_create store connection\n"); - binbuf_addv(buf->u_reconnectbuf, "ssiiii;", - gensym("#X"), gensym("connect"), - (issel1 ? nnotsel : 0) - + glist_selectionindex(x, &t.tr_ob->ob_g, issel1), - t.tr_outno, - (issel2 ? nnotsel : 0) + - glist_selectionindex(x, &t.tr_ob2->ob_g, issel2), - t.tr_inno); - } - } + //y = glist_nth(x, buf->u_index); + //fprintf(stderr,"undo_set_create: gobj_save\n"); + gobj_save(y, buf->u_objectbuf); + + buf->u_reconnectbuf = binbuf_new(); + linetraverser_start(&t, x); + while (oc = linetraverser_next(&t)) + { + //int issel1 = glist_isselected(x, &t.tr_ob->ob_g); + //int issel2 = glist_isselected(x, &t.tr_ob2->ob_g); + issel1 = ( &t.tr_ob->ob_g == y ? 1 : 0); + issel2 = ( &t.tr_ob2->ob_g == y ? 1 : 0); + //fprintf(stderr,"undo_set_create linetraverser %d %d\n", + // issel1, issel2); + if (issel1 != issel2) + { + //fprintf(stderr,"undo_set_create store connection\n"); + binbuf_addv(buf->u_reconnectbuf, "ssiiii;", + gensym("#X"), gensym("connect"), + (issel1 ? nnotsel : 0) + + glist_selectionindex(x, &t.tr_ob->ob_g, issel1), + t.tr_outno, + (issel2 ? nnotsel : 0) + + glist_selectionindex(x, &t.tr_ob2->ob_g, issel2), + t.tr_inno); + } + } return (buf); } void canvas_undo_recreate(t_canvas *x, void *z, int action) { - //fprintf(stderr,"canvas_undo_recreate\n"); + //fprintf(stderr,"canvas_undo_recreate\n"); t_undo_create *buf = z; - t_gobj *y = NULL; - if (action == UNDO_UNDO) - y = glist_nth(x, glist_getindex(x, 0) - 1); - else if (action == UNDO_REDO) - y = glist_nth(x, buf->u_index); + t_gobj *y = NULL; + if (action == UNDO_UNDO) + y = glist_nth(x, glist_getindex(x, 0) - 1); + else if (action == UNDO_REDO) + y = glist_nth(x, buf->u_index); - //fprintf(stderr,"canvas = %lx buf->u_index = %d\n", (t_int)x, buf->u_index); + //fprintf(stderr,"canvas = %lx buf->u_index = %d\n", + // (t_int)x, buf->u_index); if (action == UNDO_UNDO || action == UNDO_REDO) { - // first copy new state of the current object - t_linetraverser t; - t_outconnect *oc; - int issel1, issel2; - - t_undo_create *buf2 = (t_undo_create *)getbytes(sizeof(*buf)); - //buf2->u_index = glist_getindex(x, y); - buf2->u_index = buf->u_index; - int nnotsel= glist_selectionindex(x, 0, 0) - 1; // - 1 is a critical difference from the create - //fprintf(stderr,"buf2->u_index=%d nnotsel=%d y_getindex=%d\n", buf2->u_index, nnotsel, glist_getindex(x, y)); - buf2->u_objectbuf = binbuf_new(); - //fprintf(stderr,"undo_set_recreate: gobj_save\n"); - gobj_save(y, buf2->u_objectbuf); - - buf2->u_reconnectbuf = binbuf_duplicate(buf->u_reconnectbuf); - - // now cut the existing object - glist_noselect(x); + // first copy new state of the current object + t_linetraverser t; + t_outconnect *oc; + int issel1, issel2; + + t_undo_create *buf2 = (t_undo_create *)getbytes(sizeof(*buf)); + //buf2->u_index = glist_getindex(x, y); + buf2->u_index = buf->u_index; + int nnotsel= glist_selectionindex(x, 0, 0) - 1; // - 1 is a critical + // difference from + // the create + //fprintf(stderr,"buf2->u_index=%d nnotsel=%d y_getindex=%d\n", + // buf2->u_index, nnotsel, glist_getindex(x, y)); + buf2->u_objectbuf = binbuf_new(); + //fprintf(stderr,"undo_set_recreate: gobj_save\n"); + gobj_save(y, buf2->u_objectbuf); + + buf2->u_reconnectbuf = binbuf_duplicate(buf->u_reconnectbuf); + + // now cut the existing object + glist_noselect(x); glist_select(x, y); canvas_doclear(x); - // then paste the old object + // then paste the old object pd_bind(&x->gl_pd, gensym("#X")); - binbuf_eval(buf->u_objectbuf, 0, 0, 0); - pd_unbind(&x->gl_pd, gensym("#X")); + binbuf_eval(buf->u_objectbuf, 0, 0, 0); + pd_unbind(&x->gl_pd, gensym("#X")); pd_bind(&x->gl_pd, gensym("#X")); - binbuf_eval(buf->u_reconnectbuf, 0, 0, 0); - pd_unbind(&x->gl_pd, gensym("#X")); + binbuf_eval(buf->u_reconnectbuf, 0, 0, 0); + pd_unbind(&x->gl_pd, gensym("#X")); - // free the old data - binbuf_free(buf->u_objectbuf); - binbuf_free(buf->u_reconnectbuf); + // free the old data + binbuf_free(buf->u_objectbuf); + binbuf_free(buf->u_reconnectbuf); t_freebytes(buf, sizeof(*buf)); - // readjust pointer - // (this should probably belong into g_undo.c, but since it is a unique case, we'll let it be for the time being) - x->u_last->data = (void *)buf2; - buf = buf2; + // readjust pointer + // (this should probably belong into g_undo.c, but since it is + // a unique case, we'll let it be for the time being) + x->u_last->data = (void *)buf2; + buf = buf2; - // reposition object to its original place - if (action == UNDO_UNDO) - if (canvas_apply_restore_original_position(x, buf->u_index)) - canvas_redraw(x); + // reposition object to its original place + if (action == UNDO_UNDO) + if (canvas_apply_restore_original_position(x, buf->u_index)) + canvas_redraw(x); - // send a loadbang + // send a loadbang if (newest && pd_class(newest) == canvas_class) - canvas_loadbang((t_canvas *)newest); + canvas_loadbang((t_canvas *)newest); - // select - if (action == UNDO_REDO) - y = glist_nth(x, glist_getindex(x, 0) - 1); - else - y = glist_nth(x, buf->u_index); + // select + if (action == UNDO_REDO) + y = glist_nth(x, glist_getindex(x, 0) - 1); + else + y = glist_nth(x, buf->u_index); glist_select(x, y); } - else if (action == UNDO_FREE) { - binbuf_free(buf->u_objectbuf); - binbuf_free(buf->u_reconnectbuf); + else if (action == UNDO_FREE) + { + binbuf_free(buf->u_objectbuf); + binbuf_free(buf->u_reconnectbuf); t_freebytes(buf, sizeof(*buf)); - } + } } /* ----------- 11. font -------------- */ @@ -1971,8 +2155,8 @@ typedef struct _undo_font void *canvas_undo_set_font(t_canvas *x, int font) { - t_undo_font *u_f = (t_undo_font *)getbytes(sizeof(*u_f)); - u_f->font = font; + t_undo_font *u_f = (t_undo_font *)getbytes(sizeof(*u_f)); + u_f->font = font; return (u_f); } @@ -1982,20 +2166,23 @@ void canvas_undo_font(t_canvas *x, void *z, int action) if (action == UNDO_UNDO || action == UNDO_REDO) { - t_canvas *x2 = canvas_getrootfor(x); - int tmp_font = x2->gl_font; - t_float resize = (t_float)sys_fontwidth(u_f->font)/(t_float)sys_fontwidth(x2->gl_font); - t_int properties = gfxstub_haveproperties((void *)x2); - if (properties) { - sys_vgui(".gfxstub%lx.radiof.radio%d invoke\n", properties, u_f->font); - } - else sys_vgui("dofont_apply .x%lx %d 1\n", x2, u_f->font); - u_f->font = tmp_font; + t_canvas *x2 = canvas_getrootfor(x); + int tmp_font = x2->gl_font; + t_float resize = (t_float)sys_fontwidth(u_f->font) / + (t_float)sys_fontwidth(x2->gl_font); + t_int properties = gfxstub_haveproperties((void *)x2); + if (properties) + { + sys_vgui(".gfxstub%lx.radiof.radio%d invoke\n", + properties, u_f->font); + } + else sys_vgui("dofont_apply .x%lx %d 1\n", x2, u_f->font); + u_f->font = tmp_font; } else if (action == UNDO_FREE) { - if (u_f) - freebytes(u_f, sizeof(*u_f)); + if (u_f) + freebytes(u_f, sizeof(*u_f)); } } @@ -2016,12 +2203,12 @@ static char *cursorlist[] = { void canvas_setcursor(t_canvas *x, unsigned int cursornum) { - //fprintf(stderr,"canvas_setcursor %d\n", cursornum); + //fprintf(stderr,"canvas_setcursor %d\n", cursornum); static t_canvas *xwas; static unsigned int cursorwas; if (cursornum >= sizeof(cursorlist)/sizeof *cursorlist) { - bug("canvas_setcursor"); + bug("canvas_setcursor"); return; } if (xwas != x || cursorwas != cursornum) @@ -2063,8 +2250,8 @@ t_gobj *canvas_findhitbox(t_canvas *x, int xpos, int ypos, { 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 */ + /* 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 @@ -2084,39 +2271,45 @@ t_gobj *canvas_findhitbox(t_canvas *x, int xpos, int ypos, /* right-clicking on a canvas object pops up a menu. */ static void canvas_rightclick(t_canvas *x, int xpos, int ypos, t_gobj *y_sel) { - //fprintf(stderr,"e_onmotion=%d\n",x->gl_editor->e_onmotion); - if (x->gl_editor->e_onmotion != MA_NONE) return; + //fprintf(stderr,"e_onmotion=%d\n",x->gl_editor->e_onmotion); + if (x->gl_editor->e_onmotion != MA_NONE) return; int canprop, canopen, isobject; - t_gobj *y = NULL; - int x1, y1, x2, y2; - if (x->gl_editor->e_selection) { - glist_noselect(x); - } - t_gobj *yclick = NULL; - for (y = x->gl_list; y; y = y->g_next) { - if (y && canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2)) { - yclick = y; - } - } - if (yclick) { - y = yclick; - if (!glist_isselected(x, y)) - glist_select(x, y); - } - // if we are in K12 mode and are requesting popup on comments, bail as we don't want users - // to get into conventional help files - if (sys_k12_mode && y && pd_class(&y->g_pd) == text_class) - return; - /* abstractions should only allow for properties inside them - otherwise they end-up being dirty without visible notification - besides, why would one mess with their properties without - seeing what is inside them? CURRENTLY DISABLED */ - canprop = (!y || (y && class_getpropertiesfn(pd_class(&y->g_pd))) /*&& !canvas_isabstraction( ((t_glist*)y) )*/ ); + t_gobj *y = NULL; + int x1, y1, x2, y2; + if (x->gl_editor->e_selection) + { + glist_noselect(x); + } + t_gobj *yclick = NULL; + for (y = x->gl_list; y; y = y->g_next) + { + if (y && canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2)) + { + yclick = y; + } + } + if (yclick) + { + y = yclick; + if (!glist_isselected(x, y)) + glist_select(x, y); + } + // if we are in K12 mode and are requesting popup on comments, + // bail as we don't want users to get into conventional help files + if (sys_k12_mode && y && pd_class(&y->g_pd) == text_class) + return; + /* abstractions should only allow for properties inside them + otherwise they end-up being dirty without visible notification + besides, why would one mess with their properties without + seeing what is inside them? CURRENTLY DISABLED */ + canprop = (!y || (y && class_getpropertiesfn(pd_class(&y->g_pd))) + /*&& !canvas_isabstraction( ((t_glist*)y) )*/ ); canopen = (y && zgetfn(&y->g_pd, gensym("menu-open"))); - if (y || x->gl_editor->e_selection) { - isobject = 1; - } - else isobject = 0; + if (y || x->gl_editor->e_selection) + { + isobject = 1; + } + else isobject = 0; sys_vgui("pdtk_canvas_popup .x%lx %d %d %d %d %d\n", x, xpos, ypos, canprop, canopen, isobject); } @@ -2132,9 +2325,9 @@ static t_editor *editor_new(t_glist *owner) x->e_glist = owner; sprintf(buf, ".x%lx", (t_int)owner); x->e_guiconnect = guiconnect_new(&owner->gl_pd, gensym(buf)); - x->gl_magic_glass = magicGlass_new(owner); - x->canvas_cnct_inlet_tag[0] = 0; - x->canvas_cnct_outlet_tag[0] = 0; + x->gl_magic_glass = magicGlass_new(owner); + x->canvas_cnct_inlet_tag[0] = 0; + x->canvas_cnct_outlet_tag[0] = 0; return (x); } @@ -2145,11 +2338,12 @@ static void editor_free(t_editor *x, t_glist *y) binbuf_free(x->e_connectbuf); binbuf_free(x->e_deleted); - if (x->gl_magic_glass) { - //magicGlass_free(x->gl_magic_glass); - pd_free(&x->gl_magic_glass->x_obj.te_g.g_pd); - //x->gl_magic_glass = NULL; - } + if (x->gl_magic_glass) + { + //magicGlass_free(x->gl_magic_glass); + pd_free(&x->gl_magic_glass->x_obj.te_g.g_pd); + //x->gl_magic_glass = NULL; + } freebytes((void *)x, sizeof(*x)); } @@ -2158,7 +2352,7 @@ static void editor_free(t_editor *x, t_glist *y) sub-glists, as long as they aren't toplevels. */ void canvas_create_editor(t_glist *x) { - //fprintf(stderr,"create_editor %lx\n", x); + //fprintf(stderr,"create_editor %lx\n", x); t_gobj *y; t_object *ob; if (!x->gl_editor) @@ -2172,22 +2366,23 @@ void canvas_create_editor(t_glist *x) void canvas_destroy_editor(t_glist *x) { - //fprintf(stderr,"destroy_editor %lx\n", x); + //fprintf(stderr,"destroy_editor %lx\n", x); t_gobj *y; t_object *ob; - glist_noselect(x); + glist_noselect(x); if (x->gl_editor) { - if (x->gl_list) { - for (y = x->gl_list; y; y = y->g_next) - if (ob = pd_checkobject(&y->g_pd)) - rtext_free(glist_findrtext(x, ob)); - } - //if (x->gl_editor) { - editor_free(x->gl_editor, x); - x->gl_editor = 0; - //} - } + if (x->gl_list) + { + for (y = x->gl_list; y; y = y->g_next) + if (ob = pd_checkobject(&y->g_pd)) + rtext_free(glist_findrtext(x, ob)); + } + //if (x->gl_editor) { + editor_free(x->gl_editor, x); + x->gl_editor = 0; + //} + } } void canvas_reflecttitle(t_canvas *x); @@ -2203,10 +2398,10 @@ void canvas_map(t_canvas *x, t_floatarg f); void canvas_vis(t_canvas *x, t_floatarg f) { - //fprintf(stderr,"canvas_vis .x%lx %f\n", (t_int)x, f); + //fprintf(stderr,"canvas_vis .x%lx %f\n", (t_int)x, f); - t_gobj *g; - t_int properties; + t_gobj *g; + t_int properties; int flag = (f != 0); if (flag) @@ -2217,21 +2412,21 @@ void canvas_vis(t_canvas *x, t_floatarg f) * so its ok to run it on a canvas that already has a gl_editor. */ if (x->gl_editor && x->gl_havewindow && glist_isvisible(x)) { /* just put us in front */ - //fprintf(stderr,"existing\n"); + //fprintf(stderr,"existing\n"); sys_vgui("raise .x%lx\n", x); - sys_vgui("focus .x%lx.c\n", x); + sys_vgui("focus .x%lx.c\n", x); sys_vgui("wm deiconify .x%lx\n", x); } else { - //fprintf(stderr,"new\n"); + //fprintf(stderr,"new\n"); canvas_create_editor(x); sys_vgui("pdtk_canvas_new .x%lx %d %d +%d+%d %d\n", x, (int)(x->gl_screenx2 - x->gl_screenx1), (int)(x->gl_screeny2 - x->gl_screeny1), (int)(x->gl_screenx1), (int)(x->gl_screeny1), x->gl_edit); - sys_vgui("pdtk_canvas_set_font .x%lx %d\n", x, x->gl_font); + sys_vgui("pdtk_canvas_set_font .x%lx %d\n", x, x->gl_font); canvas_reflecttitle(x); x->gl_havewindow = 1; @@ -2239,60 +2434,60 @@ void canvas_vis(t_canvas *x, t_floatarg f) // if so, make it non-scrollable //t_gobj *g = x->gl_list; //if (g && (pd_class(&g->g_pd) == garray_class) - // sys_vgui("pdtk_canvas_set_scrollless .x%lx\n", x); + // sys_vgui("pdtk_canvas_set_scrollless .x%lx\n", x); //else - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); /* - //newly opened arrays created prior to pd-l2ork require fittograph - t_gobj *g, *gg = NULL; - t_garray *ga = NULL; - t_array *a = NULL; - int num_elem = 0; - t_text *t = NULL; - int objnamesize; - char *objname; - - for (g = x->gl_list; g; g = g->g_next) { - //fprintf(stderr, "searching\n"); - - //for subpatch garrays - if (pd_class(&g->g_pd) == garray_class) { - //fprintf(stderr,"found ya\n"); - ga = (t_garray *)g; - if (ga) { - a = garray_getarray(ga); - num_elem = a->a_n; - garray_fittograph(ga, num_elem); - } - } - //for garrays in gop inside a newly opened patch window - else { - t_text *t = (t_text *)g; - t_rtext *y = glist_findrtext(x, t); - if (y) { - rtext_gettext(y, &objname, &objnamesize); - //fprintf(stderr,"objname %s\n", objname); - if (!strcmp(objname, "graph ")) { - //fprintf(stderr,"got a graph\n"); - for (gg = ((t_glist *)g)->gl_list; gg; gg = gg->g_next) { - //fprintf(stderr, "sub-searching\n"); - if (pd_class(&gg->g_pd) == garray_class) { - //fprintf(stderr,"sub found ya\n"); - ga = (t_garray *)gg; - if (ga) { - a = garray_getarray(ga); - num_elem = a->a_n; - garray_fittograph(ga, num_elem); - canvas_dirty(x, 2); - } - } - } - } - //else fprintf(stderr,"fail %d >%s< >graph<\n", strcmp(objname, "graph"), objname); - } - } - } + //newly opened arrays created prior to pd-l2ork require fittograph + t_gobj *g, *gg = NULL; + t_garray *ga = NULL; + t_array *a = NULL; + int num_elem = 0; + t_text *t = NULL; + int objnamesize; + char *objname; + + for (g = x->gl_list; g; g = g->g_next) { + //fprintf(stderr, "searching\n"); + + //for subpatch garrays + if (pd_class(&g->g_pd) == garray_class) { + //fprintf(stderr,"found ya\n"); + ga = (t_garray *)g; + if (ga) { + a = garray_getarray(ga); + num_elem = a->a_n; + garray_fittograph(ga, num_elem); + } + } + //for garrays in gop inside a newly opened patch window + else { + t_text *t = (t_text *)g; + t_rtext *y = glist_findrtext(x, t); + if (y) { + rtext_gettext(y, &objname, &objnamesize); + //fprintf(stderr,"objname %s\n", objname); + if (!strcmp(objname, "graph ")) { + //fprintf(stderr,"got a graph\n"); + for (gg = ((t_glist *)g)->gl_list; gg; gg = gg->g_next) { + //fprintf(stderr, "sub-searching\n"); + if (pd_class(&gg->g_pd) == garray_class) { + //fprintf(stderr,"sub found ya\n"); + ga = (t_garray *)gg; + if (ga) { + a = garray_getarray(ga); + num_elem = a->a_n; + garray_fittograph(ga, num_elem); + canvas_dirty(x, 2); + } + } + } + } + //else fprintf(stderr,"fail %d >%s< >graph<\n", strcmp(objname, "graph"), objname); + } + } + } */ canvas_updatewindowlist(); } @@ -2318,27 +2513,31 @@ void canvas_vis(t_canvas *x, t_floatarg f) canvas_map(x, 0); canvas_destroy_editor(x); sys_vgui("destroy .x%lx\n", x); - // delete properties windows of objects in the patcher we're closing - g = x->gl_list; - while (g) { - properties = gfxstub_haveproperties((void *)g); - if (properties) { - //sys_vgui("destroy .gfxstub%lx\n", properties); - gfxstub_deleteforkey((void *)g); - } - g = g->g_next; - } - // now check if canvas has its properties open and - // if the canvas is not gop-enabled or its parent is not visible - // close its properties - if (!x->gl_isgraph || x->gl_owner && !glist_isvisible(x->gl_owner)) { - properties = gfxstub_haveproperties((void *)x); - if (properties) { - //sys_vgui("destroy .gfxstub%lx\n", properties); - gfxstub_deleteforkey((void *)x); - } - } - + // delete properties windows of objects in the patcher we're closing + g = x->gl_list; + while (g) + { + properties = gfxstub_haveproperties((void *)g); + if (properties) + { + //sys_vgui("destroy .gfxstub%lx\n", properties); + gfxstub_deleteforkey((void *)g); + } + g = g->g_next; + } + // now check if canvas has its properties open and + // if the canvas is not gop-enabled or its parent is not visible + // close its properties + if (!x->gl_isgraph || x->gl_owner && !glist_isvisible(x->gl_owner)) + { + properties = gfxstub_haveproperties((void *)x); + if (properties) + { + //sys_vgui("destroy .gfxstub%lx\n", properties); + gfxstub_deleteforkey((void *)x); + } + } + for (i = 1, x2 = x; x2; x2 = x2->gl_next, i++) ; //sys_vgui(".mbar.find delete %d\n", i); @@ -2362,7 +2561,7 @@ void canvas_vis(t_canvas *x, t_floatarg f) any missing paramters and redraw things if necessary. */ void canvas_setgraph(t_glist *x, int flag, int nogoprect) { - //fprintf(stderr,"flag=%d\n",flag); + //fprintf(stderr,"flag=%d\n",flag); if (!flag && glist_isgraph(x)) { int hadeditor = (x->gl_editor != 0); @@ -2371,13 +2570,13 @@ void canvas_setgraph(t_glist *x, int flag, int nogoprect) if (hadeditor && !glist_isvisible(x)) canvas_destroy_editor(x); x->gl_isgraph = 0; - x->gl_hidetext = 0; + x->gl_hidetext = 0; if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner)) { gobj_vis(&x->gl_gobj, x->gl_owner, 1); canvas_fixlinesfor(x->gl_owner, &x->gl_obj); } - x->gl_goprect = 0; + x->gl_goprect = 0; } else if (flag) { @@ -2388,30 +2587,33 @@ void canvas_setgraph(t_glist *x, int flag, int nogoprect) x->gl_pixheight = GLIST_DEFGRAPHHEIGHT; if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner)) - { + { gobj_vis(&x->gl_gobj, x->gl_owner, 0); - } + } x->gl_isgraph = 1; x->gl_hidetext = !(!(flag&2)); - // check if we have array inside GOP, if so, make sure hidetext is always hidden no matter what - t_gobj *g = x->gl_list; - int hasarray = 0; - while (g) { - if (pd_class(&g->g_pd) == garray_class) hasarray = 1; - g = g->g_next; - } - if (hasarray) x->gl_hidetext = 1; + // check if we have array inside GOP, if so, + // make sure hidetext is always hidden no matter what + t_gobj *g = x->gl_list; + int hasarray = 0; + while (g) + { + if (pd_class(&g->g_pd) == garray_class) hasarray = 1; + g = g->g_next; + } + if (hasarray) x->gl_hidetext = 1; if (!nogoprect && !x->gl_goprect && !hasarray) { - // Ivica Ico Bukvic 5/16/10 <ico@bukvic.net> - // this draws gop immediately when enabled - x->gl_goprect = 1; + // Ivica Ico Bukvic 5/16/10 <ico@bukvic.net> + // this draws gop immediately when enabled + x->gl_goprect = 1; } - if (glist_isvisible(x) && x->gl_goprect) { + if (glist_isvisible(x) && x->gl_goprect) + { glist_redraw(x); - } + } if (x->gl_owner && !x->gl_loading && glist_isvisible(x->gl_owner)) { gobj_vis(&x->gl_gobj, x->gl_owner, 1); @@ -2457,13 +2659,13 @@ static void canvas_donecanvasdialog(t_glist *x, t_symbol *s, int argc, t_atom *argv) { t_float xperpix, yperpix, x1, y1, x2, y2, xpix, ypix, xmargin, ymargin; - int rx1=0, ry1=0, rx2=0, ry2=0; //for getrect + int rx1=0, ry1=0, rx2=0, ry2=0; //for getrect int graphme, redraw = 0; xperpix = atom_getfloatarg(0, argc, argv); yperpix = atom_getfloatarg(1, argc, argv); graphme = (int)(atom_getfloatarg(2, argc, argv)); - //fprintf(stderr,"graphme=%d\n", graphme); + //fprintf(stderr,"graphme=%d\n", graphme); x1 = atom_getfloatarg(3, argc, argv); y1 = atom_getfloatarg(4, argc, argv); x2 = atom_getfloatarg(5, argc, argv); @@ -2473,18 +2675,21 @@ static void canvas_donecanvasdialog(t_glist *x, xmargin = atom_getfloatarg(9, argc, argv); ymargin = atom_getfloatarg(10, argc, argv); - /* parent windows are treated differently than applies to individual objects */ - if (glist_getcanvas(x) != x && !canvas_isabstraction(x)) { - canvas_apply_setundo(glist_getcanvas(x), (t_gobj *)x); - } - else /*if (x1!=x->gl_x1 || x2!=x->gl_x2 || y1!=x->gl_y1 || y2!=x->gl_y2 || - graphme!=(x->gl_isgraph+2*x->gl_hidetext) || x->gl_pixwidth!=xpix || - x->gl_pixheight!=ypix || x->gl_xmargin!=xmargin || x->gl_ymargin!=ymargin) {*/ - { - //canvas_canvas_setundo(x); - canvas_undo_add(x, 8, "apply", canvas_undo_set_canvas(x)); - //fprintf(stderr,"canvas_apply_undo\n"); - } + /* parent windows are treated differently than applies to + individual objects */ + if (glist_getcanvas(x) != x && !canvas_isabstraction(x)) + { + canvas_apply_setundo(glist_getcanvas(x), (t_gobj *)x); + } + else /*if (x1!=x->gl_x1 || x2!=x->gl_x2 || y1!=x->gl_y1 || y2!=x->gl_y2 || + graphme!=(x->gl_isgraph+2*x->gl_hidetext) || + x->gl_pixwidth!=xpix || x->gl_pixheight!=ypix || + x->gl_xmargin!=xmargin || x->gl_ymargin!=ymargin) {*/ + { + //canvas_canvas_setundo(x); + canvas_undo_add(x, 8, "apply", canvas_undo_set_canvas(x)); + //fprintf(stderr,"canvas_apply_undo\n"); + } x->gl_pixwidth = xpix; x->gl_pixheight = ypix; @@ -2497,16 +2702,20 @@ static void canvas_donecanvasdialog(t_glist *x, if (yperpix == 0) yperpix = 1; - // check if we have array inside GOP, if so, make sure GOP/hidetext is always enabled no matter what + // check if we have array inside GOP, if so, + // make sure GOP/hidetext is always enabled no matter what t_gobj *g = x->gl_list; int hasarray = 0; - while (g) { - if (pd_class(&g->g_pd) == garray_class) hasarray = 1; - g = g->g_next; + while (g) + { + if (pd_class(&g->g_pd) == garray_class) hasarray = 1; + g = g->g_next; } - if (hasarray && graphme != 3) { - graphme = 3; //gop flag + bit-shifted hidetext - post("Array graphs cannot have their 'graph on parent' or 'hide object name and arguments' options disabled"); + if (hasarray && graphme != 3) + { + graphme = 3; //gop flag + bit-shifted hidetext + post("Array graphs cannot have their 'graph on parent' " + "or 'hide object name and arguments' options disabled"); } if (graphme) @@ -2548,174 +2757,193 @@ static void canvas_donecanvasdialog(t_glist *x, canvas_setgraph(x, graphme, 0); canvas_dirty(x, 1); - // make sure gop is never smaller than its text - // if one wants smaller gop window, make sure to disable text - if (x->gl_isgraph && !x->gl_hidetext && x->gl_owner) { - //fprintf(stderr, "check size\n"); - gobj_getrect((t_gobj*)x, x->gl_owner, &rx1, &ry1, &rx2, &ry2); - //fprintf(stderr,"%d %d %d %d\n", rx1, rx2, ry1, ry2); - if (rx2-rx1 > x->gl_pixwidth) { - x->gl_pixwidth = rx2-rx1; - //fprintf(stderr,"change width\n"); - } - if (ry2-ry1 > x->gl_pixheight) { - x->gl_pixheight = ry2-ry1; - //fprintf(stderr,"change height\n"); - } - } - - if (x->gl_havewindow) { - //fprintf(stderr,"donecanvasdialog canvas_redraw\n"); + // make sure gop is never smaller than its text + // if one wants smaller gop window, make sure to disable text + if (x->gl_isgraph && !x->gl_hidetext && x->gl_owner) + { + //fprintf(stderr, "check size\n"); + gobj_getrect((t_gobj*)x, x->gl_owner, &rx1, &ry1, &rx2, &ry2); + //fprintf(stderr,"%d %d %d %d\n", rx1, rx2, ry1, ry2); + if (rx2-rx1 > x->gl_pixwidth) + { + x->gl_pixwidth = rx2-rx1; + //fprintf(stderr,"change width\n"); + } + if (ry2-ry1 > x->gl_pixheight) + { + x->gl_pixheight = ry2-ry1; + //fprintf(stderr,"change height\n"); + } + } + + if (x->gl_havewindow) + { + //fprintf(stderr,"donecanvasdialog canvas_redraw\n"); canvas_redraw(x); - } + } else if (x->gl_owner && glist_isvisible(x->gl_owner)) { - glist_noselect(x); + glist_noselect(x); gobj_vis(&x->gl_gobj, x->gl_owner, 0); gobj_vis(&x->gl_gobj, x->gl_owner, 1); - canvas_redraw(x->gl_owner); + canvas_redraw(x->gl_owner); } - //ico@bukvic.net 100518 update scrollbars when GOP potentially exceeds window size + // ico@bukvic.net 100518 update scrollbars when + // GOP potentially exceeds window size t_canvas *canvas=(t_canvas *)glist_getcanvas(x); - //if gop is being disabled go one level up (if u can) - if (!graphme && canvas->gl_owner) canvas=canvas->gl_owner; - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", (t_int)canvas); + //if gop is being disabled go one level up (if u can) + if (!graphme && canvas->gl_owner) canvas=canvas->gl_owner; + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", (t_int)canvas); } /* called by undo/redo arrange and done_canvas_popup. only done_canvas_popup checks if it is a valid action and activates undo option */ -static void canvas_doarrange(t_canvas *x, t_float which, t_gobj *oldy, t_gobj *oldy_prev, t_gobj *oldy_next) -{ - t_gobj *y_begin = x->gl_list; - t_gobj *y_end = glist_nth(x, glist_getindex(x,0) - 1); - - if (which == 3) /* to front */ - { - //put the object at the end of the cue - y_end->g_next = oldy; - oldy->g_next = NULL; - - // now fix links in the hole made in the list due to moving of the oldy - // (we know there is oldy_next as y_end != oldy in canvas_done_popup) - if (oldy_prev) //there is indeed more before the oldy position - oldy_prev->g_next = oldy_next; - else x->gl_list = oldy_next; - - // and finally redraw - //fprintf(stderr,"raise\n"); - sys_vgui(".x%lx.c raise selected\n", x); - sys_vgui(".x%lx.c raise all_cords\n", x); - } - if (which == 4) /* to back */ - { - x->gl_list = oldy; //put it to the beginning of the cue - oldy->g_next = y_begin; //make it point to the old beginning - - // now fix links in the hole made in the list due to moving of the oldy - // (we know there is oldy_prev as y_begin != oldy in canvas_done_popup) - if (oldy_next) //there is indeed more after oldy position - oldy_prev->g_next = oldy_next; - else oldy_prev->g_next = NULL; //oldy was the last in the cue - - // and finally redraw - //fprintf(stderr,"lower\n"); - sys_vgui(".x%lx.c lower selected\n", x); - //canvas_redraw(x); - } - canvas_dirty(x, 1); - glob_preset_node_list_check_loc_and_update(); +static void canvas_doarrange(t_canvas *x, t_float which, t_gobj *oldy, + t_gobj *oldy_prev, t_gobj *oldy_next) +{ + t_gobj *y_begin = x->gl_list; + t_gobj *y_end = glist_nth(x, glist_getindex(x,0) - 1); + + if (which == 3) /* to front */ + { + //put the object at the end of the cue + y_end->g_next = oldy; + oldy->g_next = NULL; + + // now fix links in the hole made in the list due to moving of the oldy + // (we know there is oldy_next as y_end != oldy in canvas_done_popup) + if (oldy_prev) //there is indeed more before the oldy position + oldy_prev->g_next = oldy_next; + else x->gl_list = oldy_next; + + // and finally redraw + //fprintf(stderr,"raise\n"); + sys_vgui(".x%lx.c raise selected\n", x); + sys_vgui(".x%lx.c raise all_cords\n", x); + } + if (which == 4) /* to back */ + { + x->gl_list = oldy; //put it to the beginning of the cue + oldy->g_next = y_begin; //make it point to the old beginning + + // now fix links in the hole made in the list due to moving of the oldy + // (we know there is oldy_prev as y_begin != oldy in canvas_done_popup) + if (oldy_next) //there is indeed more after oldy position + oldy_prev->g_next = oldy_next; + else oldy_prev->g_next = NULL; //oldy was the last in the cue + + // and finally redraw + //fprintf(stderr,"lower\n"); + sys_vgui(".x%lx.c lower selected\n", x); + //canvas_redraw(x); + } + canvas_dirty(x, 1); + glob_preset_node_list_check_loc_and_update(); } /* called from the gui when a popup menu comes back with "properties," "open," or "help." */ - /* Ivica Ico Bukvic <ico@bukvic.net> 2010-11-17 - also added "To Front" and "To Back" */ -static void canvas_done_popup(t_canvas *x, t_float which, t_float xpos, t_float ypos) + /* Ivica Ico Bukvic <ico@bukvic.net> 2010-11-17 + also added "To Front" and "To Back" */ +static void canvas_done_popup(t_canvas *x, t_float which, t_float xpos, + t_float ypos) { - //fprintf(stderr,"canvas_done_pupup %lx\n", (t_int)x); + //fprintf(stderr,"canvas_done_pupup %lx\n", (t_int)x); char pathbuf[FILENAME_MAX], namebuf[FILENAME_MAX]; - t_gobj *y=NULL, *oldy=NULL, *oldy_prev=NULL, *oldy_next=NULL, *y_begin, *y_end=NULL; - int x1, y1, x2, y2; - - // first deselect any objects that may be already selected if doing action 3 or 4 - if (which == 3 || which == 4) { - if (x->gl_editor->e_selection && x->gl_editor->e_selection->sel_next) - glist_noselect(x); - } - else glist_noselect(x); - - // mark the beginning of the glist for front/back - y_begin = x->gl_list; - - t_gobj *yclick = NULL; - - ///if (which == 3 || which == 4) { - // if no object has been selected for to-front/back action - if (!x->gl_editor->e_selection) { - //fprintf(stderr,"doing hitbox\n"); - for (y = x->gl_list; y; y = y->g_next) { - if (canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2)) { - yclick = y; - } - } - if (yclick) { - y = yclick; - if (!x->gl_edit) - canvas_editmode(x, 1); - if (!glist_isselected(x, y)) - glist_select(x, y); - } - } - //} - - // this was a bogus/unsupported call for tofront/back--get me out of here! - // we don't have to check for multiple objects being selected since we did noselect - // above explicitly for cases 3 and 4 when detecting more than one selected object - if ((which == 3 || which == 4) && !x->gl_editor->e_selection) { - post("Popup action could not be performed because no object was found under the cursor..."); - return; - } - + t_gobj *y=NULL, *oldy=NULL, *oldy_prev=NULL, *oldy_next=NULL, + *y_begin, *y_end=NULL; + int x1, y1, x2, y2; + + // first deselect any objects that may be already selected + // if doing action 3 or 4 + if (which == 3 || which == 4) + { + if (x->gl_editor->e_selection && x->gl_editor->e_selection->sel_next) + glist_noselect(x); + } + else glist_noselect(x); + + // mark the beginning of the glist for front/back + y_begin = x->gl_list; + + t_gobj *yclick = NULL; + + ///if (which == 3 || which == 4) { + // if no object has been selected for to-front/back action + if (!x->gl_editor->e_selection) + { + //fprintf(stderr,"doing hitbox\n"); + for (y = x->gl_list; y; y = y->g_next) + { + if (canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2)) + { + yclick = y; + } + } + if (yclick) + { + y = yclick; + if (!x->gl_edit) + canvas_editmode(x, 1); + if (!glist_isselected(x, y)) + glist_select(x, y); + } + } + //} + + // this was a bogus/unsupported call for tofront/back--get me out of here! + // we don't have to check for multiple objects being selected since we + // did noselect above explicitly for cases 3 and 4 when detecting + // more than one selected object + if ((which == 3 || which == 4) && !x->gl_editor->e_selection) + { + post("Popup action could not be performed because no object " + "was found under the cursor..."); + return; + } + for (y = x->gl_list; y; y = y->g_next) { - if (which == 3 || which == 4) /* to-front or to-back */ - { - if (!x->gl_edit) - canvas_editmode(x, 1); - - // if next one is the one selected for moving - if (y->g_next && glist_isselected(x, y->g_next)) { - oldy_prev = y; - oldy = y->g_next; - //if there is more after the selected object - if (oldy->g_next) - oldy_next = oldy->g_next; - } - else if (glist_isselected(x, y) && oldy == NULL) { - //selected obj is the first in the cue - oldy = y; - if (y->g_next) - oldy_next = y->g_next; - } - } + if (which == 3 || which == 4) /* to-front or to-back */ + { + if (!x->gl_edit) + canvas_editmode(x, 1); + + // if next one is the one selected for moving + if (y->g_next && glist_isselected(x, y->g_next)) + { + oldy_prev = y; + oldy = y->g_next; + //if there is more after the selected object + if (oldy->g_next) + oldy_next = oldy->g_next; + } + else if (glist_isselected(x, y) && oldy == NULL) + { + //selected obj is the first in the cue + oldy = y; + if (y->g_next) + oldy_next = y->g_next; + } + } else if (glist_isselected(x, y)) { if (which == 0) /* properties */ { if (!class_getpropertiesfn(pd_class(&y->g_pd))) continue; - else { - if (!x->gl_edit) - canvas_editmode(x, 1); - //if (!glist_isselected(x, y)) - // glist_select(x, y); - (*class_getpropertiesfn(pd_class(&y->g_pd)))(y, x); - return; - } + else { + if (!x->gl_edit) + canvas_editmode(x, 1); + //if (!glist_isselected(x, y)) + // glist_select(x, y); + (*class_getpropertiesfn(pd_class(&y->g_pd)))(y, x); + return; + } } else if (which == 1) /* open */ { - //fprintf(stderr,"OPEN\n"); + //fprintf(stderr,"OPEN\n"); if (!zgetfn(&y->g_pd, gensym("menu-open"))) continue; vmess(&y->g_pd, gensym("menu-open"), ""); @@ -2749,29 +2977,30 @@ static void canvas_done_popup(t_canvas *x, t_float which, t_float xpos, t_float } } - y_end = glist_nth(x, glist_getindex(x,0) - 1); + y_end = glist_nth(x, glist_getindex(x,0) - 1); - if (which == 3 && y_end != oldy) /* to front */ - { - /* create appropriate undo action */ - //canvas_arrange_setundo(x, oldy, 1); - canvas_undo_add(x, 7, "arrange", canvas_undo_set_arrange(x, oldy, 1)); + if (which == 3 && y_end != oldy) /* to front */ + { + /* create appropriate undo action */ + //canvas_arrange_setundo(x, oldy, 1); + canvas_undo_add(x, 7, "arrange", canvas_undo_set_arrange(x, oldy, 1)); - canvas_doarrange(x, which, oldy, oldy_prev, oldy_next); - } - if (which == 4 && y_begin != oldy) /* to back */ - { - /* create appropriate undo action */ - //canvas_arrange_setundo(x, oldy, 0); - canvas_undo_add(x, 7, "arrange", canvas_undo_set_arrange(x, oldy, 0)); + canvas_doarrange(x, which, oldy, oldy_prev, oldy_next); + } + if (which == 4 && y_begin != oldy) /* to back */ + { + /* create appropriate undo action */ + //canvas_arrange_setundo(x, oldy, 0); + canvas_undo_add(x, 7, "arrange", canvas_undo_set_arrange(x, oldy, 0)); - canvas_doarrange(x, which, oldy, oldy_prev, oldy_next); - } - if (which == 0) { - if (!x->gl_edit) - canvas_editmode(x, 1); + canvas_doarrange(x, which, oldy, oldy_prev, oldy_next); + } + if (which == 0) + { + if (!x->gl_edit) + canvas_editmode(x, 1); canvas_properties(x); - } + } else if (which == 2) open_via_helppath("intro.pd", canvas_getdir((t_canvas *)x)->s_name); } @@ -2790,19 +3019,20 @@ static int canvas_upx, canvas_upy; void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, int mod, int doit) { - /* here we make global array_garray pointer defined in g_canvas.h - point back to nothing--we use this pointer to pass information - to array_motion so that we can update corresponding send when - the array has been changed */ - array_garray = NULL; + /* here we make global array_garray pointer defined in g_canvas.h + point back to nothing--we use this pointer to pass information + to array_motion so that we can update corresponding send when + the array has been changed */ + array_garray = NULL; t_gobj *y; int shiftmod, runmode, altmod, doublemod = 0, rightclick; int x1=0, y1=0, x2=0, y2=0, clickreturned = 0; - t_gobj *yclick = NULL; - t_object *ob; + t_gobj *yclick = NULL; + t_object *ob; - //fprintf(stderr,"MAIN canvas_doclick %d %d %d %d %d\n", xpos, ypos, which, mod, doit); + //fprintf(stderr,"MAIN canvas_doclick %d %d %d %d %d\n", + // xpos, ypos, which, mod, doit); if (!x->gl_editor) { @@ -2810,26 +3040,29 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, return; } - // remove stale tooltips, if any - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } + // remove stale tooltips, if any + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } - // read key and mouse button states + // read key and mouse button states shiftmod = (mod & SHIFTMOD); runmode = ((mod & CTRLMOD) || (!x->gl_edit)); altmod = (mod & ALTMOD); rightclick = (mod & RIGHTCLICK); - // set global left mouse click variable - if (!rightclick) glob_lmclick = doit; + // set global left mouse click variable + if (!rightclick) glob_lmclick = doit; - // return if user is connecting and holding shift (for multiconnect) - if (x->gl_editor->e_onmotion == MA_CONNECT && glob_shift) { - //fprintf(stderr,"MA_CONNECT + glob_shift--> mouse_doclick returning\n"); - return; - } + // return if user is connecting and holding shift (for multiconnect) + if (x->gl_editor->e_onmotion == MA_CONNECT && glob_shift) + { + //fprintf(stderr, + // "MA_CONNECT + glob_shift--> mouse_doclick returning\n"); + return; + } canvas_undo_already_set_move = 0; @@ -2844,64 +3077,75 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, sys_getrealtime() - canvas_upclicktime < DCLICKINTERVAL) doublemod = 1; x->gl_editor->e_lastmoved = 0; - // this was temporarily commented out on 5-23-2013 while fixing shift+click actions - // most likely I forgot to reenable it -- need to check for any regressions as this is - // needed to re-check scrollbar after something was created->startmotion->clicked to let go + /* this was temporarily commented out on 5-23-2013 while fixing + shift+click actions most likely I forgot to reenable it -- need + to check for any regressions as this is needed to re-check + scrollbar after something was created->startmotion->clicked + to let go */ if (doit) { - //fprintf(stderr,"doit %d\n", x->gl_editor->e_onmotion); - if (x->gl_editor->e_onmotion == MA_MOVE) { - //fprintf(stderr,"letting go of objects\n"); - sys_vgui(".x%lx.c raise all_cords\n", x); - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); - } - if (x->gl_editor->e_onmotion != MA_SCROLL) { - x->gl_editor->e_grab = 0; - x->gl_editor->e_onmotion = MA_NONE; - } + //fprintf(stderr,"doit %d\n", x->gl_editor->e_onmotion); + if (x->gl_editor->e_onmotion == MA_MOVE) + { + //fprintf(stderr,"letting go of objects\n"); + sys_vgui(".x%lx.c raise all_cords\n", x); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + } + if (x->gl_editor->e_onmotion != MA_SCROLL) + { + x->gl_editor->e_grab = 0; + x->gl_editor->e_onmotion = MA_NONE; + } } //post("click %d %d %d %d", xpos, ypos, which, mod); - if (x->gl_editor->e_onmotion != MA_NONE) { - //fprintf(stderr,"onmotion != MA_NONE\n"); + if (x->gl_editor->e_onmotion != MA_NONE) + { + //fprintf(stderr,"onmotion != MA_NONE\n"); return; - } + } x->gl_editor->e_xwas = xpos; x->gl_editor->e_ywas = ypos; - //fprintf(stderr,"mouse %d %d\n", xpos, ypos); + //fprintf(stderr,"mouse %d %d\n", xpos, ypos); - // if we are in runmode and it is not middle- or right-click + // if we are in runmode and it is not middle- or right-click if (runmode && !rightclick) { - //fprintf(stderr, "runmode && !rightclick\n"); + //fprintf(stderr, "runmode && !rightclick\n"); for (y = x->gl_list; y; y = y->g_next) { - // check if the object wants to be clicked (we pick the topmost clickable) - if (canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2)) { + // check if the object wants to be clicked + // (we pick the topmost clickable) + if (canvas_hitbox(x, y, xpos, ypos, &x1, &y1, &x2, &y2)) + { ob = pd_checkobject(&y->g_pd); - if (!ob || ob->te_type != T_TEXT) // do not give clicks to comments during runtime - yclick = y; - //fprintf(stderr," MAIN found clickable %d\n", clickreturned); - } - } - if (yclick) { - clickreturned = gobj_click(yclick, x, xpos, ypos, - shiftmod, ((mod & CTRLMOD) && (!x->gl_edit)) || altmod, - 0, doit); - //fprintf(stderr, " MAIN clicking\n"); - } - // if we are not clicking + /* do not give clicks to comments during runtime */ + if (!ob || ob->te_type != T_TEXT) + yclick = y; + //fprintf(stderr," MAIN found clickable %d\n", + // clickreturned); + } + } + if (yclick) + { + clickreturned = gobj_click(yclick, x, xpos, ypos, + shiftmod, ((mod & CTRLMOD) && (!x->gl_edit)) || altmod, + 0, doit); + //fprintf(stderr, " MAIN clicking\n"); + } + // if we are not clicking if (!doit) { - //fprintf(stderr, " MAIN not clicking\n"); - if (yclick) { - //fprintf(stderr, " MAIN cursor %d\n", clickreturned); + //fprintf(stderr, " MAIN not clicking\n"); + if (yclick) + { + //fprintf(stderr, " MAIN cursor %d\n", clickreturned); canvas_setcursor(x, clickreturned); - } + } else { - //fprintf(stderr, " MAIN cursor\n"); - canvas_setcursor(x, CURSOR_RUNMODE_NOTHING); + //fprintf(stderr, " MAIN cursor\n"); + canvas_setcursor(x, CURSOR_RUNMODE_NOTHING); } } return; @@ -2915,7 +3159,7 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, canvas_rightclick(x, xpos, ypos, y); else if (shiftmod && x->gl_editor->canvas_cnct_outlet_tag[0] == 0) { - //selection (only if we are not hovering above an outlet) + //selection (only if we are not hovering above an outlet) if (doit) { t_rtext *rt; @@ -2929,23 +3173,24 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, } else { - //t_undo_redo_sel *buf = (t_undo_redo_sel *)getbytes(sizeof(*buf)); - //buf->u_undo = (t_undo_sel *)canvas_undo_set_selection(x); + //t_undo_redo_sel *buf = + // (t_undo_redo_sel *)getbytes(sizeof(*buf)); + //buf->u_undo = (t_undo_sel *)canvas_undo_set_selection(x); if (glist_isselected(x, y)) glist_deselect(x, y); else glist_select(x, y); - //buf->u_redo = (t_undo_sel *)canvas_undo_set_selection(x); - //canvas_undo_add(x, 11, "selection", buf); + //buf->u_redo = (t_undo_sel *)canvas_undo_set_selection(x); + //canvas_undo_add(x, 11, "selection", buf); } } } else { - /* look for an outlet we just clicked onto */ + /* look for an outlet we just clicked onto */ int noutlet; - int ninlet; + int ninlet; /* resize? only for "true" text boxes or canvases*/ if (!sys_k12_mode && ob && !x->gl_editor->e_textedfor && (ob->te_pd->c_wb == &text_widgetbehavior || @@ -2964,17 +3209,27 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, x->gl_editor->e_ywas = y1; x->gl_editor->e_xnew = xpos; x->gl_editor->e_ynew = ypos; - canvas_undo_add(x, 6, "resize", canvas_undo_set_apply(x, glist_getindex(x, y))); + canvas_undo_add(x, 6, "resize", + canvas_undo_set_apply(x, glist_getindex(x, y))); } - else { - if (ob->ob_pd != canvas_class || !((t_canvas *)ob)->gl_isgraph) - canvas_setcursor(x, CURSOR_EDITMODE_RESIZE); - else canvas_setcursor(x, CURSOR_EDITMODE_RESIZE_BOTTOM_RIGHT); - canvas_check_nlet_highlights(x); - } + else + { + if (ob->ob_pd != canvas_class || + !((t_canvas *)ob)->gl_isgraph) + { + canvas_setcursor(x, CURSOR_EDITMODE_RESIZE); + } + else + { + canvas_setcursor(x, + CURSOR_EDITMODE_RESIZE_BOTTOM_RIGHT); + } + canvas_check_nlet_highlights(x); + } } /* look for an outlet */ - // if object is valid, has outlets, and we are within the bottom area of an object + // if object is valid, has outlets, + // and we are within the bottom area of an object else if (ob && (noutlet = obj_noutlets(ob)) && ypos >= y2-4) { int width = x2 - x1; @@ -2982,83 +3237,112 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, int closest = ((xpos-x1) * (nout1) + width/2)/width; int hotspot = x1 + (width - IOWIDTH) * closest / (nout1); - // if we are within the boundaries of an nlet + // if we are within the boundaries of an nlet if (closest < noutlet && xpos >= (hotspot-1) && xpos <= hotspot + (IOWIDTH+1)) { if (doit) { - //fprintf(stderr,"start connection\n"); + //fprintf(stderr,"start connection\n"); int issignal = obj_issignaloutlet(ob, closest); x->gl_editor->e_onmotion = MA_CONNECT; x->gl_editor->e_xwas = xpos; x->gl_editor->e_ywas = ypos; sys_vgui( - /*".x%lx.c create polyline %d %d %d %d -stroke %s -strokewidth %s -tags x\n", - x, xpos, ypos, xpos, ypos, - (issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)"), - (issignal ? "$pd_colors(signal_cord_width)" : "$pd_colors(control_cord_width)"));*/ - // bezier is too slow for the time being - ".x%lx.c create path \"M %d %d Q %d %d %d %d Q %d %d %d %d\" -stroke %s -strokewidth %s -tags {x all_cords %s}\n", - x, xpos, ypos, xpos, ypos, xpos, ypos, xpos, ypos, xpos, ypos, - (issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)"), - (issignal ? "$pd_colors(signal_cord_width)" : "$pd_colors(control_cord_width)"), - (issignal ? "signal" : "control")); + /*".x%lx.c create polyline %d %d %d %d " + "-stroke %s -strokewidth %s -tags x\n", + x, xpos, ypos, xpos, ypos, + (issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)"), + (issignal ? + "$pd_colors(signal_cord_width)" : + "$pd_colors(control_cord_width)"));*/ + // bezier is too slow for the time being + ".x%lx.c create path " + "\"M %d %d Q %d %d %d %d Q %d %d %d %d\" " + "-stroke %s -strokewidth %s " + "-tags {x all_cords %s}\n", + x, xpos, ypos, + xpos, ypos, xpos, ypos, + xpos, ypos, xpos, ypos, + (issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)"), + (issignal ? + "$pd_colors(signal_cord_width)" : + "$pd_colors(control_cord_width)"), + (issignal ? "signal" : "control")); } - else + else // jsarlo { - t_rtext *yr = glist_findrtext(x, (t_text *)&ob->ob_g); + t_rtext *yr = glist_findrtext(x, (t_text *)&ob->ob_g); if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0) { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_outlet_tag, - (last_outlet_filter ? "black" : (outlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (outlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); + sys_vgui(".x%x.c itemconfigure %s " + "-stroke %s -fill %s -strokewidth 1\n", + x, x->gl_editor->canvas_cnct_outlet_tag, + (last_outlet_filter ? + "black" : (outlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (outlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); } if (yr) { - last_outlet_filter = gobj_filter_highlight_behavior((t_text *)&ob->ob_g); - //fprintf(stderr,"last_outlet_filter == %d\n", last_outlet_filter); + last_outlet_filter = + gobj_filter_highlight_behavior( + (t_text *)&ob->ob_g); + //fprintf(stderr,"last_outlet_filter == %d\n", + // last_outlet_filter); sprintf(x->gl_editor->canvas_cnct_outlet_tag, - "%so%d", - rtext_gettag(yr), - closest); - sys_vgui(".x%x.c itemconfigure %s -stroke $select_nlet_color -strokewidth $highlight_width\n", + "%so%d", rtext_gettag(yr), closest); + sys_vgui(".x%x.c itemconfigure %s " + "-stroke $select_nlet_color " + "-strokewidth $highlight_width\n", x, x->gl_editor->canvas_cnct_outlet_tag); - + //sys_vgui(".x%x.c raise %s\n", // x, // x->gl_editor->canvas_cnct_outlet_tag); - outlet_issignal = obj_issignaloutlet(ob,closest); - if (tooltips) { - objtooltip = 1; - sys_vgui("pdtk_canvas_enteritem .x%x.c %d %d %s -1\n;", x, xpos, ypos, x->gl_editor->canvas_cnct_outlet_tag); - } + outlet_issignal = obj_issignaloutlet(ob,closest); + if (tooltips) + { + objtooltip = 1; + sys_vgui("pdtk_canvas_enteritem " + ".x%x.c %d %d %s -1\n;", + x, xpos, ypos, + x->gl_editor->canvas_cnct_outlet_tag); + } } // jsarlo - if(x->gl_editor && x->gl_editor->gl_magic_glass) { - magicGlass_unbind(x->gl_editor->gl_magic_glass); - magicGlass_hide(x->gl_editor->gl_magic_glass); - } + if(x->gl_editor && x->gl_editor->gl_magic_glass) + { + magicGlass_unbind(x->gl_editor->gl_magic_glass); + magicGlass_hide(x->gl_editor->gl_magic_glass); + } // end jsarlo canvas_setcursor(x, CURSOR_EDITMODE_CONNECT); } // end jsarlo } else { - canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); - canvas_check_nlet_highlights(x); - if (doit) - goto nooutletafterall; - } + canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); + canvas_check_nlet_highlights(x); + if (doit) + goto nooutletafterall; + } } - /* look for an inlet (these are colored differently since they are not connectable) */ + /* look for an inlet (these are colored differently + since they are not connectable) */ else if (ob && (ninlet = obj_ninlets(ob)) && ypos <= y1+4) { - canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); + canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); int width = x2 - x1; int nin1 = (ninlet > 1 ? ninlet - 1 : 1); int closest = ((xpos-x1) * (nin1) + width/2)/width; @@ -3067,51 +3351,64 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, if (closest < ninlet && xpos >= (hotspot-1) && xpos <= hotspot + (IOWIDTH+1)) { - t_rtext *yr = glist_findrtext(x, (t_text *)&ob->ob_g); + t_rtext *yr = glist_findrtext(x, (t_text *)&ob->ob_g); if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_inlet_tag, - (last_inlet_filter ? "black" : (inlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (inlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s " + "-strokewidth 1\n", + x, x->gl_editor->canvas_cnct_inlet_tag, + (last_inlet_filter ? + "black" : + (inlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (inlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); } if (yr) { - last_inlet_filter = gobj_filter_highlight_behavior((t_text *)&ob->ob_g); - //fprintf(stderr,"last_inlet_filter == %d\n", last_inlet_filter); + last_inlet_filter = + gobj_filter_highlight_behavior((t_text *)&ob->ob_g); + //fprintf(stderr,"last_inlet_filter == %d\n", + // last_inlet_filter); sprintf(x->gl_editor->canvas_cnct_inlet_tag, - "%si%d", - rtext_gettag(yr), - closest); - sys_vgui(".x%x.c itemconfigure %s -strokewidth $highlight_width\n", - x, - x->gl_editor->canvas_cnct_inlet_tag); - + "%si%d", rtext_gettag(yr), closest); + sys_vgui(".x%x.c itemconfigure %s " + "-strokewidth $highlight_width\n", + x, x->gl_editor->canvas_cnct_inlet_tag); //sys_vgui(".x%x.c raise %s\n", // x, // x->gl_editor->canvas_cnct_inlet_tag); - inlet_issignal = obj_issignalinlet(ob,closest); - if (tooltips) { - objtooltip = 1; - sys_vgui("pdtk_canvas_enteritem .x%x.c %d %d %s -1\n;", x, xpos, ypos, x->gl_editor->canvas_cnct_inlet_tag); - } - } - } else { - if (x->gl_editor->e_onmotion != MA_CONNECT) { - canvas_check_nlet_highlights(x); - } - if (doit) - goto nooutletafterall; - } - } + inlet_issignal = obj_issignalinlet(ob,closest); + if (tooltips) + { + objtooltip = 1; + sys_vgui("pdtk_canvas_enteritem " + ".x%x.c %d %d %s -1\n;", + x, xpos, ypos, + x->gl_editor->canvas_cnct_inlet_tag); + } + } + } + else + { + if (x->gl_editor->e_onmotion != MA_CONNECT) + { + canvas_check_nlet_highlights(x); + } + if (doit) + goto nooutletafterall; + } + } /* not in an outlet; select and move */ else if (doit) { t_rtext *rt; /* check if the box is being text edited */ - nooutletafterall: + nooutletafterall: if (ob && (rt = x->gl_editor->e_textedfor) && rt == glist_findrtext(x, ob)) { @@ -3126,67 +3423,93 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, /* otherwise select and drag to displace */ if (!glist_isselected(x, y)) { - //t_undo_redo_sel *buf = (t_undo_redo_sel *)getbytes(sizeof(*buf)); - //buf->u_undo = (t_undo_sel *)canvas_undo_set_selection(x); + //t_undo_redo_sel *buf = + // (t_undo_redo_sel *)getbytes(sizeof(*buf)); + //buf->u_undo = + // (t_undo_sel *)canvas_undo_set_selection(x); glist_noselect(x); glist_select(x, y); - //buf->u_redo = (t_undo_sel *)canvas_undo_set_selection(x); - //canvas_undo_add(x, 11, "selection", buf); - } else { - canvas_check_nlet_highlights(x); - } - //toggle_moving = 1; - //sys_vgui("pdtk_update_xy_tooltip .x%lx %d %d\n", x, (int)xpos, (int)ypos); - //sys_vgui("pdtk_toggle_xy_tooltip .x%lx %d\n", x, 1); + //buf->u_redo = + // (t_undo_sel *)canvas_undo_set_selection(x); + //canvas_undo_add(x, 11, "selection", buf); + } + else + { + canvas_check_nlet_highlights(x); + } + //toggle_moving = 1; + //sys_vgui("pdtk_update_xy_tooltip .x%lx %d %d\n", + // x, (int)xpos, (int)ypos); + //sys_vgui("pdtk_toggle_xy_tooltip .x%lx %d\n", x, 1); x->gl_editor->e_onmotion = MA_MOVE; - if (tooltips) - sys_vgui("pdtk_tip .x%x.c 0 0\n;", x); + if (tooltips) + sys_vgui("pdtk_tip .x%x.c 0 0\n;", x); } } - else + else // jsarlo { if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_inlet_tag, - (last_inlet_filter ? "black" : (inlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (inlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } - x->gl_editor->canvas_cnct_inlet_tag[0] = 0; + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s " + "-strokewidth 1\n", + x, x->gl_editor->canvas_cnct_inlet_tag, + (last_inlet_filter ? + "black" : + (inlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (inlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } + x->gl_editor->canvas_cnct_inlet_tag[0] = 0; } if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0) { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_outlet_tag, - (last_outlet_filter ? "black" : (outlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (outlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s " + "-strokewidth 1\n", + x, x->gl_editor->canvas_cnct_outlet_tag, + (last_outlet_filter ? + "black" : + (outlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (outlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } x->gl_editor->canvas_cnct_outlet_tag[0] = 0; } - if(x->gl_editor && x->gl_editor->gl_magic_glass) { - magicGlass_unbind(x->gl_editor->gl_magic_glass); - magicGlass_hide(x->gl_editor->gl_magic_glass); - } + if(x->gl_editor && x->gl_editor->gl_magic_glass) + { + magicGlass_unbind(x->gl_editor->gl_magic_glass); + magicGlass_hide(x->gl_editor->gl_magic_glass); + } canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); - /* now check for tooltips object tooltips */ - if (tooltips) { - t_rtext *yr = glist_findrtext(x, (t_text *)&ob->ob_g); - objtooltip = 1; - sys_vgui("pdtk_canvas_enteritem .x%x.c %d %d %s -1;\n", x, xpos, ypos, rtext_gettag(yr)); - } - } + /* now check for tooltips object tooltips */ + if (tooltips) + { + t_rtext *yr = glist_findrtext(x, (t_text *)&ob->ob_g); + objtooltip = 1; + sys_vgui("pdtk_canvas_enteritem " + ".x%x.c %d %d %s -1;\n", + x, xpos, ypos, rtext_gettag(yr)); + } + } // end jsarlo } return; @@ -3216,119 +3539,157 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, linetraverser_start(&t, glist2); while (oc = linetraverser_next(&t)) { - //fprintf(stderr,"oc_visible %d\n", outconnect_visible(oc)); - //ignore invisible connections - if (outconnect_visible(oc)) { - - parseOb = NULL; - parseOutlet = NULL; - t_float lx1 = t.tr_lx1, ly1 = t.tr_ly1, - lx2 = t.tr_lx2, ly2 = t.tr_ly2; - t_float area = (lx2 - lx1) * (fy - ly1) - - (ly2 - ly1) * (fx - lx1); - t_float dsquare = (lx2-lx1) * (lx2-lx1) + (ly2-ly1) * (ly2-ly1); - if (area * area >= 50 * dsquare) continue; - if ((lx2-lx1) * (fx-lx1) + (ly2-ly1) * (fy-ly1) < 0) continue; - if ((lx2-lx1) * (lx2-fx) + (ly2-ly1) * (ly2-fy) < 0) continue; - if (doit) - { - glist_selectline(glist2, oc, - canvas_getindex(glist2, &t.tr_ob->ob_g), t.tr_outno, - canvas_getindex(glist2, &t.tr_ob2->ob_g), t.tr_inno); - } - // jsarlo - parseOutno = t.tr_outno; - parseOb = t.tr_ob; - for (parseOutlet = parseOb->ob_outlet; - parseOutlet && parseOutno; - parseOutlet = parseOutlet->o_next, parseOutno--); - if (parseOutlet && magicGlass_isOn(x->gl_editor->gl_magic_glass)) - { - magicGlass_bind(x->gl_editor->gl_magic_glass, - t.tr_ob, - t.tr_outno); - magicGlass_setDsp(x->gl_editor->gl_magic_glass, - obj_issignaloutlet(t.tr_ob, t.tr_outno)); - } - if (magicGlass_isOn(x->gl_editor->gl_magic_glass)) { - magicGlass_moveText(x->gl_editor->gl_magic_glass, xpos, ypos); - magicGlass_show(x->gl_editor->gl_magic_glass); - } - if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) - { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_inlet_tag, - (last_inlet_filter ? "black" : (inlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (inlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } - x->gl_editor->canvas_cnct_inlet_tag[0] = 0; - } - if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0) - { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_outlet_tag, - (last_outlet_filter ? "black" : (outlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (outlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } - x->gl_editor->canvas_cnct_outlet_tag[0] = 0; - } - // end jsarlo - canvas_setcursor(x, CURSOR_EDITMODE_DISCONNECT); - return; - } + //fprintf(stderr,"oc_visible %d\n", outconnect_visible(oc)); + //ignore invisible connections + if (outconnect_visible(oc)) + { + + parseOb = NULL; + parseOutlet = NULL; + t_float lx1 = t.tr_lx1, ly1 = t.tr_ly1, + lx2 = t.tr_lx2, ly2 = t.tr_ly2; + t_float area = (lx2 - lx1) * (fy - ly1) - + (ly2 - ly1) * (fx - lx1); + t_float dsquare = (lx2-lx1) * (lx2-lx1) + (ly2-ly1) * (ly2-ly1); + if (area * area >= 50 * dsquare) continue; + if ((lx2-lx1) * (fx-lx1) + (ly2-ly1) * (fy-ly1) < 0) continue; + if ((lx2-lx1) * (lx2-fx) + (ly2-ly1) * (ly2-fy) < 0) continue; + if (doit) + { + glist_selectline(glist2, oc, + canvas_getindex(glist2, &t.tr_ob->ob_g), t.tr_outno, + canvas_getindex(glist2, &t.tr_ob2->ob_g), t.tr_inno); + } + // jsarlo + parseOutno = t.tr_outno; + parseOb = t.tr_ob; + for (parseOutlet = parseOb->ob_outlet; + parseOutlet && parseOutno; + parseOutlet = parseOutlet->o_next, parseOutno--); + if (parseOutlet && + magicGlass_isOn(x->gl_editor->gl_magic_glass)) + { + magicGlass_bind(x->gl_editor->gl_magic_glass, + t.tr_ob, + t.tr_outno); + magicGlass_setDsp(x->gl_editor->gl_magic_glass, + obj_issignaloutlet(t.tr_ob, t.tr_outno)); + } + if (magicGlass_isOn(x->gl_editor->gl_magic_glass)) + { + magicGlass_moveText( + x->gl_editor->gl_magic_glass, xpos, ypos); + magicGlass_show(x->gl_editor->gl_magic_glass); + } + if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) + { + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s " + "-strokewidth 1\n", + x, x->gl_editor->canvas_cnct_inlet_tag, + (last_inlet_filter ? + "black" : + (inlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (inlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } + x->gl_editor->canvas_cnct_inlet_tag[0] = 0; + } + if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0) + { + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s " + "-strokewidth 1\n", + x, x->gl_editor->canvas_cnct_outlet_tag, + (last_outlet_filter ? + "black" : + (outlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (outlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } + x->gl_editor->canvas_cnct_outlet_tag[0] = 0; + } + // end jsarlo + canvas_setcursor(x, CURSOR_EDITMODE_DISCONNECT); + return; + } } } if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_inlet_tag, - (last_inlet_filter ? "black" : (inlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (inlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", + x, x->gl_editor->canvas_cnct_inlet_tag, + (last_inlet_filter ? + "black" : + (inlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (inlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } x->gl_editor->canvas_cnct_inlet_tag[0] = 0; } // jsarlo if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0) { sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_outlet_tag, - (last_outlet_filter ? "black" : (outlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (outlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } + x, x->gl_editor->canvas_cnct_outlet_tag, + (last_outlet_filter ? + "black" : + (outlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (outlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } x->gl_editor->canvas_cnct_outlet_tag[0] = 0; } - if(x->gl_editor && x->gl_editor->gl_magic_glass) { - magicGlass_unbind(x->gl_editor->gl_magic_glass); - magicGlass_hide(x->gl_editor->gl_magic_glass); - } + if(x->gl_editor && x->gl_editor->gl_magic_glass) + { + magicGlass_unbind(x->gl_editor->gl_magic_glass); + magicGlass_hide(x->gl_editor->gl_magic_glass); + } // end jsarlo - if (x->gl_editor->e_onmotion != MA_SCROLL) - canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); + if (x->gl_editor->e_onmotion != MA_SCROLL) + canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); if (doit) { - if (!shiftmod && (x->gl_editor->e_selection || x->gl_editor->e_selectedline)) { - //t_undo_redo_sel *buf = (t_undo_redo_sel *)getbytes(sizeof(*buf)); - //buf->u_undo = (t_undo_sel *)canvas_undo_set_selection(x); + if (!shiftmod && + (x->gl_editor->e_selection || x->gl_editor->e_selectedline)) + { + //t_undo_redo_sel *buf = (t_undo_redo_sel *)getbytes(sizeof(*buf)); + //buf->u_undo = (t_undo_sel *)canvas_undo_set_selection(x); - glist_noselect(x); + glist_noselect(x); - //buf->u_redo = (t_undo_sel *)canvas_undo_set_selection(x); - //canvas_undo_add(x, 11, "selection", buf); - } - sys_vgui(".x%lx.c create prect %d %d %d %d -tags x -stroke $pd_colors(selection_rectangle)\n", - x, xpos, ypos, xpos, ypos); + //buf->u_redo = (t_undo_sel *)canvas_undo_set_selection(x); + //canvas_undo_add(x, 11, "selection", buf); + } + sys_vgui(".x%lx.c create prect %d %d %d %d -tags x " + "-stroke $pd_colors(selection_rectangle)\n", + x, xpos, ypos, xpos, ypos); x->gl_editor->e_xwas = xpos; x->gl_editor->e_ywas = ypos; x->gl_editor->e_onmotion = MA_REGION; @@ -3338,7 +3699,7 @@ void canvas_doclick(t_canvas *x, int xpos, int ypos, int which, void canvas_mousedown(t_canvas *x, t_floatarg xpos, t_floatarg ypos, t_floatarg which, t_floatarg mod) { - //fprintf(stderr,"canvas_mousedown %d\n", x->gl_editor->e_onmotion); + //fprintf(stderr,"canvas_mousedown %d\n", x->gl_editor->e_onmotion); canvas_doclick(x, xpos, ypos, which, mod, 1); } @@ -3357,156 +3718,190 @@ int canvas_isconnected (t_canvas *x, t_text *ob1, int n1, void canvas_sort_selection_according_to_location(t_canvas *x) { - int n_selected = glist_selectionindex(x, 0, 1); // get all selected objects - //fprintf(stderr,"n_selected = %d\n", n_selected); - t_selection *traverse, *sel[n_selected]; - int map[n_selected]; - int already_mapped = 0; - int i = 0, j = 0, k = 0, leftmost = 99999, topmost = 99999; - t_text *yt; - for (traverse = x->gl_editor->e_selection; traverse; traverse = traverse->sel_next) { - sel[i] = traverse; - map[i] = -1; - i++; - } - for (i = 0; i < n_selected; i++) { - for (j = 0; j < n_selected; j++) { - yt = (t_text *)(sel[j]->sel_what); - if ((yt->te_xpix < leftmost) || - (yt->te_xpix == leftmost && yt->te_ypix <= topmost)) { - for (k = 0; k < n_selected; k++) { - if (map[k] == j) { - already_mapped = 1; - } - } - if (!already_mapped) { - map[i] = j; - leftmost = yt->te_xpix; - topmost = yt->te_ypix; - } - already_mapped = 0; - } - } - leftmost = 99999; - topmost = 99999; - } - /* - // debug - for (i = 0; i < n_selected; i++) { - yt = (t_text *)(sel[map[i]]->sel_what); - fprintf(stderr,"sorted: %d (%d) x=%d y=%d\n", i, map[i], yt->te_xpix, yt->te_ypix); - }*/ - x->gl_editor->e_selection = sel[map[0]]; - for (i = 0; i < n_selected-1; i++) { - sel[map[i]]->sel_next = sel[map[i+1]]; - } - sel[map[n_selected-1]]->sel_next = 0; - - /* - // debug - i = 0; - for (traverse = x->gl_editor->e_selection; traverse; traverse = traverse->sel_next) { - yt = (t_text *)(traverse->sel_what); - fprintf(stderr,"final: %d x=%d y=%d\n", i, yt->te_xpix, yt->te_ypix); - i++; - }*/ -} - -void canvas_drawconnection(t_canvas *x, int lx1, int ly1, int lx2, int ly2, t_int tag, int issignal) { - int ymax = 0; - int halfx = (lx2 - lx1)/2; - int halfy = (ly2 - ly1)/2; - //int yoff = (abs(halfx)+abs(halfy))/2; - int yoff = abs(halfy); - //if (yoff < 2) yoff = 2; - if (halfy >= 0) { - //second object is below the first - if (abs(halfx) <=10) { - ymax = abs(halfy * pow((halfx/10.0),2)); - if (ymax > 10) ymax = 10; - } - else ymax = 10; - } else { - //second object is above the first - ymax = 20; - } - if (yoff > ymax) yoff = ymax; - /*sys_vgui(".x%lx.c create polyline %d %d %d %d -stroke %s -strokewidth %s -tags {l%lx all_cords}\n", - x, lx1, ly1, lx2, ly2, - (issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)"), - (issignal ? "$pd_colors(signal_cord_width)" : "$pd_colors(control_cord_width)"), - tag);*/ - //bezier curves FTW - sys_vgui(".x%lx.c create path \"M %d %d Q %d %d %d %d Q %d %d %d %d\" -stroke %s -strokewidth %s -tags {l%lx all_cords %s}\n", - x, lx1, ly1, - lx1, ly1 + yoff, lx1 + halfx, ly1 + halfy, - lx2, ly2 - yoff, lx2, ly2, - (issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)"), - (issignal ? "$pd_colors(signal_cord_width)" : "$pd_colors(control_cord_width)"), - tag, (issignal ? "signal" : "control")); - -} - -void canvas_updateconnection(t_canvas *x, int lx1, int ly1, int lx2, int ly2, t_int tag) { - int ymax = 0; - int halfx = (lx2 - lx1)/2; - int halfy = (ly2 - ly1)/2; - //int yoff = (abs(halfx)+abs(halfy))/2; - int yoff = abs(halfy); - //if (yoff < 2) yoff = 2; - if (halfy >= 0) { - //second object is below the first - if (abs(halfx) <=10) { - ymax = abs(halfy * pow((halfx/10.0),2)); - if (ymax > 10) ymax = 10; - } - else ymax = 10; - } else { - //second object is above the first - ymax = 20; - } - //fprintf(stderr,"pow%f halfx%d yoff%d ymax%d\n", pow((halfx/10.0),2), halfx, yoff, ymax); - if (yoff > ymax) yoff = ymax; - if (tag) { - //sys_vgui(".x%lx.c coords l%lx %d %d %d %d\n", x, tag, lx1, ly1, lx2, ly2); - //bezier curves FTW - sys_vgui(".x%lx.c coords l%lx \"M %d %d Q %d %d %d %d Q %d %d %d %d\"\n", - x, tag, lx1, ly1, - lx1, ly1 + yoff, lx1 + halfx, ly1 + halfy, - lx2, ly2 - yoff, lx2, ly2); - } else { - //sys_vgui(".x%lx.c coords x %d %d %d %d\n", x, lx1, ly1, lx2, ly2); - //bezier curves FTW - sys_vgui(".x%lx.c coords x \"M %d %d Q %d %d %d %d Q %d %d %d %d\"\n", - x, lx1, ly1, - lx1, ly1 + yoff, lx1 + halfx, ly1 + halfy, - lx2, ly2 - yoff, lx2, ly2); - } -} - -int canvas_doconnect_doit(t_canvas *x, t_gobj *y1, t_gobj *y2, int closest1, int closest2, int multi, int create_undo) + int n_selected = glist_selectionindex(x, 0, 1); // get all selected objects + //fprintf(stderr,"n_selected = %d\n", n_selected); + t_selection *traverse, *sel[n_selected]; + int map[n_selected]; + int already_mapped = 0; + int i = 0, j = 0, k = 0, leftmost = 99999, topmost = 99999; + t_text *yt; + for (traverse = x->gl_editor->e_selection; traverse; traverse = traverse->sel_next) + { + sel[i] = traverse; + map[i] = -1; + i++; + } + for (i = 0; i < n_selected; i++) + { + for (j = 0; j < n_selected; j++) + { + yt = (t_text *)(sel[j]->sel_what); + if ((yt->te_xpix < leftmost) || + (yt->te_xpix == leftmost && yt->te_ypix <= topmost)) + { + for (k = 0; k < n_selected; k++) + { + if (map[k] == j) + { + already_mapped = 1; + } + } + if (!already_mapped) + { + map[i] = j; + leftmost = yt->te_xpix; + topmost = yt->te_ypix; + } + already_mapped = 0; + } + } + leftmost = 99999; + topmost = 99999; + } + /* + // debug + for (i = 0; i < n_selected; i++) { + yt = (t_text *)(sel[map[i]]->sel_what); + fprintf(stderr,"sorted: %d (%d) x=%d y=%d\n", + i, map[i], yt->te_xpix, yt->te_ypix); + }*/ + x->gl_editor->e_selection = sel[map[0]]; + for (i = 0; i < n_selected-1; i++) + { + sel[map[i]]->sel_next = sel[map[i+1]]; + } + sel[map[n_selected-1]]->sel_next = 0; + + /* + // debug + i = 0; + for (traverse = x->gl_editor->e_selection; traverse; traverse = traverse->sel_next) { + yt = (t_text *)(traverse->sel_what); + fprintf(stderr,"final: %d x=%d y=%d\n", i, yt->te_xpix, yt->te_ypix); + i++; + }*/ +} + +void canvas_drawconnection(t_canvas *x, int lx1, int ly1, int lx2, int ly2, + t_int tag, int issignal) +{ + int ymax = 0; + int halfx = (lx2 - lx1)/2; + int halfy = (ly2 - ly1)/2; + //int yoff = (abs(halfx)+abs(halfy))/2; + int yoff = abs(halfy); + //if (yoff < 2) yoff = 2; + if (halfy >= 0) + { + //second object is below the first + if (abs(halfx) <=10) + { + ymax = abs(halfy * pow((halfx/10.0),2)); + if (ymax > 10) ymax = 10; + } + else ymax = 10; + } + else + { + //second object is above the first + ymax = 20; + } + if (yoff > ymax) yoff = ymax; + /*sys_vgui(".x%lx.c create polyline %d %d %d %d -stroke %s " + "-strokewidth %s -tags {l%lx all_cords}\n", + x, lx1, ly1, lx2, ly2, + (issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)"), + (issignal ? + "$pd_colors(signal_cord_width)" : + "$pd_colors(control_cord_width)"), + tag);*/ + //bezier curves FTW + sys_vgui(".x%lx.c create path \"M %d %d Q %d %d %d %d Q %d %d %d %d\" " + "-stroke %s -strokewidth %s -tags {l%lx all_cords %s}\n", + x, lx1, ly1, + lx1, ly1 + yoff, lx1 + halfx, ly1 + halfy, + lx2, ly2 - yoff, lx2, ly2, + (issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)"), + (issignal ? + "$pd_colors(signal_cord_width)" : + "$pd_colors(control_cord_width)"), + tag, (issignal ? "signal" : "control")); +} + +void canvas_updateconnection(t_canvas *x, int lx1, int ly1, int lx2, int ly2, + t_int tag) +{ + int ymax = 0; + int halfx = (lx2 - lx1)/2; + int halfy = (ly2 - ly1)/2; + //int yoff = (abs(halfx)+abs(halfy))/2; + int yoff = abs(halfy); + //if (yoff < 2) yoff = 2; + if (halfy >= 0) + { + //second object is below the first + if (abs(halfx) <=10) + { + ymax = abs(halfy * pow((halfx/10.0),2)); + if (ymax > 10) ymax = 10; + } + else ymax = 10; + } + else + { + //second object is above the first + ymax = 20; + } + //fprintf(stderr,"pow%f halfx%d yoff%d ymax%d\n", + // pow((halfx/10.0),2), halfx, yoff, ymax); + if (yoff > ymax) yoff = ymax; + if (tag) + { + //sys_vgui(".x%lx.c coords l%lx %d %d %d %d\n", + // x, tag, lx1, ly1, lx2, ly2); + //bezier curves FTW + sys_vgui(".x%lx.c coords l%lx " + "\"M %d %d Q %d %d %d %d Q %d %d %d %d\"\n", + x, tag, lx1, ly1, + lx1, ly1 + yoff, lx1 + halfx, ly1 + halfy, + lx2, ly2 - yoff, lx2, ly2); + } + else + { + //sys_vgui(".x%lx.c coords x %d %d %d %d\n", x, lx1, ly1, lx2, ly2); + //bezier curves FTW + sys_vgui(".x%lx.c coords x \"M %d %d Q %d %d %d %d Q %d %d %d %d\"\n", + x, lx1, ly1, + lx1, ly1 + yoff, lx1 + halfx, ly1 + halfy, + lx2, ly2 - yoff, lx2, ly2); + } +} + +int canvas_doconnect_doit(t_canvas *x, t_gobj *y1, t_gobj *y2, + int closest1, int closest2, int multi, int create_undo) { int x11=0, y11=0, x12=0, y12=0; int x21=0, y21=0, x22=0, y22=0; - int lx1, lx2, ly1, ly2; + int lx1, lx2, ly1, ly2; int noutlet1, ninlet2; - t_object *ob1, *ob2; - t_outconnect *oc, *oc2; + t_object *ob1, *ob2; + t_outconnect *oc, *oc2; ob1 = pd_checkobject(&y1->g_pd); ob2 = pd_checkobject(&y2->g_pd); noutlet1 = obj_noutlets(ob1); ninlet2 = obj_ninlets(ob2); - gobj_getrect(y1, x, &x11, &y11, &x12, &y12); - gobj_getrect(y2, x, &x21, &y21, &x22, &y22); + gobj_getrect(y1, x, &x11, &y11, &x12, &y12); + gobj_getrect(y2, x, &x21, &y21, &x22, &y22); if (canvas_isconnected (x, ob1, closest1, ob2, closest2)) { - if(x->gl_editor && x->gl_editor->gl_magic_glass) { - magicGlass_unbind(x->gl_editor->gl_magic_glass); - magicGlass_hide(x->gl_editor->gl_magic_glass); - } - if (!multi) + if(x->gl_editor && x->gl_editor->gl_magic_glass) + { + magicGlass_unbind(x->gl_editor->gl_magic_glass); + magicGlass_hide(x->gl_editor->gl_magic_glass); + } + if (!multi) canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); return(1); } @@ -3514,39 +3909,48 @@ int canvas_doconnect_doit(t_canvas *x, t_gobj *y1, t_gobj *y2, int closest1, int !obj_issignalinlet(ob2, closest2)) { error("cannot connect signal outlet to control inlet"); - if(x->gl_editor && x->gl_editor->gl_magic_glass) { - magicGlass_unbind(x->gl_editor->gl_magic_glass); + if(x->gl_editor && x->gl_editor->gl_magic_glass) + { + magicGlass_unbind(x->gl_editor->gl_magic_glass); magicGlass_hide(x->gl_editor->gl_magic_glass); - } + } if (!multi) canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); return(1); } - // if the first object is preset_node, check if the object we are connecting to - // is supported. If not, disallow connection - - if (pd_class(&y1->g_pd) == preset_node_class) { - if (pd_class(&y2->g_pd) == message_class) { - error("preset_node does not work with messages."); - return(1); - } - if (obj_noutlets(ob2) == 0) { - error("preset_node does not work with objects with zero or undefined number of outlets\n"); - return(1); - } - } - - // now check if explicit user-made connection into preset_node is other than message - // messages may be used to change node's operation - if (pd_class(&y2->g_pd) == preset_node_class && pd_class(&y1->g_pd) != message_class) { - error("preset node only accepts messages as input to adjust its settings...\n"); - return(1); - } + // if the first object is preset_node, check if the object + // we are connecting to is supported. If not, disallow connection + + if (pd_class(&y1->g_pd) == preset_node_class) + { + if (pd_class(&y2->g_pd) == message_class) + { + error("preset_node does not work with messages."); + return(1); + } + if (obj_noutlets(ob2) == 0) + { + error("preset_node does not work with objects with zero " + "or undefined number of outlets\n"); + return(1); + } + } + + // now check if explicit user-made connection into preset_node + // is other than message. + // messages may be used to change node's operation + if (pd_class(&y2->g_pd) == preset_node_class && + pd_class(&y1->g_pd) != message_class) + { + error("preset node only accepts messages " + "as input to adjust its settings...\n"); + return(1); + } int issignal = obj_issignaloutlet(ob1, closest1); oc = obj_connect(ob1, closest1, ob2, closest2); - outconnect_setvisible(oc, 1); + outconnect_setvisible(oc, 1); lx1 = x11 + (noutlet1 > 1 ? ((x12-x11-IOWIDTH) * closest1)/(noutlet1-1) : 0) + IOMIDDLE; @@ -3556,35 +3960,51 @@ int canvas_doconnect_doit(t_canvas *x, t_gobj *y1, t_gobj *y2, int closest1, int + IOMIDDLE; ly2 = y21; - canvas_drawconnection(x, lx1, ly1, lx2, ly2, (t_int)oc, issignal); - /*sys_vgui(".x%lx.c create polyline %d %d %d %d -stroke %s -strokewidth %s -tags {l%lx all_cords}\n", - glist_getcanvas(x), - lx1, ly1, lx2, ly2, - (issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)"), - (issignal ? "$pd_colors(signal_cord_width)" : "$pd_colors(control_cord_width)"), + canvas_drawconnection(x, lx1, ly1, lx2, ly2, (t_int)oc, issignal); + /*sys_vgui(".x%lx.c create polyline %d %d %d %d -stroke %s " + "-strokewidth %s -tags {l%lx all_cords}\n", + glist_getcanvas(x), + lx1, ly1, lx2, ly2, + (issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)"), + (issignal ? + "$pd_colors(signal_cord_width)" : + "$pd_colors(control_cord_width)"), oc);*/ if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) { sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_inlet_tag, - (last_inlet_filter ? "black" : (obj_issignalinlet(ob2, closest2) ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (inlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } + x, x->gl_editor->canvas_cnct_inlet_tag, + (last_inlet_filter ? + "black" : + (obj_issignalinlet(ob2, closest2) ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (inlet_issignal ? + "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } x->gl_editor->canvas_cnct_inlet_tag[0] = 0; } if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0 && !glob_shift) { sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_outlet_tag, - (last_outlet_filter ? "black" : (outlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (outlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } + x, x->gl_editor->canvas_cnct_outlet_tag, + (last_outlet_filter ? + "black" : + (outlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (outlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } x->gl_editor->canvas_cnct_outlet_tag[0] = 0; } // end jsarlo @@ -3595,412 +4015,490 @@ int canvas_doconnect_doit(t_canvas *x, t_gobj *y1, t_gobj *y2, int closest1, int canvas_getindex(x, &ob2->ob_g), closest2), "connect");*/ - if (create_undo) { - canvas_undo_add(x, 1, "connect", canvas_undo_set_connect(x, - canvas_getindex(x, &ob1->ob_g), closest1, - canvas_getindex(x, &ob2->ob_g), closest2)); - } + if (create_undo) + { + canvas_undo_add(x, 1, "connect", canvas_undo_set_connect(x, + canvas_getindex(x, &ob1->ob_g), closest1, + canvas_getindex(x, &ob2->ob_g), closest2)); + } - // add auto-connect back to preset_node object - // (by this time we know we are connecting only to legal objects who have at least one outlet) - if (pd_class(&y1->g_pd) == preset_node_class) { - - //fprintf(stderr,"gotta do auto-connect back to preset_node\n"); - if (!canvas_isconnected(x, ob2, 0, ob1, 0) && pd_class(&y2->g_pd) != print_class) { - oc2 = obj_connect(ob2, 0, ob1, 0); - outconnect_setvisible(oc2, 0); - } - //else - // fprintf(stderr,"error: already connected (this happens when loading from file and is ok)\n"); - } + // add auto-connect back to preset_node object + // (by this time we know we are connecting only to legal objects + // who have at least one outlet) + if (pd_class(&y1->g_pd) == preset_node_class) + { + + //fprintf(stderr,"gotta do auto-connect back to preset_node\n"); + if (!canvas_isconnected(x, ob2, 0, ob1, 0) && + pd_class(&y2->g_pd) != print_class) + { + oc2 = obj_connect(ob2, 0, ob1, 0); + outconnect_setvisible(oc2, 0); + } + //else + // fprintf(stderr, "error: already connected (this happens " + // "when loading from file and is ok)\n"); + } - return(0); + return(0); } int canvas_trymulticonnect(t_canvas *x, int xpos, int ypos, int which, int doit) { - //fprintf(stderr,"canvas_trymulticonnect\n"); + //fprintf(stderr,"canvas_trymulticonnect\n"); int x11=0, y11=0, x12=0, y12=0; t_gobj *y1; int x21=0, y21=0, x22=0, y22=0; t_gobj *y2; int xwas = x->gl_editor->e_xwas, ywas = x->gl_editor->e_ywas; - t_object *ob1, *ob2; - int noutlet1, ninlet2; - int i; - int return_val = 1; + t_object *ob1, *ob2; + int noutlet1, ninlet2; + int i; + int return_val = 1; if (!glob_shift) sys_vgui(".x%lx.c delete x\n", x); - if ((y1 = canvas_findhitbox(x, xwas, ywas, &x11, &y11, &x12, &y12)) - && (y2 = canvas_findhitbox(x, xpos, ypos, &x21, &y21, &x22, &y22))) - { - // FIRST OPTION: if two objects are selected and the one that is originating - // is one of the selected objects try multi-connecting all outlets into - // all inlets starting with the user-made one as an offset - if (!x->gl_editor->e_selection->sel_next->sel_next && glist_isselected(x, y1) && glist_isselected(x, y2)) - { - //fprintf(stderr,"first option\n"); - ob1 = pd_checkobject(&y1->g_pd); - ob2 = pd_checkobject(&y2->g_pd); - if (ob1 && ob2 && ob1 != ob2 && - (noutlet1 = obj_noutlets(ob1)) - && (ninlet2 = obj_ninlets(ob2))) - { - int width1 = x12 - x11, closest1, hotspot1; - int width2 = x22 - x21, closest2, hotspot2; - int lx1, lx2, ly1, ly2; - t_outconnect *oc, *oc2; - - if (noutlet1 > 1) - { - closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1; - hotspot1 = x11 + - (width1 - IOWIDTH) * closest1 / (noutlet1-1); - } - else closest1 = 0, hotspot1 = x11; - - if (ninlet2 > 1) - { - closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2; - hotspot2 = x21 + - (width2 - IOWIDTH) * closest2 / (ninlet2-1); - } - else closest2 = 0, hotspot2 = x21; - - if (closest1 >= noutlet1) - closest1 = noutlet1 - 1; - if (closest2 >= ninlet2) - closest2 = ninlet2 - 1; - - int nconnections = ( noutlet1 - closest1 < ninlet2 - closest2 ? noutlet1 - closest1 : ninlet2 - closest2 ); - for (i = 0; i < nconnections; i++) { - return_val = canvas_doconnect_doit(x, y1, y2, closest1 + i, closest2 + i, 1, 1); - } - } - return(return_val); - // end of FIRST OPTION - } - // SECOND OPTION: if two or more objects are selected and the one that is originating - // is not one of the selected, connect originating to all selected objects' the outlets - // specified by the first connection - else if (x->gl_editor->e_selection->sel_next && !glist_isselected(x, y1) && glist_isselected(x, y2)) - { - //fprintf(stderr,"second option\n"); - ob1 = pd_checkobject(&y1->g_pd); - ob2 = pd_checkobject(&y2->g_pd); - int noutlet1, ninlet2; - if (ob1 && ob2 && ob1 != ob2 && - (noutlet1 = obj_noutlets(ob1)) - && (ninlet2 = obj_ninlets(ob2))) - { - int width1 = x12 - x11, closest1, hotspot1; - int width2 = x22 - x21, closest2, hotspot2; - int lx1, lx2, ly1, ly2; - t_outconnect *oc, *oc2; - - if (noutlet1 > 1) - { - closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1; - hotspot1 = x11 + - (width1 - IOWIDTH) * closest1 / (noutlet1-1); - } - else closest1 = 0, hotspot1 = x11; - - if (ninlet2 > 1) - { - closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2; - hotspot2 = x21 + - (width2 - IOWIDTH) * closest2 / (ninlet2-1); - } - else closest2 = 0, hotspot2 = x21; - - if (closest1 >= noutlet1) - closest1 = noutlet1 - 1; - if (closest2 >= ninlet2) - closest2 = ninlet2 - 1; - - return_val = canvas_doconnect_doit(x, y1, y2, closest1, closest2, 1, 1); - - // now that we made the initial connection and know where to begin and where to connect to, let's connect the rest - t_selection *sel; - for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) { - // do this only with objects that have not been connected as of yet - if (sel->sel_what != y1 && sel->sel_what != y2) { - ob2 = pd_checkobject(&sel->sel_what->g_pd); - ninlet2 = obj_ninlets(ob2); - if (closest2 < ninlet2) { - return_val = canvas_doconnect_doit(x, y1, sel->sel_what, closest1, closest2, 1, 1); - } - } - } - } - return(return_val); - // end of SECOND OPTION - } - - // THIRD OPTION: if two or more objects are selected and the one that is receiving connection - // is one of the selected, and the target object is selected, connect nth outlet (as specified by - // the first connection) from all selected objects into the inlet of the unselected one - else if (x->gl_editor->e_selection->sel_next && glist_isselected(x, y1) && !glist_isselected(x, y2)) - { - //fprintf(stderr,"third option\n"); - ob1 = pd_checkobject(&y1->g_pd); - ob2 = pd_checkobject(&y2->g_pd); - int noutlet1, ninlet2; - if (ob1 && ob2 && ob1 != ob2 && - (noutlet1 = obj_noutlets(ob1)) - && (ninlet2 = obj_ninlets(ob2))) - { - int width1 = x12 - x11, closest1, hotspot1; - int width2 = x22 - x21, closest2, hotspot2; - int lx1, lx2, ly1, ly2; - t_outconnect *oc, *oc2; - - if (noutlet1 > 1) - { - closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1; - hotspot1 = x11 + - (width1 - IOWIDTH) * closest1 / (noutlet1-1); - } - else closest1 = 0, hotspot1 = x11; - - if (ninlet2 > 1) - { - closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2; - hotspot2 = x21 + - (width2 - IOWIDTH) * closest2 / (ninlet2-1); - } - else closest2 = 0, hotspot2 = x21; - - if (closest1 >= noutlet1) - closest1 = noutlet1 - 1; - if (closest2 >= ninlet2) - closest2 = ninlet2 - 1; - - return_val = canvas_doconnect_doit(x, y1, y2, closest1, closest2, 1, 1); - - // now that we made the initial connection and know where to begin and where to connect to, let's connect the rest - t_selection *sel; - for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) { - // do this only with objects that have not been connected as of yet - if (sel->sel_what != y1 && sel->sel_what != y2) { - ob2 = pd_checkobject(&sel->sel_what->g_pd); - noutlet1 = obj_noutlets(ob2); - if (closest1 < noutlet1) { - return_val = canvas_doconnect_doit(x, sel->sel_what, y2, closest1, closest2, 1, 1); - } - } - } - } - return(return_val); - // end of THIRD OPTION - } - - // FOURTH OPTION: if more than two objects are selected and both y1 and y2 are selected - // connect each originating object's outlet to each of the outgoing objects' inlets until you run - // out of objects or outlets. This one is tricky as there is no guarrantee that objects will be selected - // in proper visual order, so we order the selection from left to right and top to bottom - // to ensure proper visual pairing. This option has two variants, A and B. - - // OPTION A VS B: we either connect outgoing to each of other objects (A) or incoming to all other objects (B). We - // determine which one of the two options is selected based on which condition will yield more successful connections. - else if (x->gl_editor->e_selection->sel_next->sel_next && glist_isselected(x, y1) && glist_isselected(x, y2)) - { - //fprintf(stderr,"fourth option\n"); - ob1 = pd_checkobject(&y1->g_pd); - ob2 = pd_checkobject(&y2->g_pd); - int noutlet1, ninlet2; - if (ob1 && ob2 && ob1 != ob2 && - (noutlet1 = obj_noutlets(ob1)) - && (ninlet2 = obj_ninlets(ob2))) - { - int width1 = x12 - x11, closest1, hotspot1; - int width2 = x22 - x21, closest2, hotspot2; - int lx1, lx2, ly1, ly2; - t_outconnect *oc, *oc2; - - if (noutlet1 > 1) - { - closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1; - hotspot1 = x11 + - (width1 - IOWIDTH) * closest1 / (noutlet1-1); - } - else closest1 = 0, hotspot1 = x11; - - if (ninlet2 > 1) - { - closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2; - hotspot2 = x21 + - (width2 - IOWIDTH) * closest2 / (ninlet2-1); - } - else closest2 = 0, hotspot2 = x21; - - if (closest1 >= noutlet1) - closest1 = noutlet1 - 1; - if (closest2 >= ninlet2) - closest2 = ninlet2 - 1; - - return_val = canvas_doconnect_doit(x, y1, y2, closest1, closest2, 1, 1); - - // now that we made the initial connection and know where to begin and where to connect to, let's connect the rest - t_selection *sel; - // resort selection - canvas_sort_selection_according_to_location(x); - // now check for OPTION A vs. B (see description above) - int successA = 0; - int successB = 0; - int do_count; - - // try option A - int tmp_closest1 = closest1; - int tmp_closest2 = closest2; - t_object *tmp_ob1 = ob1; - t_object *tmp_ob2 = ob2; - int tmp_noutlet1 = noutlet1; - int tmp_ninlet2 = ninlet2; - for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) { - if (sel->sel_what != y1 && sel->sel_what != y2) { - tmp_ob2 = pd_checkobject(&sel->sel_what->g_pd); - tmp_ninlet2 = obj_ninlets(tmp_ob2); - tmp_closest1++; - if (tmp_closest1 >= tmp_noutlet1) { - break; - } - else if (tmp_closest2 < tmp_ninlet2) { - do_count = 1; - if (canvas_isconnected (x, tmp_ob1, tmp_closest1, tmp_ob2, tmp_closest2)) - { - do_count = 0; - } - if (obj_issignaloutlet(ob1, closest1) && - !obj_issignalinlet(ob2, closest2)) - { - do_count = 0; - } - if (pd_class(&tmp_ob1->ob_pd) == preset_node_class) { - if (pd_class(&tmp_ob2->ob_pd) == message_class) { - do_count = 0; - } - } - if (pd_class(&tmp_ob2->ob_pd) == preset_node_class && pd_class(&tmp_ob1->ob_pd) != message_class) { - do_count = 0; - } - successA += do_count; - } - } - } - //fprintf(stderr,"successA %d\n", successA); - - // try option B - tmp_closest1 = closest1; - tmp_closest2 = closest2; - tmp_ob1 = ob1; - tmp_ob2 = ob2; - tmp_noutlet1 = noutlet1; - tmp_ninlet2 = ninlet2; - for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) { - if (sel->sel_what != y1 && sel->sel_what != y2) { - tmp_ob1 = pd_checkobject(&sel->sel_what->g_pd); - tmp_noutlet1 = obj_noutlets(tmp_ob1); - tmp_closest2++; - if (tmp_closest2 >= tmp_ninlet2) { - break; - } - else if (tmp_closest1 < tmp_noutlet1) { - do_count = 1; - if (canvas_isconnected (x, tmp_ob1, tmp_closest1, tmp_ob2, tmp_closest2)) - { - do_count = 0; - } - if (obj_issignaloutlet(ob1, closest1) && - !obj_issignalinlet(ob2, closest2)) - { - do_count = 0; - } - if (pd_class(&tmp_ob1->ob_pd) == preset_node_class) { - if (pd_class(&tmp_ob2->ob_pd) == message_class) { - do_count = 0; - } - } - if (pd_class(&tmp_ob2->ob_pd) == preset_node_class && pd_class(&tmp_ob1->ob_pd) != message_class) { - do_count = 0; - } - successB += do_count; - } - } - } - //fprintf(stderr,"successB %d\n", successB); - - // now decide which one is better (we give preference to option A if both are equal) - if (successA >= successB) - { - // OPTION A (see description above) - for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) - { - // do this only with objects that have not been connected as of yet - if (sel->sel_what != y1 && sel->sel_what != y2) { - ob2 = pd_checkobject(&sel->sel_what->g_pd); - ninlet2 = obj_ninlets(ob2); - closest1++; - if (closest1 >= noutlet1) { - break; - } - else if (closest2 < ninlet2) { - return_val = canvas_doconnect_doit(x, y1, sel->sel_what, closest1, closest2, 1, 1); - } - } - } - } - else - { - // OPTION B (see description above) - for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) - { - // do this only with objects that have not been connected as of yet - if (sel->sel_what != y1 && sel->sel_what != y2) { - ob1 = pd_checkobject(&sel->sel_what->g_pd); - noutlet1 = obj_ninlets(ob1); - closest2++; - if (closest2 >= ninlet2) { - break; - } - else if (closest1 < noutlet1) { - return_val = canvas_doconnect_doit(x, sel->sel_what, y2, closest1, closest2, 1, 1); - } - } - } - } - } - return(return_val); - // end of FOURTH OPTION - } - } - - return(1); + if ((y1 = canvas_findhitbox(x, xwas, ywas, &x11, &y11, &x12, &y12)) + && (y2 = canvas_findhitbox(x, xpos, ypos, &x21, &y21, &x22, &y22))) + { + /* FIRST OPTION: if two objects are selected and the one that is + originating is one of the selected objects try multi-connecting + all outlets into all inlets starting with the user-made one as + an offset */ + if (!x->gl_editor->e_selection->sel_next->sel_next && + glist_isselected(x, y1) && glist_isselected(x, y2)) + { + //fprintf(stderr,"first option\n"); + ob1 = pd_checkobject(&y1->g_pd); + ob2 = pd_checkobject(&y2->g_pd); + if (ob1 && ob2 && ob1 != ob2 && + (noutlet1 = obj_noutlets(ob1)) + && (ninlet2 = obj_ninlets(ob2))) + { + int width1 = x12 - x11, closest1, hotspot1; + int width2 = x22 - x21, closest2, hotspot2; + int lx1, lx2, ly1, ly2; + t_outconnect *oc, *oc2; + + if (noutlet1 > 1) + { + closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1; + hotspot1 = x11 + + (width1 - IOWIDTH) * closest1 / (noutlet1-1); + } + else closest1 = 0, hotspot1 = x11; + + if (ninlet2 > 1) + { + closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2; + hotspot2 = x21 + + (width2 - IOWIDTH) * closest2 / (ninlet2-1); + } + else closest2 = 0, hotspot2 = x21; + + if (closest1 >= noutlet1) + closest1 = noutlet1 - 1; + if (closest2 >= ninlet2) + closest2 = ninlet2 - 1; + + int nconnections = ( noutlet1 - closest1 < ninlet2 - closest2 ? + noutlet1 - closest1 : + ninlet2 - closest2 ); + for (i = 0; i < nconnections; i++) + { + return_val = canvas_doconnect_doit( + x, y1, y2, closest1 + i, closest2 + i, 1, 1); + } + } + return(return_val); + /* end of FIRST OPTION */ + } + /* SECOND OPTION: if two or more objects are selected and the one + that is originating is not one of the selected, connect originating + to all selected objects' the outlets specified by the first + connection */ + else if (x->gl_editor->e_selection->sel_next && + !glist_isselected(x, y1) && glist_isselected(x, y2)) + { + //fprintf(stderr,"second option\n"); + ob1 = pd_checkobject(&y1->g_pd); + ob2 = pd_checkobject(&y2->g_pd); + int noutlet1, ninlet2; + if (ob1 && ob2 && ob1 != ob2 && + (noutlet1 = obj_noutlets(ob1)) + && (ninlet2 = obj_ninlets(ob2))) + { + int width1 = x12 - x11, closest1, hotspot1; + int width2 = x22 - x21, closest2, hotspot2; + int lx1, lx2, ly1, ly2; + t_outconnect *oc, *oc2; + + if (noutlet1 > 1) + { + closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1; + hotspot1 = x11 + + (width1 - IOWIDTH) * closest1 / (noutlet1-1); + } + else closest1 = 0, hotspot1 = x11; + + if (ninlet2 > 1) + { + closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2; + hotspot2 = x21 + + (width2 - IOWIDTH) * closest2 / (ninlet2-1); + } + else closest2 = 0, hotspot2 = x21; + + if (closest1 >= noutlet1) + closest1 = noutlet1 - 1; + if (closest2 >= ninlet2) + closest2 = ninlet2 - 1; + + return_val = canvas_doconnect_doit( + x, y1, y2, closest1, closest2, 1, 1); + + // now that we made the initial connection and know where + // to begin and where to connect to, let's connect the rest + t_selection *sel; + for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) + { + // do this only with objects that have not been + // connected as of yet + if (sel->sel_what != y1 && sel->sel_what != y2) + { + ob2 = pd_checkobject(&sel->sel_what->g_pd); + ninlet2 = obj_ninlets(ob2); + if (closest2 < ninlet2) + { + return_val = canvas_doconnect_doit( + x, y1, sel->sel_what, closest1, closest2, 1, 1); + } + } + } + } + return(return_val); + /* end of SECOND OPTION */ + } + + /* THIRD OPTION: if two or more objects are selected and the one + that is receiving connection is one of the selected, and the + target object is selected, connect nth outlet (as specified by + the first connection) from all selected objects into the inlet + of the unselected one */ + else if (x->gl_editor->e_selection->sel_next && + glist_isselected(x, y1) && !glist_isselected(x, y2)) + { + //fprintf(stderr,"third option\n"); + ob1 = pd_checkobject(&y1->g_pd); + ob2 = pd_checkobject(&y2->g_pd); + int noutlet1, ninlet2; + if (ob1 && ob2 && ob1 != ob2 && + (noutlet1 = obj_noutlets(ob1)) + && (ninlet2 = obj_ninlets(ob2))) + { + int width1 = x12 - x11, closest1, hotspot1; + int width2 = x22 - x21, closest2, hotspot2; + int lx1, lx2, ly1, ly2; + t_outconnect *oc, *oc2; + + if (noutlet1 > 1) + { + closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1; + hotspot1 = x11 + + (width1 - IOWIDTH) * closest1 / (noutlet1-1); + } + else closest1 = 0, hotspot1 = x11; + + if (ninlet2 > 1) + { + closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2; + hotspot2 = x21 + + (width2 - IOWIDTH) * closest2 / (ninlet2-1); + } + else closest2 = 0, hotspot2 = x21; + + if (closest1 >= noutlet1) + closest1 = noutlet1 - 1; + if (closest2 >= ninlet2) + closest2 = ninlet2 - 1; + + return_val = canvas_doconnect_doit( + x, y1, y2, closest1, closest2, 1, 1); + + // now that we made the initial connection and + // know where to begin and where to connect to, + // let's connect the rest + t_selection *sel; + for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) + { + // do this only with objects that have not been + // connected as of yet + if (sel->sel_what != y1 && sel->sel_what != y2) + { + ob2 = pd_checkobject(&sel->sel_what->g_pd); + noutlet1 = obj_noutlets(ob2); + if (closest1 < noutlet1) + { + return_val = canvas_doconnect_doit( + x, sel->sel_what, y2, closest1, closest2, 1, 1); + } + } + } + } + return(return_val); + /* end of THIRD OPTION */ + } + + /* FOURTH OPTION: if more than two objects are selected and both y1 + and y2 are selected connect each originating object's outlet to + each of the outgoing objects' inlets until you run out of objects + or outlets. This one is tricky as there is no guarrantee that + objects will be selected in proper visual order, so we order the + selection from left to right and top to bottom to ensure proper + visual pairing. This option has two variants, A and B. + + OPTION A VS B: we either connect outgoing to each of other objects + (A) or incoming to all other objects (B). We determine which one of + the two options is selected based on which condition will yield more + successful connections. */ + else if (x->gl_editor->e_selection->sel_next->sel_next && + glist_isselected(x, y1) && glist_isselected(x, y2)) + { + //fprintf(stderr,"fourth option\n"); + ob1 = pd_checkobject(&y1->g_pd); + ob2 = pd_checkobject(&y2->g_pd); + int noutlet1, ninlet2; + if (ob1 && ob2 && ob1 != ob2 && + (noutlet1 = obj_noutlets(ob1)) + && (ninlet2 = obj_ninlets(ob2))) + { + int width1 = x12 - x11, closest1, hotspot1; + int width2 = x22 - x21, closest2, hotspot2; + int lx1, lx2, ly1, ly2; + t_outconnect *oc, *oc2; + + if (noutlet1 > 1) + { + closest1 = ((xwas-x11) * (noutlet1-1) + width1/2)/width1; + hotspot1 = x11 + + (width1 - IOWIDTH) * closest1 / (noutlet1-1); + } + else closest1 = 0, hotspot1 = x11; + + if (ninlet2 > 1) + { + closest2 = ((xpos-x21) * (ninlet2-1) + width2/2)/width2; + hotspot2 = x21 + + (width2 - IOWIDTH) * closest2 / (ninlet2-1); + } + else closest2 = 0, hotspot2 = x21; + + if (closest1 >= noutlet1) + closest1 = noutlet1 - 1; + if (closest2 >= ninlet2) + closest2 = ninlet2 - 1; + + return_val = canvas_doconnect_doit( + x, y1, y2, closest1, closest2, 1, 1); + + // now that we made the initial connection and know where to + // begin and where to connect to, let's connect the rest + t_selection *sel; + // resort selection + canvas_sort_selection_according_to_location(x); + // now check for OPTION A vs. B (see description above) + int successA = 0; + int successB = 0; + int do_count; + + // try option A + int tmp_closest1 = closest1; + int tmp_closest2 = closest2; + t_object *tmp_ob1 = ob1; + t_object *tmp_ob2 = ob2; + int tmp_noutlet1 = noutlet1; + int tmp_ninlet2 = ninlet2; + for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) + { + if (sel->sel_what != y1 && sel->sel_what != y2) + { + tmp_ob2 = pd_checkobject(&sel->sel_what->g_pd); + tmp_ninlet2 = obj_ninlets(tmp_ob2); + tmp_closest1++; + if (tmp_closest1 >= tmp_noutlet1) + { + break; + } + else if (tmp_closest2 < tmp_ninlet2) + { + do_count = 1; + if (canvas_isconnected( + x, tmp_ob1, tmp_closest1, + tmp_ob2, tmp_closest2)) + { + do_count = 0; + } + if (obj_issignaloutlet(ob1, closest1) && + !obj_issignalinlet(ob2, closest2)) + { + do_count = 0; + } + if (pd_class(&tmp_ob1->ob_pd) == preset_node_class) + { + if (pd_class(&tmp_ob2->ob_pd) == message_class) + { + do_count = 0; + } + } + if (pd_class(&tmp_ob2->ob_pd) == preset_node_class + && pd_class(&tmp_ob1->ob_pd) != message_class) + { + do_count = 0; + } + successA += do_count; + } + } + } + //fprintf(stderr,"successA %d\n", successA); + + // try option B + tmp_closest1 = closest1; + tmp_closest2 = closest2; + tmp_ob1 = ob1; + tmp_ob2 = ob2; + tmp_noutlet1 = noutlet1; + tmp_ninlet2 = ninlet2; + for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) + { + if (sel->sel_what != y1 && sel->sel_what != y2) + { + tmp_ob1 = pd_checkobject(&sel->sel_what->g_pd); + tmp_noutlet1 = obj_noutlets(tmp_ob1); + tmp_closest2++; + if (tmp_closest2 >= tmp_ninlet2) + { + break; + } + else if (tmp_closest1 < tmp_noutlet1) + { + do_count = 1; + if (canvas_isconnected( + x, tmp_ob1, tmp_closest1, + tmp_ob2, tmp_closest2)) + { + do_count = 0; + } + if (obj_issignaloutlet(ob1, closest1) && + !obj_issignalinlet(ob2, closest2)) + { + do_count = 0; + } + if (pd_class(&tmp_ob1->ob_pd) == preset_node_class) + { + if (pd_class(&tmp_ob2->ob_pd) == message_class) + { + do_count = 0; + } + } + if (pd_class(&tmp_ob2->ob_pd) == preset_node_class + && pd_class(&tmp_ob1->ob_pd) != message_class) + { + do_count = 0; + } + successB += do_count; + } + } + } + //fprintf(stderr,"successB %d\n", successB); + + // now decide which one is better + // (we give preference to option A if both are equal) + if (successA >= successB) + { + // OPTION A (see description above) + for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) + { + /* do this only with objects that have not + been connected as of yet */ + if (sel->sel_what != y1 && sel->sel_what != y2) + { + ob2 = pd_checkobject(&sel->sel_what->g_pd); + ninlet2 = obj_ninlets(ob2); + closest1++; + if (closest1 >= noutlet1) + { + break; + } + else if (closest2 < ninlet2) + { + return_val = canvas_doconnect_doit( + x, y1, sel->sel_what, + closest1, closest2, 1, 1); + } + } + } + } + else + { + // OPTION B (see description above) + for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) + { + // do this only with objects that have not + // been connected as of yet + if (sel->sel_what != y1 && sel->sel_what != y2) + { + ob1 = pd_checkobject(&sel->sel_what->g_pd); + noutlet1 = obj_ninlets(ob1); + closest2++; + if (closest2 >= ninlet2) + { + break; + } + else if (closest1 < noutlet1) + { + return_val = canvas_doconnect_doit( + x, sel->sel_what, y2, + closest1, closest2, 1, 1); + } + } + } + } + } + return(return_val); + // end of FOURTH OPTION + } + } + + return(1); } void canvas_doconnect(t_canvas *x, int xpos, int ypos, int which, int doit) { - //fprintf(stderr,"canvas_doconnect\n"); - if (doit && x->gl_editor->e_selection && x->gl_editor->e_selection->sel_next) { - int result = canvas_trymulticonnect(x, xpos, ypos, which, doit); - if (!result) { - return; - } - } + //fprintf(stderr,"canvas_doconnect\n"); + if (doit && x->gl_editor->e_selection && + x->gl_editor->e_selection->sel_next) + { + int result = canvas_trymulticonnect(x, xpos, ypos, which, doit); + if (!result) + { + return; + } + } int x11=0, y11=0, x12=0, y12=0; t_gobj *y1; int x21=0, y21=0, x22=0, y22=0; t_gobj *y2; int xwas = x->gl_editor->e_xwas, ywas = x->gl_editor->e_ywas; - if (doit && !glob_shift) sys_vgui(".x%lx.c delete x\n", x); - else { - canvas_updateconnection(x, x->gl_editor->e_xwas, x->gl_editor->e_ywas, xpos, ypos, 0); - sys_vgui("pdtk_check_scroll_on_motion .x%lx.c 0\n", x); - } + if (doit && !glob_shift) + sys_vgui(".x%lx.c delete x\n", x); + else + { + canvas_updateconnection(x, x->gl_editor->e_xwas, x->gl_editor->e_ywas, + xpos, ypos, 0); + sys_vgui("pdtk_check_scroll_on_motion .x%lx.c 0\n", x); + } if ((y1 = canvas_findhitbox(x, xwas, ywas, &x11, &y11, &x12, &y12)) && (y2 = canvas_findhitbox(x, xpos, ypos, &x21, &y21, &x22, &y22))) @@ -4040,92 +4538,113 @@ void canvas_doconnect(t_canvas *x, int xpos, int ypos, int which, int doit) if (doit) { - canvas_doconnect_doit(x, y1, y2, closest1, closest2, 0, 1); + canvas_doconnect_doit(x, y1, y2, closest1, closest2, 0, 1); } - else + else // jsarlo { - t_rtext *y = glist_findrtext(x, (t_text *)&ob2->ob_g); + t_rtext *y = glist_findrtext(x, (t_text *)&ob2->ob_g); if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_inlet_tag, - (last_inlet_filter ? "black" : (inlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (inlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s " + "-strokewidth 1\n", + x, x->gl_editor->canvas_cnct_inlet_tag, + (last_inlet_filter ? + "black" : + (inlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (inlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); } if (y) { - last_inlet_filter = gobj_filter_highlight_behavior((t_text *)&ob2->ob_g); - //fprintf(stderr,"last_inlet_filter == %d\n", last_inlet_filter); + last_inlet_filter = + gobj_filter_highlight_behavior((t_text *)&ob2->ob_g); + //fprintf(stderr,"last_inlet_filter == %d\n", + // last_inlet_filter); sprintf(x->gl_editor->canvas_cnct_inlet_tag, "%si%d", rtext_gettag(y), closest2); - sys_vgui(".x%x.c itemconfigure %s -stroke $select_nlet_color -strokewidth $highlight_width\n", - x, - x->gl_editor->canvas_cnct_inlet_tag); + sys_vgui(".x%x.c itemconfigure %s " + "-stroke $select_nlet_color " + "-strokewidth $highlight_width\n", + x, x->gl_editor->canvas_cnct_inlet_tag); //sys_vgui(".x%x.c raise %s\n", // x, // x->gl_editor->canvas_cnct_inlet_tag); - inlet_issignal = obj_issignalinlet(ob2, closest2); - if (tooltips) { - objtooltip = 1; - sys_vgui("pdtk_canvas_enteritem .x%x.c %d %d %s -1;\n", - x, xpos, ypos, x->gl_editor->canvas_cnct_inlet_tag); - } + inlet_issignal = obj_issignalinlet(ob2, closest2); + if (tooltips) + { + objtooltip = 1; + sys_vgui("pdtk_canvas_enteritem .x%x.c %d %d %s -1;\n", + x, xpos, ypos, x->gl_editor->canvas_cnct_inlet_tag); + } } canvas_setcursor(x, CURSOR_EDITMODE_CONNECT); } // end jsarlo return; - } + } } // jsarlo if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) { sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_inlet_tag, - (last_inlet_filter ? "black" : (inlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (inlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } - x->gl_editor->canvas_cnct_inlet_tag[0] = 0; - } - if(x->gl_editor && x->gl_editor->gl_magic_glass) { - magicGlass_unbind(x->gl_editor->gl_magic_glass); - magicGlass_hide(x->gl_editor->gl_magic_glass); - } + x, x->gl_editor->canvas_cnct_inlet_tag, + (last_inlet_filter ? + "black" : + (inlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (inlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } + x->gl_editor->canvas_cnct_inlet_tag[0] = 0; + } + if(x->gl_editor && x->gl_editor->gl_magic_glass) + { + magicGlass_unbind(x->gl_editor->gl_magic_glass); + magicGlass_hide(x->gl_editor->gl_magic_glass); + } // end jsarlo - canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); + canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); } void canvas_selectinrect(t_canvas *x, int lox, int loy, int hix, int hiy) { - //fprintf(stderr,"canvas_selectinrect\n"); + //fprintf(stderr,"canvas_selectinrect\n"); t_gobj *y; - //t_undo_redo_sel *buf=NULL; - int selection_changed = 0; + //t_undo_redo_sel *buf=NULL; + int selection_changed = 0; for (y = x->gl_list; y; y = y->g_next) { int x1, y1, x2, y2; gobj_getrect(y, x, &x1, &y1, &x2, &y2); - if (hix >= x1 && lox <= x2 && hiy >= y1 && loy <= y2) { - if (!selection_changed) { - //buf = (t_undo_redo_sel *)getbytes(sizeof(*buf)); - //buf->u_undo = (t_undo_sel *)canvas_undo_set_selection(x); - selection_changed = 1; - } - if (!glist_isselected(x, y)) - glist_select(x, y); - else glist_deselect(x, y); - } - } - /*if (buf) { - buf->u_redo = (t_undo_sel *)canvas_undo_set_selection(x); - canvas_undo_add(x, 11, "selection", buf); - }*/ + if (hix >= x1 && lox <= x2 && hiy >= y1 && loy <= y2) + { + if (!selection_changed) + { + //buf = (t_undo_redo_sel *)getbytes(sizeof(*buf)); + //buf->u_undo = (t_undo_sel *)canvas_undo_set_selection(x); + selection_changed = 1; + } + if (!glist_isselected(x, y)) + glist_select(x, y); + else glist_deselect(x, y); + } + } + /*if (buf) { + buf->u_redo = (t_undo_sel *)canvas_undo_set_selection(x); + canvas_undo_add(x, 11, "selection", buf); + }*/ } static void canvas_doregion(t_canvas *x, int xpos, int ypos, int doit) @@ -4151,49 +4670,49 @@ static void canvas_doregion(t_canvas *x, int xpos, int ypos, int doit) /* static void canvas_mouseup_gop(t_canvas *x, t_gobj *g) { - //simulate clearing and recreating object - gobj_activate(g, x, 1); - t_object *ob = pd_checkobject(&g->g_pd); - t_rtext *yyyy = glist_findrtext(x, (t_text *)&ob->ob_g); - //copy current text + //simulate clearing and recreating object + gobj_activate(g, x, 1); + t_object *ob = pd_checkobject(&g->g_pd); + t_rtext *yyyy = glist_findrtext(x, (t_text *)&ob->ob_g); + //copy current text char *buf; int bufsize; rtext_gettext(yyyy, &buf, &bufsize); - //fprintf(stderr, ">%s<\n", buf); - rtext_key(yyyy, 127, NULL); + //fprintf(stderr, ">%s<\n", buf); + rtext_key(yyyy, 127, NULL); - //recreate object with no args - glist_deselect(x, g); + //recreate object with no args + glist_deselect(x, g); - //object was recreated, so now it is latest in the queue - t_gobj *z = x->gl_list; + //object was recreated, so now it is latest in the queue + t_gobj *z = x->gl_list; - while (z->g_next) { - z = z->g_next; - } + while (z->g_next) { + z = z->g_next; + } - glist_select(x, z); - g = z; - ob = pd_checkobject(&g->g_pd); - yyyy = glist_findrtext(x, (t_text *)&ob->ob_g); + glist_select(x, z); + g = z; + ob = pd_checkobject(&g->g_pd); + yyyy = glist_findrtext(x, (t_text *)&ob->ob_g); - //redo the old text - int i; - for (i = 0; i < bufsize; i++) { - rtext_key(yyyy, (int)buf[i], NULL); - } - gobj_activate(z, x, 1); - x->gl_editor->e_textdirty = 1; + //redo the old text + int i; + for (i = 0; i < bufsize; i++) { + rtext_key(yyyy, (int)buf[i], NULL); + } + gobj_activate(z, x, 1); + x->gl_editor->e_textdirty = 1; } */ void canvas_mouseup(t_canvas *x, t_floatarg fxpos, t_floatarg fypos, t_floatarg fwhich) { - //if (toggle_moving == 1) { - // toggle_moving = 0; - // sys_vgui("pdtk_toggle_xy_tooltip .x%lx %d\n", x, 0); - //} + //if (toggle_moving == 1) { + // toggle_moving = 0; + // sys_vgui("pdtk_toggle_xy_tooltip .x%lx %d\n", x, 0); + //} int xpos = fxpos, ypos = fypos, which = fwhich; /* post("mouseup %d %d %d", xpos, ypos, which); */ if (!x->gl_editor) @@ -4205,7 +4724,7 @@ void canvas_mouseup(t_canvas *x, canvas_upclicktime = sys_getrealtime(); canvas_upx = xpos; canvas_upy = ypos; - glob_lmclick = 0; + glob_lmclick = 0; if (x->gl_editor->e_onmotion == MA_CONNECT) canvas_doconnect(x, xpos, ypos, which, 1); @@ -4230,166 +4749,201 @@ void canvas_mouseup(t_canvas *x, vmess(&gl2->gl_pd, gensym("menu-open"), ""); x->gl_editor->e_onmotion = MA_NONE; sys_vgui( - "pdtk_check .x%lx {Discard changes to '%s'?} {.x%lx dirty 0;\n} no\n", + "pdtk_check .x%lx {Discard changes to '%s'?} {.x%lx dirty 0;\n} no\n", canvas_getrootfor(gl2), canvas_getrootfor(gl2)->gl_name->s_name, gl2); return; }*/ /* OK, activate it */ - /* - // but before we do, check if this is GOP and adjust accordingly - //fprintf(stderr,"activate..."); - if (pd_class(&g->g_pd) == canvas_class && - ((t_glist *)g)->gl_isgraph && - canvas_isabstraction((t_glist *)g)) - { - //fprintf(stderr,"gop..."); - // if mouse has not moved AND this object does not have its text hidden (otherwise we only translate the selection) - if (!(((t_glist *)g)->gl_hidetext) && !x->gl_editor->e_lastmoved) { - //fprintf(stderr,"yes\n"); - canvas_mouseup_gop(x, x->gl_editor->e_selection->sel_what); - } - //else fprintf(stderr,"no\n"); - } - // else if it is a regular object - */ - //else { - //fprintf(stderr,"reg_obj\n"); - gobj_activate(x->gl_editor->e_selection->sel_what, x, 1); - //} - } - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); - } else if (x->gl_editor->e_onmotion == MA_SCROLL) { - sys_vgui("pdtk_canvas_scroll_xy_click .x%lx %d %d 0\n", (t_int)x, (int)fxpos, (int)fypos); - x->gl_editor->e_onmotion = MA_NONE; - canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); - } + /* + // but before we do, check if this is GOP and adjust accordingly + //fprintf(stderr,"activate..."); + if (pd_class(&g->g_pd) == canvas_class && + ((t_glist *)g)->gl_isgraph && + canvas_isabstraction((t_glist *)g)) + { + //fprintf(stderr,"gop..."); + // if mouse has not moved AND this object does not have its text hidden (otherwise we only translate the selection) + if (!(((t_glist *)g)->gl_hidetext) && !x->gl_editor->e_lastmoved) { + //fprintf(stderr,"yes\n"); + canvas_mouseup_gop(x, x->gl_editor->e_selection->sel_what); + } + //else fprintf(stderr,"no\n"); + } + // else if it is a regular object + */ + //else { + //fprintf(stderr,"reg_obj\n"); + gobj_activate(x->gl_editor->e_selection->sel_what, x, 1); + //} + } + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + } + else if (x->gl_editor->e_onmotion == MA_SCROLL) + { + sys_vgui("pdtk_canvas_scroll_xy_click .x%lx %d %d 0\n", + (t_int)x, (int)fxpos, (int)fypos); + x->gl_editor->e_onmotion = MA_NONE; + canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); + } - if (x->gl_editor->e_onmotion != MA_CONNECT || x->gl_editor->e_onmotion == MA_CONNECT && !glob_shift) { - //fprintf(stderr,"releasing shift during connect without the button pressed\n"); - if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0) - { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_outlet_tag, - (last_outlet_filter ? "black" : (outlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (outlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - } - if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) - { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_inlet_tag, - (last_inlet_filter ? "black" : (inlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (inlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); - x->gl_editor->canvas_cnct_inlet_tag[0] = 0; - } - - x->gl_editor->e_onmotion = MA_NONE; - } - //fprintf(stderr,"canvas_mouseup -> canvas_doclick %d\n", which); - if (canvas_last_glist_mod == -1) //this is to ignore scrollbar clicks from within tcl - canvas_doclick(x, xpos, ypos, 0, (glob_shift + glob_ctrl*2 + glob_alt*4), 0); + if (x->gl_editor->e_onmotion != MA_CONNECT || + x->gl_editor->e_onmotion == MA_CONNECT && !glob_shift) + { + //fprintf(stderr,"releasing shift during connect without " + // "the button pressed\n"); + if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0) + { + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s " + "-strokewidth 1\n", + x, x->gl_editor->canvas_cnct_outlet_tag, + (last_outlet_filter ? + "black" : + (outlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (outlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); + } + if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) + { + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s " + "-strokewidth 1\n", + x, x->gl_editor->canvas_cnct_inlet_tag, + (last_inlet_filter ? + "black" : + (inlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (inlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); + x->gl_editor->canvas_cnct_inlet_tag[0] = 0; + } + + x->gl_editor->e_onmotion = MA_NONE; + } + //fprintf(stderr,"canvas_mouseup -> canvas_doclick %d\n", which); + /* this is to ignore scrollbar clicks from within tcl */ + if (canvas_last_glist_mod == -1) + canvas_doclick(x, xpos, ypos, 0, + (glob_shift + glob_ctrl*2 + glob_alt*4), 0); } void canvas_mousedown_middle(t_canvas *x, t_floatarg xpos, t_floatarg ypos, t_floatarg which, t_floatarg mod) { - int shiftmod, runmode, altmod, rightclick, middleclick; + int shiftmod, runmode, altmod, rightclick, middleclick; - // remove stale tooltips, if any - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } + // remove stale tooltips, if any + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } - // read key and mouse button states + // read key and mouse button states shiftmod = ((int)mod & SHIFTMOD); runmode = (((int)mod & CTRLMOD) || (!x->gl_edit)); altmod = ((int)mod & ALTMOD); rightclick = ((int)mod & RIGHTCLICK); x->gl_editor->e_xwas = (int)xpos; x->gl_editor->e_ywas = (int)ypos; - middleclick = (which == 2 ? 1 : 0); - - /* let's check if we are not middle-clicking */ - //fprintf(stderr,"middleclick=%d doit=%d\n", middleclick, doit); - if (middleclick) - { - if (x->gl_editor && x->gl_editor->e_textedfor) { - canvas_mousedown(x, xpos, ypos, which, mod); - canvas_mouseup(x, xpos, ypos, which); - sys_vgui("pdtk_pastetext\n"); - } else { - sys_vgui("pdtk_canvas_scroll_xy_click .x%lx %d %d 3\n", (t_int)x, (int)xpos, (int)ypos); - x->gl_editor->e_onmotion = MA_SCROLL; - canvas_setcursor(x, CURSOR_SCROLL); - } - } + middleclick = (which == 2 ? 1 : 0); + + /* let's check if we are not middle-clicking */ + //fprintf(stderr,"middleclick=%d doit=%d\n", middleclick, doit); + if (middleclick) + { + if (x->gl_editor && x->gl_editor->e_textedfor) + { + canvas_mousedown(x, xpos, ypos, which, mod); + canvas_mouseup(x, xpos, ypos, which); + sys_vgui("pdtk_pastetext\n"); + } + else + { + sys_vgui("pdtk_canvas_scroll_xy_click .x%lx %d %d 3\n", + (t_int)x, (int)xpos, (int)ypos); + x->gl_editor->e_onmotion = MA_SCROLL; + canvas_setcursor(x, CURSOR_SCROLL); + } + } } /* displace the selection by (dx, dy) pixels */ static void canvas_displaceselection(t_canvas *x, int dx, int dy) { - //fprintf(stderr,"canvas_displaceselection %d %d\n", dx, dy); + //fprintf(stderr,"canvas_displaceselection %d %d\n", dx, dy); t_selection *y; char *tag = NULL; int resortin = 0, resortout = 0; - old_displace = 0; - if (!we_are_undoing && !canvas_undo_already_set_move && x->gl_editor->e_selection) + old_displace = 0; + if (!we_are_undoing && + !canvas_undo_already_set_move && + x->gl_editor->e_selection) { //canvas_setundo(x, canvas_undo_move, canvas_undo_set_move(x, 1), // "motion"); - canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 1)); + canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 1)); canvas_undo_already_set_move = 1; } for (y = x->gl_editor->e_selection; y; y = y->sel_next) { - /* for the time being let's discern from vanilla objects and those that don't conform */ - t_glist *yglist = (t_glist *)(y->sel_what); - if (y->sel_what->g_pd->c_wb && y->sel_what->g_pd->c_wb->w_displacefnwtag) { - /* this is a vanilla object */ - gobj_displace_withtag(y->sel_what, x, dx, dy); - //fprintf(stderr, "displaceselection with tag\n"); - } - else { - /* we will move the non-conforming objects the old way THIS SHOULD GO AWAY SOON*/ - gobj_displace(y->sel_what, x, dx, dy); - t_object *ob = pd_checkobject(&y->sel_what->g_pd); - t_rtext *yyyy = glist_findrtext(x, (t_text *)&ob->ob_g); - if (yyyy) tag = rtext_gettag(yyyy); - if (tag) - canvas_restore_original_position(x, y->sel_what, tag, -1); - else - old_displace = 1; - tag = NULL; - //fprintf(stderr, "displaceselection old_displace=%d\n", old_displace); - } + /* for the time being let's discern from vanilla objects + and those that don't conform */ + t_glist *yglist = (t_glist *)(y->sel_what); + if (y->sel_what->g_pd->c_wb && + y->sel_what->g_pd->c_wb->w_displacefnwtag) + { + /* this is a vanilla object */ + gobj_displace_withtag(y->sel_what, x, dx, dy); + //fprintf(stderr, "displaceselection with tag\n"); + } + else { + /* we will move the non-conforming objects the old way + THIS SHOULD GO AWAY SOON*/ + gobj_displace(y->sel_what, x, dx, dy); + t_object *ob = pd_checkobject(&y->sel_what->g_pd); + t_rtext *yyyy = glist_findrtext(x, (t_text *)&ob->ob_g); + if (yyyy) tag = rtext_gettag(yyyy); + if (tag) + canvas_restore_original_position(x, y->sel_what, tag, -1); + else + old_displace = 1; + tag = NULL; + //fprintf(stderr, "displaceselection old_displace=%d\n", + // old_displace); + } t_class *cl = pd_class(&y->sel_what->g_pd); if (cl == vinlet_class) resortin = 1; else if (cl == voutlet_class) resortout = 1; } - if (dx || dy) { - sys_vgui(".x%lx.c move selected %d %d\n", x, dx, dy); - if (resortin) canvas_resortinlets(x); - if (resortout) canvas_resortoutlets(x); - //sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); - if (x->gl_editor->e_selection) - canvas_dirty(x, 1); - } - // if we have old_displace, legacy displaced objects won't conform - // to proper ordering of objects as they have been redrawn on top - // of everything else rather than where they were supposed to be - // (e.g. possibly in the middle or at the bottom) - if (old_displace) canvas_redraw(x); - old_displace = 0; + if (dx || dy) + { + sys_vgui(".x%lx.c move selected %d %d\n", x, dx, dy); + if (resortin) canvas_resortinlets(x); + if (resortout) canvas_resortoutlets(x); + //sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + if (x->gl_editor->e_selection) + canvas_dirty(x, 1); + } + // if we have old_displace, legacy displaced objects won't conform + // to proper ordering of objects as they have been redrawn on top + // of everything else rather than where they were supposed to be + // (e.g. possibly in the middle or at the bottom) + if (old_displace) canvas_redraw(x); + old_displace = 0; } /* this routine is called whenever a key is pressed or released. "x" may be zero if there's no current canvas. The first argument is true or false for down/up; the second one is either a symbolic key name (e.g., "Right" or an Ascii key number. The third is the shift key. - In Pd-L2Ork additional argument is to determine whether we're pasting - to ignore unnecessary getscroll calls at paste time */ + In Pd-L2Ork additional argument is to determine whether we're pasting + to ignore unnecessary getscroll calls at paste time */ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av) { static t_symbol *keynumsym, *keyupsym, *keynamesym; @@ -4397,14 +4951,15 @@ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av) t_symbol *gotkeysym; int down, shift; - int focus = 1; - int autorepeat = 0; - - /* remove stale tooltips, if any */ - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } + int focus = 1; + int autorepeat = 0; + + /* remove stale tooltips, if any */ + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } if (ac < 5) return; @@ -4415,25 +4970,30 @@ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av) shift = (atom_getfloat(av+2) != 0); /* nonzero if shift-ed */ autorepeat = (int)(atom_getfloat(av+4)); //fprintf(stderr,"canvas_key autorepeat=%d\n", autorepeat); - glob_shift = shift; - //fprintf(stderr,"%d %d %d %d\n", (x->gl_editor != NULL ? 1 : 0), (x->gl_editor->e_onmotion == MA_CONNECT ? 1 : 0), glob_shift, glob_lmclick); - - // check if user released shift while trying manual multi-connect - if (x->gl_editor->e_onmotion == MA_CONNECT && !glob_shift && !glob_lmclick) { - //fprintf(stderr,"shift released during connect\n"); - sys_vgui(".x%lx.c delete x\n", x); - canvas_mouseup(x, canvas_last_glist_x, canvas_last_glist_y, 0); - } - - // check if user released shift while dragging inside an object - if (x->gl_editor->e_onmotion == MA_PASSOUT && !glob_shift && !glob_lmclick) { - //fprintf(stderr,"shift released during button+shift drag\n"); - canvas_mouseup(x, x->gl_editor->e_xwas, x->gl_editor->e_ywas, 0); - } - - if (av[1].a_type == A_SYMBOL) { + glob_shift = shift; + //fprintf(stderr,"%d %d %d %d\n", (x->gl_editor != NULL ? 1 : 0), + // (x->gl_editor->e_onmotion == MA_CONNECT ? 1 : 0), + // glob_shift, glob_lmclick); + + // check if user released shift while trying manual multi-connect + if (x->gl_editor->e_onmotion == MA_CONNECT && !glob_shift && !glob_lmclick) + { + //fprintf(stderr,"shift released during connect\n"); + sys_vgui(".x%lx.c delete x\n", x); + canvas_mouseup(x, canvas_last_glist_x, canvas_last_glist_y, 0); + } + + // check if user released shift while dragging inside an object + if (x->gl_editor->e_onmotion == MA_PASSOUT && !glob_shift && !glob_lmclick) + { + //fprintf(stderr,"shift released during button+shift drag\n"); + canvas_mouseup(x, x->gl_editor->e_xwas, x->gl_editor->e_ywas, 0); + } + + if (av[1].a_type == A_SYMBOL) + { gotkeysym = av[1].a_w.w_symbol; - } + } else if (av[1].a_type == A_FLOAT) { char buf[3]; @@ -4447,9 +5007,9 @@ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av) case 127:gotkeysym = gensym("Delete"); break; default: sprintf(buf, "%c", (int)(av[1].a_w.w_float)); - /*-- moo: assume keynum is a Unicode codepoint; encode as UTF-8 --*/ - char buf[UTF8_MAXBYTES1]; - u8_wc_toutf8_nul(buf, (UCS4)(av[1].a_w.w_float)); + /*-- moo: assume keynum is a Unicode codepoint; encode as UTF-8 --*/ + char buf[UTF8_MAXBYTES1]; + u8_wc_toutf8_nul(buf, (UCS4)(av[1].a_w.w_float)); gotkeysym = gensym(buf); } } @@ -4462,9 +5022,10 @@ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av) return; } #if 0 - post("keynum %d, down %d, gotkeysym %s", (int)keynum, down, gotkeysym->s_name); + post("keynum %d, down %d, gotkeysym %s", + (int)keynum, down, gotkeysym->s_name); #endif - if (ac == 4) focus = (int)(av[3].a_w.w_float); + if (ac == 4) focus = (int)(av[3].a_w.w_float); if (keynum == '\r') keynum = '\n'; if (av[1].a_type == A_SYMBOL && !strcmp(av[1].a_w.w_symbol->s_name, "Return")) @@ -4485,20 +5046,21 @@ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av) else if (keynum == 29) keynum = 0, gotkeysym = gensym("Right"); #endif - if (!autorepeat) { - if (keynumsym->s_thing && down) - pd_float(keynumsym->s_thing, (t_float)keynum); - if (keyupsym->s_thing && !down) - pd_float(keyupsym->s_thing, (t_float)keynum); - if (keynamesym->s_thing) - { - t_atom at[2]; - at[0] = av[0]; - SETFLOAT(at, down); - SETSYMBOL(at+1, gotkeysym); - pd_list(keynamesym->s_thing, 0, 2, at); - } - } + if (!autorepeat) + { + if (keynumsym->s_thing && down) + pd_float(keynumsym->s_thing, (t_float)keynum); + if (keyupsym->s_thing && !down) + pd_float(keyupsym->s_thing, (t_float)keynum); + if (keynamesym->s_thing) + { + t_atom at[2]; + at[0] = av[0]; + SETFLOAT(at, down); + SETSYMBOL(at+1, gotkeysym); + pd_list(keynamesym->s_thing, 0, 2, at); + } + } if (!x->gl_editor) /* if that 'invis'ed the window, we'd better stop. */ return; if (x && down) @@ -4519,87 +5081,102 @@ void canvas_key(t_canvas *x, t_symbol *s, int ac, t_atom *av) || !strcmp(gotkeysym->s_name, "Down") || !strcmp(gotkeysym->s_name, "Left") || !strcmp(gotkeysym->s_name, "Right") - || !strcmp(gotkeysym->s_name, "CtrlLeft") - || !strcmp(gotkeysym->s_name, "CtrlRight") - || !strcmp(gotkeysym->s_name, "ShiftLeft") - || !strcmp(gotkeysym->s_name, "ShiftRight") - || !strcmp(gotkeysym->s_name, "CtrlShiftLeft") - || !strcmp(gotkeysym->s_name, "CtrlShiftRight") - || !strcmp(gotkeysym->s_name, "Home") - || !strcmp(gotkeysym->s_name, "End"))) + || !strcmp(gotkeysym->s_name, "CtrlLeft") + || !strcmp(gotkeysym->s_name, "CtrlRight") + || !strcmp(gotkeysym->s_name, "ShiftLeft") + || !strcmp(gotkeysym->s_name, "ShiftRight") + || !strcmp(gotkeysym->s_name, "CtrlShiftLeft") + || !strcmp(gotkeysym->s_name, "CtrlShiftRight") + || !strcmp(gotkeysym->s_name, "Home") + || !strcmp(gotkeysym->s_name, "End"))) { /* send the key to the box's editor */ /*if (!x->gl_editor->e_textdirty) { //canvas_setundo(x, canvas_undo_cut, // canvas_undo_set_cut(x, UCUT_TEXT), "typing"); - canvas_undo_add(x, 3, "typing", canvas_undo_set_cut(x, UCUT_TEXT)); + canvas_undo_add(x, 3, "typing", + canvas_undo_set_cut(x, UCUT_TEXT)); }*/ rtext_key(x->gl_editor->e_textedfor, (int)keynum, gotkeysym); - canvas_fixlinesfor(x, (t_text *)(x->gl_editor->e_selection->sel_what)); + canvas_fixlinesfor(x, + (t_text *)(x->gl_editor->e_selection->sel_what)); if (x->gl_editor->e_textdirty) canvas_dirty(x, 1); } /* check for backspace or clear */ else if ((keynum == 8 || keynum == 127) && focus) { - //fprintf(stderr,"backspace or clear\n"); + //fprintf(stderr,"backspace or clear\n"); if (x->gl_editor->e_selectedline) canvas_clearline(x); else if (x->gl_editor->e_selection) { //canvas_setundo(x, canvas_undo_cut, // canvas_undo_set_cut(x, UCUT_CLEAR), "clear"); - canvas_undo_add(x, 3, "clear", canvas_undo_set_cut(x, UCUT_CLEAR)); + canvas_undo_add(x, 3, "clear", + canvas_undo_set_cut(x, UCUT_CLEAR)); canvas_doclear(x); - glob_preset_node_list_check_loc_and_update(); + glob_preset_node_list_check_loc_and_update(); } } /* check for arrow keys */ - else if (x->gl_editor->e_selection) { - if (!strcmp(gotkeysym->s_name, "Up")) { - canvas_displaceselection(x, 0, shift ? -10 : -1); - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); - } - else if (!strcmp(gotkeysym->s_name, "Down")) { - canvas_displaceselection(x, 0, shift ? 10 : 1); - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); - } - else if (!strcmp(gotkeysym->s_name, "Left") || !strcmp(gotkeysym->s_name, "ShiftLeft")) { - canvas_displaceselection(x, shift ? -10 : -1, 0); - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); - } - else if (!strcmp(gotkeysym->s_name, "Right") || !strcmp(gotkeysym->s_name, "ShiftRight")) { - canvas_displaceselection(x, shift ? 10 : 1, 0); - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); - } - } + else if (x->gl_editor->e_selection) + { + if (!strcmp(gotkeysym->s_name, "Up")) + { + canvas_displaceselection(x, 0, shift ? -10 : -1); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + } + else if (!strcmp(gotkeysym->s_name, "Down")) + { + canvas_displaceselection(x, 0, shift ? 10 : 1); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + } + else if (!strcmp(gotkeysym->s_name, "Left") || + !strcmp(gotkeysym->s_name, "ShiftLeft")) + { + canvas_displaceselection(x, shift ? -10 : -1, 0); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + } + else if (!strcmp(gotkeysym->s_name, "Right") || + !strcmp(gotkeysym->s_name, "ShiftRight")) + { + canvas_displaceselection(x, shift ? 10 : 1, 0); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + } + } } if (x && keynum == 0 && x->gl_edit && !strncmp(gotkeysym->s_name, "Alt", 3)) - { - glob_alt = down; - } + { + glob_alt = down; + } /* if control key goes up or down, and if we're in edit mode, change cursor to indicate how the click action changes - NEW: do so only if not doing anything else in edit mode */ + NEW: do so only if not doing anything else in edit mode */ if (x && keynum == 0 && !strncmp(gotkeysym->s_name, "Control", 7)) - { - //fprintf(stderr,"ctrl\n"); - glob_ctrl = down; - if(x->gl_edit && x->gl_editor->e_onmotion == MA_NONE) { - canvas_setcursor(x, down ? - CURSOR_RUNMODE_NOTHING : CURSOR_EDITMODE_NOTHING); - sys_vgui("pdtk_canvas_editval .x%lx %d\n", (t_int)x, down ? 0 : 1); + { + //fprintf(stderr,"ctrl\n"); + glob_ctrl = down; + if(x->gl_edit && x->gl_editor->e_onmotion == MA_NONE) + { + canvas_setcursor(x, down ? + CURSOR_RUNMODE_NOTHING : CURSOR_EDITMODE_NOTHING); + sys_vgui("pdtk_canvas_editval .x%lx %d\n", (t_int)x, down ? 0 : 1); } - } - //fprintf(stderr," %d %d %d %s %d %d\n", glob_shift, glob_ctrl, glob_alt, gotkeysym->s_name, keynum, down); - //canvas_motion(x, canvas_last_glist_x, canvas_last_glist_y, canvas_last_glist_mod); - pd_vmess(&x->gl_pd, gensym("motion"), "fff", (double)canvas_last_glist_x, (double)canvas_last_glist_y, (double)(glob_shift+glob_ctrl*2+glob_alt*4)); + } + //fprintf(stderr," %d %d %d %s %d %d\n", + // glob_shift, glob_ctrl, glob_alt, gotkeysym->s_name, keynum, down); + //canvas_motion(x, canvas_last_glist_x, canvas_last_glist_y, canvas_last_glist_mod); + pd_vmess(&x->gl_pd, gensym("motion"), "fff", + (double)canvas_last_glist_x, + (double)canvas_last_glist_y, + (double)(glob_shift+glob_ctrl*2+glob_alt*4)); } extern void graph_checkgop_rect(t_gobj *z, t_glist *glist, @@ -4608,7 +5185,8 @@ extern void graph_checkgop_rect(t_gobj *z, t_glist *glist, void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos, t_floatarg fmod) { - //fprintf(stderr,"motion %d %d %d %d\n", (int)xpos, (int)ypos, (int)fmod, canvas_last_glist_mod); + //fprintf(stderr,"motion %d %d %d %d\n", + // (int)xpos, (int)ypos, (int)fmod, canvas_last_glist_mod); //fprintf(stderr,"canvas_motion=%d\n",x->gl_editor->e_onmotion); int mod = fmod; if (!x->gl_editor) @@ -4616,12 +5194,13 @@ void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos, bug("editor"); return; } - if (canvas_last_glist_mod == -1 && mod != -1) { - //fprintf(stderr,"revert the cursor %d\n", x->gl_edit); - if (x->gl_edit) - canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); - else - canvas_setcursor(x, CURSOR_RUNMODE_NOTHING); + if (canvas_last_glist_mod == -1 && mod != -1) + { + //fprintf(stderr,"revert the cursor %d\n", x->gl_edit); + if (x->gl_edit) + canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); + else + canvas_setcursor(x, CURSOR_RUNMODE_NOTHING); } glist_setlastxymod(x, xpos, ypos, mod); if (x->gl_editor->e_onmotion == MA_MOVE) @@ -4632,17 +5211,19 @@ void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos, x->gl_editor->e_ywas = ypos; x->gl_editor->e_xnew = xpos; x->gl_editor->e_ynew = ypos; - //sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); - //sys_vgui("pdtk_check_scroll_on_motion .x%lx.c 20\n", x); + //sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + //sys_vgui("pdtk_check_scroll_on_motion .x%lx.c 20\n", x); } - else if (x->gl_editor->e_onmotion == MA_REGION) { + else if (x->gl_editor->e_onmotion == MA_REGION) + { canvas_doregion(x, xpos, ypos, 0); - sys_vgui("pdtk_check_scroll_on_motion .x%lx.c 0\n", x); - } - else if (x->gl_editor->e_onmotion == MA_CONNECT) { - //fprintf(stderr,"MA_CONNECT\n"); + sys_vgui("pdtk_check_scroll_on_motion .x%lx.c 0\n", x); + } + else if (x->gl_editor->e_onmotion == MA_CONNECT) + { + //fprintf(stderr,"MA_CONNECT\n"); canvas_doconnect(x, xpos, ypos, 0, 0); - } + } else if (x->gl_editor->e_onmotion == MA_PASSOUT) { if (!x->gl_editor->e_motionfn) @@ -4682,60 +5263,68 @@ void canvas_motion(t_canvas *x, t_floatarg xpos, t_floatarg ypos, gobj_vis(y1, x, 0); canvas_fixlinesfor(x, ob); gobj_vis(y1, x, 1); - canvas_dirty(x, 1); + canvas_dirty(x, 1); } else if (ob && ob->ob_pd == canvas_class) { - int tmpx1 = 0, tmpy1 = 0, tmpx2 = 0, tmpy2 = 0; - int tmp_x_final = 0, tmp_y_final = 0; + int tmpx1 = 0, tmpy1 = 0, tmpx2 = 0, tmpy2 = 0; + int tmp_x_final = 0, tmp_y_final = 0; gobj_vis(y1, x, 0); ((t_canvas *)ob)->gl_pixwidth += xpos - x->gl_editor->e_xnew; ((t_canvas *)ob)->gl_pixheight += ypos - x->gl_editor->e_ynew; - graph_checkgop_rect((t_gobj *)ob, x, &tmpx1, &tmpy1, &tmpx2, &tmpy2); - tmpx1 = ob->te_xpix; - tmpy1 = ob->te_ypix; - //fprintf(stderr,"%d %d %d %d\n", tmpx1, tmpy1, tmpx2, tmpy2); - if (!((t_canvas *)ob)->gl_hidetext) { - tmp_x_final = tmpx2 - tmpx1; - tmp_y_final = tmpy2 - tmpy1; - } else { - tmp_x_final = tmpx2; - tmp_y_final = tmpy2; - } - if (tmp_x_final > ((t_canvas *)ob)->gl_pixwidth) - ((t_canvas *)ob)->gl_pixwidth = tmp_x_final; - if (tmp_y_final > ((t_canvas *)ob)->gl_pixheight) - ((t_canvas *)ob)->gl_pixheight = tmp_y_final; + graph_checkgop_rect((t_gobj *)ob, x, &tmpx1, &tmpy1, &tmpx2, + &tmpy2); + tmpx1 = ob->te_xpix; + tmpy1 = ob->te_ypix; + //fprintf(stderr,"%d %d %d %d\n", tmpx1, tmpy1, tmpx2, tmpy2); + if (!((t_canvas *)ob)->gl_hidetext) + { + tmp_x_final = tmpx2 - tmpx1; + tmp_y_final = tmpy2 - tmpy1; + } + else + { + tmp_x_final = tmpx2; + tmp_y_final = tmpy2; + } + if (tmp_x_final > ((t_canvas *)ob)->gl_pixwidth) + ((t_canvas *)ob)->gl_pixwidth = tmp_x_final; + if (tmp_y_final > ((t_canvas *)ob)->gl_pixheight) + ((t_canvas *)ob)->gl_pixheight = tmp_y_final; x->gl_editor->e_xnew = xpos; x->gl_editor->e_ynew = ypos; canvas_fixlinesfor(x, ob); gobj_vis(y1, x, 1); - canvas_dirty(x, 1); + canvas_dirty(x, 1); } else post("not resizable"); } } - else if (x->gl_editor->e_onmotion == MA_SCROLL || mod == -1) { - // we use bogus mod from tcl to let editor know we are scrolling - if (mod == -1) - canvas_setcursor(x, CURSOR_RUNMODE_CLICKME); - //fprintf(stderr,"canvas_motion MA_SCROLL\n"); - } + else if (x->gl_editor->e_onmotion == MA_SCROLL || mod == -1) + { + // we use bogus mod from tcl to let editor know we are scrolling + if (mod == -1) + canvas_setcursor(x, CURSOR_RUNMODE_CLICKME); + //fprintf(stderr,"canvas_motion MA_SCROLL\n"); + } else { - //fprintf(stderr,"canvas_motion -> doclick %d %d\n", x->gl_editor->e_onmotion, mod); - //sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); - canvas_doclick(x, xpos, ypos, 0, mod, 0); - //pd_vmess(&x->gl_pd, gensym("mouse"), "ffff", (double)xpos, (double)ypos, 0, (double)mod); - } - //if (toggle_moving == 1) { - // sys_vgui("pdtk_update_xy_tooltip .x%lx %d %d\n", x, (int)xpos, (int)ypos); - //} + //fprintf(stderr,"canvas_motion -> doclick %d %d\n", + // x->gl_editor->e_onmotion, mod); + //sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + canvas_doclick(x, xpos, ypos, 0, mod, 0); + //pd_vmess(&x->gl_pd, gensym("mouse"), "ffff", + // (double)xpos, (double)ypos, 0, (double)mod); + } + //if (toggle_moving == 1) { + // sys_vgui("pdtk_update_xy_tooltip .x%lx %d %d\n", + // x, (int)xpos, (int)ypos); + //} x->gl_editor->e_lastmoved = 1; } void canvas_startmotion(t_canvas *x) { - //fprintf(stderr,"canvas_startmotion\n"); + //fprintf(stderr,"canvas_startmotion\n"); int xval, yval; if (!x->gl_editor) return; glist_getnextxy(x, &xval, &yval); @@ -4785,28 +5374,34 @@ void glob_closeall(void*dummy, t_floatarg fforce) the user really wants to discard changes */ void glob_verifyquit(void *dummy, t_floatarg f) { - //fprintf(stderr, "glob_verifyquit %f\n", f); + //fprintf(stderr, "glob_verifyquit %f\n", f); t_glist *g, *g2; /* find all root canvases */ for (g = canvas_list; g; g = g->gl_next) if (g2 = glist_finddirty(g)) { - /* first open window */ - if (!glist_istoplevel(g2) && g2->gl_env) { - /* if this is an abstraction */ - vmess(&g2->gl_pd, gensym("menu-open"), ""); - } else { - /* is this even necessary? */ - canvas_vis(g2, 1); - } - if (!glist_istoplevel(g2) && g->gl_env) { - /* if this is an abstraction */ - sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 3;}\n", + /* first open window */ + if (!glist_istoplevel(g2) && g2->gl_env) + { + /* if this is an abstraction */ + vmess(&g2->gl_pd, gensym("menu-open"), ""); + } + else + { + /* is this even necessary? */ + canvas_vis(g2, 1); + } + if (!glist_istoplevel(g2) && g->gl_env) + { + /* if this is an abstraction */ + sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 3;}\n", g2, g2); - } else { - sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 3;}\n", + } + else + { + sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 3;}\n", canvas_getrootfor(g2), g2); - } + } //canvas_vis(g2, 1); //sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 3;\n}\n", // canvas_getrootfor(g2), g2); @@ -4819,10 +5414,10 @@ void glob_verifyquit(void *dummy, t_floatarg f) //void canvas_dofree(t_gobj *dummy, t_glist *x) //{ - //int dspstate = canvas_suspend_dsp(); - //sys_flushqueue(); - //pd_free(&x->gl_pd); - //canvas_resume_dsp(dspstate); + //int dspstate = canvas_suspend_dsp(); + //sys_flushqueue(); + //pd_free(&x->gl_pd); + //canvas_resume_dsp(dspstate); //} /* close a window (or possibly quit Pd), checking for dirty flags. @@ -4834,11 +5429,12 @@ void glob_verifyquit(void *dummy, t_floatarg f) */ void canvas_menuclose(t_canvas *x, t_floatarg fforce) { - //fprintf(stderr,"canvas_menuclose %lx %f\n", (t_int)x, fforce); + //fprintf(stderr,"canvas_menuclose %lx %f\n", (t_int)x, fforce); int force = fforce; t_glist *g; - if (x->gl_owner && (force == 0 || force == 1)) { - //fprintf(stderr," invis\n"); + if (x->gl_owner && (force == 0 || force == 1)) + { + //fprintf(stderr," invis\n"); canvas_vis(x, 0); /* if subpatch, just invis it */ } else if (force == 0) @@ -4846,22 +5442,28 @@ void canvas_menuclose(t_canvas *x, t_floatarg fforce) g = glist_finddirty(x); if (g) { - /* first open window */ - if (!glist_istoplevel(g) && g->gl_env) { - /* if this is an abstraction */ - vmess(&g->gl_pd, gensym("menu-open"), ""); - } else { - // is this even necessary? - canvas_vis(g, 1); - } - if (!glist_istoplevel(g) && g->gl_env) { - /* if this is an abstraction */ - sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;}\n", + /* first open window */ + if (!glist_istoplevel(g) && g->gl_env) + { + /* if this is an abstraction */ + vmess(&g->gl_pd, gensym("menu-open"), ""); + } + else + { + // is this even necessary? + canvas_vis(g, 1); + } + if (!glist_istoplevel(g) && g->gl_env) + { + /* if this is an abstraction */ + sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;}\n", g, g); - } else { - sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;}\n", + } + else + { + sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;}\n", canvas_getrootfor(g), g); - } + } return; } /* @@ -4873,19 +5475,20 @@ void canvas_menuclose(t_canvas *x, t_floatarg fforce) } */ else pd_free(&x->gl_pd); - //sys_queuegui(x, x, canvas_dofree); - //clock_delay(x->gl_destroy, 0); - } - else if (force == 1) { - //sys_vgui("pd {.x%lx menuclose -1;}\n", x); - //sys_vgui("menu_close .x%lx\n", x); - //sys_queuegui(x, x, canvas_dofree); - //canvas_vis(x, 0); - //canvas_free(x); - pd_free(&x->gl_pd); - //fprintf(stderr,"pd_free queued------------\n"); - //clock_delay(x->gl_destroy, 0); - } + //sys_queuegui(x, x, canvas_dofree); + //clock_delay(x->gl_destroy, 0); + } + else if (force == 1) + { + //sys_vgui("pd {.x%lx menuclose -1;}\n", x); + //sys_vgui("menu_close .x%lx\n", x); + //sys_queuegui(x, x, canvas_dofree); + //canvas_vis(x, 0); + //canvas_free(x); + pd_free(&x->gl_pd); + //fprintf(stderr,"pd_free queued------------\n"); + //clock_delay(x->gl_destroy, 0); + } else if (force == 2) { canvas_dirty(x, 0); @@ -4894,30 +5497,36 @@ void canvas_menuclose(t_canvas *x, t_floatarg fforce) g = glist_finddirty(x); if (g) { - if (!glist_istoplevel(g) && g->gl_env) { - /* if this is an abstraction */ - vmess(&g->gl_pd, gensym("menu-open"), ""); - } else { - /* is this even necessary? */ - canvas_vis(g, 1); - } + if (!glist_istoplevel(g) && g->gl_env) + { + /* if this is an abstraction */ + vmess(&g->gl_pd, gensym("menu-open"), ""); + } + else + { + /* is this even necessary? */ + canvas_vis(g, 1); + } //vmess(&g->gl_pd, gensym("menu-open"), ""); - if (!glist_istoplevel(g) && g->gl_env) { - /* if this is an abstraction */ - sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;}\n", + if (!glist_istoplevel(g) && g->gl_env) + { + /* if this is an abstraction */ + sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;}\n", g, g); - } else { - sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;}\n", + } + else + { + sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;}\n", canvas_getrootfor(g), g); - } + } //sys_vgui("pdtk_canvas_menuclose .x%lx {.x%lx menuclose 2;\n}\n", // canvas_getrootfor(x), g); return; } else pd_free(&x->gl_pd); - //sys_vgui("pd {.x%lx menuclose -1;}\n", x); - //sys_queuegui(x, x, canvas_dofree); - //clock_delay(x->gl_destroy, 0); + //sys_vgui("pd {.x%lx menuclose -1;}\n", x); + //sys_queuegui(x, x, canvas_dofree); + //clock_delay(x->gl_destroy, 0); } else if (force == 3) { @@ -5018,16 +5627,18 @@ static void canvas_find_again(t_canvas *x) and focuses first visible parent (not the immediate parent) */ static void canvas_find_parent(t_canvas *x) { - if (x->gl_owner) { - t_glist *owner = x->gl_owner; - while (!glist_isvisible(owner) && !owner->gl_havewindow && owner->gl_owner) - owner = owner->gl_owner; - if (glist_isvisible(owner) && owner->gl_havewindow) - canvas_vis(owner, 1); - } - else { - sys_gui("menu_raise_console;\n"); - } + if (x->gl_owner) + { + t_glist *owner = x->gl_owner; + while (!glist_isvisible(owner) && + !owner->gl_havewindow && owner->gl_owner) + owner = owner->gl_owner; + if (glist_isvisible(owner) && owner->gl_havewindow) + canvas_vis(owner, 1); + } + else { + sys_gui("menu_raise_console;\n"); + } } static int glist_dofinderror(t_glist *gl, void *error_object) @@ -5073,7 +5684,7 @@ void canvas_finderror(void *error_object) void canvas_stowconnections(t_canvas *x) { - //fprintf(stderr,"canvas_stowconnections\n"); + //fprintf(stderr,"canvas_stowconnections\n"); t_gobj *selhead = 0, *seltail = 0, *nonhead = 0, *nontail = 0, *y, *y2; t_linetraverser t; t_outconnect *oc; @@ -5132,7 +5743,7 @@ void canvas_stowconnections(t_canvas *x) void canvas_restoreconnections(t_canvas *x) { - //fprintf(stderr,"canvas_restoreconnections\n"); + //fprintf(stderr,"canvas_restoreconnections\n"); pd_bind(&x->gl_pd, gensym("#X")); binbuf_eval(x->gl_editor->e_connectbuf, 0, 0, 0); pd_unbind(&x->gl_pd, gensym("#X")); @@ -5140,26 +5751,29 @@ void canvas_restoreconnections(t_canvas *x) static t_binbuf *canvas_docopy(t_canvas *x) { - //fprintf(stderr,"canvas_docopy\n"); + //fprintf(stderr,"canvas_docopy\n"); t_gobj *y, *last; t_linetraverser t; t_outconnect *oc; t_binbuf *b = binbuf_new(); for (y = x->gl_list; y; y = y->g_next) { - if (glist_isselected(x, y)) { - //fprintf(stderr,"saving object\n"); + if (glist_isselected(x, y)) + { + //fprintf(stderr,"saving object\n"); gobj_save(y, b); - } + } } linetraverser_start(&t, x); while (oc = linetraverser_next(&t)) { - //fprintf(stderr,"found some lines %d %d\n", glist_isselected(x, &t.tr_ob->ob_g), glist_isselected(x, &t.tr_ob2->ob_g)); + //fprintf(stderr,"found some lines %d %d\n", + // glist_isselected(x, &t.tr_ob->ob_g), + // glist_isselected(x, &t.tr_ob2->ob_g)); if (glist_isselected(x, &t.tr_ob->ob_g) && glist_isselected(x, &t.tr_ob2->ob_g)) { - //fprintf(stderr,"saving lines leading into selected object\n"); + //fprintf(stderr,"saving lines leading into selected object\n"); binbuf_addv(b, "ssiiii;", gensym("#X"), gensym("connect"), glist_selectionindex(x, &t.tr_ob->ob_g, 1), t.tr_outno, glist_selectionindex(x, &t.tr_ob2->ob_g, 1), t.tr_inno); @@ -5170,86 +5784,110 @@ static t_binbuf *canvas_docopy(t_canvas *x) static void canvas_reset_copyfromexternalbuffer(t_canvas *x) { - copyfromexternalbuffer = 0; + copyfromexternalbuffer = 0; } int abort_when_pasting_from_external_buffer = 0; -static void canvas_copyfromexternalbuffer(t_canvas *x, t_symbol *s, int ac, t_atom *av) -{ - if (!x->gl_editor) - return; - - if (!ac && !copyfromexternalbuffer) { - //fprintf(stderr,"init\n"); - copyfromexternalbuffer = 1; - screenx1 = 0; - screeny1 = 0; - screenx2 = 0; - screeny2 = 0; - copiedfont = 0; - binbuf_free(copy_binbuf); - copy_binbuf = binbuf_new(); - } else if (ac && copyfromexternalbuffer) { - //fprintf(stderr,"fill %d\n", ac); - if (av[0].a_type == A_SYMBOL && strcmp(av[0].a_w.w_symbol->s_name, "#N") || copyfromexternalbuffer != 1) { - binbuf_add(copy_binbuf, ac, av); - binbuf_addsemi(copy_binbuf); - copyfromexternalbuffer++; - } else if (copyfromexternalbuffer == 1 && av[0].a_type == A_SYMBOL && !strcmp(av[0].a_w.w_symbol->s_name, "#N") && ac == 7) { - int check = 0; - //if the canvas is empty resize window size and position here... - //fprintf(stderr,"copying canvas properties for copyfromexternalbuffer\n"); - if (av[2].a_type == A_FLOAT) { - screenx1 = av[2].a_w.w_float; - check++; - } - if (av[3].a_type == A_FLOAT) { - screeny1 = av[3].a_w.w_float; - check++; - } - if (av[4].a_type == A_FLOAT) { - screenx2 = av[4].a_w.w_float; - check++; - } - if (av[5].a_type == A_FLOAT) { - screeny2 = av[5].a_w.w_float; - check++; - } - if (av[6].a_type == A_FLOAT) { - copiedfont = av[6].a_w.w_float; - check++; - } - if (check != 5) { - post("error copying: copyfromexternalbuffer: canvas info has invalid data\n"); - copyfromexternalbuffer = 0; - } else { - copyfromexternalbuffer++; - } - } - } else if (!ac && copyfromexternalbuffer) { - //here we can do things after the copying process has been completed. currently we don't need this. - } +static void canvas_copyfromexternalbuffer(t_canvas *x, t_symbol *s, + int ac, t_atom *av) +{ + if (!x->gl_editor) + return; + + if (!ac && !copyfromexternalbuffer) + { + //fprintf(stderr,"init\n"); + copyfromexternalbuffer = 1; + screenx1 = 0; + screeny1 = 0; + screenx2 = 0; + screeny2 = 0; + copiedfont = 0; + binbuf_free(copy_binbuf); + copy_binbuf = binbuf_new(); + } + else if (ac && copyfromexternalbuffer) + { + //fprintf(stderr,"fill %d\n", ac); + if (av[0].a_type == A_SYMBOL && + strcmp(av[0].a_w.w_symbol->s_name, "#N") || + copyfromexternalbuffer != 1) + { + binbuf_add(copy_binbuf, ac, av); + binbuf_addsemi(copy_binbuf); + copyfromexternalbuffer++; + } + else if (copyfromexternalbuffer == 1 && + av[0].a_type == A_SYMBOL && + !strcmp(av[0].a_w.w_symbol->s_name, "#N") && ac == 7) + { + int check = 0; + //if the canvas is empty resize window size and position here... + //fprintf(stderr, + // "copying canvas properties for copyfromexternalbuffer\n"); + if (av[2].a_type == A_FLOAT) + { + screenx1 = av[2].a_w.w_float; + check++; + } + if (av[3].a_type == A_FLOAT) + { + screeny1 = av[3].a_w.w_float; + check++; + } + if (av[4].a_type == A_FLOAT) + { + screenx2 = av[4].a_w.w_float; + check++; + } + if (av[5].a_type == A_FLOAT) + { + screeny2 = av[5].a_w.w_float; + check++; + } + if (av[6].a_type == A_FLOAT) + { + copiedfont = av[6].a_w.w_float; + check++; + } + if (check != 5) + { + post("error copying: copyfromexternalbuffer: " + "canvas info has invalid data\n"); + copyfromexternalbuffer = 0; + } + else + { + copyfromexternalbuffer++; + } + } + } + else if (!ac && copyfromexternalbuffer) + { + // here we can do things after the copying process has been completed. + // currently we don't need this. + } } static void canvas_copy(t_canvas *x) { if (!x->gl_editor || !x->gl_editor->e_selection) return; - copyfromexternalbuffer = 0; - screenx1 = 0; - screeny1 = 0; - screenx2 = 0; - screeny2 = 0; - copiedfont = 0; + copyfromexternalbuffer = 0; + screenx1 = 0; + screeny1 = 0; + screenx2 = 0; + screeny2 = 0; + copiedfont = 0; binbuf_free(copy_binbuf); - //fprintf(stderr, "canvas_copy\n"); - sys_vgui("pdtk_canvas_reset_last_clipboard\n"); + //fprintf(stderr, "canvas_copy\n"); + sys_vgui("pdtk_canvas_reset_last_clipboard\n"); copy_binbuf = canvas_docopy(x); - if (!x->gl_editor->e_selection) - sys_vgui("pdtk_canvas_update_edit_menu .x%lx 0\n", x); - else - sys_vgui("pdtk_canvas_update_edit_menu .x%lx 1\n", x); + if (!x->gl_editor->e_selection) + sys_vgui("pdtk_canvas_update_edit_menu .x%lx 0\n", x); + else + sys_vgui("pdtk_canvas_update_edit_menu .x%lx 1\n", x); paste_xyoffset = 1; if (x->gl_editor->e_textedfor) { @@ -5290,7 +5928,7 @@ static void canvas_clearline(t_canvas *x) x->gl_editor->e_selectline_index2, x->gl_editor->e_selectline_inno), "disconnect");*/ - canvas_undo_add(x, 2, "disconnect", canvas_undo_set_disconnect(x, + canvas_undo_add(x, 2, "disconnect", canvas_undo_set_disconnect(x, x->gl_editor->e_selectline_index1, x->gl_editor->e_selectline_outno, x->gl_editor->e_selectline_index2, @@ -5318,7 +5956,7 @@ static void canvas_doclear(t_canvas *x) x->gl_editor->e_selectline_index2, x->gl_editor->e_selectline_inno), "disconnect");*/ - canvas_undo_add(x, 2, "disconnect", canvas_undo_set_disconnect(x, + canvas_undo_add(x, 2, "disconnect", canvas_undo_set_disconnect(x, x->gl_editor->e_selectline_index1, x->gl_editor->e_selectline_outno, x->gl_editor->e_selectline_index2, @@ -5344,18 +5982,18 @@ static void canvas_doclear(t_canvas *x) y2 = y->g_next; if (glist_isselected(x, y)) { - /* if it is a graph and the window is open, destroy it first - this will avoid leaving stale gop rectangle and name */ - if (pd_class(&y->g_pd) == canvas_class && - ((t_glist *)y)->gl_havewindow) - { - canvas_menuclose((t_glist *)y, 0); - } - - /* delete any stale visual cords */ - canvas_eraselinesfor(x, (t_text *)y); - - /* now destroy the object */ + /* if it is a graph and the window is open, destroy it first + this will avoid leaving stale gop rectangle and name */ + if (pd_class(&y->g_pd) == canvas_class && + ((t_glist *)y)->gl_havewindow) + { + canvas_menuclose((t_glist *)y, 0); + } + + /* delete any stale visual cords */ + canvas_eraselinesfor(x, (t_text *)y); + + /* now destroy the object */ glist_delete(x, y); #if 0 if (y2) post("cut 5 %lx %lx", y2, y2->g_next); @@ -5369,8 +6007,8 @@ static void canvas_doclear(t_canvas *x) } restore: canvas_dirty(x, 1); - //canvas_redraw(x); - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + //canvas_redraw(x); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); canvas_resume_dsp(dspstate); } @@ -5378,10 +6016,10 @@ static void canvas_cut(t_canvas *x) { if (x->gl_editor && x->gl_editor->e_selectedline) canvas_clearline(x); - /* if we are cutting text */ + /* if we are cutting text */ else if (x->gl_editor && x->gl_editor->e_textedfor) { - //fprintf(stderr,"canvas_cut textedfor\n"); + //fprintf(stderr,"canvas_cut textedfor\n"); char *buf; int bufsize; rtext_getseltext(x->gl_editor->e_textedfor, &buf, &bufsize); @@ -5389,18 +6027,18 @@ static void canvas_cut(t_canvas *x) return; canvas_copy(x); rtext_key(x->gl_editor->e_textedfor, 127, &s_); - canvas_fixlinesfor(x,(t_text*) x->gl_editor->e_selection->sel_what); + canvas_fixlinesfor(x,(t_text*) x->gl_editor->e_selection->sel_what); canvas_dirty(x, 1); } - /* else we are cutting objects */ + /* else we are cutting objects */ else if (x->gl_editor && x->gl_editor->e_selection) { //canvas_setundo(x, canvas_undo_cut, // canvas_undo_set_cut(x, UCUT_CUT), "cut"); - canvas_undo_add(x, 3, "cut", canvas_undo_set_cut(x, UCUT_CUT)); + canvas_undo_add(x, 3, "cut", canvas_undo_set_cut(x, UCUT_CUT)); canvas_copy(x); canvas_doclear(x); - glob_preset_node_list_check_loc_and_update(); + glob_preset_node_list_check_loc_and_update(); paste_xyoffset = 0; sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); } @@ -5423,24 +6061,25 @@ static void glist_donewloadbangs(t_glist *x) static void canvas_paste_xyoffset(t_canvas *x) { t_selection *sel; - t_class *cl; + t_class *cl; int resortin = 0; int resortout = 0; - for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) { + for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) + { //gobj_displace(sel->sel_what, x, paste_xyoffset*10, paste_xyoffset*10); - cl = pd_class(&sel->sel_what->g_pd); + cl = pd_class(&sel->sel_what->g_pd); if (cl == vinlet_class) resortin = 1; if (cl == voutlet_class) resortout = 1; - } - canvas_displaceselection(x, paste_xyoffset*10, paste_xyoffset*10); + } + canvas_displaceselection(x, paste_xyoffset*10, paste_xyoffset*10); //if (resortin) canvas_resortinlets(x); //if (resortout) canvas_resortoutlets(x); - // alternative one-line implementation that - // replaces the entire function - //canvas_displaceselection(x, 10, 10); + // alternative one-line implementation that + // replaces the entire function + //canvas_displaceselection(x, 10, 10); //paste_xyoffset++; //a part of original way } @@ -5449,41 +6088,51 @@ static void canvas_paste_atmouse(t_canvas *x) { t_selection *sel; //fprintf(stderr,"paste_atmouse\n"); - /* use safe values for x1 and y1 which are essentially the same as xyoffset */ - int x1 = x->gl_editor->e_xwas+10, y1 = x->gl_editor->e_ywas+10, init = 0; - t_float sx = 0.0, sy = 0.0; - t_glist *g; - t_text *t; - - /* find the initial offset--we use leftmost object as our reference */ - for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) { - //fprintf(stderr,"got selection\n"); - g = (t_glist *)sel->sel_what; - if (pd_class(&((t_gobj *)g)->g_pd) == canvas_class && g->gl_isgraph) { - // hack: if any objects are GOPs re-select them, otherwise we may get stray nlets - // due to networked nature between the gui and the engine, so we select - // it explicitly here once again to prevent that from being a problem - gobj_select((t_gobj *)g, x, 1); - } - if (pd_class(&((t_gobj *)g)->g_pd) == scalar_class) { - scalar_getbasexy((t_scalar *)g, &sx, &sy); - x1 = (int)sx; - y1 = (int)sy; - } else { - t = (t_text *)g; - if (!init) { - x1 = t->te_xpix; - y1 = t->te_ypix; - init = 1; - } else if ( t->te_xpix < x1 ) { - x1 = t->te_xpix; - } - } - } - /* redraw objects */ - canvas_undo_already_set_move = 1; - canvas_displaceselection(x, (x->gl_editor->e_xwas)+5-x1, (x->gl_editor->e_ywas)-y1); - canvas_startmotion(x); + /* use safe values for x1 and y1 which are essentially the same as xyoffset */ + int x1 = x->gl_editor->e_xwas+10, y1 = x->gl_editor->e_ywas+10, init = 0; + t_float sx = 0.0, sy = 0.0; + t_glist *g; + t_text *t; + + /* find the initial offset--we use leftmost object as our reference */ + for (sel = x->gl_editor->e_selection; sel; sel = sel->sel_next) + { + //fprintf(stderr,"got selection\n"); + g = (t_glist *)sel->sel_what; + if (pd_class(&((t_gobj *)g)->g_pd) == canvas_class && g->gl_isgraph) + { + /* hack: if any objects are GOPs re-select them, otherwise + we may get stray nlets due to networked nature between + the gui and the engine, so we select it explicitly here + once again to prevent that from being a problem */ + gobj_select((t_gobj *)g, x, 1); + } + if (pd_class(&((t_gobj *)g)->g_pd) == scalar_class) + { + scalar_getbasexy((t_scalar *)g, &sx, &sy); + x1 = (int)sx; + y1 = (int)sy; + } + else + { + t = (t_text *)g; + if (!init) + { + x1 = t->te_xpix; + y1 = t->te_ypix; + init = 1; + } + else if ( t->te_xpix < x1 ) + { + x1 = t->te_xpix; + } + } + } + /* redraw objects */ + canvas_undo_already_set_move = 1; + canvas_displaceselection(x, + (x->gl_editor->e_xwas)+5-x1, (x->gl_editor->e_ywas)-y1); + canvas_startmotion(x); } extern void canvas_obj(t_glist *gl, t_symbol *s, int argc, t_atom *argv); @@ -5493,145 +6142,165 @@ extern int we_are_undoing; static void canvas_dopaste(t_canvas *x, t_binbuf *b) { - //fprintf(stderr,"start dopaste\n"); - do_not_redraw += 1; - int was_dnr = do_not_redraw; - + //fprintf(stderr,"start dopaste\n"); + do_not_redraw += 1; + int was_dnr = do_not_redraw; + t_gobj *newgobj, *last, *g2, *first; int dspstate = canvas_suspend_dsp(), nbox, count; - int canvas_empty = 0; - int offset = 1; + int canvas_empty = 0; + int offset = 1; - //first let's see if we are pasting into an empty canvas - //this will be used below when pasting from copyfromexternalbuffer, usually text editor - if (!x->gl_list) canvas_empty = 1; + /* first let's see if we are pasting into an empty canvas. + this will be used below when pasting from copyfromexternalbuffer, + usually text editor */ + if (!x->gl_list) canvas_empty = 1; - //autopatching variables - int connectme, xpix, ypix, indx, nobj; - t_float sx = 0.0, sy = 0.0; - connectme = 0; + //autopatching variables + int connectme, xpix, ypix, indx, nobj; + t_float sx = 0.0, sy = 0.0; + connectme = 0; canvas_editmode(x, 1.); - /* abolish potential displacing of object that may have been - created with the first new object on canvas, but now we are - pasting and therefore MA_MOVE should not apply to new objects - */ - x->gl_editor->e_onmotion = MA_NONE; - - if (copyfromexternalbuffer && canvas_empty) { - if (screenx2 && screeny2 && copiedfont) { - x->gl_screenx1 = screenx1; - x->gl_screenx2 = screenx1 + screenx2; - x->gl_screeny1 = screeny1; - x->gl_screeny2 = screeny1 + screeny2; - //canvas_setbounds(x, screenx1, screeny1, screenx1+screenx2, screeny1+screeny2); - sys_vgui("wm geometry .x%lx =%dx%d+%d+%d\n", x, + /* abolish potential displacing of object that may have been + created with the first new object on canvas, but now we are + pasting and therefore MA_MOVE should not apply to new objects + */ + x->gl_editor->e_onmotion = MA_NONE; + + if (copyfromexternalbuffer && canvas_empty) + { + if (screenx2 && screeny2 && copiedfont) + { + x->gl_screenx1 = screenx1; + x->gl_screenx2 = screenx1 + screenx2; + x->gl_screeny1 = screeny1; + x->gl_screeny2 = screeny1 + screeny2; + //canvas_setbounds(x, screenx1, screeny1, + // screenx1+screenx2, screeny1+screeny2); + sys_vgui("wm geometry .x%lx =%dx%d+%d+%d\n", x, (int)(x->gl_screenx2 - x->gl_screenx1), (int)(x->gl_screeny2 - x->gl_screeny1), (int)(x->gl_screenx1), (int)(x->gl_screeny1)); - //hardwired stretchval and whichstretch until we figure out proper resizing - canvas_dofont(x, copiedfont, 1, 1); - //sys_vgui("pdtk_canvas_checkgeometry .x%lx\n", x); - canvas_redraw(x); - } - } - - //if we have something selected in another canvas - if (c_selection && c_selection != x) { - offset = 0; - glist_noselect(c_selection); - } - //if we are undoing, offset should be also 0 - if (we_are_undoing) offset = 0; - - //if we are pasting see if we can autopatch - if (canvas_undo_name && !strcmp(canvas_undo_name, "paste")) { - canvas_howputnew(x, &connectme, &xpix, &ypix, &indx, &nobj); - //glist_noselect(x); - } - //else we are duplicating - else glist_noselect(x); + // hardwired stretchval and whichstretch + // until we figure out proper resizing + canvas_dofont(x, copiedfont, 1, 1); + //sys_vgui("pdtk_canvas_checkgeometry .x%lx\n", x); + canvas_redraw(x); + } + } + + //if we have something selected in another canvas + if (c_selection && c_selection != x) + { + offset = 0; + glist_noselect(c_selection); + } + //if we are undoing, offset should be also 0 + if (we_are_undoing) offset = 0; + + //if we are pasting see if we can autopatch + if (canvas_undo_name && !strcmp(canvas_undo_name, "paste")) + { + canvas_howputnew(x, &connectme, &xpix, &ypix, &indx, &nobj); + //glist_noselect(x); + } + //else we are duplicating + else glist_noselect(x); for (g2 = x->gl_list, nbox = 0; g2; g2 = g2->g_next) nbox++; - /* found the end of the queue */ + /* found the end of the queue */ paste_onset = nbox; paste_canvas = x; - do_not_redraw = 0; + do_not_redraw = 0; pd_bind(&x->gl_pd, gensym("#X")); binbuf_eval(b, 0, 0, 0); pd_unbind(&x->gl_pd, gensym("#X")); - do_not_redraw = was_dnr; + do_not_redraw = was_dnr; - /* select newly created objects */ + /* select newly created objects */ for (g2 = x->gl_list, count = 0; g2; g2 = g2->g_next, count++) - if (count >= nbox) + if (count >= nbox) glist_select(x, g2); paste_canvas = 0; - //fprintf(stderr,"dopaste autopatching? %d==%d %d\n", count, nbox, connectme); - do_not_redraw -= 1; - - // TODO: Ico: because figuring out exact position/size for a scalar is not simple to assess - // and besides, I am not even sure if we can have a scalar with an inlet, - // we currently ignore scalar autopatching - if (connectme == 1 && pd_class(&(x->gl_editor->e_selection->sel_what)->g_pd) == scalar_class) { - connectme = 0; - } - - //if we are pasting only one object autoposition it below our selection - if (count == nbox+1 && connectme == 1) { - - canvas_connect(x, indx, 0, nobj, 0); - - //is this universally safe? Not for scalars - t_text *z = (t_text *)x->gl_editor->e_selection->sel_what; - //fprintf(stderr,"%d %d %d %d\n", z->te_xpix, z->te_ypix, xpix, ypix); - - //calculate delta (since displace is always relative) - int delta_x = xpix - z->te_xpix; - int delta_y = ypix - z->te_ypix; - - //now displace it but without undo - //(by spoofing canvas_undo_already_set_move) - canvas_undo_already_set_move = 1; - canvas_displaceselection(x, delta_x, delta_y); - //reset canvas_undo_already_set_move - canvas_undo_already_set_move = 0; - } - //if we are pasting into a new window and this is not copied from external buffer OR - //if we are copying from external buffer and the current canvas is not empty - else if (canvas_undo_name && !strcmp(canvas_undo_name, "paste") && !copyfromexternalbuffer || - copyfromexternalbuffer && !canvas_empty) { - //if (!copyfromexternalbuffer) canvas_paste_xyoffset(x); - if (!we_are_undoing) canvas_paste_atmouse(x); - //fprintf(stderr,"doing a paste\n"); - } - //else let's provide courtesy offset - else if (!copyfromexternalbuffer && offset) { - canvas_paste_xyoffset(x); - } + //fprintf(stderr,"dopaste autopatching? %d==%d %d\n", + // count, nbox, connectme); + do_not_redraw -= 1; + + /* TODO: Ico: because figuring out exact position/size for a scalar + is not simple to assess and besides, I am not even sure if we can + have a scalar with an inlet, we currently ignore scalar autopatching */ + if (connectme == 1 && + pd_class(&(x->gl_editor->e_selection->sel_what)->g_pd) == scalar_class) + { + connectme = 0; + } + + //if we are pasting only one object autoposition it below our selection + if (count == nbox+1 && connectme == 1) + { + canvas_connect(x, indx, 0, nobj, 0); + + //is this universally safe? Not for scalars + t_text *z = (t_text *)x->gl_editor->e_selection->sel_what; + //fprintf(stderr,"%d %d %d %d\n", z->te_xpix, z->te_ypix, xpix, ypix); + + //calculate delta (since displace is always relative) + int delta_x = xpix - z->te_xpix; + int delta_y = ypix - z->te_ypix; + + //now displace it but without undo + //(by spoofing canvas_undo_already_set_move) + canvas_undo_already_set_move = 1; + canvas_displaceselection(x, delta_x, delta_y); + //reset canvas_undo_already_set_move + canvas_undo_already_set_move = 0; + } + /* if we are pasting into a new window and this is not copied from external + buffer OR if we are copying from external buffer and the current canvas + is not empty */ + else if (canvas_undo_name && !strcmp(canvas_undo_name, "paste") && + !copyfromexternalbuffer || + copyfromexternalbuffer && !canvas_empty) + { + //if (!copyfromexternalbuffer) canvas_paste_xyoffset(x); + if (!we_are_undoing) canvas_paste_atmouse(x); + //fprintf(stderr,"doing a paste\n"); + } + //else let's provide courtesy offset + else if (!copyfromexternalbuffer && offset) + { + canvas_paste_xyoffset(x); + } canvas_dirty(x, 1); - //fprintf(stderr,"dopaste redraw %d\n", do_not_redraw); - //if (!canvas_undo_name || !strcmp(canvas_undo_name, "duplicate")) { - // need to redraw duplicated objects as they need to be drawn with an offset - // fprintf(stderr,"canvas_dopaste redraw objects\n"); - // canvas_redraw(x); - //} + //fprintf(stderr,"dopaste redraw %d\n", do_not_redraw); + //if (!canvas_undo_name || !strcmp(canvas_undo_name, "duplicate")) { + // need to redraw duplicated objects as + // they need to be drawn with an offset + // fprintf(stderr,"canvas_dopaste redraw objects\n"); + // canvas_redraw(x); + //} sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); - if (!abort_when_pasting_from_external_buffer) { - glist_donewloadbangs(x); - } else { - error("failed pasting correctly from external buffer, likely due to incomplete text selection. hopefully you saved your work... please get ready to crash..."); - } + if (!abort_when_pasting_from_external_buffer) + { + glist_donewloadbangs(x); + } + else + { + error("failed pasting correctly from external buffer, " + "likely due to incomplete text selection. hopefully " + "you saved your work... please get ready to crash..."); + } canvas_resume_dsp(dspstate); - abort_when_pasting_from_external_buffer = 0; - glob_preset_node_list_check_loc_and_update(); - //fprintf(stderr,"end dopaste\n"); + abort_when_pasting_from_external_buffer = 0; + glob_preset_node_list_check_loc_and_update(); + //fprintf(stderr,"end dopaste\n"); } static void canvas_paste(t_canvas *x) @@ -5658,7 +6327,8 @@ static void canvas_paste(t_canvas *x) { //canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x), // "paste"); - canvas_undo_add(x, 5, "paste", (void *)canvas_undo_set_paste(x, 0, 0, 0)); + canvas_undo_add(x, 5, "paste", + (void *)canvas_undo_set_paste(x, 0, 0, 0)); canvas_dopaste(x, copy_binbuf); //canvas_paste_xyoffset(x); } @@ -5666,30 +6336,33 @@ static void canvas_paste(t_canvas *x) static void canvas_duplicate(t_canvas *x) { - //if (x->gl_editor->e_onmotion == MA_NONE && x->gl_editor->e_selection) - if (x->gl_editor->e_onmotion == MA_NONE && c_selection && c_selection->gl_editor->e_selection) - { - // Check if we are trying to duplicate an object that we just typed in and which has not been - // instantiated yet. If so, let's deselect it to instatiate it and then reselect it again. - // If this is the case, only one object will be selected. We temporarily borrow g object for - // this operation. - t_gobj *g; - - g = c_selection->gl_editor->e_selection->sel_what; - if (!c_selection->gl_editor->e_selection->sel_next && - c_selection->gl_editor->e_textedfor && - pd_class(&g->g_pd) == text_class && - ((t_text *)x)->te_type == T_OBJECT) - { - //fprintf(stderr,"got uninitiated object we are trying to duplicate...\n"); - glist_deselect(x, g); - // now we need to find the newly instantiated object and reselect it - g = x->gl_list; - if (g) - while (g->g_next) - g = g->g_next; - - } + //if (x->gl_editor->e_onmotion == MA_NONE && x->gl_editor->e_selection) + if (x->gl_editor->e_onmotion == MA_NONE && c_selection && + c_selection->gl_editor->e_selection) + { + /* Check if we are trying to duplicate an object that we just + typed in and which has not been instantiated yet. If so, + let's deselect it to instatiate it and then reselect it again. + If this is the case, only one object will be selected. We + temporarily borrow g object for this operation. */ + t_gobj *g; + + g = c_selection->gl_editor->e_selection->sel_what; + if (!c_selection->gl_editor->e_selection->sel_next && + c_selection->gl_editor->e_textedfor && + pd_class(&g->g_pd) == text_class && + ((t_text *)x)->te_type == T_OBJECT) + { + //fprintf(stderr, + // "got uninitiated object we are trying to duplicate...\n"); + glist_deselect(x, g); + // now we need to find the newly instantiated object and reselect it + g = x->gl_list; + if (g) + while (g->g_next) + g = g->g_next; + + } //canvas_copy(x); //canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x), @@ -5697,38 +6370,51 @@ static void canvas_duplicate(t_canvas *x) //canvas_dopaste(x, copy_binbuf); //canvas_paste_xyoffset(x); //canvas_dirty(x, 1); - g = x->gl_list; - if (g) - while (g->g_next) - g = g->g_next; + g = x->gl_list; + if (g) + while (g->g_next) + g = g->g_next; canvas_copy(c_selection); - canvas_undo_add(x, 5, "duplicate", (void *)canvas_undo_set_paste(x, 0, 1, (c_selection == x ? 1 : 0))); - canvas_dopaste(x, copy_binbuf); - //if (c_selection == x) //{ - /* we are in the same window */ - //canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x), - // "duplicate"); - //canvas_paste_xyoffset(x); - //canvas_dirty(x, 1); - //} else { - //canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x), - // "duplicate"); - //canvas_dopaste(x, copy_binbuf); - //canvas_paste_xyoffset(x); - //} - canvas_dirty(x, 1); - if (g) //if we already have objects on the newly duplicated canvas, this will be invoked - g = g->g_next; - else g = x->gl_list; //this is if the duplicated object is the first one on the new canvas - while (g) { - if (pd_class(&g->g_pd) == canvas_class && ((t_canvas *)g)->gl_isgraph) { - // hack: if any objects are GOPs re-select them, otherwise we may get stray unselected - // objects due to networked nature between the gui and the engine, so we select - // it explicitly here once again to prevent that from being a problem - gobj_select(g, x, 1); - } - g = g->g_next; - } + canvas_undo_add(x, 5, "duplicate", + (void *)canvas_undo_set_paste(x, 0, 1, (c_selection == x ? 1 : 0))); + canvas_dopaste(x, copy_binbuf); + //if (c_selection == x) //{ + /* we are in the same window */ + //canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x), + // "duplicate"); + //canvas_paste_xyoffset(x); + //canvas_dirty(x, 1); + //} else { + //canvas_setundo(x, canvas_undo_paste, canvas_undo_set_paste(x), + // "duplicate"); + //canvas_dopaste(x, copy_binbuf); + //canvas_paste_xyoffset(x); + //} + canvas_dirty(x, 1); + /* if we already have objects on the newly duplicated canvas, + this will be invoked */ + if (g) + g = g->g_next; + else + { + /* this is if the duplicated object is the first one + on the new canvas */ + g = x->gl_list; + } + while (g) + { + if (pd_class(&g->g_pd) == canvas_class && + ((t_canvas *)g)->gl_isgraph) + { + /* hack: if any objects are GOPs re-select them, otherwise + we may get stray unselected objects due to networked + nature between the gui and the engine, so we select it + explicitly here once again to prevent that from being + a problem */ + gobj_select(g, x, 1); + } + g = g->g_next; + } } } @@ -5744,24 +6430,30 @@ static void canvas_selectall(t_canvas *x) if (x->gl_editor->e_selection->sel_what && !x->gl_editor->e_selection->sel_next) { - t_gobj *z = x->gl_editor->e_selection->sel_what; - /* reactivate */ - gobj_activate(z, x, 1); - /* make canvas dirty in case this was done at creation time */ - x->gl_editor->e_textdirty = 1; - } - } - else { - - /* if everyone is already selected deselect everyone */ - if (!glist_selectionindex(x, 0, 0)) - glist_noselect(x); - else for (y = x->gl_list; y; y = y->g_next) - { - if (!glist_isselected(x, y)) - glist_select(x, y); - } - } + t_gobj *z = x->gl_editor->e_selection->sel_what; + /* reactivate */ + gobj_activate(z, x, 1); + /* make canvas dirty in case this was done at creation time */ + x->gl_editor->e_textdirty = 1; + } + } + else + { + + /* if everyone is already selected deselect everyone */ + if (!glist_selectionindex(x, 0, 0)) + { + glist_noselect(x); + } + else + { + for (y = x->gl_list; y; y = y->g_next) + { + if (!glist_isselected(x, y)) + glist_select(x, y); + } + } + } } static void canvas_reselect(t_canvas *x) @@ -5802,11 +6494,14 @@ static void canvas_reselect(t_canvas *x) void canvas_connect(t_canvas *x, t_floatarg fwhoout, t_floatarg foutno, t_floatarg fwhoin, t_floatarg finno) { - //fprintf(stderr,"canvas_connect\n"); - if (!x->gl_list) { - post("paste error: no objects to connect, probably incomplete clipboard copy from an external source (e.g. from a text editor)"); - return; - } + //fprintf(stderr,"canvas_connect\n"); + if (!x->gl_list) + { + post("paste error: no objects to connect, " + "probably incomplete clipboard copy from an external source " + "(e.g. from a text editor)"); + return; + } int whoout = fwhoout, outno = foutno, whoin = fwhoin, inno = finno; t_gobj *src = 0, *sink = 0; t_object *objsrc, *objsink; @@ -5823,22 +6518,32 @@ void canvas_connect(t_canvas *x, t_floatarg fwhoout, t_floatarg foutno, !(objsink = pd_checkobject(&sink->g_pd))) goto bad; - /* check signal outlets don't try to connect to non-signal inlet, but only do so when there is no exception active due to autopatching */ - if (!connect_exception && obj_issignaloutlet(objsrc, outno) && !obj_issignalinlet(objsink, inno)) { - error("cannot connect signal outlet to control inlet"); - goto bad; - } - /* now check for illegal connections between preset_node object and other non-supported objects */ - if (pd_class(&src->g_pd) == preset_node_class) { - if (pd_class(&sink->g_pd) == message_class) { - error("preset_node does not work with messages."); - goto bad; - } - if (obj_noutlets(pd_checkobject(&sink->g_pd)) == 0) { - error("preset_node does not work with objects with zero or undefined number of outlets\n"); - goto bad; - } - } + /* check signal outlets don't try to connect to non-signal inlet, + but only do so when there is no exception active due to + autopatching */ + if (!connect_exception && + obj_issignaloutlet(objsrc, outno) && + !obj_issignalinlet(objsink, inno)) + { + error("cannot connect signal outlet to control inlet"); + goto bad; + } + /* now check for illegal connections between preset_node object + and other non-supported objects */ + if (pd_class(&src->g_pd) == preset_node_class) + { + if (pd_class(&sink->g_pd) == message_class) + { + error("preset_node does not work with messages."); + goto bad; + } + if (obj_noutlets(pd_checkobject(&sink->g_pd)) == 0) + { + error("preset_node does not work with objects with zero or " + "undefined number of outlets\n"); + goto bad; + } + } /* if object creation failed, make dummy inlets or outlets as needed */ @@ -5849,30 +6554,44 @@ void canvas_connect(t_canvas *x, t_floatarg fwhoout, t_floatarg foutno, while (inno >= obj_ninlets(objsink)) inlet_new(objsink, &objsink->ob_pd, 0, 0); - if (!canvas_isconnected(x, objsrc, outno, objsink, inno)) { - if (!(oc = obj_connect(objsrc, outno, objsink, inno))) goto bad; - outconnect_setvisible(oc, 1); - // add auto-connect back to preset_node object - // (by this time we know we are connecting only to legal objects who have at least one outlet) - // EXCEPTION: we do not connect back to the print class - if (pd_class(&objsrc->ob_pd) == preset_node_class && pd_class(&sink->g_pd) != print_class) { - //fprintf(stderr,"canvas_connect: gotta do auto-connect back to preset_node\n"); - if (!canvas_isconnected(x, objsink, 0, objsrc, 0)) { - oc2 = obj_connect(objsink, 0, objsrc, 0); - outconnect_setvisible(oc2, 0); - } - } - if (glist_isvisible(x) && (pd_class(&sink->g_pd) != preset_node_class || (pd_class(&sink->g_pd) == preset_node_class && pd_class(&src->g_pd) == message_class))) - { - //fprintf(stderr,"draw line\n"); - canvas_drawconnection(x, 0, 0, 0, 0, (t_int)oc, obj_issignaloutlet(objsrc, outno)); - /*sys_vgui(".x%lx.c create polyline %d %d %d %d -strokewidth %s -stroke %s -tags {l%lx all_cords}\n", - glist_getcanvas(x), 0, 0, 0, 0, - (obj_issignaloutlet(objsrc, outno) ? "$pd_colors(signal_cord_width)" : "$pd_colors(control_cord_width)"), - (obj_issignaloutlet(objsrc, outno) ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)"), oc);*/ - canvas_fixlinesfor(x, objsrc); - } - } + if (!canvas_isconnected(x, objsrc, outno, objsink, inno)) + { + if (!(oc = obj_connect(objsrc, outno, objsink, inno))) goto bad; + outconnect_setvisible(oc, 1); + /* add auto-connect back to preset_node object + (by this time we know we are connecting only to legal objects + who have at least one outlet) + EXCEPTION: we do not connect back to the print class */ + if (pd_class(&objsrc->ob_pd) == preset_node_class && + pd_class(&sink->g_pd) != print_class) + { + //fprintf(stderr, + // "canvas_connect: gotta do auto-connect back to preset_node\n"); + if (!canvas_isconnected(x, objsink, 0, objsrc, 0)) + { + oc2 = obj_connect(objsink, 0, objsrc, 0); + outconnect_setvisible(oc2, 0); + } + } + if (glist_isvisible(x) && + (pd_class(&sink->g_pd) != preset_node_class || + (pd_class(&sink->g_pd) == preset_node_class && + pd_class(&src->g_pd) == message_class))) + { + //fprintf(stderr,"draw line\n"); + canvas_drawconnection(x, 0, 0, 0, 0, (t_int)oc, obj_issignaloutlet(objsrc, outno)); + /*sys_vgui(".x%lx.c create polyline %d %d %d %d -strokewidth %s " + "-stroke %s -tags {l%lx all_cords}\n", + glist_getcanvas(x), 0, 0, 0, 0, + (obj_issignaloutlet(objsrc, outno) ? + "$pd_colors(signal_cord_width)" : + "$pd_colors(control_cord_width)"), + (obj_issignaloutlet(objsrc, outno) ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)"), oc);*/ + canvas_fixlinesfor(x, objsrc); + } + } return; bad: @@ -5888,427 +6607,519 @@ bad: typedef struct _sgobj { t_gobj *s_g; - int s_x1; - int s_x2; - int s_y1; - int s_y2; + int s_x1; + int s_x2; + int s_y1; + int s_y2; struct _sgobj *s_next; } t_sgobj; -static int sgobj_already_processed(t_gobj *y, t_sgobj *sg) { - while (sg) { - if (sg->s_g == y) - return(1); - sg = sg->s_next; - } - return(0); +static int sgobj_already_processed(t_gobj *y, t_sgobj *sg) +{ + while (sg) + { + if (sg->s_g == y) + return(1); + sg = sg->s_next; + } + return(0); } -static int canvas_tidy_gobj_width(t_canvas *x, t_gobj *y) { +static int canvas_tidy_gobj_width(t_canvas *x, t_gobj *y) +{ - int w = 0; - int x1, y1, x2, y2; - gobj_getrect(y, x, &x1, &y1, &x2, &y2); - w = x2 - x1; - //fprintf(stderr,"width = %d\n", w); - return(w); + int w = 0; + int x1, y1, x2, y2; + gobj_getrect(y, x, &x1, &y1, &x2, &y2); + w = x2 - x1; + //fprintf(stderr,"width = %d\n", w); + return(w); } -static int canvas_tidy_gobj_height(t_canvas *x, t_gobj *y) { +static int canvas_tidy_gobj_height(t_canvas *x, t_gobj *y) +{ - int h = 0; - int x1, y1, x2, y2; - gobj_getrect(y, x, &x1, &y1, &x2, &y2); - h = y2 - y1; - //fprintf(stderr,"height = %d\n", h); - return(h); + int h = 0; + int x1, y1, x2, y2; + gobj_getrect(y, x, &x1, &y1, &x2, &y2); + h = y2 - y1; + //fprintf(stderr,"height = %d\n", h); + return(h); } static void canvas_tidy(t_canvas *x) { - // if we have no editor, no selection, or only one object selected, return - if (!x->gl_editor || !x->gl_editor->e_selection || !x->gl_editor->e_selection->sel_next) return; - - //fprintf(stderr,"canvas_tidy\n"); - t_gobj *y; - t_text *yt, *rightmost_t = NULL, *topmost_t = NULL; - int h, v, hs, vs; // horizontal, vertical, horizontal respacing, vertical respacing - t_gobj *leftmost, *rightmost, *topmost, *bottommost; - int x1, x2, y1, y2; - int ox1, ox2, oy1, oy2; // object x and y dimensions - int cox1, cox2, coy1, coy2; // comparing object x and y dimensions - int dx, dy; // displacement variables - int i; // generic counter var - t_sgobj *sg, *tmpsg; // list of objects ordered spatially - int spacing = 0; // spacing between objects on respacing (this is adjustable) - int delta = 0; - - dx = dy = h = v = hs = vs = 0; - - t_selection *sel = x->gl_editor->e_selection; - y = sel->sel_what; - yt = (t_text *)y; - x1 = yt->te_xpix; - x2 = x1; - y1 = yt->te_ypix; - y2 = y1; - - leftmost = y; - topmost = y; - rightmost = y; - bottommost = y; - - sel = sel->sel_next; - - // first find out whether we are dealing with horizontal or vertical alignment or spatialization - while (sel) { - y = sel->sel_what; - yt = (t_text *)y; - - if (yt->te_xpix < x1) { - x1 = yt->te_xpix; - } - - if (yt->te_xpix > x2) { - x2 = yt->te_xpix; - } - - if (yt->te_ypix < y1) { - y1 = yt->te_ypix; - } - - if (yt->te_ypix > y2) { - y2 = yt->te_ypix; - } - - sel = sel->sel_next; - } - if (x2-x1 != 0 && x2-x1 < y2-y1) v = 1; //horizontal - else if (y2-y1 != 0 && y2-y1 <= x2-x1) h = 1; //vertical (takes precedence over vertical if two are equal) - else if (x2-x1 == 0) vs = 1; //vertically aligned respacing - else if (y2-y1 == 0) hs = 1; //horizontally aligned respacing - - //fprintf(stderr,"h=%d v=%d hs=%d vs=%d\n", h, v, hs, vs); - - // now find leftmost, topmost, rightmost, and bottommost object - sel = x->gl_editor->e_selection; - while (sel) { - y = sel->sel_what; - yt = (t_text *)y; - if(yt->te_xpix == x1) { - leftmost = y; - //fprintf(stderr,"leftmost %d\n", x1); - } - if(yt->te_xpix == x2) { - rightmost = y; - rightmost_t = (t_text *)y; - //fprintf(stderr,"rightmost %d\n", x2); - } - if(yt->te_ypix == y2) { - topmost = y; - topmost_t = (t_text *)y; - //fprintf(stderr,"topmost %d\n", y2); - } - if(yt->te_ypix == y1) { - bottommost = y; - //fprintf(stderr,"bottommost %d\n", y1); - } - sel = sel->sel_next; - } - - if (h == 1) { - // horizontal tidy (everyone lines up to the y of the leftmost object) - canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 1)); - sel = x->gl_editor->e_selection; - yt = (t_text *)leftmost; - dy = yt->te_ypix; - - while (sel) { - y = sel->sel_what; - yt = (t_text *)y; - - //fprintf(stderr,"displace %d\n", dy - yt->te_ypix); - gobj_displace(y, x, 0, dy - yt->te_ypix); - - sel = sel->sel_next; - } - } - else if (v == 1) { - // vertical tidy (everyone lines up to the x of the bottommost object, since y axis is inverted) - canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 1)); - sel = x->gl_editor->e_selection; - yt = (t_text *)bottommost; - dx = yt->te_xpix; - - while (sel) { - y = sel->sel_what; - yt = (t_text *)y; - - //fprintf(stderr,"displace %d\n", dx - yt->te_xpix); - gobj_displace(y, x, dx - yt->te_xpix, 0); - - sel = sel->sel_next; - } - } - else { - // first check if we have more than 2 objects selected (otherwise there is no point in doing this - sel = x->gl_editor->e_selection; - i = 1; - while (sel->sel_next) { - i++; - sel = sel->sel_next; - } - - // we now know we will do a respace which means we need to first order objects according to their physical location (horizontal or vertical) - if (hs == 1) { - - t_gobj *next_right = NULL; - t_text *next_right_t = NULL; - - yt = (t_text *)rightmost; - sg = (t_sgobj *)getbytes(sizeof(*sg)); - sg->s_g = rightmost; - sg->s_x1 = yt->te_xpix; - sg->s_x2 = yt->te_xpix + canvas_tidy_gobj_width(x, y); - sg->s_y1 = yt->te_ypix; - sg->s_y2 = yt->te_ypix + canvas_tidy_gobj_height(x, y); - sg->s_next = NULL; - - //fprintf(stderr,"%d: x=%d y=%d width=%d height=%d\n", i, yt->te_xpix, yt->te_ypix, canvas_tidy_gobj_width(x, y), canvas_tidy_gobj_height(x, y)); - - i--; - - while (i) { - //fprintf(stderr,"i=%d\n", i); - sel = x->gl_editor->e_selection; - while (sel) { - y = sel->sel_what; - yt = (t_text *)y; - - //fprintf(stderr, "already processed ? %d ... x=%d y=%d\n", sgobj_already_processed(y, sg), yt->te_xpix, yt->te_ypix); - - // we need to avoid duplicates - if (!sgobj_already_processed(y, sg)) { - if (!next_right && yt->te_xpix <= rightmost_t->te_xpix) { - next_right = y; - next_right_t = yt; - } - else if (next_right && yt->te_xpix >= next_right_t->te_xpix && yt->te_xpix <= rightmost_t->te_xpix) { - next_right = y; - next_right_t = yt; - } - } - - sel = sel->sel_next; - } - - tmpsg = (t_sgobj *)getbytes(sizeof(*sg)); - tmpsg->s_g = next_right; - tmpsg->s_x1 = next_right_t->te_xpix; - tmpsg->s_x2 = next_right_t->te_xpix + canvas_tidy_gobj_width(x, next_right); - tmpsg->s_y1 = next_right_t->te_ypix; - tmpsg->s_y2 = next_right_t->te_ypix + canvas_tidy_gobj_height(x, next_right); - tmpsg->s_next = sg; - sg = tmpsg; - - //fprintf(stderr,"%d: x=%d y=%d width=%d height=%d\n", i, next_right_t->te_xpix, next_right_t->te_ypix, canvas_tidy_gobj_width(x, next_right), canvas_tidy_gobj_height(x, next_right)); - - rightmost = next_right; - rightmost_t = next_right_t; - next_right = NULL; - - i--; - } - - //fprintf(stderr,"got this far\n"); - // now let's traverse the new list and find minimal spacing and use that as our reference - // if spacing is anywhere less than 0 (meaning objects overlap), use next legal value - // one that is greater than 0. If all values are < 0 then use default value (10). - tmpsg = sg; - while (tmpsg->s_next) { - //fprintf(stderr,"calculating spacing from: %d and %d\n", tmpsg->s_next->s_x1, tmpsg->s_x2); - if (tmpsg->s_next->s_x1 > tmpsg->s_x2 && (spacing <= 0 || (spacing > 0 && tmpsg->s_next->s_x1 - tmpsg->s_x2 < spacing))) - spacing = tmpsg->s_next->s_x1 - tmpsg->s_x2; - //fprintf(stderr,"spacing = %d\n", spacing); - tmpsg = tmpsg->s_next; - } - if (spacing <= 0) { + // if we have no editor, no selection, or only one object selected, return + if (!x->gl_editor || !x->gl_editor->e_selection || !x->gl_editor->e_selection->sel_next) return; + + //fprintf(stderr,"canvas_tidy\n"); + t_gobj *y; + t_text *yt, *rightmost_t = NULL, *topmost_t = NULL; + int h, v; // horizontal, vertical + int hs, vs; // horizontal respacing, vertical respacing + t_gobj *leftmost, *rightmost, *topmost, *bottommost; + int x1, x2, y1, y2; + int ox1, ox2, oy1, oy2; // object x and y dimensions + int cox1, cox2, coy1, coy2; // comparing object x and y dimensions + int dx, dy; // displacement variables + int i; // generic counter var + t_sgobj *sg, *tmpsg; // list of objects ordered spatially + int spacing = 0; // spacing between objects on respacing (adjustable) + int delta = 0; + + dx = dy = h = v = hs = vs = 0; + + t_selection *sel = x->gl_editor->e_selection; + y = sel->sel_what; + yt = (t_text *)y; + x1 = yt->te_xpix; + x2 = x1; + y1 = yt->te_ypix; + y2 = y1; + + leftmost = y; + topmost = y; + rightmost = y; + bottommost = y; + + sel = sel->sel_next; + + // first find out whether we are dealing with horizontal or vertical + // alignment or spatialization + while (sel) + { + y = sel->sel_what; + yt = (t_text *)y; + + if (yt->te_xpix < x1) + { + x1 = yt->te_xpix; + } + + if (yt->te_xpix > x2) + { + x2 = yt->te_xpix; + } + + if (yt->te_ypix < y1) + { + y1 = yt->te_ypix; + } + + if (yt->te_ypix > y2) + { + y2 = yt->te_ypix; + } + + sel = sel->sel_next; + } + if (x2-x1 != 0 && x2-x1 < y2-y1) + v = 1; //horizontal + else if (y2-y1 != 0 && y2-y1 <= x2-x1) + h = 1; //vertical (takes precedence over vertical if two are equal) + else if (x2-x1 == 0) + vs = 1; //vertically aligned respacing + else if (y2-y1 == 0) + hs = 1; //horizontally aligned respacing + + //fprintf(stderr,"h=%d v=%d hs=%d vs=%d\n", h, v, hs, vs); + + // now find leftmost, topmost, rightmost, and bottommost object + sel = x->gl_editor->e_selection; + while (sel) + { + y = sel->sel_what; + yt = (t_text *)y; + if(yt->te_xpix == x1) + { + leftmost = y; + //fprintf(stderr,"leftmost %d\n", x1); + } + if(yt->te_xpix == x2) + { + rightmost = y; + rightmost_t = (t_text *)y; + //fprintf(stderr,"rightmost %d\n", x2); + } + if(yt->te_ypix == y2) + { + topmost = y; + topmost_t = (t_text *)y; + //fprintf(stderr,"topmost %d\n", y2); + } + if(yt->te_ypix == y1) + { + bottommost = y; + //fprintf(stderr,"bottommost %d\n", y1); + } + sel = sel->sel_next; + } + + if (h == 1) + { + // horizontal tidy (everyone lines up to the y of the leftmost object) + canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 1)); + sel = x->gl_editor->e_selection; + yt = (t_text *)leftmost; + dy = yt->te_ypix; + + while (sel) + { + y = sel->sel_what; + yt = (t_text *)y; + + //fprintf(stderr,"displace %d\n", dy - yt->te_ypix); + gobj_displace(y, x, 0, dy - yt->te_ypix); + + sel = sel->sel_next; + } + } + else if (v == 1) + { + // vertical tidy (everyone lines up to the x of the bottommost object, + // since y axis is inverted) + canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 1)); + sel = x->gl_editor->e_selection; + yt = (t_text *)bottommost; + dx = yt->te_xpix; + + while (sel) + { + y = sel->sel_what; + yt = (t_text *)y; + + //fprintf(stderr,"displace %d\n", dx - yt->te_xpix); + gobj_displace(y, x, dx - yt->te_xpix, 0); + + sel = sel->sel_next; + } + } + else + { + // first check if we have more than 2 objects selected + // (otherwise there is no point in doing this + sel = x->gl_editor->e_selection; + i = 1; + while (sel->sel_next) + { + i++; + sel = sel->sel_next; + } + + // we now know we will do a respace which means we need to + // first order objects according to their physical location + // (horizontal or vertical) + if (hs == 1) + { + + t_gobj *next_right = NULL; + t_text *next_right_t = NULL; + + yt = (t_text *)rightmost; + sg = (t_sgobj *)getbytes(sizeof(*sg)); + sg->s_g = rightmost; + sg->s_x1 = yt->te_xpix; + sg->s_x2 = yt->te_xpix + canvas_tidy_gobj_width(x, y); + sg->s_y1 = yt->te_ypix; + sg->s_y2 = yt->te_ypix + canvas_tidy_gobj_height(x, y); + sg->s_next = NULL; + + //fprintf(stderr,"%d: x=%d y=%d width=%d height=%d\n", + // i, yt->te_xpix, yt->te_ypix, canvas_tidy_gobj_width(x, y), + // canvas_tidy_gobj_height(x, y)); + + i--; + + while (i) + { + //fprintf(stderr,"i=%d\n", i); + sel = x->gl_editor->e_selection; + while (sel) + { + y = sel->sel_what; + yt = (t_text *)y; + + //fprintf(stderr, "already processed ? %d ... x=%d y=%d\n", + // sgobj_already_processed(y, sg), + // yt->te_xpix, yt->te_ypix); + + // we need to avoid duplicates + if (!sgobj_already_processed(y, sg)) + { + if (!next_right && yt->te_xpix <= rightmost_t->te_xpix) + { + next_right = y; + next_right_t = yt; + } + else if (next_right && + yt->te_xpix >= next_right_t->te_xpix && + yt->te_xpix <= rightmost_t->te_xpix) + { + next_right = y; + next_right_t = yt; + } + } + + sel = sel->sel_next; + } + + tmpsg = (t_sgobj *)getbytes(sizeof(*sg)); + tmpsg->s_g = next_right; + tmpsg->s_x1 = next_right_t->te_xpix; + tmpsg->s_x2 = next_right_t->te_xpix + canvas_tidy_gobj_width(x, next_right); + tmpsg->s_y1 = next_right_t->te_ypix; + tmpsg->s_y2 = next_right_t->te_ypix + canvas_tidy_gobj_height(x, next_right); + tmpsg->s_next = sg; + sg = tmpsg; + + //fprintf(stderr,"%d: x=%d y=%d width=%d height=%d\n", + // i, next_right_t->te_xpix, next_right_t->te_ypix, + // canvas_tidy_gobj_width(x, next_right), + // canvas_tidy_gobj_height(x, next_right)); + + rightmost = next_right; + rightmost_t = next_right_t; + next_right = NULL; + + i--; + } + + //fprintf(stderr,"got this far\n"); + /* now let's traverse the new list and find minimal spacing and + use that as our reference if spacing is anywhere less than 0 + (meaning objects overlap), use next legal value one that is + greater than 0. If all values are < 0 then use default value + (10). */ + tmpsg = sg; + while (tmpsg->s_next) + { + //fprintf(stderr,"calculating spacing from: %d and %d\n", + // tmpsg->s_next->s_x1, tmpsg->s_x2); + if (tmpsg->s_next->s_x1 > tmpsg->s_x2 && + (spacing <= 0 || + (spacing > 0 && tmpsg->s_next->s_x1 - + tmpsg->s_x2 < spacing))) + { + spacing = tmpsg->s_next->s_x1 - tmpsg->s_x2; + } + //fprintf(stderr,"spacing = %d\n", spacing); + tmpsg = tmpsg->s_next; + } + if (spacing <= 0) + { #ifdef PDL2ORK - if (sys_k12_mode) - spacing = 25; - else + if (sys_k12_mode) + spacing = 25; + else #endif - spacing = 5; - } - - //fprintf(stderr,"final spacing = %d\n", spacing); - - //fprintf(stderr,"0...\n"); - - // now change all values in the list to their target values - tmpsg = sg; - while (tmpsg->s_next) { - //fprintf(stderr,"adjusting %d to %d + %d\n", tmpsg->s_next->s_x1, tmpsg->s_x2, spacing); - delta = tmpsg->s_next->s_x1 - (tmpsg->s_x2 + spacing); - tmpsg->s_next->s_x1 = tmpsg->s_next->s_x1 - delta; - tmpsg->s_next->s_x2 = tmpsg->s_next->s_x2 - delta; - tmpsg = tmpsg->s_next; - } - - //fprintf(stderr,"1...\n"); - - // create an undo checkpoint - canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 1)); - - //fprintf(stderr,"2...\n"); - - // reposition all objects - tmpsg = sg; - while (tmpsg->s_next) { - yt = (t_text *)tmpsg->s_next->s_g; - //fprintf(stderr,"displace: %d %d\n", tmpsg->s_next->s_x1, yt->te_xpix); - gobj_displace(tmpsg->s_next->s_g, x, tmpsg->s_next->s_x1 - yt->te_xpix, 0); - tmpsg = tmpsg->s_next; - } - - //fprintf(stderr,"3...\n"); - - // free the temporary list of spatialized objects - while (sg) { - tmpsg = sg->s_next; - freebytes(sg, sizeof(*sg)); - sg = tmpsg; - } - } - else if (vs == 1) { - - t_gobj *next_top = NULL; - t_text *next_top_t = NULL; - - yt = (t_text *)topmost; - sg = (t_sgobj *)getbytes(sizeof(*sg)); - sg->s_g = topmost; - sg->s_x1 = yt->te_xpix; - sg->s_x2 = yt->te_xpix + canvas_tidy_gobj_width(x, y); - sg->s_y1 = yt->te_ypix; - sg->s_y2 = yt->te_ypix + canvas_tidy_gobj_height(x, y); - sg->s_next = NULL; - - //fprintf(stderr,"%d: x=%d y=%d width=%d height=%d\n", i, yt->te_xpix, yt->te_ypix, canvas_tidy_gobj_width(x, y), canvas_tidy_gobj_height(x, y)); - - i--; - - while (i) { - //fprintf(stderr,"i=%d\n", i); - sel = x->gl_editor->e_selection; - while (sel) { - y = sel->sel_what; - yt = (t_text *)y; - - //fprintf(stderr, "already processed ? %d ... x=%d y=%d\n", sgobj_already_processed(y, sg), yt->te_xpix, yt->te_ypix); - - // we need to avoid duplicates - if (!sgobj_already_processed(y, sg)) { - if (!next_top && yt->te_ypix <= topmost_t->te_ypix) { - next_top = y; - next_top_t = yt; - } - else if (next_top && yt->te_ypix >= next_top_t->te_ypix && yt->te_ypix <= topmost_t->te_ypix) { - next_top = y; - next_top_t = yt; - } - } - - sel = sel->sel_next; - } - - tmpsg = (t_sgobj *)getbytes(sizeof(*sg)); - tmpsg->s_g = next_top; - tmpsg->s_x1 = next_top_t->te_xpix; - tmpsg->s_x2 = next_top_t->te_xpix + canvas_tidy_gobj_width(x, next_top); - tmpsg->s_y1 = next_top_t->te_ypix; - tmpsg->s_y2 = next_top_t->te_ypix + canvas_tidy_gobj_height(x, next_top); - tmpsg->s_next = sg; - sg = tmpsg; - - //fprintf(stderr,"%d: x=%d y=%d width=%d height=%d\n", i, next_top_t->te_xpix, next_top_t->te_ypix, canvas_tidy_gobj_width(x, next_top), canvas_tidy_gobj_height(x, next_top)); - - topmost = next_top; - topmost_t = next_top_t; - next_top = NULL; - - i--; - } - - //fprintf(stderr,"got this far\n"); - // now let's traverse the new list and find minimal spacing and use that as our reference - // if spacing is anywhere less than 0 (meaning objects overlap), use next legal value - // one that is greater than 0. If all values are < 0 then use default value (10). - tmpsg = sg; - while (tmpsg->s_next) { - //fprintf(stderr,"calculating spacing from: %d and %d\n", tmpsg->s_next->s_y1, tmpsg->s_y2); - if (tmpsg->s_next->s_y1 > tmpsg->s_y2 && (spacing <= 0 || (spacing > 0 && tmpsg->s_next->s_y1 - tmpsg->s_y2 < spacing))) - spacing = tmpsg->s_next->s_y1 - tmpsg->s_y2; - //fprintf(stderr,"spacing = %d\n", spacing); - tmpsg = tmpsg->s_next; - } - if (spacing <= 0) { + spacing = 5; + } + + //fprintf(stderr,"final spacing = %d\n", spacing); + + //fprintf(stderr,"0...\n"); + + // now change all values in the list to their target values + tmpsg = sg; + while (tmpsg->s_next) + { + //fprintf(stderr,"adjusting %d to %d + %d\n", + // tmpsg->s_next->s_x1, tmpsg->s_x2, spacing); + delta = tmpsg->s_next->s_x1 - (tmpsg->s_x2 + spacing); + tmpsg->s_next->s_x1 = tmpsg->s_next->s_x1 - delta; + tmpsg->s_next->s_x2 = tmpsg->s_next->s_x2 - delta; + tmpsg = tmpsg->s_next; + } + + //fprintf(stderr,"1...\n"); + + // create an undo checkpoint + canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 1)); + + //fprintf(stderr,"2...\n"); + + // reposition all objects + tmpsg = sg; + while (tmpsg->s_next) + { + yt = (t_text *)tmpsg->s_next->s_g; + //fprintf(stderr,"displace: %d %d\n", + // tmpsg->s_next->s_x1, yt->te_xpix); + gobj_displace(tmpsg->s_next->s_g, x, + tmpsg->s_next->s_x1 - yt->te_xpix, 0); + tmpsg = tmpsg->s_next; + } + + //fprintf(stderr,"3...\n"); + + // free the temporary list of spatialized objects + while (sg) + { + tmpsg = sg->s_next; + freebytes(sg, sizeof(*sg)); + sg = tmpsg; + } + } + else if (vs == 1) + { + + t_gobj *next_top = NULL; + t_text *next_top_t = NULL; + + yt = (t_text *)topmost; + sg = (t_sgobj *)getbytes(sizeof(*sg)); + sg->s_g = topmost; + sg->s_x1 = yt->te_xpix; + sg->s_x2 = yt->te_xpix + canvas_tidy_gobj_width(x, y); + sg->s_y1 = yt->te_ypix; + sg->s_y2 = yt->te_ypix + canvas_tidy_gobj_height(x, y); + sg->s_next = NULL; + + //fprintf(stderr,"%d: x=%d y=%d width=%d height=%d\n", + // i, yt->te_xpix, yt->te_ypix, canvas_tidy_gobj_width(x, y), + // canvas_tidy_gobj_height(x, y)); + + i--; + + while (i) + { + //fprintf(stderr,"i=%d\n", i); + sel = x->gl_editor->e_selection; + while (sel) + { + y = sel->sel_what; + yt = (t_text *)y; + + //fprintf(stderr, "already processed ? %d ... x=%d y=%d\n", + // sgobj_already_processed(y, sg), + // yt->te_xpix, yt->te_ypix); + + // we need to avoid duplicates + if (!sgobj_already_processed(y, sg)) + { + if (!next_top && yt->te_ypix <= topmost_t->te_ypix) + { + next_top = y; + next_top_t = yt; + } + else if (next_top && + yt->te_ypix >= next_top_t->te_ypix && + yt->te_ypix <= topmost_t->te_ypix) + { + next_top = y; + next_top_t = yt; + } + } + + sel = sel->sel_next; + } + + tmpsg = (t_sgobj *)getbytes(sizeof(*sg)); + tmpsg->s_g = next_top; + tmpsg->s_x1 = next_top_t->te_xpix; + tmpsg->s_x2 = next_top_t->te_xpix + canvas_tidy_gobj_width(x, next_top); + tmpsg->s_y1 = next_top_t->te_ypix; + tmpsg->s_y2 = next_top_t->te_ypix + canvas_tidy_gobj_height(x, next_top); + tmpsg->s_next = sg; + sg = tmpsg; + + //fprintf(stderr,"%d: x=%d y=%d width=%d height=%d\n", + // i, next_top_t->te_xpix, next_top_t->te_ypix, + // canvas_tidy_gobj_width(x, next_top), + // canvas_tidy_gobj_height(x, next_top)); + + topmost = next_top; + topmost_t = next_top_t; + next_top = NULL; + + i--; + } + + //fprintf(stderr,"got this far\n"); + /* now let's traverse the new list and find minimal spacing + and use that as our reference if spacing is anywhere less + than 0 (meaning objects overlap), use next legal value one + that is greater than 0. If all values are < 0 then use + default value (10). */ + tmpsg = sg; + while (tmpsg->s_next) + { + //fprintf(stderr,"calculating spacing from: %d and %d\n", + // tmpsg->s_next->s_y1, tmpsg->s_y2); + if (tmpsg->s_next->s_y1 > tmpsg->s_y2 && + (spacing <= 0 || + (spacing > 0 && tmpsg->s_next->s_y1 - + tmpsg->s_y2 < spacing))) + { + spacing = tmpsg->s_next->s_y1 - tmpsg->s_y2; + } + //fprintf(stderr,"spacing = %d\n", spacing); + tmpsg = tmpsg->s_next; + } + if (spacing <= 0) + { #ifdef PDL2ORK - if (sys_k12_mode) - spacing = 25; - else + if (sys_k12_mode) + spacing = 25; + else #endif - spacing = 5; - } + spacing = 5; + } - //fprintf(stderr,"final spacing = %d\n", spacing); + //fprintf(stderr,"final spacing = %d\n", spacing); - //fprintf(stderr,"0...\n"); + //fprintf(stderr,"0...\n"); - // now change all values in the list to their target values - tmpsg = sg; - while (tmpsg->s_next) { - //fprintf(stderr,"adjusting %d to %d + %d\n", tmpsg->s_next->s_y1, tmpsg->s_y2, spacing); - delta = tmpsg->s_next->s_y1 - (tmpsg->s_y2 + spacing); - tmpsg->s_next->s_y1 = tmpsg->s_next->s_y1 - delta; - tmpsg->s_next->s_y2 = tmpsg->s_next->s_y2 - delta; - tmpsg = tmpsg->s_next; - } + // now change all values in the list to their target values + tmpsg = sg; + while (tmpsg->s_next) + { + //fprintf(stderr,"adjusting %d to %d + %d\n", + // tmpsg->s_next->s_y1, tmpsg->s_y2, spacing); + delta = tmpsg->s_next->s_y1 - (tmpsg->s_y2 + spacing); + tmpsg->s_next->s_y1 = tmpsg->s_next->s_y1 - delta; + tmpsg->s_next->s_y2 = tmpsg->s_next->s_y2 - delta; + tmpsg = tmpsg->s_next; + } - //fprintf(stderr,"1...\n"); + //fprintf(stderr,"1...\n"); - // create an undo checkpoint - canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 1)); + // create an undo checkpoint + canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 1)); - //fprintf(stderr,"2...\n"); + //fprintf(stderr,"2...\n"); - // reposition all objects - tmpsg = sg; - while (tmpsg->s_next) { - yt = (t_text *)tmpsg->s_next->s_g; - //fprintf(stderr,"displace: %d %d\n", tmpsg->s_next->s_y1, yt->te_ypix); - gobj_displace(tmpsg->s_next->s_g, x, 0, tmpsg->s_next->s_y1 - yt->te_ypix); - tmpsg = tmpsg->s_next; - } + // reposition all objects + tmpsg = sg; + while (tmpsg->s_next) + { + yt = (t_text *)tmpsg->s_next->s_g; + //fprintf(stderr,"displace: %d %d\n", + // tmpsg->s_next->s_y1, yt->te_ypix); + gobj_displace(tmpsg->s_next->s_g, x, 0, + tmpsg->s_next->s_y1 - yt->te_ypix); + tmpsg = tmpsg->s_next; + } - //fprintf(stderr,"3...\n"); + //fprintf(stderr,"3...\n"); - // free the temporary list of spatialized objects - while (sg) { - tmpsg = sg->s_next; - freebytes(sg, sizeof(*sg)); - sg = tmpsg; - } - } + // free the temporary list of spatialized objects + while (sg) + { + tmpsg = sg->s_next; + freebytes(sg, sizeof(*sg)); + sg = tmpsg; + } + } - } - canvas_dirty(x, 1); - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + } + canvas_dirty(x, 1); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); } -/* below is deprecated/old version of tidy left here for documentation/reuse purposes - currently it is inactive */ +/* below is deprecated/old version of tidy left here for + documentation/reuse purposes currently it is inactive */ #define XTOLERANCE 20 #define YTOLERANCE 20 #define NHIST 15 @@ -6325,7 +7136,7 @@ static void canvas_tidyold(t_canvas *x) //canvas_setundo(x, canvas_undo_move, canvas_undo_set_move(x, !all), // "motion"); - canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, !all)); + canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, !all)); /* tidy horizontally */ for (y = x->gl_list; y; y = y->g_next) @@ -6438,34 +7249,37 @@ void glob_key(void *dummy, t_symbol *s, int ac, t_atom *av) void glob_pastetext(void *dummy, t_symbol *s, int ac, t_atom *av) { - //fprintf(stderr,"glob_pastetext %s\n", s->s_name); - canvas_key(canvas_editing, s, ac-1, av+1); - if ((int)atom_getfloat(av) == 1) { - //fprintf(stderr,"force getscroll\n"); - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", canvas_editing); - } + //fprintf(stderr,"glob_pastetext %s\n", s->s_name); + canvas_key(canvas_editing, s, ac-1, av+1); + if ((int)atom_getfloat(av) == 1) + { + //fprintf(stderr,"force getscroll\n"); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", canvas_editing); + } } void canvas_editmode(t_canvas *x, t_floatarg fyesplease) { - //fprintf(stderr,"canvas_editmode %f\n", fyesplease); + //fprintf(stderr,"canvas_editmode %f\n", fyesplease); - //first check if this is a canvas hosting an array and if so refuse to add any further objects + /* first check if this is a canvas hosting an array and if so + refuse to add any further objects */ if (canvas_hasarray(x)) return; int yesplease = fyesplease; - if (yesplease && x->gl_edit) { - //if (x->gl_edit && glist_isvisible(x) && glist_istoplevel(x)) - // canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); + if (yesplease && x->gl_edit) + { + //if (x->gl_edit && glist_isvisible(x) && glist_istoplevel(x)) + // canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); return; - } + } x->gl_edit = !x->gl_edit; if (x->gl_edit && glist_isvisible(x) && glist_istoplevel(x)){ - //dpsaha@vt.edu add the resize blobs on GOP - t_gobj *g; + //dpsaha@vt.edu add the resize blobs on GOP + t_gobj *g; t_object *ob; - if (x->gl_goprect) canvas_draw_gop_resize_hooks(x); - canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); + if (x->gl_goprect) canvas_draw_gop_resize_hooks(x); + canvas_setcursor(x, CURSOR_EDITMODE_NOTHING); for (g = x->gl_list; g; g = g->g_next) if ((ob = pd_checkobject(&g->g_pd)) && ob->te_type == T_TEXT) { @@ -6473,10 +7287,10 @@ void canvas_editmode(t_canvas *x, t_floatarg fyesplease) text_drawborder(ob, x, rtext_gettag(y), rtext_width(y), rtext_height(y), 1); } - } + } else { - //fprintf(stderr,"we are out of edit\n"); + //fprintf(stderr,"we are out of edit\n"); glist_noselect(x); if (glist_isvisible(x) && glist_istoplevel(x)) { @@ -6485,49 +7299,68 @@ void canvas_editmode(t_canvas *x, t_floatarg fyesplease) // jsarlo if (x->gl_editor->canvas_cnct_inlet_tag[0] != 0) { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_inlet_tag, - (last_inlet_filter ? "black" : (inlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (inlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s " + "-strokewidth 1\n", + x, x->gl_editor->canvas_cnct_inlet_tag, + (last_inlet_filter ? + "black" : + (inlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (inlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); x->gl_editor->canvas_cnct_inlet_tag[0] = 0; } if (x->gl_editor->canvas_cnct_outlet_tag[0] != 0) { - sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s -strokewidth 1\n", - x, x->gl_editor->canvas_cnct_outlet_tag, - (last_outlet_filter ? "black" : (outlet_issignal ? "$pd_colors(signal_cord)" : "$pd_colors(control_cord)")), - (outlet_issignal ? "$pd_colors(signal_nlet)" : "$pd_colors(control_nlet)")); + sys_vgui(".x%x.c itemconfigure %s -stroke %s -fill %s " + "-strokewidth 1\n", + x, x->gl_editor->canvas_cnct_outlet_tag, + (last_outlet_filter ? + "black" : + (outlet_issignal ? + "$pd_colors(signal_cord)" : + "$pd_colors(control_cord)")), + (outlet_issignal ? + "$pd_colors(signal_nlet)" : + "$pd_colors(control_nlet)")); x->gl_editor->canvas_cnct_outlet_tag[0] = 0; } - if(x->gl_editor && x->gl_editor->gl_magic_glass) { - magicGlass_unbind(x->gl_editor->gl_magic_glass); - magicGlass_hide(x->gl_editor->gl_magic_glass); - } - // end jsarlo - //dpsaha@vt.edu called to delete the GOP_blob - if (x->gl_goprect) canvas_draw_gop_resize_hooks(x); + if(x->gl_editor && x->gl_editor->gl_magic_glass) + { + magicGlass_unbind(x->gl_editor->gl_magic_glass); + magicGlass_hide(x->gl_editor->gl_magic_glass); + } + // end jsarlo + //dpsaha@vt.edu called to delete the GOP_blob + if (x->gl_goprect) canvas_draw_gop_resize_hooks(x); } - canvas_setcursor(x, CURSOR_RUNMODE_NOTHING); + canvas_setcursor(x, CURSOR_RUNMODE_NOTHING); } if (glist_isvisible(x)) - sys_vgui("pdtk_canvas_editval .x%lx %d\n", - glist_getcanvas(x), x->gl_edit); - /*if (!x->gl_edit) { - sys_vgui(".x%lx.m.edit entryconfigure \"Cord Inspector\" -indicatoron false -state disabled\n", glist_getcanvas(x)); - } - else { - sys_vgui(".x%lx.m.edit entryconfigure \"Cord Inspector\" -indicatoron false -state normal\n", glist_getcanvas(x)); - }*/ + sys_vgui("pdtk_canvas_editval .x%lx %d\n", + glist_getcanvas(x), x->gl_edit); + /*if (!x->gl_edit) { + sys_vgui(".x%lx.m.edit entryconfigure \"Cord Inspector\" " + "-indicatoron false -state disabled\n", glist_getcanvas(x)); + } + else { + sys_vgui(".x%lx.m.edit entryconfigure \"Cord Inspector\" " + "-indicatoron false -state normal\n", glist_getcanvas(x)); + }*/ } // jsarlo void canvas_magicglass(t_canvas *x, t_floatarg fyesplease) { int yesplease = fyesplease; - if (yesplease && x->gl_editor && magicGlass_isOn(x->gl_editor->gl_magic_glass)) - return; - if (!magicGlass_isOn(x->gl_editor->gl_magic_glass)) { - canvas_editmode(x, 1.); + if (yesplease && x->gl_editor && + magicGlass_isOn(x->gl_editor->gl_magic_glass)) + return; + if (!magicGlass_isOn(x->gl_editor->gl_magic_glass)) + { + canvas_editmode(x, 1.); magicGlass_setOn(x->gl_editor->gl_magic_glass, 1); if (magicGlass_bound(x->gl_editor->gl_magic_glass)) { @@ -6545,22 +7378,24 @@ void canvas_magicglass(t_canvas *x, t_floatarg fyesplease) void canvas_tooltips(t_canvas *x, t_floatarg fyesplease) { - //fprintf(stderr,"canvas_tooltips %f\n", fyesplease); + //fprintf(stderr,"canvas_tooltips %f\n", fyesplease); int yesplease = fyesplease; if (yesplease && tooltips) - return; - if (!tooltips) { - if (!sys_k12_mode) canvas_editmode(x, 1.); + return; + if (!tooltips) + { + if (!sys_k12_mode) canvas_editmode(x, 1.); tooltips = 1; } else { tooltips = 0; - if (objtooltip) { - objtooltip = 0; - sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); - } + if (objtooltip) + { + objtooltip = 0; + sys_vgui("pdtk_canvas_leaveitem .x%x.c;\n", x); + } } - sys_vgui("pdtk_canvas_tooltips .x%lx %d\n", + sys_vgui("pdtk_canvas_tooltips .x%lx %d\n", x, tooltips); } @@ -6570,8 +7405,11 @@ static void canvas_dofont(t_canvas *x, t_floatarg font, t_floatarg xresize, { t_gobj *y; x->gl_font = font; - if (x->gl_isgraph && !canvas_isabstraction(x) && (xresize != 1 || yresize != 1) && !glist_istoplevel(x)) - vmess(&x->gl_pd, gensym("menu-open"), ""); + if (x->gl_isgraph && !canvas_isabstraction(x) && + (xresize != 1 || yresize != 1) && !glist_istoplevel(x)) + { + vmess(&x->gl_pd, gensym("menu-open"), ""); + } if (xresize != 1 || yresize != 1) { for (y = x->gl_list; y; y = y->g_next) @@ -6580,42 +7418,51 @@ static void canvas_dofont(t_canvas *x, t_floatarg font, t_floatarg xresize, gobj_getrect(y, x, &x1, &y1, &x2, &y2); nx1 = x1 * xresize + 0.5; ny1 = y1 * yresize + 0.5; - if (pd_class(&y->g_pd) != scalar_class) { - //fprintf(stderr,"dofont gobj displace %lx %d %d %d %d : %f %f : %d %d\n", y, x1, x2, y1, y2, xresize, yresize, nx1, ny1); - gobj_displace(y, x, nx1-x1, ny1-y1); - } + if (pd_class(&y->g_pd) != scalar_class) + { + //fprintf(stderr,"dofont gobj displace %lx %d %d %d %d : " + // "%f %f : %d %d\n", + // y, x1, x2, y1, y2, xresize, yresize, nx1, ny1); + gobj_displace(y, x, nx1-x1, ny1-y1); + } } } if (glist_isvisible(x)) - { - //fprintf(stderr,"glist_redraw %lx\n", x); - if (x->gl_editor && magicGlass_isOn(x->gl_editor->gl_magic_glass)) - magicGlass_hide(x->gl_editor->gl_magic_glass); + { + //fprintf(stderr,"glist_redraw %lx\n", x); + if (x->gl_editor && magicGlass_isOn(x->gl_editor->gl_magic_glass)) + magicGlass_hide(x->gl_editor->gl_magic_glass); glist_redraw(x); - } + } for (y = x->gl_list; y; y = y->g_next) if (pd_class(&y->g_pd) == canvas_class && !canvas_isabstraction((t_canvas *)y)) canvas_dofont((t_canvas *)y, font, xresize, yresize); - sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); + sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); } /* canvas_menufont calls up a TK dialog which calls this back */ -static void canvas_font(t_canvas *x, t_floatarg font, t_floatarg oldfont, t_floatarg resize, t_floatarg noundo) +static void canvas_font(t_canvas *x, t_floatarg font, t_floatarg oldfont, + t_floatarg resize, t_floatarg noundo) { t_float realresize; t_canvas *x2 = canvas_getrootfor(x); - if (!resize) realresize = 1; + if (!resize) + realresize = 1; else - realresize = (t_float)sys_fontwidth(font)/(t_float)sys_fontwidth(x2->gl_font); + realresize = (t_float)sys_fontwidth(font) / + (t_float)sys_fontwidth(x2->gl_font); - if (!noundo) { - if (!oldfont && font != x2->gl_font) - canvas_undo_add(x, 11, "font", canvas_undo_set_font(x, x2->gl_font)); - else if (oldfont != font) canvas_undo_add(x, 11, "font", canvas_undo_set_font(x, oldfont)); - } + if (!noundo) + { + if (!oldfont && font != x2->gl_font) + canvas_undo_add(x, 11, "font", + canvas_undo_set_font(x, x2->gl_font)); + else if (oldfont != font) + canvas_undo_add(x, 11, "font", canvas_undo_set_font(x, oldfont)); + } - canvas_dirty(x2, 1); + canvas_dirty(x2, 1); canvas_dofont(x2, font, realresize, realresize); } @@ -6639,70 +7486,70 @@ void glist_setlastxymod(t_glist *gl, int xval, int yval, int mod) canvas_last_glist = gl; canvas_last_glist_x = xval; canvas_last_glist_y = yval; - canvas_last_glist_mod = mod; + canvas_last_glist_mod = mod; } static void canvas_enterobj(t_canvas *x, t_symbol *item, t_floatarg xpos, t_floatarg ypos, t_floatarg xletno) { - if (x->gl_editor->e_onmotion == MA_MOVE) { return; } + if (x->gl_editor->e_onmotion == MA_MOVE) { return; } t_symbol *name = 0, *helpname, *dir; int yoffset = 0, xoffset = 0; if (item == gensym("inlet")) { - yoffset = 1; + yoffset = 1; xoffset = xletno==0 ? 1 : -1; } else if (item == gensym("outlet")) { - yoffset = -1; - xoffset = xletno== 0 ? 1 : -1; + yoffset = -1; + xoffset = xletno== 0 ? 1 : -1; } int x1, y1, x2, y2; t_gobj *g; if (g = canvas_findhitbox(x, xpos+xoffset, ypos+yoffset, - &x1, &y1, &x2, &y2)) + &x1, &y1, &x2, &y2)) { if (pd_class((t_pd *)g)==canvas_class ? - canvas_isabstraction((t_canvas *)g) : 0) - { - t_canvas *z = (t_canvas *)g; - name = z->gl_name; - helpname = z->gl_name; - dir = canvas_getdir(z); - } - else - { - name = g->g_pd->c_name; - helpname = g->g_pd->c_helpname; - dir = g->g_pd->c_externdir; - } + canvas_isabstraction((t_canvas *)g) : 0) + { + t_canvas *z = (t_canvas *)g; + name = z->gl_name; + helpname = z->gl_name; + dir = canvas_getdir(z); + } + else + { + name = g->g_pd->c_name; + helpname = g->g_pd->c_helpname; + dir = g->g_pd->c_externdir; + } sys_vgui("pdtk_gettip .x%lx.c %s %d \ - [list %s] [list %s] [list %s]\n", - x, item->s_name, (int)xletno, - name->s_name, helpname->s_name, dir->s_name); + [list %s] [list %s] [list %s]\n", + x, item->s_name, (int)xletno, + name->s_name, helpname->s_name, dir->s_name); } } static void canvas_tip(t_canvas *x, t_symbol *s, int argc, t_atom *argv) { if (s == gensym("echo")) - return; + return; if (argv->a_type != A_FLOAT) error("canvas_tip: bad argument"); else { - sys_vgui("pdtk_tip .x%lx.c 1", x); - t_atom *at = argv; - int i; - for (i=0; i<argc; i++) - { - if (at[i].a_type == A_FLOAT) - sys_vgui(" %g", at[i].a_w.w_float); - else if (at[i].a_type == A_SYMBOL) - sys_vgui(" %s", at[i].a_w.w_symbol->s_name); - } - sys_gui("\n"); + sys_vgui("pdtk_tip .x%lx.c 1", x); + t_atom *at = argv; + int i; + for (i=0; i<argc; i++) + { + if (at[i].a_type == A_FLOAT) + sys_vgui(" %g", at[i].a_w.w_float); + else if (at[i].a_type == A_SYMBOL) + sys_vgui(" %s", at[i].a_w.w_symbol->s_name); + } + sys_gui("\n"); } } @@ -6722,9 +7569,9 @@ void g_editor_setup(void) class_addmethod(canvas_class, (t_method)glist_noselect, gensym("noselect"), A_NULL); class_addmethod(canvas_class, (t_method)canvas_enterobj, gensym("enter"), - A_SYMBOL, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); + A_SYMBOL, A_FLOAT, A_FLOAT, A_FLOAT, A_NULL); class_addmethod(canvas_class, (t_method)canvas_tip, gensym("tip"), - A_GIMME, A_NULL); + A_GIMME, A_NULL); class_addmethod(canvas_class, (t_method)canvas_tip, gensym("echo"), A_GIMME, A_NULL); /* ------------------------ menu actions ---------------------------- */ -- GitLab