home *** CD-ROM | disk | FTP | other *** search
/ PC World 2001 February / PCWorld_2001-02_cd.bin / Software / Topware / gimp / gimp-setup-20001226.exe / Main / selection-round.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2000-12-27  |  3.9 KB  |  135 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; This program is free software; you can redistribute it and/or modify
  4. ; it under the terms of the GNU General Public License as published by
  5. ; the Free Software Foundation; either version 2 of the License, or
  6. ; (at your option) any later version.  
  7. ; This program is distributed in the hope that it will be useful,
  8. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. ; GNU General Public License for more details.
  11. ; You should have received a copy of the GNU General Public License
  12. ; along with this program; if not, write to the Free Software
  13. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. ;
  15. ;
  16. ; selection-round.scm   version 1.02   1998/02/06
  17. ;
  18. ; CHANGE-LOG:
  19. ; 1.00 - initial release
  20. ; 1.01 - some code cleanup, no real changes
  21. ; 1.02 - made script undoable
  22. ;
  23. ; Copyright (C) 1997, 1998 Sven Neumann <sven@gimp.org>
  24. ;  
  25. ; Rounds the current selection by cutting of rectangles from the edges and 
  26. ; adding circles. The relative radius describes the radius of this cricles
  27. ; in relation to the selections width or height (depends on which of these 
  28. ; is smaller) 
  29.  
  30. (define (script-fu-selection-round image
  31.                         drawable
  32.                                    radius)
  33.  
  34.   (let* ((radius (min radius 1.0))
  35.      (radius (max radius 0.0))
  36.      (select-bounds (gimp-selection-bounds image))
  37.      (has-selection (car select-bounds))
  38.      (select-x1 (cadr select-bounds))
  39.      (select-y1 (caddr select-bounds))
  40.      (select-x2 (cadr (cddr select-bounds)))
  41.      (select-y2 (caddr (cddr select-bounds)))
  42.      (select-width (- select-x2 select-x1))
  43.      (select-height (- select-y2 select-y1))
  44.      (cut-radius 0)
  45.      (ellipse-radius 0))
  46.  
  47.   (gimp-undo-push-group-start image)
  48.  
  49.   (if (> select-width select-height)
  50.       (begin
  51.     (set! cut-radius (* radius (/ select-height 2)))
  52.     (set! ellipse-radius (* radius select-height)))
  53.       (begin
  54.     (set! cut-radius (* radius (/ select-width 2)))
  55.     (set! ellipse-radius (* radius select-width))))
  56.   (gimp-rect-select image
  57.             select-x1
  58.             select-y1
  59.             (+ cut-radius 1)
  60.             (+ cut-radius 1)
  61.             SUB
  62.             FALSE 0)
  63.   (gimp-rect-select image
  64.             select-x1
  65.             (- select-y2 cut-radius)
  66.             (+ cut-radius 1)
  67.             (+ cut-radius 1)
  68.             SUB
  69.             FALSE 0)
  70.   (gimp-rect-select image
  71.             (- select-x2 cut-radius)
  72.             select-y1
  73.             (+ cut-radius 1)
  74.             (+ cut-radius 1)
  75.             SUB
  76.             FALSE 0)
  77.   (gimp-rect-select image
  78.             (- select-x2 cut-radius)
  79.             (- select-y2 cut-radius)
  80.             (+ cut-radius 1)
  81.             (+ cut-radius 1)
  82.             SUB
  83.             FALSE 0)
  84.   (gimp-ellipse-select image
  85.                select-x1
  86.                select-y1
  87.                ellipse-radius
  88.                ellipse-radius
  89.                ADD
  90.                TRUE
  91.                FALSE 0)
  92.   (gimp-ellipse-select image
  93.                select-x1
  94.                (- select-y2 ellipse-radius)
  95.                ellipse-radius
  96.                ellipse-radius
  97.                ADD
  98.                TRUE
  99.                FALSE 0)
  100.   (gimp-ellipse-select image
  101.                (- select-x2 ellipse-radius)
  102.                select-y1
  103.                ellipse-radius
  104.                ellipse-radius
  105.                ADD
  106.                TRUE
  107.                FALSE 0)
  108.   (gimp-ellipse-select image
  109.                (- select-x2 ellipse-radius)
  110.                (- select-y2 ellipse-radius)
  111.                ellipse-radius
  112.                ellipse-radius
  113.                ADD
  114.                TRUE
  115.                FALSE 0)
  116.  
  117.   (gimp-undo-push-group-end image)
  118.   (gimp-displays-flush)))
  119.  
  120.  
  121. (script-fu-register "script-fu-selection-round"
  122.             _"<Image>/Script-Fu/Selection/Round..."
  123.             "Rounds the active selection. The selection should be rectangular."
  124.             "Sven Neumann <sven@gimp.org>"
  125.             "Sven Neumann"
  126.             "1998/02/06"
  127.             "*"
  128.             SF-IMAGE "Image" 0
  129.             SF-DRAWABLE "Drawable" 0
  130.             SF-ADJUSTMENT _"Relative Radius" '(1 0 128 .1 1 1 1))
  131.