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

  1. ;;; grid-system.scm -*-scheme-*-
  2. ;;; Time-stamp: <1998/01/20 23:22:02 narazaki@InetQ.or.jp>
  3. ;;; This file is a part of:
  4. ;;;   The GIMP (Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis)
  5. ;;; Author: Shuji Narazaki (narazaki@InetQ.or.jp)
  6. ;;; Version 0.6
  7.  
  8. ;;; Code:
  9. (if (not (symbol-bound? 'script-fu-grid-system-x-divides (the-environment)))
  10.     (define script-fu-grid-system-x-divides "'(1 g 1)"))
  11. (if (not (symbol-bound? 'script-fu-grid-system-y-divides (the-environment)))
  12.     (define script-fu-grid-system-y-divides "'(1 g 1)"))
  13.  
  14. (define (script-fu-grid-system img drw x-divides-orig y-divides-orig)
  15.   (define (update-segment! s x0 y0 x1 y1)
  16.     (aset s 0 x0)
  17.     (aset s 1 y0)
  18.     (aset s 2 x1)
  19.     (aset s 3 y1))
  20.   (define (convert-g l)
  21.     (cond ((null? l) '())
  22.       ((eq? (car l) 'g) (cons 1.618 (convert-g (cdr l))))
  23.       ((eq? (car l) '1/g) (cons 0.618 (convert-g (cdr l))))
  24.       ('else (cons (car l) (convert-g (cdr l))))))
  25.   (define (wrap-list l)
  26.     (define (wrap-object obj)
  27.       (cond ((number? obj) (string-append (number->string obj) " "))
  28.         ((eq? obj 'g) "g ")
  29.         (eq? ojb '1/g) "1/g "))
  30.     (string-append "'("
  31.            (apply string-append (map wrap-object l))
  32.            ")"))
  33.   (let* ((drw-width (car (gimp-drawable-width drw)))
  34.      (drw-height (car (gimp-drawable-height drw)))
  35.      (drw-offset-x (nth 0 (gimp-drawable-offsets drw)))
  36.      (drw-offset-y (nth 1 (gimp-drawable-offsets drw)))
  37.      (grid-layer #f)
  38.      (segment (cons-array 4 'double))
  39.      (stepped-x 0)
  40.      (stepped-y 0)
  41.      (temp 0)
  42.      (total-step-x 0)
  43.      (total-step-y 0))
  44.     (set! x-divides (convert-g x-divides-orig))
  45.     (set! y-divides (convert-g y-divides-orig))
  46.     (set! total-step-x (apply + x-divides))
  47.     (set! total-step-y (apply + y-divides))
  48.     ;(gimp-undo-push-group-start img)
  49.     (set! grid-layer (car (gimp-layer-copy drw TRUE)))
  50.     (gimp-edit-clear grid-layer)
  51.     (gimp-layer-set-name grid-layer "grid layer")
  52.     (while (not (null? (cdr x-divides)))
  53.       (set! stepped-x (+ stepped-x (car x-divides)))
  54.       (set! temp (* drw-width (/ stepped-x total-step-x)))
  55.       (set! x-divides (cdr x-divides))
  56.       (update-segment! segment
  57.                (+ drw-offset-x temp) drw-offset-y
  58.                (+ drw-offset-x temp) (+ drw-offset-y drw-height))
  59.       (gimp-pencil grid-layer 4 segment))
  60.     (while (not (null? (cdr y-divides)))
  61.       (set! stepped-y (+ stepped-y (car y-divides)))
  62.       (set! temp (* drw-height (/ stepped-y total-step-y)))
  63.       (set! y-divides (cdr y-divides))
  64.       (update-segment! segment
  65.                drw-offset-x (+ drw-offset-y temp)
  66.                (+ drw-offset-x drw-width) (+ drw-offset-y temp))
  67.       (gimp-pencil grid-layer 4 segment))
  68.     (gimp-image-add-layer img grid-layer 0)
  69.     ;(gimp-undo-push-group-end img)
  70.     (set! script-fu-grid-system-x-divides (wrap-list x-divides-orig))
  71.     (set! script-fu-grid-system-y-divides (wrap-list y-divides-orig))
  72.     (gimp-displays-flush)))
  73.  
  74. (script-fu-register "script-fu-grid-system"
  75.             _"<Image>/Script-Fu/Render/Make Grid System..."
  76.             "Draw grid as specified by X-DIVIDES (list of propotions relative to the drawable) and Y-DIVIDES. The color and width of grid is detemined by the current settings of brush."
  77.             "Shuji Narazaki <narazaki@InetQ.or.jp>"
  78.             "Shuji Narazaki"
  79.             "1997"
  80.             "RGB*, INDEXED*, GRAY*"
  81.             SF-IMAGE "Image to use" 0
  82.             SF-DRAWABLE "Drawable to draw grid" 0
  83.             SF-VALUE _"Grids X" script-fu-grid-system-x-divides
  84.             SF-VALUE _"Grids Y" script-fu-grid-system-y-divides
  85. )
  86.   
  87. ;;; grid-system.scm ends here
  88.