It is currently Sat May 25, 2013 8:33 am


Latest GIMP Scripts & Plug-ins

All times are UTC - 5 hours [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: REVISED Defaulting to the Current Font, Brush, Pattern, etc
PostPosted: Fri Jan 13, 2012 2:02 pm  (#1) 
Offline
GimpChat Member

Joined: Mar 29, 2011
Posts: 347
Location: Wisconsin
I haven't seen this posted before, so here it is.

My initial tests using the gimp-context-get-<parameter> functions to to set the Script-fu inputs looked good and very easy.

Unfortunately, the values were the active ones when GIMP started or when the scripts were refreshed. They did not reflect the current state. :oops:

So here is a revised process, and it is more work. But the default values will be the currently active ones.

Use null strings for the names in the user interface section:
Code:

    SF-FONT       "Font"       ""

    SF-BRUSH      "Brush"      '("" 100 10 0)

    SF-PALETTE    "Palette"    ""

    SF-PATTERN    "Pattern"    ""

    SF-GRADIENT   "Gradient"   ""



In the body of the script, set the new values before you use them - but only if they have changed!
Code:

    (if (> (string-length (car brush)) 0)
      (begin                                            ;user selected a brush
        (gimp-context-set-brush (car brush))
        (gimp-context-set-opacity (cadr brush))
        (gimp-context-set-paint-mode (cadddr brush))    ;ignore the spacing - gives error
    ) )

    (if (> (string-length font) 0)
        (gimp-context-set-font font)                ;font changed, use it
        (set! font (car (gimp-context-get-font)))   ;get name of current font
    )
   
    (if (> (string-length palette) 0)
        (gimp-context-set-palette palette)      ;palette changed, make it the active palette
    )

    (if (> (string-length pattern) 0)
        (gimp-context-set-pattern pattern)      ;pattern changed, make it the active pattern
    )
   
    (if (> (string-length gradient) 0)
        (gimp-context-set-gradient gradient)    ;gradient changed, make it the active gradient
    )
   

The variable names brush font palette pattern gradient should be whatever you called those entries in the script declaration.

The font entry is a special case. All of the others are used through calls that use the currently active <whatever>. But the font name is needed for the text procedures so you need to set the variable to the currently active name if the input name is <null>.

Tested in GIMP 2.6.11

I hope this helps you. :)

_________________
Image


Last edited by bkh1914 on Sat Jan 14, 2012 11:50 am, edited 1 time in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Profile  
 

 Post subject: Re: REVISED Defaulting to the Current Font, Brush, Pattern, etc
PostPosted: Fri Jan 13, 2012 3:34 pm  (#2) 
Offline
GimpChat Member

Joined: Mar 29, 2011
Posts: 347
Location: Wisconsin
I've revised (radically changed) the process. My testing wasn't as thorough as it should have been. :oops:

_________________
Image


Top
 Profile  
 
 Post subject: Re: REVISED Defaulting to the Current Font, Brush, Pattern, etc
PostPosted: Sat Jan 14, 2012 7:13 am  (#3) 
Offline
Global Moderator
User avatar

Joined: May 16, 2010
Posts: 9030
Location: "Looking for my eraser" =P
What would greatly help is if there was a way to protect DEFAULT resources so they can not be moved or deleted.
That would definitely benefit script writers that rely on default files for their scripts or filters to function correctly.

_________________
Image
Gimp Rocks Blog
Simply Gimp Tutorials
"Once your in the cloud, you're in the net"
____________
OK, . . . . so what's the speed of dark?


Top
 Profile  
 
 Post subject: Re: REVISED Defaulting to the Current Font, Brush, Pattern, etc
PostPosted: Sat Jan 14, 2012 9:02 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Apr 23, 2010
Posts: 823
Location: not from Guildford after all
This is quite clever. I might suggest that instead of using the null string, one might use "Currently active gradient" or such to make it more clear to the user; and then instead of testing for string-length, using string=?.

Also, it might be beneficial to create "dummy" patterns/palettes/gradients/etc -- appropriately named (e.g., "Currently active gradient") -- so that the user has the option to revert to that choice after selecting an alternative. Note that merely clicking the selector button will force an actual existing resource to be selected and there is no way to "reset" the input to the null string once this has occurred. By providing resources with the appropriate name, their name will appear in the selector dialog (though with the incorrect corresponding thumbnail icons).

For patterns, brushes, gradients, and palettes, it is possible to include Script-fu code that will create such dummy resources; however, it is not readily possible to create a new font from within Script-fu (I will investigate the feasibility of doing this) so it may very well be necessary to create a suitably named font outside of GIMP (ugh).

_________________
There are two types of people in the world. Those who believe in the principle of bivalence, and those who do not.


Top
 Profile  
 
 Post subject: Re: REVISED Defaulting to the Current Font, Brush, Pattern, etc
PostPosted: Sat Jan 14, 2012 11:20 am  (#5) 
Offline
GimpChat Member

Joined: Mar 29, 2011
Posts: 347
Location: Wisconsin
The advantage of using the null string is that the script's input window shows the correct current values for all of the entries -- except it doesn't show the font name.

Image

My first attempt at this was very simple. Just use the gimp-context-get-<name> functions to set the defaults. This provided real names for all of the values and no additional code was needed to use the values.
Code:
    SF-FONT       "Font"       (car (gimp-context-get-font))

Image

Unfortunately, those values were evaluated when the scripts were initialize (at start-up) and did not reflect the current values when the script was actually run. That was better than a hard-coded value; but not necessarily the correct value.


Fonts, brushes and patterns are widely available and many people customize their collections.

I have done this, especially with the brush and patterns. I didn't like the names of the default brushes so I replaced them with a set that was more appropriately named and got rid of the brushes I never used. Likewise, I replaced many of the default patterns with better patterns, or at least changed the pattern name to more accurately reflect the pattern's contents. But I also saved all the defaults so I could retrieve them when a script had a brush or pattern name hard-coded in.

_________________
Image


Last edited by bkh1914 on Sat Jan 14, 2012 11:54 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: REVISED Defaulting to the Current Font, Brush, Pattern, etc
PostPosted: Sat Jan 14, 2012 11:52 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: Apr 23, 2010
Posts: 823
Location: not from Guildford after all
bkh1914 wrote:
The advantage of using the null string is that the script's input window shows the correct current values for all of the entries -- except it doesn't show the font name, although it does show the active palette's name.

Oh, I did not catch that. I only played around with SF-FONT (which displays an empty button). There is still the limitation (with null string) of not being able to go back to the currently active resource (without explicitly choosing it in the resource dialog) but I can certainly see the desirability of your approach.

_________________
There are two types of people in the world. Those who believe in the principle of bivalence, and those who do not.


Top
 Profile  
 
 Post subject: Re: REVISED Defaulting to the Current Font, Brush, Pattern, etc
PostPosted: Sat Jan 14, 2012 12:01 pm  (#7) 
Offline
GimpChat Member

Joined: Mar 29, 2011
Posts: 347
Location: Wisconsin
saulgoode wrote:
There is still the limitation (with null string) of not being able to go back to the currently active resource (without explicitly choosing it in the resource dialog) but I can certainly see the desirability of your approach.

The Reset button in the dialog returns the values to the null string.

Filters > Reset all filters does not reset the inputs. :(

_________________
Image


Top
 Profile  
 

 Post subject: Re: REVISED Defaulting to the Current Font, Brush, Pattern, etc
PostPosted: Sat Jan 14, 2012 1:10 pm  (#8) 
Offline
GimpChat Member
User avatar

Joined: Apr 23, 2010
Posts: 823
Location: not from Guildford after all
bkh1914 wrote:
Filters > Reset all filters does not reset the inputs. :(

Yes, I'd noticed that before as well, though the command does work with plug-ins. It is unfortunate that the command does not work with scripts.

_________________
There are two types of people in the world. Those who believe in the principle of bivalence, and those who do not.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

* Login   * Subscribe to RSS Feed


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group