add sbutton, a simple script for turning the current selection

into a beveled button.

squash a few bugs in consolio.  mostly in regards to additional
console windows

-Eric
This commit is contained in:
Eric L. Hernes 1997-12-17 16:02:20 +00:00
parent 68d5ba4b8b
commit 2d9d16fec7
3 changed files with 289 additions and 11 deletions

View File

@ -2,7 +2,7 @@
pluginlibdir = $(gimpplugindir)/plug-ins
pluginlib_SCRIPTS = consolio pdb_help stained_glass
pluginlib_SCRIPTS = consolio pdb_help stained_glass sbutton
SUFFIXES = .tcl

View File

@ -27,13 +27,13 @@
#
proc gimptcl_query {} {
gimp-install-procedure "gimptcl_consolio2" \
gimp-install-procedure "gimptcl_consolio" \
"An interactive gimptcl shell" \
"Type commands at the prompt to do stuff" \
"Eric L. Hernes" \
"ELH" \
"1997" \
"<Toolbox>/Xtns/Gimptcl Consolio2" \
"<Toolbox>/Xtns/Gimptcl Consolio" \
"" \
extension \
{
@ -297,7 +297,7 @@ proc tkConInitSlave {slave args} {
$slave alias source tkConSafeSource $slave
$slave alias load tkConSafeLoad $slave
$slave alias open tkConSafeOpen $slave
$slave alias exit tkConExit
$slave alias exit tkConDestroy
$slave alias file file
interp eval $slave [dump var tcl_library env]
interp eval $slave [list source [file join $tcl_library init.tcl]]
@ -307,7 +307,7 @@ proc tkConInitSlave {slave args} {
foreach cmd $tkCon(slavealias) {
$slave alias $cmd $cmd
}
$slave alias exit tkConExit
$slave alias exit tkConDestroy
interp alias $slave ls $slave dir
interp eval $slave set tcl_interactive $tcl_interactive \; \
set argv0 [list $argv0] \; set argc [llength $args] \; \
@ -702,7 +702,7 @@ proc tkConInitMenus {w title} {
$m add separator
$m add cascade -label "Attach Console " -un 0 -menu $m.apps
$m add separator
$m add command -label "Quit" -un 0 -acc Ctrl-q -command tkConExit
$m add command -label "Quit" -un 0 -acc Ctrl-q -command tkConDestroy
## Attach Console Menu
##
@ -885,7 +885,7 @@ proc tkConInterpMenu w {
}
if {[info exists loaded] && [info exists loadable]} { $m add separator }
foreach pkg [array names loaded] {
$m add command -label "${pkg}$loaded($pkg) Loaded" -state disabled
$m add command -label "${pkg}-$loaded($pkg) Loaded" -state disabled
}
}
@ -1184,6 +1184,7 @@ proc tkConMainInit {} {
set tmp [interp create Slave[incr tkCon(slave)]]
lappend tkCon(slaves) $tmp
load {} Tk $tmp
tkConInitSlave $tmp
lappend tkCon(interps) [$tmp eval [list tk appname "[tk appname] $tmp"]]
$tmp eval set argc $argc \; set argv [list $argv] \; \
set argv0 [list $argv0]
@ -1197,7 +1198,7 @@ proc tkConMainInit {} {
$tmp alias tkConStateCleanup tkConStateCleanup
$tmp alias tkConStateCompare tkConStateCompare
$tmp alias tkConStateRevert tkConStateRevert
$tmp alias exit tkConExit
$tmp alias exit tkConDestroy
$tmp eval [list source $tkCon(SCRIPT)]
return $tmp
}
@ -1211,9 +1212,9 @@ proc tkConMainInit {} {
global tkCon
if [string match {} $slave] {
## Main interpreter close request
if [tk_dialog $tkCon(base).destroyme {Quit TkCon?} \
if [tk_dialog $tkCon(base).destroyme {Quit Gimptcl Consolio?} \
{Closing the Main console will quit TkCon} \
warning 0 "Don't Quit" "Quit TkCon"] tkConExit
warning 0 "Don't Quit" "Quit Consolio"] tkConExit
} else {
## Slave interpreter close request
set name [tkConInterpEval $slave]
@ -2606,7 +2607,7 @@ proc tkConBindings {} {
}
## <<TkCon_Exit>>
bind $tkCon(root) <Control-q> tkConExit
bind $tkCon(root) <Control-q> tkConDestroy
## <<TkCon_New>>
bind $tkCon(root) <Control-N> { tkConNew }
## <<TkCon_Close>>

View File

@ -0,0 +1,277 @@
#!@THEGIMPTCL@
proc gimptcl_query {} {
gimp-install-procedure "plug_in_sbutton" \
"Turn the selection into a button" \
"None Yet" \
"Eric L. Hernes" \
"ELH" \
"1997" \
"<Image>/Select/Make Button" \
"RGB*, GRAY*" \
plugin \
{
{int32 "run_mode" "Interactive, non-interactive"}
{image "image" "The image"}
{drawable "drawable" "The drawable"}
{int32 "width" "The Button Width"}
{int32 "hightlight" "The amount of highlight"}
{int32 "shadow" "The amount of shadow"}
{string "angle" "one of `TopLeft' `TopRight' 'BottomLeft' `BottomRight' or a number in the rage [0-360]'"}
} \
{
}
}
proc gimptcl_run {mode image drawable width highlight shadow angle} {
global theImage theDrawable
global theBorderWidth theHighlightLevel theShadowLevel
global theLightAngle theLightAngleMode theLightAngleValue
set theImage $image
set theDrawable $drawable
set stuff [gimp-get-data plug_in_sbutton]
if {$stuff == ""} {
set theBorderWidth 10
set theHighlightLevel 100
set theShadowLevel 100
set theLightAngle TopLeft
set theLightAngleMode TopLeft
set theLightAngleValue 135
} else {
set theBorderWidth [lindex $stuff 0]
set theHighlightLevel [lindex $stuff 1]
set theShadowLevel [lindex $stuff 2]
set theLightAngleMode [lindex $stuff 3]
set theLightAngleValue [lindex $stuff 4]
}
switch $mode {
0 {
buttonUi
}
1 {
set theBorderWidth $width
set theHighlightLevel $highlight
set theShadowLevel $shadow
set theLightAngle $angle
buttonCore
}
2 {
set theBorderWidth [lindex $stuff 0]
set theHighlightLevel [lindex $stuff 1]
set theShadowLevel [lindex $stuff 2]
set theLightAngle [lindex $stuff 3]
buttonCore
}
default {
puts stderr "don't know how to handle run mode $mode"
}
}
}
proc buttonCore {} {
global theImage theDrawable
global theBorderWidth theHighlightLevel theShadowLevel
global theLightAngleMode theLightAngleValue
set s_bounds [gimp-selection-bounds $theImage]
set sx1 [lindex $s_bounds 1]
set sy1 [lindex $s_bounds 2]
set sx2 [lindex $s_bounds 3]
set sy2 [lindex $s_bounds 4]
set sw [expr $sx2 - $sx1].0
set sh [expr $sy2 - $sy1].0
set theta [expr atan($sh/$sw) * 180 / 3.1415926]
switch $theLightAngleMode {
TopLeft {
set theAngle [expr 180 - $theta]
}
TopRight {
set theAngle [expr 180 + $theta]
}
BottomLeft {
set theAngle $theta
}
BottomRight {
set theAngle [expr 360 - $theta]
}
default {
set theAngle $theLightAngle
}
}
doButton $theImage $theDrawable $theBorderWidth $theHighlightLevel \
$theShadowLevel $theAngle
set saveData [list $theBorderWidth $theHighlightLevel \
$theShadowLevel $theLightAngleMode $theAngle]
gimp-set-data plug_in_sbutton $saveData
# puts stderr "setting (plug_in_sbutton :$saveData:)"
destroy .
}
proc doButton {img drw width highlight shadow angle} {
set theta [expr ($angle * 3.1415926 / 180) + (3.1415926 / 2)]
set bg [gimp-palette-get-background]
set fg [gimp-palette-get-foreground]
set selection [gimp-selection-save $img]
set w [gimp-image-width $img]
set h [gimp-image-height $img]
set layers [lindex [gimp-image-get-layers $img] 1]
set vlayers [list]
foreach l $layers {
if [gimp-layer-get-visible layer-$l] {
lappend vlayers $l
}
gimp-layer-set-visible layer-$l 0
}
gimp-layer-set-visible $drw 1
gimp-undo-push-group-start $img
set button_layer [gimp-layer-new $img $w $h RGBA_IMAGE \
"button (angle $angle)" 100 OVERLAY]
gimp-image-add-layer $img $button_layer -1
gimp-drawable-fill $button_layer TRANS_IMAGE_FILL
# gimp-selection-border $img $width
gimp-palette-set-background {0 0 0}
gimp-edit-fill $img $button_layer
gimp-selection-shrink $img $width
gimp-edit-clear $img $button_layer
gimp-selection-layer-alpha $img $button_layer
set hl [expr 128 + $highlight]
set sl [expr 128 - $shadow]
gimp-palette-set-background "$hl $hl $hl"
gimp-palette-set-foreground "$sl $sl $sl"
set s_bounds [gimp-selection-bounds $img]
set sx1 [lindex $s_bounds 1]
set sy1 [lindex $s_bounds 2]
set sx2 [lindex $s_bounds 3]
set sy2 [lindex $s_bounds 4]
set sw [expr $sx2 - $sx1]
set sh [expr $sy2 - $sy1]
set sw2 [expr $sw / 2]
set sh2 [expr $sh / 2]
set xdelta [expr cos($theta) * ($sw / 2)]
set ydelta [expr sin($theta) * ($sh / 2)]
set x1 [expr $sw2 - $xdelta + $sx1]
set y1 [expr $sh2 - $ydelta + $sy1]
set x2 [expr $sw2 + $xdelta + $sx1]
set y2 [expr $sh2 + $ydelta + $sy1]
gimp-blend $img $button_layer FG-BG-RGB NORMAL LINEAR 100 0 0 0 0 0 $x1 $y1 $x2 $y2
gimp-image-merge-visible-layers $img EXPAND-AS-NECESSARY
foreach l $vlayers {
gimp-layer-set-visible layer-$l 1
}
gimp-palette-set-background $bg
gimp-palette-set-foreground $fg
gimp-selection-load $img $selection
gimp-image-remove-channel $img $selection
gimp-undo-push-group-end $img
gimp-drawable-update $button_layer 0 0 $w $h
gimp-displays-flush
}
proc buttonUi {} {
#
# defaults...
wm title . "Selection to Button"
frame .control
button .control.ok -text "Ok" -command {
buttonCore
}
button .control.cancel -text "Cancel" -command {destroy .}
pack .control.ok .control.cancel -side left
frame .parameters
set lev [frame .parameters.levels -relief groove -borderwidth 3]
scale $lev.width -label "Border Width" \
-from 0 -to 50 -variable theBorderWidth -orient horizontal
scale $lev.highlight -label "Highlight Level" \
-from 0 -to 127 -variable theHighlightLevel -orient horizontal
scale $lev.shadow -label "Shadow Level" \
-from 0 -to 127 -variable theShadowLevel -orient horizontal
pack $lev.width $lev.highlight $lev.shadow
set la [frame .parameters.lightAngle -relief groove -borderwidth 3]
label $la.label -text "Light Angle"
radiobutton $la.topLeft -text "Top Left" \
-variable theLightAngleMode -value TopLeft \
-command "$la.ui.scale configure -state disabled"
radiobutton $la.topRight -text "Top Right" \
-variable theLightAngleMode -value TopRight \
-command "$la.ui.scale configure -state disabled"
radiobutton $la.bottomLeft -text "Bottom Left" \
-variable theLightAngleMode -value BottomLeft \
-command "$la.ui.scale configure -state disabled"
radiobutton $la.bottomRight -text "Bottom Right" \
-variable theLightAngleMode -value BottomRight \
-command "$la.ui.scale configure -state disabled"
frame $la.ui
radiobutton $la.ui.button -text "Set Angle" \
-variable theLightAngleMode -value UserSet \
-command "$la.ui.scale configure -state normal"
scale $la.ui.scale -state disabled \
-from 0 -to 360 -variable theLightAngleValue -orient horizontal
pack $la.ui.button $la.ui.scale -side left
pack $la.label
pack $la.topLeft $la.topRight $la.bottomLeft $la.bottomRight $la.ui \
-anchor w
pack $lev $la -side left -anchor n -fill both
pack .parameters .control
}