Jump to content

Access to current palette from plugins?


MJW

Recommended Posts

Is there a way for a plugin to get the list of colors in the current palette? By "current palette," I mean the colors displayed in the color window, which may have been modified by the user from the loaded palette file or default palette.

Link to comment
Share on other sites

Nope.

EDIT:

Well....... maybe.

It is stored in the registry under Computer\HKEY_CURRENT_USER\Software\Paint.NET\CurrentPalette

Not sure the format... you'll have to play with it.

Also, you could prompt the user for a palette file (from the palette folder) and go that way.

Here is some code to get you started: http://forums.getpaint.net/index.php?/topic/31921-adding-a-help-button-to-codelab-plugins/?p=427601

  • Upvote 1
Link to comment
Share on other sites

Thanks, BoltBait (even though it isn't the answer I would have preferred). I wanted some relatively easy way for the user to pass a list of colors to the plugin, selected using the Color Picker. Unfortunately, having to create then open a new palette file each time seems a bit too roundabout for my purposes.

Link to comment
Share on other sites

Is reading the PDN variables through the registry Rick-approved?

 

I looked at the Palette entry in Regedit, and it's a text string which includes comments documenting the format. The colors are stored as strings representing the hex values as "aarrggbb." It should be very easy to parse. I changed a palette value in PDN, and the registry value changed exactly in the way I expected it to.

Link to comment
Share on other sites

I could also just give you an IUserPalettesService accessible via the Services property. I already have this it's just not exposed for effects. It would require v4.0.6+ though.

 

In general, I would rather add access to stuff in this way vs. requiring you to reverse engineer something like what you're proposing. But I can't just say "no" to everything, so if you want to read from the registry, and as long as you've got reasonable error handling in there (plz don't crash), and as long as you're not writing back to it, I don't really see the harm.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

I could also just give you an IUserPalettesService accessible via the Services property. I already have this it's just not exposed for effects. It would require v4.0.6+ though.

That would be really handy. This is not the first request we've had for access to the current palette.

Link to comment
Share on other sites

I would definitely prefer the cleaner interface. I'm in no hurry to write this particular plugin, so I'll probably wait and see if palette access available by a non-registry method in a future version. Or perhaps I'll write it using the registry, with the idea of changing it later. (I always do my best to avoid crashing PDN with a plugin.)

Link to comment
Share on other sites

Okay you can expect this in the next update

namespace PaintDotNet.AppModel
{
    public interface IPalettesService
    {
        IReadOnlyList<ColorBgra> DefaultPalette
        {
            get;
        }
 
        IReadOnlyList<ColorBgra> CurrentPalette
        {
            get;
        }
    }
}
  • Upvote 2

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...