home *** CD-ROM | disk | FTP | other *** search
/ ftp.sunet.sepub/pictures / 2014.11.ftp.sunet.se-pictures.tar / ftp.sunet.se / pub / pictures / ACiD-artpacks / programs / unix / editors / gimp-plugins-unstable-0_99_23_tar.gz / gimp-plugins-unstable-0_99_23_tar / gimp-plugins-unstable-0.99.23 / gimptcl / scripts / sbutton.tcl < prev    next >
Text File  |  1998-02-20  |  7KB  |  278 lines

  1. #!@THEGIMPTCL@
  2.  
  3. proc gimptcl_query {} {
  4.     gimp-install-procedure "plug_in_sbutton" \
  5.     "Turn the selection into a button" \
  6.     "None Yet" \
  7.     "Eric L. Hernes" \
  8.     "ELH" \
  9.     "1997" \
  10.     "<Image>/Select/Make Button" \
  11.     "RGB*, GRAY*" \
  12.     plugin \
  13.     {
  14.         {int32 "run_mode" "Interactive, non-interactive"}
  15.         {image "image" "The image"}
  16.         {drawable "drawable" "The drawable"}
  17.         {int32 "width" "The Button Width"}
  18.         {int32 "hightlight" "The amount of highlight"}
  19.         {int32 "shadow" "The amount of shadow"}
  20.         {string "angle" "one of `TopLeft' `TopRight' 'BottomLeft' `BottomRight' or a number in the rage [0-360]'"}
  21.     } \
  22.     {
  23.     }
  24. }
  25.  
  26. proc gimptcl_run {mode image drawable width highlight shadow angle} {
  27.     global theImage theDrawable
  28.     global theBorderWidth theHighlightLevel theShadowLevel
  29.     global theLightAngle theLightAngleMode theLightAngleValue
  30.  
  31.     set theImage $image
  32.     set theDrawable $drawable
  33.  
  34.     set stuff [gimp-get-data plug_in_sbutton]
  35.     if {$stuff == ""} {
  36.     set theBorderWidth 10
  37.     set theHighlightLevel 100
  38.     set theShadowLevel 100
  39.     set theLightAngle TopLeft
  40.  
  41.     set theLightAngleMode TopLeft
  42.     set theLightAngleValue 135
  43.     } else {
  44.     set theBorderWidth [lindex $stuff 0]
  45.     set theHighlightLevel [lindex $stuff 1]
  46.     set theShadowLevel [lindex $stuff 2]
  47.     set theLightAngleMode [lindex $stuff 3]
  48.     set theLightAngleValue [lindex $stuff 4]
  49.     }
  50.  
  51.     switch $mode {
  52.     0 {
  53.         buttonUi
  54.     }
  55.  
  56.     1 {
  57.         set theBorderWidth $width
  58.         set theHighlightLevel $highlight
  59.         set theShadowLevel $shadow
  60.         set theLightAngle $angle
  61.         buttonCore
  62.     }
  63.  
  64.     2 {
  65.         set theBorderWidth [lindex $stuff 0]
  66.         set theHighlightLevel [lindex $stuff 1]
  67.         set theShadowLevel [lindex $stuff 2]
  68.         set theLightAngle [lindex $stuff 3]
  69.         buttonCore
  70.     }
  71.     default {
  72.         puts stderr "don't know how to handle run mode $mode"
  73.     }
  74.     }
  75. }
  76.  
  77. proc buttonCore {} {
  78.     global theImage theDrawable
  79.     global theBorderWidth theHighlightLevel theShadowLevel
  80.     global theLightAngleMode theLightAngleValue
  81.  
  82.     set s_bounds [gimp-selection-bounds $theImage]
  83.  
  84.     set sx1 [lindex $s_bounds 1]
  85.     set sy1 [lindex $s_bounds 2]
  86.  
  87.     set sx2 [lindex $s_bounds 3]
  88.     set sy2 [lindex $s_bounds 4]
  89.    
  90.     set sw [expr $sx2 - $sx1].0
  91.     set sh [expr $sy2 - $sy1].0
  92.  
  93.     set theta [expr atan($sh/$sw) * 180 / 3.1415926]
  94.  
  95.     switch  $theLightAngleMode {
  96.     TopLeft {
  97.         set theAngle [expr 180 - $theta]
  98.     }
  99.     TopRight {
  100.         set theAngle [expr 180 + $theta]
  101.     }
  102.     BottomLeft {
  103.         set theAngle $theta
  104.     }
  105.     BottomRight {
  106.         set theAngle [expr 360 - $theta]
  107.     }
  108.     default {
  109.         set theAngle $theLightAngle
  110.     }
  111.     }
  112.  
  113.     doButton $theImage $theDrawable $theBorderWidth $theHighlightLevel \
  114.     $theShadowLevel $theAngle
  115.  
  116.     set saveData [list $theBorderWidth $theHighlightLevel \
  117.           $theShadowLevel $theLightAngleMode $theAngle]
  118.  
  119.     gimp-set-data plug_in_sbutton $saveData
  120.  
  121. #    puts stderr "setting (plug_in_sbutton :$saveData:)"
  122.  
  123.     destroy .
  124. }
  125.  
  126. proc doButton {img drw width highlight shadow angle} {
  127.  
  128.     set theta [expr ($angle * 3.1415926 / 180) + (3.1415926 / 2)]
  129.  
  130.     set bg [gimp-palette-get-background]
  131.     set fg [gimp-palette-get-foreground]
  132.     set selection [gimp-selection-save $img]
  133.  
  134.     set w [gimp-image-width $img]
  135.     set h [gimp-image-height $img]
  136.  
  137.     set layers [lindex [gimp-image-get-layers $img] 1]
  138.  
  139.     set vlayers [list]
  140.  
  141.     foreach l $layers {
  142.     if [gimp-layer-get-visible layer-$l] {
  143.         lappend vlayers $l
  144.     }
  145.     gimp-layer-set-visible layer-$l 0
  146.     }
  147.     gimp-layer-set-visible $drw 1
  148.  
  149.     gimp-undo-push-group-start $img
  150.  
  151.     set button_layer [gimp-layer-new $img $w $h RGBA_IMAGE \
  152.               "button (angle $angle)" 100 OVERLAY]
  153.     gimp-image-add-layer $img $button_layer -1
  154.     gimp-drawable-fill $button_layer TRANS_IMAGE_FILL
  155.  
  156.     #    gimp-selection-border $img $width
  157.     gimp-palette-set-background {0 0 0}
  158.     gimp-edit-fill $img $button_layer
  159.     gimp-selection-shrink $img $width
  160.     gimp-edit-clear $img $button_layer
  161.     gimp-selection-layer-alpha $img $button_layer
  162.  
  163.     set hl [expr 128 + $highlight]
  164.     set sl [expr 128 - $shadow]
  165.     gimp-palette-set-background "$hl $hl $hl"
  166.     gimp-palette-set-foreground "$sl $sl $sl"
  167.  
  168.     set s_bounds [gimp-selection-bounds $img]
  169.  
  170.     set sx1 [lindex $s_bounds 1]
  171.     set sy1 [lindex $s_bounds 2]
  172.  
  173.     set sx2 [lindex $s_bounds 3]
  174.     set sy2 [lindex $s_bounds 4]
  175.    
  176.     set sw [expr $sx2 - $sx1]
  177.     set sh [expr $sy2 - $sy1]
  178.  
  179.     set sw2 [expr $sw / 2]
  180.     set sh2 [expr $sh / 2]
  181.  
  182.     set xdelta [expr cos($theta) * ($sw / 2)]
  183.     set ydelta [expr sin($theta) * ($sh / 2)]
  184.  
  185.     set x1 [expr $sw2 - $xdelta + $sx1]
  186.     set y1 [expr $sh2 - $ydelta + $sy1]
  187.  
  188.     set x2 [expr $sw2 + $xdelta + $sx1]
  189.     set y2 [expr $sh2 + $ydelta + $sy1]
  190.  
  191.     gimp-blend $img $button_layer FG-BG-RGB NORMAL LINEAR 100 0 0 0 0 0 $x1 $y1 $x2 $y2 
  192.  
  193.     gimp-image-merge-visible-layers $img EXPAND-AS-NECESSARY
  194.     foreach l $vlayers {
  195.       gimp-layer-set-visible layer-$l 1
  196.     }
  197.  
  198.     gimp-palette-set-background $bg
  199.     gimp-palette-set-foreground $fg
  200.     gimp-selection-load $img $selection
  201.     gimp-image-remove-channel $img $selection
  202.  
  203.     gimp-undo-push-group-end $img
  204.  
  205.     gimp-drawable-update $button_layer 0 0 $w $h
  206.     gimp-displays-flush
  207. }
  208.  
  209. proc buttonUi {} {
  210.     #
  211.     # defaults...
  212.  
  213.     wm title . "Selection to Button"
  214.  
  215.     frame .control
  216.     button .control.ok -text "Ok" -command {
  217.     buttonCore
  218.     }
  219.  
  220.     button .control.cancel -text "Cancel" -command {destroy .}
  221.  
  222.     pack .control.ok .control.cancel -side left
  223.  
  224.     frame .parameters
  225.  
  226.     set lev [frame .parameters.levels -relief groove -borderwidth 3]
  227.  
  228.     scale $lev.width -label "Border Width" \
  229.     -from 0 -to 50 -variable theBorderWidth -orient horizontal
  230.  
  231.     scale $lev.highlight -label "Highlight Level" \
  232.     -from 0 -to 127 -variable theHighlightLevel -orient horizontal
  233.  
  234.     scale $lev.shadow -label "Shadow Level" \
  235.     -from 0 -to 127 -variable theShadowLevel -orient horizontal
  236.  
  237.     pack $lev.width $lev.highlight $lev.shadow
  238.  
  239.     set la [frame .parameters.lightAngle -relief groove -borderwidth 3]
  240.  
  241.     label $la.label -text "Light Angle"
  242.  
  243.     radiobutton $la.topLeft -text "Top Left" \
  244.     -variable theLightAngleMode -value TopLeft \
  245.     -command "$la.ui.scale configure -state disabled"
  246.  
  247.     radiobutton $la.topRight -text "Top Right" \
  248.     -variable theLightAngleMode -value TopRight \
  249.     -command "$la.ui.scale configure -state disabled"
  250.  
  251.     radiobutton $la.bottomLeft -text "Bottom Left" \
  252.     -variable theLightAngleMode -value BottomLeft \
  253.     -command "$la.ui.scale configure -state disabled"
  254.  
  255.     radiobutton $la.bottomRight -text "Bottom Right" \
  256.     -variable theLightAngleMode -value BottomRight \
  257.     -command "$la.ui.scale configure -state disabled"
  258.  
  259.     frame $la.ui
  260.     radiobutton $la.ui.button -text "Set Angle" \
  261.     -variable theLightAngleMode -value UserSet \
  262.     -command "$la.ui.scale configure -state normal"
  263.  
  264.     scale $la.ui.scale -state disabled \
  265.     -from 0 -to 360 -variable theLightAngleValue -orient horizontal
  266.  
  267.     pack $la.ui.button $la.ui.scale -side left
  268.  
  269.     pack $la.label
  270.  
  271.     pack $la.topLeft $la.topRight $la.bottomLeft $la.bottomRight $la.ui \
  272.     -anchor w
  273.  
  274.     pack $lev $la -side left -anchor n -fill both
  275.  
  276.     pack .parameters .control
  277. }
  278.