home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / selection-round.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  5.8 KB  |  181 lines

  1. ; selection-rounded-rectangle.scm -*-scheme-*-
  2.  
  3. ; GIMP - The GNU Image Manipulation Program
  4. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  5. ;
  6. ; This program is free software: you can redistribute it and/or modify
  7. ; it under the terms of the GNU General Public License as published by
  8. ; the Free Software Foundation; either version 3 of the License, or
  9. ; (at your option) any later version.
  10. ;
  11. ; This program is distributed in the hope that it will be useful,
  12. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ; GNU General Public License for more details.
  15. ;
  16. ; You should have received a copy of the GNU General Public License
  17. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  
  19. ; CHANGE-LOG:
  20. ; 1.00 - initial release
  21. ; 1.01 - some code cleanup, no real changes
  22. ; 1.02 - made script undoable
  23.  
  24. ; 2.00 - ALAN's Branch.  changed name, menu, location, and description
  25. ; 2.01 - fixed to work if there was no current selection.
  26. ; 2.02 - changed scale to percentages, usability tweaking.
  27. ; 2.10 - added concave round edges, updated description.
  28. ; 2.11 - tweeked description, changed comments, relinquished any rights.
  29.  
  30. ; Copyright (C) 1997, 1998, Sven Neumann
  31. ; Copyright (C) 2004, Alan Horkan.
  32. ; Alan Horkan relinquishes all rights to his changes,
  33. ; full ownership of this script belongs to Sven Neumann.
  34.  
  35. (define (script-fu-selection-rounded-rectangle image drawable radius concave)
  36.   (gimp-image-undo-group-start image)
  37.  
  38.   (if (= (car (gimp-selection-is-empty image)) TRUE) (gimp-selection-all image))
  39.   (let* (
  40.         (radius (/ radius 100)) ; convert from percentages
  41.         (radius (min radius 1.0))
  42.         (radius (max radius 0.0))
  43.         (select-bounds (gimp-selection-bounds image))
  44.         (has-selection (car select-bounds))
  45.         (select-x1 (cadr select-bounds))
  46.         (select-y1 (caddr select-bounds))
  47.         (select-x2 (cadr (cddr select-bounds)))
  48.         (select-y2 (caddr (cddr select-bounds)))
  49.         (select-width (- select-x2 select-x1))
  50.         (select-height (- select-y2 select-y1))
  51.         (cut-radius 0)
  52.         (ellipse-radius 0)
  53.         )
  54.  
  55.     ;; select to the full bounds of the selection,
  56.     ;; fills in irregular shapes or holes.
  57.     (gimp-rect-select image
  58.               select-x1 select-y1 select-width select-height
  59.               CHANNEL-OP-ADD FALSE 0)
  60.  
  61.     (if (> select-width select-height)
  62.       (set! cut-radius (trunc (+ 1 (* radius (/ select-height 2)))))
  63.       (set! cut-radius (trunc (+ 1 (* radius (/ select-width 2)))))
  64.     )
  65.     (set! ellipse-radius (* cut-radius 2))
  66.  
  67.     ;; cut away rounded (concave) corners
  68.     ; top right
  69.     (gimp-ellipse-select image
  70.              (- select-x1 cut-radius)
  71.              (- select-y1 cut-radius)
  72.              (* cut-radius 2)
  73.              (* cut-radius 2)
  74.              CHANNEL-OP-SUBTRACT
  75.              TRUE
  76.              FALSE 0)
  77.     ; lower left
  78.     (gimp-ellipse-select image
  79.              (- select-x1 cut-radius)
  80.              (- select-y2 cut-radius)
  81.              (* cut-radius 2)
  82.              (* cut-radius 2)
  83.              CHANNEL-OP-SUBTRACT
  84.              TRUE
  85.              FALSE 0)
  86.     ; top right
  87.     (gimp-ellipse-select image
  88.              (- select-x2 cut-radius)
  89.              (- select-y1 cut-radius)
  90.              (* cut-radius 2)
  91.              (* cut-radius 2)
  92.              CHANNEL-OP-SUBTRACT
  93.              TRUE
  94.              FALSE 0)
  95.     ; bottom left
  96.     (gimp-ellipse-select image
  97.              (- select-x2 cut-radius)
  98.              (- select-y2 cut-radius)
  99.              (* cut-radius 2)
  100.              (* cut-radius 2)
  101.              CHANNEL-OP-SUBTRACT
  102.              TRUE
  103.              FALSE 0)
  104.  
  105.     ;; add in rounded (convex) corners
  106.     (if (= concave FALSE)
  107.       (begin
  108.         (gimp-ellipse-select image
  109.                      select-x1
  110.                      select-y1
  111.                      ellipse-radius
  112.                      ellipse-radius
  113.                      CHANNEL-OP-ADD
  114.                      TRUE
  115.                      FALSE 0)
  116.         (gimp-ellipse-select image
  117.                      select-x1
  118.                      (- select-y2 ellipse-radius)
  119.                      ellipse-radius
  120.                      ellipse-radius
  121.                      CHANNEL-OP-ADD
  122.                      TRUE
  123.                      FALSE 0)
  124.         (gimp-ellipse-select image
  125.                      (- select-x2 ellipse-radius)
  126.                      select-y1
  127.                      ellipse-radius
  128.                      ellipse-radius
  129.                      CHANNEL-OP-ADD
  130.                      TRUE
  131.                      FALSE 0)
  132.         (gimp-ellipse-select image
  133.                      (- select-x2 ellipse-radius)
  134.                      (- select-y2 ellipse-radius)
  135.                      ellipse-radius
  136.                      ellipse-radius
  137.                      CHANNEL-OP-ADD
  138.                      TRUE
  139.                      FALSE 0)
  140.       )
  141.     )
  142.  
  143.     (gimp-image-undo-group-end image)
  144.     (gimp-displays-flush)
  145.   )
  146. )
  147.  
  148.  
  149. (define (script-fu-selection-round image drawable radius)
  150.   (script-fu-selection-rounded-rectangle image drawable (* radius 100))
  151. )
  152.  
  153.  
  154. (script-fu-register "script-fu-selection-rounded-rectangle"
  155.   _"Rounded R_ectangle..."
  156.   _"Round the corners of the current selection"
  157.   "Alan Horkan, Sven Neumann" ; authors
  158.   "Sven Neumann"              ; copyright
  159.   "2004/06/07"
  160.   "*"
  161.   SF-IMAGE       "Image"      0
  162.   SF-DRAWABLE    "Drawable"   0
  163.   SF-ADJUSTMENT _"Radius (%)" '(50 0 100 1 10 0 0)
  164.   SF-TOGGLE     _"Concave"    FALSE
  165. )
  166.  
  167. (script-fu-register "script-fu-selection-round"
  168.   ""
  169.   "Round the corners of the current selection (deprecated, use Rounded Rectangle)"
  170.   "Sven Neumann"              ; authors
  171.   "Sven Neumann"              ; copyright
  172.   "1998/02/06"
  173.   "*"
  174.   SF-IMAGE       "Image"      0
  175.   SF-DRAWABLE    "Drawable"   0
  176.   SF-ADJUSTMENT  "Relative radius" '(1 0 128 0.1 1 1 1)
  177. )
  178.  
  179. (script-fu-menu-register "script-fu-selection-rounded-rectangle"
  180.                          "<Image>/Select/Modify")
  181.