Commit 051fd72c authored by Ivica Ico Bukvic's avatar Ivica Ico Bukvic
Browse files

cleaned up font resize and ctrl+mousewheel feature

parent ce82ca59
......@@ -55,12 +55,11 @@ static int screenx2;
static int screeny2;
static int copiedfont;
static void canvas_dofont(t_canvas *x, t_floatarg font, t_floatarg xresize,
t_floatarg yresize, int preview);
t_floatarg yresize);
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);
static void canvas_font(t_canvas *x, t_floatarg font, t_floatarg oldfont, t_floatarg resize, t_floatarg preview);
struct _outlet
{
......@@ -1378,7 +1377,8 @@ void canvas_undo_canvas_apply(t_canvas *x, void *z, int action)
//close properties window first
t_int properties = gfxstub_haveproperties((void *)x);
if (properties) {
sys_vgui("destroy .gfxstub%lx\n", properties);
//sys_vgui("destroy .gfxstub%lx\n", properties);
gfxstub_deleteforkey(x);
}
//store current canvas values into temporary data holder
......@@ -1735,7 +1735,11 @@ void canvas_undo_font(t_canvas *x, void *z, int action)
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_font(x2, u_f->font, 100.0, (t_floatarg)x2->gl_font, -1);
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)
......@@ -3650,7 +3654,7 @@ static void canvas_menufont(t_canvas *x)
char buf[80];
t_canvas *x2 = canvas_getrootfor(x);
gfxstub_deleteforkey(x2);
sprintf(buf, "pdtk_canvas_dofont %%s %d\n", x2->gl_font);
sprintf(buf, "pdtk_canvas_dofont %%s .x%lx %d\n", (t_int)x2, x2->gl_font);
gfxstub_new(&x2->gl_pd, &x2->gl_pd, buf);
}
......@@ -4209,7 +4213,7 @@ static void canvas_dopaste(t_canvas *x, t_binbuf *b)
(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, 100, 1, 1);
canvas_dofont(x, copiedfont, 1, 1);
//sys_vgui("pdtk_canvas_checkgeometry .x%lx\n", x);
canvas_redraw(x);
}
......@@ -4697,16 +4701,12 @@ void canvas_tooltips(t_canvas *x, t_floatarg fyesplease)
/* called by canvas_font below */
static void canvas_dofont(t_canvas *x, t_floatarg font, t_floatarg xresize,
t_floatarg yresize, int preview)
t_floatarg yresize)
{
t_gobj *y;
x->gl_font = font;
if (xresize != 1 || yresize != 1)
{
//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));
for (y = x->gl_list; y; y = y->g_next)
{
int x1, x2, y1, y2, nx1, ny1;
......@@ -4722,36 +4722,28 @@ static void canvas_dofont(t_canvas *x, t_floatarg font, t_floatarg xresize,
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, preview);
canvas_dofont((t_canvas *)y, font, xresize, yresize);
sys_vgui("pdtk_canvas_getscroll .x%lx.c\n", x);
}
/* 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 oldfont, t_floatarg preview)
/* 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)
{
t_float realresize, realresx = 1, realresy = 1;
t_float realresize;
t_canvas *x2 = canvas_getrootfor(x);
if (!resize) realresize = 1;
else
realresize = (t_float)sys_fontwidth(font)/(t_float)sys_fontwidth(oldfont);
realresize = (t_float)sys_fontwidth(font)/(t_float)sys_fontwidth(x2->gl_font);
realresx = realresize;
realresy = realresize;
if (!preview && font != oldfont) {
canvas_undo_add(x, 11, "font", canvas_undo_set_font(x, oldfont));
canvas_dirty(x2, 1);
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));
}
t_int properties = gfxstub_haveproperties((void *)x2);
if (preview <= 0 && properties)
gfxstub_deleteforkey(x2);
canvas_dirty(x2, 1);
if (x2->gl_font != (int)font) {
canvas_dofont(x2, font, realresx, realresy, preview);
}
canvas_dofont(x2, font, realresize, realresize);
}
static t_glist *canvas_last_glist;
......
......@@ -3390,23 +3390,6 @@ proc pdtk_canvas_saveas {name initfile initdir} {
set untitled_directory $directory
}
# zooming
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
} else {
set ::font($name) [lindex $font_array [expr $index + $direction]]
dofont_apply $name $::font($name) 0
}
}
# zooming (a subset of dofont)
#set zoom_fontsize 10
......@@ -3466,46 +3449,78 @@ proc pdtk_zoom {name direction} {
############ pdtk_canvas_dofont -- run a font and resize dialog #########
set fontsize 10
set dofont_fontsize 10
set stretchval 100
set whichstretch 1
set oldfontsize 10
set previewfontsize 10
set font_array { 8 10 12 16 24 36 }
set font_properties 0
set font_canvas 0
# zooming (a subset of dofont)
proc pdtk_zoom {name direction} {
global font_array oldfontsize previewfontsize font_properties font_canvas
set index [lsearch $font_array $::font($name)]
if { $index == 5 && $direction == 1 || $index == 0 && $direction == -1 } {
return
} else {
set previewfontsize $::font($name)
set ::font($name) [lindex $font_array [expr $index + $direction]]
if { $font_properties != 0 && $font_canvas == $name } {
[format "$font_properties.radiof.radio%d" $::font($name)] invoke
} else {
dofont_apply $name $::font($name) 0
}
}
}
proc dofont_apply {name myfontsize noundo} {
global oldfontsize
set cmd [concat $name font $myfontsize $oldfontsize 100 $noundo \;]
pd $cmd
set oldfontsize $myfontsize
set ::font($name) $myfontsize
}
proc dofont_apply {name myfontsize preview} {
global stretchval
global fontsize
set cmd [concat $name font $myfontsize $stretchval $fontsize $preview \;]
proc dofont_preview {name myfontsize} {
global previewfontsize
set cmd [concat $name font $myfontsize 0 100 1 \;]
pd $cmd
set previewfontsize $myfontsize
}
proc dofont_close {name} {
global font_properties font_canvas
set cmd [concat $name cancel \;]
pd $cmd
set font_properties 0
set font_canvas 0
}
proc dofont_cancel {name} {
global fontsize
dofont_apply $name $fontsize 1
global oldfontsize
dofont_preview $name $oldfontsize
set cmd [concat $name cancel \;]
pd $cmd
}
proc dofont_ok {name} {
global fontsize dofont_fontsize
dofont_apply $name $dofont_fontsize 0
global previewfontsize font_canvas
dofont_apply $font_canvas $previewfontsize 0
dofont_close $name
}
proc pdtk_canvas_dofont {name initsize} {
global fontsize dofont_fontsize pd_nt
set fontsize $initsize
set dofont_fontsize $initsize
proc pdtk_canvas_dofont {name canvas initsize} {
global oldfontsize previewfontsize pd_nt font_properties font_canvas
set oldfontsize $initsize
set previewfontsize $initsize
global stretchval
#set stretchval 100
global whichstretch
#set whichstretch 1
if {[winfo exists $font_properties]} {
destroy $font_properties
}
set font_properties $name
set font_canvas $canvas
toplevel $name
match_linux_wm [list $name configure]
......@@ -3532,22 +3547,22 @@ proc pdtk_canvas_dofont {name initsize} {
match_linux_wm [list radiobutton $name.radiof.radio8 -value 8 \
-variable dofont_fontsize -text "8" \
-command [concat dofont_apply $name 8 1]]
-command [concat dofont_preview $name 8]]
match_linux_wm [list radiobutton $name.radiof.radio10 -value 10 \
-variable dofont_fontsize -text "10" \
-command [concat dofont_apply $name 10 1]]
-command [concat dofont_preview $name 10]]
match_linux_wm [list radiobutton $name.radiof.radio12 -value 12 \
-variable dofont_fontsize -text "12" \
-command [concat dofont_apply $name 12 1]]
-command [concat dofont_preview $name 12]]
match_linux_wm [list radiobutton $name.radiof.radio16 -value 16 \
-variable dofont_fontsize -text "16" \
-command [concat dofont_apply $name 16 1]]
-command [concat dofont_preview $name 16]]
match_linux_wm [list radiobutton $name.radiof.radio24 -value 24 \
-variable dofont_fontsize -text "24" \
-command [concat dofont_apply $name 24 1]]
-command [concat dofont_preview $name 24]]
match_linux_wm [list radiobutton $name.radiof.radio36 -value 36 \
-variable dofont_fontsize -text "36" \
-command [concat dofont_apply $name 36 1]]
-command [concat dofont_preview $name 36]]
pack $name.radiof.radio8 -side top -anchor w
pack $name.radiof.radio10 -side top -anchor w
pack $name.radiof.radio12 -side top -anchor w
......@@ -3561,34 +3576,6 @@ proc pdtk_canvas_dofont {name initsize} {
} else {
$current_radiobutton select
}
# match_linux_wm [list frame $name.stretchf]
# pack $name.stretchf -side left
#
# match_linux_wm [list label $name.stretchf.label -text {Stretch:}]
# pack $name.stretchf.label -side top
# match_linux_wm [list entry $name.stretchf.entry -textvariable stretchval -width 5]
# pack $name.stretchf.entry -side left
#
# match_linux_wm [list radiobutton $name.stretchf.radio1 \
# -value 1 -variable whichstretc -text "X and Y" \
# -command [concat dofont_apply $name $dofont_fontsize 1]]
# match_linux_wm [list radiobutton $name.stretchf.radio2 \
# -value 2 -variable whichstretch -text "X only" \
# -command [concat dofont_apply $name $dofont_fontsize 1]]
# match_linux_wm [list radiobutton $name.stretchf.radio3 \
# -value 3 -variable whichstretch -text "Y only" \
# -command [concat dofont_apply $name $dofont_fontsize 1]]
# pack $name.stretchf.radio1 -side top -anchor w
# pack $name.stretchf.radio2 -side top -anchor w
# pack $name.stretchf.radio3 -side top -anchor w
#
# if {[info tclversion] >= 8.5 && $pd_nt == 0} {
# $name.stretchf.radio1 invoke
# } else {
# $name.stretchf.radio1 select
# }
}
############ pdtk_gatom_dialog -- run a gatom dialog #########
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment