MJW Posted June 16, 2021 Share Posted June 16, 2021 This is likely the same issue as the long coveted ability to detect the final rendering pass, but in case it's different and possible I'll ask anyway. Is there some way in a IndirectUI plugin to something once, as the plugin exits? I'm writing a little CodeLab plugin that writes text to clipboard in PreRender() using Services.GetService<IClipboardService>().SetText(text). The Render() routine does nothing but copy src to dst. The plugin has controls which change what gets written to the clipboard. It works fine if the slider controls aren't changed, but if they're moved around, it crashes with some kind of clipboard-access error. Presumably it doesn't like all the repeated writing to the clipboard. I was hoping (against hope) that there's some way of writing to the clipboard once, as the plugin exits (though not, of course, if it's cancelled). Quote Link to comment Share on other sites More sharing options...
BoltBait Posted June 16, 2021 Share Posted June 16, 2021 3 hours ago, MJW said: This is likely the same issue as the long coveted ability to detect the final rendering pass Yes it is. 3 hours ago, MJW said: Is there some way in a IndirectUI plugin to something once, as the plugin exits? Nope. Your best bet might be to include a button on your UI and then when the button is pressed, in the Render loop, check to see when x==0 and y==0 and put your value on the clipboard at that time. 1 Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted June 16, 2021 Author Share Posted June 16, 2021 3 minutes ago, BoltBait said: Your best bet might be to include a button on your UI and then when the button is pressed, in the Render loop, check to see when x==0 and y==0 and put your value on the clipboard at that time. Thanks. Something of that sort probably is the best option. Quote Link to comment Share on other sites More sharing options...
BoltBait Posted June 16, 2021 Share Posted June 16, 2021 Here's some code to get you started: // Name: Button example // Author: BoltBait // Force Aliased Selection // Force Single Threaded #region UICode ReseedButtonControl Amount1 = 0; // Do it! #endregion int MyButton = 0; // initialize to -1 instead if you want to trigger when effect is run void Render(Surface dst, Surface src, Rectangle rect) { if (Amount1 != MyButton) { // Replace this block of code with your code: Form IndirectUIForm = Form.ActiveForm; if (IndirectUIForm != null) { IndirectUIForm.Invoke(new Action(delegate () { // This code runs on the UI thread: MessageBox.Show("Button pressed."); })); } // End of block MyButton = Amount1; } // Copy the src surface to the dst surface dst.CopySurface(src, rect.Location, rect); } Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted June 16, 2021 Author Share Posted June 16, 2021 I just tested for a change of the button value in PreRender() and wrote to the clipboard there. So far, it seems to work. Quote Link to comment Share on other sites More sharing options...
BoltBait Posted June 16, 2021 Share Posted June 16, 2021 That's fine for a button. Just be aware that the PreRender() code doesn't always run... What?! Yup. If there are no UI changes between the initial run and when you press the OK button, only Render() gets called. This usually isn't a problem unless you use Ctrl-F to repeat an effect. In that case, PreRender() doesn't get called but Render() does. Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted June 16, 2021 Author Share Posted June 16, 2021 8 minutes ago, BoltBait said: Just be aware that the PreRender() code doesn't always run... That's a good point; though I think way my rather silly little plugin works, it would be hard to fix it to work correctly in that circumstance anyway, and probably not worth the effort. Quote Link to comment Share on other sites More sharing options...
BoltBait Posted June 16, 2021 Share Posted June 16, 2021 That's probably fine for your own plugin. Something to remember: Be sure to use the following option comment: // Force Aliased Selection Otherwise, when copying the pixels from the source canvas to the dest canvas you might get anti-aliasing if your selection is round. It's easy to forget if you always test your plugin with a square (or no) selection. Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
MJW Posted June 16, 2021 Author Share Posted June 16, 2021 1 hour ago, BoltBait said: Otherwise, when copying the pixels from the source canvas to the dest canvas you might get anti-aliasing if your selection is round. I should have done it that way, but didn't think of it. Instead, I used Ceiling() and Floor(). If I update it, I'll change to your method. Quote Link to comment Share on other sites More sharing options...
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.