mahvin wrote:
1. Is it crucial to set a statement for the other options to be false, in order for the new pattern option to be true, or is simply adding another (begin (if (= inPatterns TRUE) sufficient? My thoughts are, I wouldn't want the user to be able to make 2 or 3 options to be true at the same time. Something to flag the user that they cannot use more than one option at a time.
Script-fu's dialog interface does not support the concept of
"radio buttons" (where only one of a group of options can be chosen). The best alternative, in my opinion, is to use the SF-OPTION widget to provide a drop-down list.
SF-OPTION "Fill mode" '("Random colours" "Colours from palette" "Patterns from directory")
Codewise, you will probably want to use Scheme's
'cond' statement, rather than nested 'if's.
mahvin wrote:
2. Could I continue using (nextcolour) in the same fashion with patterns as it is used in palettes and random colors, or would I need to make a new definition? (My gut says a new definition to assign patterns randomly is needed)
Better to treat pattern filling as a separate "fill mode", for this is what is really being done (see code below). But basically you are correct that pattern filling is little different from filling with a solid color.
mahvin wrote:
3. I am aware of (palettecount) so I would also need to establish a (patterncount).
Correct. In the code below, I use a 'palettecount' variable to index into a list of all the .pat files in the specified directory. (Note: I did not attempt to randomly select patterns from the pattern directory. If you wish to provide support for such randomization, I would be glad to assist.)
mahvin wrote:
4. I'm totally lost on how I would assign the script to look for a subset folder of patterns, and not the .gimp-2.6/patterns folder. I would want the ability to assign this value on the script menu, as the folder location could change for a different project.
When registering your script (script-fu-register), include an SF-DIRNAME widget.
SF-DIRNAME "Pattern directory" "/some/default/directory"
mahvin wrote:
A menu to elaborate my intentions:
[snip]...
Kudos on putting so much effort into describing your expectations -- and even providing a mockup of the desired dialog (instead of merely writing down a few thousand millipictures). Clearly understanding what software is supposed to accomplish is the first step in writing the code -- and for me is the most challenging part. The time you've put into requesting help makes it much easier for those who would provide it to do so (this is true not just for coding requests, but for reporting bugs -- or seeking help in general). I would say, however, that it would have been nice had you provided a link to the location of the original script.
Since your goal seems to be learning more about scripting (and since I did not write the original script), I submit the following code fragment to demonstrate how I would approach adding such a feature. I have not tested the code (or even modified the script to attempt so). I leave it to you to incorporate the appropriate changes to your version of RobA's script (remember to add the SF-DIRNAME and SF-OPTION widgets as previously mentioned).
(Note: I did not use RobA's 'listeq?' function since the same thing can be accomplished with Scheme's
'equal?' procedure.)
Add the following variables to your 'let*' bindings:
(patterns (cadr (file-glob (string-append inPatternDirectory DIR-SEPARATOR "*.pat"))))
(numpatterns (length patterns)) ; NOTE: should generate error if zero
(patterncount 0) ; index into list of patterns
The following code (or somesuch) should be substituted into the appropriate location of the original script.
EDIT: this code will definitely not work. One cannot set the current active pattern based on the pattern's filename (which the file-glob provides). We will have to either extract the pattern's name from the file, or load the pattern file as an image, copy it to the clipboard, and fill using the clipboard as pattern. The second approach is probably better since it doesn't depend upon the pattern being in GIMP's path for pattern directories. (if (or (and (= inHowCheck 0)
(<= (- (cadddr bounds) (cadr bounds)) inIgnoreSize)
(<= (- (list-ref bounds 4) (caddr bounds)) inIgnoreSize) ) ; X and Y size
(and (= inHowCheck 1)
(<= (cadddr (gimp-histogram inLayer HISTOGRAM-VALUE 0 255)) inIgnoreSize) )) ; area
(begin
(gimp-context-set-foreground (list 0 0 0)) ; fill with black - will be ignored in flatten step
(gimp-edit-fill inLayer FOREGROUND-FILL) )
(if (or (and (= inHowCheck 0)
(> (- (cadddr bounds) (cadr bounds)) inFlagSize)
(> (- (list-ref bounds 4) (caddr bounds)) inFlagSize) ) ; X and Y size
(and (= inHowCheck 1)
(> (cadddr (gimp-histogram inLayer HISTOGRAM-VALUE 0 255)) inFlagSize) )) ; area
(cond
((= fill-type 0) ; Random color fill
(set! nextcolour inFlagColour) ; guarantees 'while' will loop at least once
(while (equal? nextcolour inFlagColour) ; random color must not be the flag color
(set! nextcolour (list (+ (rand 254) 1) ; not black or white either
(+ (rand 254) 1) ; hence color is ([1-254],[1-254],[1-254])
(+ (rand 254) 1) )))
(gimp-context-set-foreground nextcolour)
(gimp-edit-fill inLayer FOREGROUND-FILL)
)
((= fill-type 1) ; get color from palette
(set! nextcolour (car (gimp-palette-entry-get-color inPalette palettecount))) ; next palette colour, - not B, W or flagcoulor
(while (or (= (apply + nextcolour) 765)
(= (apply + nextcolour) 0)
(equal? nextcolour inFlagColour) )
(set! palettecount (modulo (+ palettecount 1) numcolours)) ; increment palette
(set! nextcolour (car (gimp-palette-entry-get-color inPalette palettecount))) )
(set! palettecount (modulo (+ palettecount 1) numcolours))
(gimp-context-set-foreground nextcolour)
(gimp-edit-fill inLayer FOREGROUND-FILL) )
((= fill-type 2) ; fill with a pattern from specified directory
(gimp-context-set-pattern (list-ref patterns patterncount))
(gimp-edit-fill inLayer PATTERN-FILL)
(set! patterncount (modulo (+ patterncount 1) numpatterns)) ))
(gimp-context-set-foreground inFlagColour) ))