MJW Posted February 10, 2021 Posted February 10, 2021 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. Quote
Rick Brewster Posted February 10, 2021 Posted February 10, 2021 Not really. Overwrite can't work like a regular blend mode, it requires an additional alpha channel; it needs to know which pixels to overwrite and by how much. Without that it's just copy/replace. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
MJW Posted February 10, 2021 Author Posted February 10, 2021 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. Quote
Rick Brewster Posted February 10, 2021 Posted February 10, 2021 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. 1 Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.