diff --git a/src/g_canvas.c b/src/g_canvas.c index 5a5970812ad6020f6a03b298ce96e22a7a6023e0..665a6b17690a4aee98e0838cc2c5b1f04de03be4 100644 --- a/src/g_canvas.c +++ b/src/g_canvas.c @@ -328,11 +328,6 @@ void linetraverser_skipobject(t_linetraverser *t) /* -------------------- the canvas object -------------------------- */ int glist_valid = 10000; -//static void canvas_manual_pd_free(t_canvas *x) { -// sys_flushtogui(); -// pd_free(&x->gl_pd); -//} - void glist_init(t_glist *x) { /* zero out everyone except "pd" field */ @@ -343,44 +338,12 @@ void glist_init(t_glist *x) x->gl_ylabel = (t_symbol **)t_getbytes(0); } -/* global var used by pd_new() to work with redundant memory, originally defined in m_pd.c */ -//extern int canvas_check_duplicate; - /* make a new glist. It will either be a "root" canvas or else it appears as a "text" object in another window (canvas_getcurrent() tells us which.) */ t_canvas *canvas_new(void *dummy, t_symbol *sel, int argc, t_atom *argv) { - /* first alloc one byte or redundant memory to prevent creation of objects with the same "name" - which leads to double-action invoked from every single action and eventually possible crashes - we keep a list of these redundant allocations and destroy them when pd quits */ - - //if (x->gl_owner && x->gl_env) { - -/* - t_redundant_mem *new_rm = (t_redundant_mem *)t_getbytes(sizeof(*new_rm)); - //new_rm->rm_what = (int)getbytes(1); - if (rm_start == NULL) { - //fprintf(stderr,"first allocation\n"); - rm_start = new_rm; - rm_end = new_rm; - } - else if (rm_start == rm_end) { - //fprintf(stderr,"second allocation\n"); - rm_end = new_rm; - rm_start->rm_next = rm_end; - } - else { - //fprintf(stderr,"allocation\n"); - rm_end->rm_next = new_rm; - rm_end = new_rm; - } - //} - - - canvas_check_duplicate = -1;*/ t_canvas *x = (t_canvas *)pd_new(canvas_class); - //rm_end->rm_canvas = x; t_canvas *owner = canvas_getcurrent(); t_symbol *s = &s_; int vis = 0, width = GLIST_DEFCANVASWIDTH, height = GLIST_DEFCANVASHEIGHT; diff --git a/src/g_editor.c b/src/g_editor.c index 5a3eb4b9ba649bdcc954209bc6b4b326fdb4527e..048889fa74968760734e7c136e80293d7ec4dd4a 100644 --- a/src/g_editor.c +++ b/src/g_editor.c @@ -59,6 +59,8 @@ 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 resize, + t_floatarg oldfont, t_floatarg preview); struct _outlet { @@ -68,20 +70,6 @@ struct _outlet t_symbol *o_sym; }; -/* ----------- ??. selection -------------- */ -/*typedef struct _undo_sel -{ - int u_index; - struct _undo_sel *sel_next; -} t_undo_sel; - -typedef struct _undo_redo_sel -{ - t_undo_sel *u_undo; - t_undo_sel *u_redo; -} t_undo_redo_sel;*/ -/* ---------------------------------------- */ - /* used for new duplicate behavior where we can "duplicate" into new window */ static t_canvas *c_selection; @@ -1744,14 +1732,10 @@ void canvas_undo_font(t_canvas *x, void *z, int action) if (action == UNDO_UNDO || action == UNDO_REDO) { - int tmp_font = sys_defaultfont; 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); - - canvas_dofont(x2, u_f->font, resize, resize, 1); - sys_defaultfont = u_f->font; - + canvas_font(x2, u_f->font, 100.0, (t_floatarg)x2->gl_font, -1); u_f->font = tmp_font; } else if (action == UNDO_FREE) @@ -1761,73 +1745,6 @@ void canvas_undo_font(t_canvas *x, void *z, int action) } } - -/* ----------- ??. selection -------------- */ - -//structs are defined at the top of the file due to unusual undo/redo design of the selection - -/*void *canvas_undo_set_selection(t_canvas *x) -{ - t_undo_sel *u_sel = (t_undo_sel *)getbytes(sizeof(*u_sel)); - u_sel->u_index = -1; - if (x->gl_editor->e_selection) { - t_gobj *g = x->gl_list; - int index = 0; - t_undo_sel *tmp = u_sel; - - while (g) { - if (glist_isselected(x, g)) { - tmp->u_index = index; - if (g->g_next) { - t_undo_sel *u_sel_next = (t_undo_sel *)getbytes(sizeof(*u_sel_next)); - u_sel_next->u_index = -1; - tmp->sel_next = u_sel_next; - tmp = u_sel_next; - } - } - index++; - g = g->g_next; - } - } - return (u_sel); -} - -void canvas_undo_selection(t_canvas *x, void *z, int action) -{ - t_undo_redo_sel *u_main = z; - t_undo_sel *u_sel; - - if (action == UNDO_UNDO || action == UNDO_REDO) - { - if (action == UNDO_UNDO) u_sel = u_main->u_undo; - else u_sel = u_main->u_redo; - - glist_noselect(x); - - while(u_sel) { - if (u_sel->u_index > -1) - glist_select(x, glist_nth(x, u_sel->u_index)); - u_sel = u_sel->sel_next; - } - } - else if (action == UNDO_FREE) - { - u_sel = u_main->u_undo; - while (u_sel) { - t_undo_sel *destroy = u_sel; - u_sel = u_sel->sel_next; - freebytes(destroy, sizeof(*destroy)); - } - u_sel = u_main->u_redo; - while (u_sel) { - t_undo_sel *destroy = u_sel; - u_sel = u_sel->sel_next; - freebytes(destroy, sizeof(*destroy)); - } - freebytes(u_main, sizeof(*u_main)); - } -} -*/ /* ------------------------ event handling ------------------------ */ static char *cursorlist[] = { @@ -4788,8 +4705,8 @@ static void canvas_dofont(t_canvas *x, t_floatarg font, t_floatarg xresize, { //canvas_setundo(x, canvas_undo_move, canvas_undo_set_move(x, 0), // "motion"); - if (!preview) - canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 0)); + //if (!preview) + // canvas_undo_add(x, 4, "motion", canvas_undo_set_move(x, 0)); for (y = x->gl_list; y; y = y->g_next) { int x1, x2, y1, y2, nx1, ny1; @@ -4809,31 +4726,32 @@ static void canvas_dofont(t_canvas *x, t_floatarg font, t_floatarg xresize, sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x); } - /* canvas_menufont calls up a TK dialog which calls this back */ + /* canvas_menufont calls up a TK dialog which calls this back (0 for apply, 1 for preview) + this is also called by ctrl+mousewheel (0) for faux zoom, as well as undo_font (-1) */ static void canvas_font(t_canvas *x, t_floatarg font, t_floatarg resize, - t_floatarg whichresize, t_floatarg preview) + t_floatarg oldfont, t_floatarg preview) { t_float realresize, realresx = 1, realresy = 1; t_canvas *x2 = canvas_getrootfor(x); if (!resize) realresize = 1; else - { - //fprintf(stderr,"%d %d %d\n", sys_fontwidth(font), sys_fontwidth(x->gl_font), x->gl_font); - realresize = (t_float)sys_fontwidth(font)/(t_float)sys_fontwidth(x2->gl_font); //*100.0; - //if (resize < 20) resize = 20; - //if (resize > 500) resize = 500; - //realresize = resize * 0.01; - } - if (whichresize != 3) realresx = realresize; - if (whichresize != 2) realresy = realresize; + realresize = (t_float)sys_fontwidth(font)/(t_float)sys_fontwidth(oldfont); + + realresx = realresize; + realresy = realresize; - if (!preview) { - if (sys_defaultfont != font) - canvas_undo_add(x, 11, "font", canvas_undo_set_font(x, sys_defaultfont)); - sys_defaultfont = font; + if (!preview && font != oldfont) { + canvas_undo_add(x, 11, "font", canvas_undo_set_font(x, oldfont)); canvas_dirty(x2, 1); } - canvas_dofont(x2, font, realresx, realresy, preview); + + t_int properties = gfxstub_haveproperties((void *)x2); + if (preview <= 0 && properties) + gfxstub_deleteforkey(x2); + + if (x2->gl_font != (int)font) { + canvas_dofont(x2, font, realresx, realresy, preview); + } } static t_glist *canvas_last_glist; diff --git a/src/pd.tk b/src/pd.tk index 30d94c7eefd9dec804c7b467b53d9e91f4d25ac3..363870e7677e5ddd08c59ae2a5d10af70ac23788 100644 --- a/src/pd.tk +++ b/src/pd.tk @@ -1676,10 +1676,12 @@ proc menu_duplicate {name} { } proc menu_selectall {name} { - if {![string match .gfxstub* $name] && ![string match *entry $name]} { + if {![string match .gfxstub* $name] && ![string match *ent* $name]} { pd [concat $name selectall \;] } else { - $name selection range 0 end + if { [string match *ent* $name] } { + $name selection range 0 end + } } } @@ -3288,7 +3290,7 @@ proc pdtk_canvas_ctrlkey {name key shift} { if {$key == "c" || $key == "C"} {pdtk_canvas_edit_menu_actions $topname Copy} #if {$key == "v" || $key == "V"} {menu_paste $topname} if {$key == "v" || $key == "V"} {pdtk_canvas_edit_menu_actions $topname Paste} - if {$key == "a" || $key == "A"} {menu_selectall $topname} + if {$key == "a" || $key == "A"} {menu_selectall $topname} if {!$ignore} { if {$key == "w" || $key == "W"} {menu_close $topname} if {$key == "s" || $key == "S"} {menu_save $topname} @@ -3394,6 +3396,8 @@ set font_array { 8 10 12 16 24 36 } proc pdtk_zoom {name direction} { #puts stderr "pdtk_zoom $name $direction" global font_array + global fontsize + set fontsize $::font($name) set index [lsearch $font_array $::font($name)] if { $index == 5 && $direction == 1 || $index == 0 && $direction == -1 } { return @@ -3468,17 +3472,14 @@ set stretchval 100 set whichstretch 1 proc dofont_apply {name myfontsize preview} { - #puts stderr "dofont_apply $name $myfontsize $preview" global stretchval - global whichstretch - set cmd [concat $name font $myfontsize $stretchval $whichstretch $preview \;] - # puts stderr $cmd + global fontsize + set cmd [concat $name font $myfontsize $stretchval $fontsize $preview \;] pd $cmd } proc dofont_close {name} { set cmd [concat $name cancel \;] - # puts stderr $cmd pd $cmd } @@ -3486,14 +3487,12 @@ proc dofont_cancel {name} { global fontsize dofont_apply $name $fontsize 1 set cmd [concat $name cancel \;] - # puts stderr $cmd pd $cmd } proc dofont_ok {name} { global fontsize dofont_fontsize - set fontsize $dofont_fontsize - dofont_apply $name $fontsize 0 + dofont_apply $name $dofont_fontsize 0 dofont_close $name }