Jump to content

Do something once, when exiting plugin?


Recommended Posts

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

Link to comment
Share on other sites

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.

 

 

  • Like 1

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
}

 

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

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.

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Click to play:
j.pngs.pngd.pnga.pngp.png
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...