home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 April / com_0405_1.iso / opensource / gimp-2.2.1-i586-setup / gimp-2.2.1-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / test-sphere.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-01-05  |  9.7 KB  |  259 lines

  1. ; This is a slightly modified copy of the sphere script to show and test
  2. ; the possibilities of the new Script-Fu API extensions.
  3. ;
  4. ; ----------------------------------------------------------------------
  5. ; SF-ADJUSTMENT
  6. ; is only useful in interactive mode, if you call a script from
  7. ; the console, it acts just like a normal SF-VALUE
  8. ; In interactive mode it creates an adjustment widget in the dialog.
  9. ;
  10. ; Usage:
  11. ; SF-ADJUSTMENT "label" '(value, lower, upper, step_inc, page_inc, digits, type)
  12. ;
  13. ; type is one of: SF-SLIDER(0), SF-SPINNER(1)
  14. ; ----------------------------------------------------------------------
  15. ; SF-FONT
  16. ; creates a font-selection widget in the dialog. It returns a fontname as
  17. ; a string. There are two new gimp-text procedures to ease the use of this
  18. ; return parameter:
  19. ;
  20. ;  (gimp-text-fontname image drawable
  21. ;                      x-pos y-pos text border antialias size unit font)
  22. ;  (gimp-text-get-extents-fontname text size unit font))
  23. ;
  24. ; where font is the fontname you get. The size specified in the fontname
  25. ; is silently ignored. It is only used in the font-selector. So you are
  26. ; asked to set it to a useful value (24 pixels is a good choice) when
  27. ; using SF-FONT.
  28. ;
  29. ; Usage:
  30. ; SF-FONT "label" "fontname"
  31. ; ----------------------------------------------------------------------
  32. ; SF-BRUSH
  33. ; is only useful in interactive mode. It will create a widget in the control
  34. ; dialog. The widget consists of a preview area (which when pressed will
  35. ; produce a popup preview ) and a button with the "..." label. The button will
  36. ; popup a dialog where brushes can be selected and each of the
  37. ; characteristics of the brush can be modified.
  38. ;
  39. ; The actual value returned when the script is invoked is a list
  40. ; consisting of Brush name, opacity, spacing and brush mode in the same
  41. ; units as passed in as the default value.
  42. ;
  43. ; Usage:
  44. ; SF-BRUSH "Brush" '("Circle (03)" 1.0 44 0)
  45. ;
  46. ; Here the brush dialog will be popped up with a default brush of Circle (03)
  47. ; opacity 1.0, spacing 44 and paint mode of Normal (value 0).
  48. ; If this selection was unchanged the value passed to the function as a
  49. ; paramater would be '("Circle (03)" 1.0 44 0). BTW the widget used
  50. ; is generally available in the libgimpui library for any plugin that
  51. ; wishes to select a brush.
  52. ; ----------------------------------------------------------------------
  53. ; SF-PATTERN
  54. ; Only useful in interactive mode. It will create a widget in the control
  55. ; dialog. The widget consists of a preview area (which when pressed will
  56. ; produce a popup preview ) and a button with the "..." label. The button will
  57. ; popup a dialog where patterns can be selected.
  58. ;
  59. ; Usage:
  60. ; SF-PATTERN "Pattern" "Maple Leaves"
  61. ;
  62. ; The value returned when the script is invoked is a string containing the
  63. ; pattern name. If the above selection was not altered the string would
  64. ; contain "Maple Leaves"
  65. ; ----------------------------------------------------------------------
  66. ; SF-GRADIENT
  67. ; Only useful in interactive mode. It will create a widget in the control
  68. ; dialog. The widget consists of a button containing a preview of the selected
  69. ; gradient. If the button is pressed a gradient selection dialog will popup.
  70. ;
  71. ; Usage:
  72. ; SF-GRADIENT "Gradient" "Deep Sea"
  73. ;
  74. ; The value returned when the script is invoked is a string containing the
  75. ; gradient name. If the above selection was not altered the string would
  76. ; contain "Deep Sea"
  77. ; ----------------------------------------------------------------------
  78. ; SF-PALETTE
  79. ; Only useful in interactive mode. It will create a widget in the control
  80. ; dialog. The widget consists of a button containing a preview of the selected
  81. ; palette. If the button is pressed a palette selection dialog will popup.
  82. ;
  83. ; Usage:
  84. ; SF-PALETTE "Palette" "Named Colors"
  85. ;
  86. ; The value returned when the script is invoked is a string containing the
  87. ; palette name. If the above selection was not altered the string would
  88. ; contain "Named Colors"
  89. ; ----------------------------------------------------------------------
  90. ; SF-FILENAME
  91. ; Only useful in interactive mode. It will create a widget in the control
  92. ; dialog. The widget consists of a button containing the name of a file.
  93. ; If the button is pressed a file selection dialog will popup.
  94. ;
  95. ; Usage:
  96. ; SF-FILENAME "Environment Map"
  97. ;             (string-append "" gimp-data-directory "/scripts/beavis.jpg")
  98. ;
  99. ; The value returned when the script is invoked is a string containing the
  100. ; filename.
  101. ; ----------------------------------------------------------------------
  102. ; SF-DIRNAME
  103. ; Only useful in interactive mode. Very similar to SF-FILENAME, but the
  104. ; created widget allows to choose a directory instead of a file.
  105. ;
  106. ; Usage:
  107. ; SF-DIRNAME "Image Directory" "/var/tmp/images"
  108. ;
  109. ; The value returned when the script is invoked is a string containing the
  110. ; dirname.
  111. ; ----------------------------------------------------------------------
  112. ; SF-OPTION
  113. ; Only useful in interactive mode. It will create a widget in the control
  114. ; dialog. The widget is an option_menu showing the options that are passed
  115. ; as a list. The first option is the default choice.
  116. ;
  117. ; Usage:
  118. ; SF-OPTION "Orientation" '("Horizontal" "Vertical")
  119. ;
  120. ; The value returned when the script is invoked is the number of the
  121. ; choosen option, where the option first is counted as 0.
  122. ; ----------------------------------------------------------------------
  123.  
  124.  
  125. (define (script-fu-test-sphere radius
  126.                    light
  127.                    shadow
  128.                    bg-color
  129.                    sphere-color
  130.                    brush
  131.                    text
  132.                    multi-text
  133.                    pattern
  134.                    gradient
  135.                    gradient-reverse
  136.                    font
  137.                    size
  138.                    unused-palette
  139.                    unused-filename
  140.                    unused-orientation
  141.                    unused-dirname
  142.                    unused-image
  143.                    unused-layer
  144.                    unused-channel
  145.                    unused-drawable)
  146.   (let* ((width (* radius 3.75))
  147.      (height (* radius 2.5))
  148.      (img (car (gimp-image-new width height RGB)))
  149.      (drawable (car (gimp-layer-new img width height RGB-IMAGE
  150.                     "Sphere Layer" 100 NORMAL-MODE)))
  151.      (radians (/ (* light *pi*) 180))
  152.      (cx (/ width 2))
  153.      (cy (/ height 2))
  154.      (light-x (+ cx (* radius (* 0.6 (cos radians)))))
  155.      (light-y (- cy (* radius (* 0.6 (sin radians)))))
  156.      (light-end-x (+ cx (* radius (cos (+ *pi* radians)))))
  157.      (light-end-y (- cy (* radius (sin (+ *pi* radians)))))
  158.      (offset (* radius 0.1))
  159.      (text-extents (gimp-text-get-extents-fontname multi-text
  160.                                size PIXELS
  161.                                font))
  162.      (x-position (- cx (/ (car text-extents) 2)))
  163.      (y-position (- cy (/ (cadr text-extents) 2))))
  164.  
  165.     (gimp-context-push)
  166.  
  167.     (gimp-image-undo-disable img)
  168.     (gimp-image-add-layer img drawable 0)
  169.     (gimp-context-set-foreground sphere-color)
  170.     (gimp-context-set-background bg-color)
  171.     (gimp-edit-fill drawable BACKGROUND-FILL)
  172.     (gimp-context-set-background '(20 20 20))
  173.  
  174.     (if (and
  175.      (or (and (>= light 45) (<= light 75))
  176.          (and (<= light 135) (>= light 105)))
  177.      (= shadow TRUE))
  178.     (let ((shadow-w (* (* radius 2.5) (cos (+ *pi* radians))))
  179.           (shadow-h (* radius 0.5))
  180.           (shadow-x cx)
  181.           (shadow-y (+ cy (* radius 0.65))))
  182.       (if (< shadow-w 0)
  183.           (prog1 (set! shadow-x (+ cx shadow-w))
  184.              (set! shadow-w (- shadow-w))))
  185.  
  186.       (gimp-ellipse-select img shadow-x shadow-y shadow-w shadow-h
  187.                    CHANNEL-OP-REPLACE TRUE TRUE 7.5)
  188.       (gimp-context-set-pattern pattern)
  189.       (gimp-edit-bucket-fill drawable PATTERN-BUCKET-FILL MULTIPLY-MODE
  190.                 100 0 FALSE 0 0)))
  191.  
  192.     (gimp-ellipse-select img (- cx radius) (- cy radius)
  193.              (* 2 radius) (* 2 radius) CHANNEL-OP-REPLACE TRUE FALSE 0)
  194.  
  195.     (gimp-edit-blend drawable FG-BG-RGB-MODE NORMAL-MODE
  196.              GRADIENT-RADIAL 100 offset REPEAT-NONE FALSE
  197.              FALSE 0 0 TRUE
  198.              light-x light-y light-end-x light-end-y)
  199.  
  200.     (gimp-selection-none img)
  201.  
  202.     (gimp-context-set-gradient gradient)
  203.     (gimp-ellipse-select img 10 10 50 50 CHANNEL-OP-REPLACE TRUE FALSE 0)
  204.  
  205.     (gimp-edit-blend drawable CUSTOM-MODE NORMAL-MODE
  206.              GRADIENT-LINEAR 100 offset REPEAT-NONE gradient-reverse
  207.              FALSE 0 0 TRUE
  208.              10 10 30 60)
  209.  
  210.     (gimp-selection-none img)
  211.  
  212.     (gimp-context-set-foreground '(0 0 0))
  213.     (gimp-floating-sel-anchor (car (gimp-text-fontname img drawable
  214.                                x-position y-position
  215.                                multi-text
  216.                                0 TRUE
  217.                                size PIXELS
  218.                                font)))
  219.  
  220.     (gimp-image-undo-enable img)
  221.     (gimp-display-new img)
  222.  
  223.     (gimp-context-pop)))
  224.  
  225. (script-fu-register "script-fu-test-sphere"
  226.             "_Sphere..."
  227.             "Simple script to test and show the usage of the new Script-Fu API extensions."
  228.             "Spencer Kimball, Sven Neumann"
  229.             "Spencer Kimball"
  230.             "1996, 1998"
  231.             ""
  232.             SF-ADJUSTMENT "Radius (in pixels)" '(100 1 5000 1 10 0 1)
  233.             SF-ADJUSTMENT "Lighting (degrees)" '(45 0 360 1 10 1 0)
  234.             SF-TOGGLE     "Shadow"             TRUE
  235.             SF-COLOR      "Background color"   '(255 255 255)
  236.             SF-COLOR      "Sphere color"       '(255 0 0)
  237.             SF-BRUSH      "Brush"              '("Circle (03)" 1.0 44 0)
  238.             SF-STRING     "Text"               "Script-Fu rocks!"
  239.             SF-TEXT       "Multi-line text"    "Hello,\nWorld!"
  240.             SF-PATTERN    "Pattern"            "Maple Leaves"
  241.             SF-GRADIENT   "Gradient"           "Deep Sea"
  242.             SF-TOGGLE     "Gradient reverse"   FALSE
  243.             SF-FONT       "Font"               "Agate"
  244.             SF-ADJUSTMENT "Font size (pixels)" '(50 1 1000 1 10 0 1)
  245.             SF-PALETTE    "Palette"            "Default"
  246.             SF-FILENAME   "Environment map"
  247.                           (string-append ""
  248.                          gimp-data-directory
  249.                          "/scripts/images/beavis.jpg")
  250.             SF-OPTION     "Orientation"        '("Horizontal" "Vertical")
  251.             SF-DIRNAME    "Output directory"   "/var/tmp/"
  252.             SF-IMAGE      "Image"              -1
  253.             SF-LAYER      "Layer"              -1
  254.             SF-CHANNEL    "Channel"            -1
  255.             SF-DRAWABLE   "Drawable"           -1)
  256.  
  257. (script-fu-menu-register "script-fu-test-sphere"
  258.              "<Toolbox>/Xtns/Script-Fu/Test")
  259.