Jump to content
Paint.NET 5.1 is now available! ×

Recommended Posts

Posted

I'd like to add an Overwrite option to a Blend Mode menu, and I'm not sure the best way to do it. I want a menu like the Paint Bucket and other such tools use, where the final option is Overwrite.

 

I must admit I don't really understand all that's going on with the code that creates and configures the menu, some of which looks like this:

 

            // setup for a user selected blend mode
            IEnumLocalizerFactory factory = Services.GetService<IEnumLocalizerFactory>();
            IEnumLocalizer blendModeLocalizer = factory.Create(typeof(LayerBlendMode));
            IList<ILocalizedEnumValue> blendModes = blendModeLocalizer.GetLocalizedEnumValues();
            object[] blendModesArray = blendModes.Select(lev => lev.EnumValue).ToArrayEx();
            int defaultBlendModeIndex = blendModesArray.IndexOf(LayerBlendMode.Normal);

 

 

I do know, though, that it uses enumerations and such that don't include Overwrite. I'm hoping there's some reasonably simpe way to add the option to a menu while still being compatible with the standard method of creating the Blend Mode drop-down-list control.

  • MJW changed the title to Is there an easy way to add Overwrite to a Blend Mode menu?
Posted

In my case, copy/replace is all I want to do; however, if that's not what Overwrite does, calling my mode Overwrite would probably be misleading. I thought all Overwrite does is replace the RGB and alpha of the old pixel with with the new pixel -- something that's simpler, not more complex, than the other blend modes.

 

EDIT: Though it's actually for a different plugin, I'll use my Paste From Clipboard plugin to illustrate. The plugin normally copies the clipboard image to the canvas. It has an option to blend it with the canvas instead. Currently, there's a checkbox that switches it from the normal mode of replacing the destination pixels to blending with the pixels. The checkbox enables the Blend Mode control. I'd like to replace the checkbox with an "Overwrite" (or perhaps, "Replace") selection in the drop-down menu, which would be the default.

Posted

I would call it Replace

 

StaticListChoiceProperty takes an object[] so it can use whatever values you want, even mixed-type enum values. You'll just have to do type checking when reading the value. So create a List<object>, populate it with the LayerBlendModes, and then add another value, anything you want really, to use for Replace.

  • Like 1

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

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

forumSig_bmwE60.jpg

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...