Jump to content

Render effect when its dialog changes


Recommended Posts

I've instantiated an effect from an assembly and displayed a dialog so the user can tweak the effect settings. I then stored the effect token and used it to render the effect later without re-displaying the dialog.

 

The effect is of type Effect.

The effect token is of type ConfigEffectToken.

Therefore, the effect can't make use of properties.

 

I would like to know if it's possible to render the effect whenever a control in the dialog is changed, or alternatively, when the corresponding effect token changes.

Edited by Joshua Lamusga
Link to comment
Share on other sites

8 hours ago, Joshua Lamusga said:

I would like to know if it's possible to render the effect whenever a control in the dialog is changed, or alternatively, when the corresponding effect token changes.

Sure, just call FinishTokenUpdate() in the control's ValueChanged Event.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

@toe_head2001 Ah, I didn't know about that event. It all works perfectly fine, except that I have to replicate the things that paint.net usually passes to effects in order for them to work, including Selection, EffectSourceSurface, and so on.

//Creates and displays the dialog.
using (var dlg = customEffect.CreateConfigDialog())
{
    dlg.Selection = new PdnRegion(Selection.GetRegionData());
    dlg.EffectSourceSurface = Surface.CopyFromBitmap(bmpCurrentDrawing);
    dlg.ShowDialog();                                
}

So now the issue becomes: how do I pass in Services? The dialog's services are null, as seen by the fact that any time I try to instantiate one of Pyrochild's dialogs, he tries to use services to search for updates, which crashes. If I call brush factory from brush filter, I also get that the static bitmap for brush factory's rendering is "in use" somehow; of course that never occurs in normal usage of the plugin. So now I have three other questions:

1. How do I instantiate Services or in some way get the dialog to use it?
2. Is there an explanation for why I'm hitting concurrency errors when calling other effects? I pay attention to the EffectFlags.
3. How can I shield my program from these exceptions? I tried registering at the AppDomain level; no luck since it's in another assembly.

Edited by Joshua Lamusga
Link to comment
Share on other sites

1 hour ago, Joshua Lamusga said:

Ah, I didn't know about that event.

oh... I was not clear. Sorry for the confusion.

I was not referring to the EffectTokenChanged event. You shouldn't need to handle that at all.

 

I meant the event(s) for when your control(s) change.

For example, when a checkbox is clicked:

private void myCheckBox_CheckedStateChanged(object sender, EventArgs e)
{
    FinishTokenUpdate();
}

 

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

Quote

I meant the event(s) for when your control(s) change.

I can't plunge through the Form and register a handler on every control. I've loaded this effect from a completely different assembly; I have no access to its source code. I depend on the effect API to work with it. The "confusion" is the only reason I found a working solution.

 

So by a happy accident, the original problem was solved. Do you have thoughts on the three questions I posed?

Link to comment
Share on other sites

2 hours ago, Joshua Lamusga said:

1. How do I instantiate Services or in some way get the dialog to use it?

You need to set the Effect property; the dialog gets Services from it.

using (var dlg = customEffect.CreateConfigDialog())
{
    dlg.Selection = new PdnRegion(Selection.GetRegionData());
    dlg.EffectSourceSurface = Surface.CopyFromBitmap(bmpCurrentDrawing);
    dlg.Effect = customEffect;
    dlg.ShowDialog();                             
}

 

2 hours ago, Joshua Lamusga said:

2. Is there an explanation for why I'm hitting concurrency errors when calling other effects? I pay attention to the EffectFlags.

What sort of concurrency errors? I think if it does not have the EffectFlags.Configurable flag, then you have to do the rending in a separate thread. I never investigated as to why. It seems to work though.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

Quote

You need to set the Effect property; the dialog gets Services from it.

The dialog was created from the effect in the using statement. I tried this anyway, but it didn't change anything.

 

Quote

What sort of concurrency errors? I think if it does not have the EffectFlags.Configurable flag, then you have to do the rending in a separate thread. I never investigated as to why. It seems to work though.

I've been rendering in a separate thread with Parallel.For() using 64x64 rectangles unless the EffectFlags request single threaded or calling render once, in which case I render on the same thread.

 

Thanks for the help, though.

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.

×
×
  • Create New...