From 22a829cb1907c79bfe68ad91314a1dddbf1beeb3 Mon Sep 17 00:00:00 2001 From: Miller Puckette Date: Tue, 1 Sep 2009 18:22:23 +0000 Subject: merge in HC's new tcl code and start taking patches svn path=/trunk/; revision=12166 --- pd/tcl/dialog_font.tcl | 184 ++++++++++++++++++++++++++++--------------------- 1 file changed, 105 insertions(+), 79 deletions(-) (limited to 'pd/tcl/dialog_font.tcl') diff --git a/pd/tcl/dialog_font.tcl b/pd/tcl/dialog_font.tcl index cebfcb08..578d155e 100644 --- a/pd/tcl/dialog_font.tcl +++ b/pd/tcl/dialog_font.tcl @@ -2,106 +2,132 @@ package provide dialog_font 0.1 namespace eval ::dialog_font:: { - variable fontsize 0 - variable dofont_fontsize 0 - variable stretchval 0 - variable whichstretch 0 - + variable fontsize 10 + variable stretchval 100 + variable whichstretch 1 + variable canvaswindow + variable sizes {8 10 12 16 24 36} + variable gfxstub + namespace export pdtk_canvas_dofont } +# TODO this should use the pd_font_$size fonts created in pd-gui.tcl + +# TODO this should really be changed on the C side so that it doesn't have to +# work around gfxstub/x_gui.c. The gfxstub stuff assumes that there are +# multiple panels, for properties panels like this, its much easier to use if +# there is a single properties panel that adjusts based on which CanvasWindow +# has focus + proc ::dialog_font::apply {mytoplevel myfontsize} { - pdsend "$mytoplevel font $myfontsize $stretchval $whichstretch" + if {$mytoplevel eq ".pdwindow"} { + .pdwindow.text configure -font "-size $myfontsize" + } else { + variable stretchval + variable whichstretch + pdsend "$mytoplevel font $myfontsize $stretchval $whichstretch" + } +} + +proc ::dialog_font::cancel {mygfxstub} { + if {$mygfxstub ne ".pdwindow"} { + pdsend "$mygfxstub cancel" + } + destroy .font } -proc ::dialog_font::close {mytoplevel} { - pdsend "$mytoplevel cancel" +proc ::dialog_font::ok {mygfxstub} { + variable fontsize + ::dialog_font::apply $mygfxstub $fontsize + ::dialog_font::cancel $mygfxstub } -proc ::dialog_font::cancel {mytoplevel} { - ::dialog_font::apply $mytoplevel $fontsize ;# reinstate previous font size - pdsend "$mytoplevel cancel" +proc ::dialog_font::update_font_dialog {mytoplevel} { + set ::dialog_font::canvaswindow $mytoplevel + if {$mytoplevel eq ".pdwindow"} { + set windowname [_ "Pd window"] + } else { + set windowname [lookup_windowname $mytoplevel] + } + if {[winfo exists .font]} { + wm title .font [format [_ "%s Font"] $windowname] + } } -proc ::dialog_font::ok {mytoplevel} { - set fontsize $::dialog_font::fontsize - ::dialog_font::apply $mytoplevel $fontsize - ::dialog_font::close $mytoplevel +proc ::dialog_font::arrow_fontchange {change} { + variable sizes + set position [expr [lsearch $sizes $::dialog_font::fontsize] + $change] + if {$position < 0} {set position 0} + set max [llength $sizes] + if {$position >= $max} {set position [expr $max-1]} + set ::dialog_font::fontsize [lindex $sizes $position] + ::dialog_font::apply $::dialog_font::canvaswindow $::dialog_font::fontsize } # this should be called pdtk_font_dialog like the rest of the panels, but it # is called from the C side, so we'll leave it be -proc ::dialog_font::pdtk_canvas_dofont {mytoplevel initsize} { - create_panel $mytoplevel $initsize +proc ::dialog_font::pdtk_canvas_dofont {mygfxstub initsize} { + variable fontsize $initsize + variable whichstretch 1 + variable stretchval 100 + if {[winfo exists .font]} { + wm deiconify .font + raise .font + # the gfxstub stuff expects multiple font windows, we only have one, + # so kill the new gfxstub requests as the come in. We'll save the + # original gfxstub for when the font panel gets closed + pdsend "$mygfxstub cancel" + } else { + create_dialog $mygfxstub + } } -proc ::dialog_font::create_panel {mytoplevel initsize} { - set fontsize $initsize - set dofont_fontsize $initsize - set stretchval 100 - set whichstretch 1 +proc ::dialog_font::create_dialog {mygfxstub} { + variable gfxstub $mygfxstub + toplevel .font -class DialogWindow + if {$::windowingsystem eq "aqua"} {.font configure -menu .menubar} + ::pd_bindings::dialog_bindings .font "font" + # replace standard bindings to work around the gfxstub stuff + bind .font "::dialog_font::cancel $mygfxstub" + bind .font "::dialog_font::ok $mygfxstub" + bind .font <$::pd_bindings::modifier-Key-w> "::dialog_font::cancel $mygfxstub" + bind .font "::dialog_font::arrow_fontchange -1" + bind .font "::dialog_font::arrow_fontchange 1" - toplevel $mytoplevel - wm title $mytoplevel {Patch Font} - wm protocol $mytoplevel WM_DELETE_WINDOW "::dialog_font::cancel $mytoplevel" - - pdtk_panelkeybindings $mytoplevel font - - frame $mytoplevel.buttonframe - pack $mytoplevel.buttonframe -side bottom -fill x -pady 2m - button $mytoplevel.buttonframe.cancel -text "Cancel" \ - -command "::dialog_font::cancel $mytoplevel" - button $mytoplevel.buttonframe.ok -text "OK" \ - -command "::dialog_font::ok $mytoplevel" - pack $mytoplevel.buttonframe.cancel -side left -expand 1 - pack $mytoplevel.buttonframe.ok -side left -expand 1 + frame .font.buttonframe + pack .font.buttonframe -side bottom -fill x -pady 2m + button .font.buttonframe.ok -text [_ "OK"] \ + -command "::dialog_font::ok $mygfxstub" + pack .font.buttonframe.ok -side left -expand 1 - frame $mytoplevel.radiof - pack $mytoplevel.radiof -side left + labelframe .font.fontsize -text [_ "Font Size"] -padx 5 -pady 4 -borderwidth 1 \ + -width [::msgcat::mcmax "Font Size"] -labelanchor n + pack .font.fontsize -side left -padx 5 - label $mytoplevel.radiof.label -text {Font Size:} - pack $mytoplevel.radiof.label -side top - - radiobutton $mytoplevel.radiof.radio8 -value 8 -variable ::dialog_font::fontsize -text "8" \ - -command "::dialog_font::apply $mytoplevel 8" - radiobutton $mytoplevel.radiof.radio10 -value 10 -variable ::dialog_font::fontsize -text "10" \ - -command "::dialog_font::apply $mytoplevel 10" - radiobutton $mytoplevel.radiof.radio12 -value 12 -variable ::dialog_font::fontsize -text "12" \ - -command "::dialog_font::apply $mytoplevel 12" - radiobutton $mytoplevel.radiof.radio16 -value 16 -variable ::dialog_font::fontsize -text "16" \ - -command "::dialog_font::apply $mytoplevel 16" - radiobutton $mytoplevel.radiof.radio24 -value 24 -variable ::dialog_font::fontsize -text "24" \ - -command "::dialog_font::apply $mytoplevel 24" - radiobutton $mytoplevel.radiof.radio36 -value 36 -variable ::dialog_font::fontsize -text "36" \ - -command "::dialog_font::apply $mytoplevel 36" - pack $mytoplevel.radiof.radio8 -side top -anchor w - pack $mytoplevel.radiof.radio10 -side top -anchor w - pack $mytoplevel.radiof.radio12 -side top -anchor w - pack $mytoplevel.radiof.radio16 -side top -anchor w - pack $mytoplevel.radiof.radio24 -side top -anchor w - pack $mytoplevel.radiof.radio36 -side top -anchor w - - set current_radiobutton [format "$mytoplevel.radiof.radio%d" $initsize] - $current_radiobutton select + # this is whacky Tcl at its finest, but I couldn't resist... + foreach size $::dialog_font::sizes { + radiobutton .font.fontsize.radio$size -value $size -text $size \ + -variable ::dialog_font::fontsize \ + -command [format {::dialog_font::apply $::dialog_font::canvaswindow %s} $size] + pack .font.fontsize.radio$size -side top -anchor w + } - frame $mytoplevel.stretchf - pack $mytoplevel.stretchf -side left - - label $mytoplevel.stretchf.label -text "Stretch:" - pack $mytoplevel.stretchf.label -side top - - entry $mytoplevel.stretchf.entry -textvariable stretchval -width 5 - pack $mytoplevel.stretchf.entry -side left + labelframe .font.stretch -text [_ "Stretch"] -padx 5 -pady 5 -borderwidth 1 \ + -width [::msgcat::mcmax "Stretch"] -labelanchor n + pack .font.stretch -side left -padx 5 -fill y - radiobutton $mytoplevel.stretchf.radio1 \ - -value 1 -variable whichstretch -text "X and Y" - radiobutton $mytoplevel.stretchf.radio2 \ - -value 2 -variable whichstretch -text "X only" - radiobutton $mytoplevel.stretchf.radio3 \ - -value 3 -variable whichstretch -text "Y only" + entry .font.stretch.entry -textvariable ::dialog_font::stretchval -width 5 + pack .font.stretch.entry -side top -pady 5 - pack $mytoplevel.stretchf.radio1 -side top -anchor w - pack $mytoplevel.stretchf.radio2 -side top -anchor w - pack $mytoplevel.stretchf.radio3 -side top -anchor w + radiobutton .font.stretch.radio1 -text [_ "X and Y"] \ + -value 1 -variable ::dialog_font::whichstretch + radiobutton .font.stretch.radio2 -text [_ "X only"] \ + -value 2 -variable ::dialog_font::whichstretch + radiobutton .font.stretch.radio3 -text [_ "Y only"] \ + -value 3 -variable ::dialog_font::whichstretch + pack .font.stretch.radio1 -side top -anchor w + pack .font.stretch.radio2 -side top -anchor w + pack .font.stretch.radio3 -side top -anchor w } -- cgit v1.2.1