Jump to content

How to Write an Effect Plugin (Part 1 of 4 - Simple)


Recommended Posts

ive just started wanting to know how to make an effect :D its still a bit complicated seeing as the ony expierience if had has been with html at school which was very simple and we only learnt how to make a website with just text :) lol. im gonna start with htis and i might try to play around with some other simple effects. hopefully i want to make one which takes the current selection and copies it and pastes it everywhere :D so sort of like a landscape gen thing. it might be complicated lol and well it may take a few years for me to learn dll :D

section8.png

psn id: R3V-fiR3

Link to comment
Share on other sites

  • 3 months later...

Wait a second, what is 'rect'? Shouldn't one be using 'selection', as rect isn't even defined in that code. I just ran into a bunch of headache where I was using the bounds of rect to do my looping. It working fine for loops like so:

    for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           CurrentPixel = src[x,y];
           if (x % 2 == 0 && y % 2 == 0) dst[x,y] = PrimaryColor;
       }     
   }

But when I tried the following, I found that rect.Bottom and rect.Top where MOVING during the loop. O_O:

    for(int y = rect.Top; y < rect.Bottom; y++)
   {
       dst[rect.Bottom, y] = PrimaryColor;     
   }

That code isn't supposed to do anything useful, but it show that rect.Bottom is incrementing every iteration. Perhaps every time a change is made to dst. I don't have Visual Studio on this machine so I'm using CodeLab and thus no debugging.

Using selection Rectangle solves this awkwardness.

Link to comment
Share on other sites

Oh, I see, that makes sense if that's the case.

Should all plugins, then, be in the form of:

    ColorBgra current;
   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           current = src[x,y];
           // TODO: Add pixel processing code here
           if (somecondition)
           {
               current = ; //modify current pixel
           }
           dst[x,y] = current;
       }
   }

I'm going to have to look at some of the other plugins after lunch.

Link to comment
Share on other sites

  • 1 year later...
  • 2 weeks later...

A minor thing to change immediately in CodeLab would be to have a "Pause" button, so that the code will not be executed as we are editing it.

Sometimes, I type code, and the fact that it runs immediately, despite it is not complete, can cause the code to turn into an infinite loop. This caused CodeLab and in fact all of PaintDotNet to become unresponsive, and I had to kill the process.

For this reason, I generally don't edit code in CodeLab itself, but in an safer external editor, and I use full copy/paste operations from the external editor into the CodeLab window. But this is irritating (note that when pasting code in CodeLab, there's a lengthy scrollbar operation running, just to recolor the text (note one minor bug in this coloring: it recolors keywords found in comments.)

One way to avoid the immediate execution is to start editing after leaving a syntax error, for example a "=" sign alone on the first line at the begining of the script. To effectively run the script, just remove that equal sign.

I wonder if CodeLab could not simply just monitor the content of a filename (edited and saved from an external editor) and then automatically refresh itself by loading it after it has been closed by the other application, without bothering displaying and coloring it in its window. It will just perform the compilation and execution task in this case: in this case, if the code immediately crashes or hangs in an infinite loop, nothing is lost if we kill PaintDotNet from the task manager.

However, the status window should first display the correct line numbers in case of compilation errors (not the line numbers after the automatically generated and hidden lines, so that they can be easily found in the external editor), and we won't even need the code frame in this case : the status frame could take the full height of the window below the menu, and the CodeLab window could be reduced in height; or the code window could be replaced by the automatically generated parameters controls, if there's no compilation error.

Link to comment
Share on other sites

  • 7 months later...
  • 10 months later...
  • 4 months later...

Yes, but much more complex. I use VS 2010 Express Edition.

Codelab is a much easier introduction to C# and effect coding boltbait.wink.png

Link to comment
Share on other sites

  • 4 months later...
  • 6 months later...

Awesome tutorial BoltBait. It has gone on my bookmark bar for when I'm not so tired. Coding things is very hard when tired, and can often lead to many mistakes. So when I'm awake more, I will have a look at what plugins aren't available & what features PDN doesn't have, so I can work from there.

signature-1.png
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...