Jump to content

Help needed: Using Visual Studio instead of CodeLab for developing


qwertyuu

Recommended Posts

I know, CodeLab is very well done, and I like it.

I still don't totally love it yet, as in some stuff is lacking.

 

I want to debug my plugins, which is impossible to do inside CodeLab.

 

So, I need help... for starting my own project inside VisualStudio, and using the same template as CodeLab

#region UICode
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    // Delete any of these lines you don't need
    Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    int CenterX = ((selection.Right - selection.Left) / 2)+selection.Left;
    int CenterY = ((selection.Bottom - selection.Top) / 2)+selection.Top;
    ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
    ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
    int BrushWidth = (int)EnvironmentParameters.BrushWidth;
    ColorBgra CurrentPixel;
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        for (int x = rect.Left; x < rect.Right; x++)
        {
            CurrentPixel = src[x,y];
            dst[x,y] = CurrentPixel;
        }
    }
    }
}

So... What are the references that I need? (the important ones, because I know I can just select them all)

What are the "using" statements I should put?

Do I have to make a class, namespace and everything?

 

Any template example would be really appreciated, thanks!

borderg.png

Link to comment
Share on other sites

So... What are the references that I need? (the important ones, because I know I can just select them all)

What are the "using" statements I should put?

Do I have to make a class, namespace and everything?

 

Any template example would be really appreciated, thanks!

If you are using IndirectUI the required refrences are: System.Drawing, PaintDotNet.Base, PaintDotNet.Core and PaintDotNet.Effects.

 

The using statements should be: PaintDotNet, PaintDotNet.Effects and System.Drawing.

 

The Class Library project template will create a new class with the proper namespace.

 

The View source checkbox in CodeLab's Save dll dialog allows you to copy the generated effect to Visual Studio, and an example template is below.

Hidden Content:
using System;
using PaintDotNet;
using PaintDotNet.Effects;
using System.Drawing;

namespace EffectName
{
    public class Class1 : PropertyBasedEffect
    {
        public static string StaticName
        {
            get
            { 
                return "Effect Name";
            }
        }


        public Class1() : base(StaticName, null, null, EffectFlags.None)
        {
        }

        protected override PaintDotNet.PropertySystem.PropertyCollection OnCreatePropertyCollection()
        {
            throw new NotImplementedException(); 
        }

        protected override void OnRender(Rectangle[] renderRects, int startIndex, int length)
        {
            for (int i = startIndex; i < startIndex + length; i++)
			{
			    Render(DstArgs.Surface, SrcArgs.Surface, renderRects[i]);
			}
        }

        private void Render(Surface dst, Surface src, Rectangle rect)
        {
            // Delete any of these lines you don't need
            Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
            int CenterX = ((selection.Right - selection.Left) / 2) + selection.Left;
            int CenterY = ((selection.Bottom - selection.Top) / 2) + selection.Top;
            ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
            ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
            int BrushWidth = (int)EnvironmentParameters.BrushWidth;
            ColorBgra CurrentPixel;
            for (int y = rect.Top; y < rect.Bottom; y++)
            {
                for (int x = rect.Left; x < rect.Right; x++)
                {
                    CurrentPixel = src[x, y];
                    dst[x, y] = CurrentPixel;
                }
            }
        }
    }
}

 

  • Upvote 1

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Link to comment
Share on other sites

You should have a read of this: http://forums.getpaint.net/index.php?/topic/2248-visual-studio-2005-effect-plugin-template/

 

Read and follow BoltBait's suggestions in post #4.

 

This might also prove useful: http://forums.getpaint.net/index.php?/topic/4209-how-to-debug-your-plugin/

 

All that might be a bit of overkill.  See next post for a walk through of how to set up and start using the template.

Link to comment
Share on other sites

I've had this noted down on a piece of paper for some time - it's how I use the VS template (updated & attached below)

Customize VS (if required)

Right click on the VS express 2010 shortcut. Select 'open file location', this should highlight the VCSexpress.exe file. Right click on this and select 'Properties', then 'Compatability' and tick the 'Run this program as an administrator' box.

This should allow VCS to copy the built .dll into Pdn. If you just choose 'run as administrator' straight from the right-click context, it will return to normal privilege level each time you restart the program. If you build without admin level, it won't build, error code 1.

Setting the template up

 

1. Download VS template below (I've updated the references and added some notes).

 

2. Move the template to the correct directory (e.g. My Documents\Visual Studio 2010\Templates\ProjectTemplates\).  Don't unzip it (as per the original instructions).

 

Customizing the setup - just for your plugin

 

3. Open VS  (I'm using VS express 2010).

 

4. Select New Project from the left hand pane.

 

5. Select the Plugin Template - updated Dec2010 with a single click.

 

6. At the foot of the dialog type in your plugin name.  This is important as the plugin namespace is derived from the project name.  Just save yourself the grief.

 

7. Click OK to open the template which will automatically name some aspects for you.

 

8. Save the project immediately.  File > Save project name

 

9. Open Project > project name Properties.  Select the Application tab.

 

10. Change Target Framework to .NET 3.5 (not 3.5 Client Profile)

 

11. Save again then close the project and reopen.  This is usually required when the framework is changed.  Best just to do it.

 

12. Double click the Resources entry in the Solution Explorer.  Double click the icon to open it.  Use the icon as a canvas & create your own.  The one supplied is the one I used for WhichSymbol+.

 

13. Save finished icon & return to VS.

 

14. Open EffectPlugin.cs by double clicking it in Solution Explorer.

 

15. Find phrase "Plugin name here" and insert your plugin name.  Quotes are required I believe.

 

16. Set the menu that the plugin should appear in.  Some samples are included to get you started.  I'd generally use the SubmenuNames.Render option rather than the return null option.

 

17. Return to the Project > project name Properties > Application tab.  Delete the Assembly Name and substitute your own.  Make sure it has no spaces in it.

 

18. Click on the Assembly Information button in the same tab.   Update title, Description and Copyright info as required.  OK.

 

19  Open the Build Events tab and check the path to Paint.NET is correct.  This copies the built effect directly to the Paint.NET/effects directory.  FOR FUTURE REFERENCE >> In between builds you need to delete the old *.dll file and close Paint.NET.

 

19. Save project.

 

20.  Build project (F6).  The post-build copy should drop the *.dll into the correct PDN folder.  Open PDN and see if the plugin appears.

 

(If the build fails with an error in "resx" file, change the icon reference in the resx file to 2.0.0.0).

 

 

If the dll builds successfully with no errors and is in Pdn/effects folder ok, but the effect does not show up in the PDN menu. Try building it without an Icon i.e. 'return null' to see if that is where the problem lies.

Let's do code!

 

21.  Return to the EffectPlugin.cs file (it should be a tab on the main window).  Scroll to the bottom of the file and you'll find the Render method.  This is where the heart of your plugin should go.   See where it says // Render code Here  - bung your code in there!

PluginTemplate - updated Dec 2010.zip

Edited by Ego Eram Reputo
Added suggestions from Red Ochre and null54
  • Upvote 3
Link to comment
Share on other sites

Well done EER, thanks for setting this out logically.
(Personally I think your instructions & template should be 'stickied' as an up to date guide. - I've finally got an Icon to work in VCS now!)

May I suggest :
1a. Right click on the VS express 2010 shortcut. Select 'open file location', this should highlight the VCSexpress.exe file. Right click on this and select 'Properties', then 'Compatability' and tick the 'Run this program as an administrator' box.
This should allow VCS to copy the built .dll into Pdn.

I am very new to VCsexpress - so if that's wrong in any way, I 'm happy to edit/delete this post.
(If you just choose 'run as administrator' straight from the right-click context, it will return to normal privelege level each time you restart the program. If you build without admin level, it won't build, error code 1.)

12a. If the dll builds successfully with no errors and is in Pdn/effects folder ok., but the effect does not show up in the Pdn menu. Try building it without an Icon ie. 'return null' and see if that is where the problem lies.

  • Upvote 1

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

Most of the credit goes to Sepcot and BoltBait ;)

Most common cause of the latter issue is targetting .NET 4. I've not come across the icon causing the plugin to go missing from pdn.

1a. You're probably correct. Did you have trouble with VS not copying the finished dll?

Link to comment
Share on other sites

Re:1a - It kept going back to not admin status, so when I tried to build it would fail presumably because it didn't have the permission to copy the built .dll to Pdn effects. - Easy to sort out.

Re: The Icon - spent days trying to figure this out - mainly because no errors are shown and it builds fine and shows up in Pdn/effects fine then doesn't show up in the menu. I even managed to crash Pdn with one desperate try!

Anyway many thanks to all those that share their knowledge on the plugin side of things, especially Null54 who set up the original project files (using unsafe pointers) for me. :star:

My latest one is nearly ready to publish - I will put the project files in its dev/central thread first - just to be safe.
I must also write some instructions and decide which menu to put it under.  
I now have an idea of what I'm doing and have successfully added and removed controls, removed a whole method and significantly improved the speed. I won't attempt anti-aliasing at this stage - it would slow everything down and the results are reasonable as is. (well I thinks so!  :roll:  :lol: - new pics on my gallery).

The learning curve gets a bit steep between codelab and Visual Studio - thanks to all that have carved some steps in the rock face!
 

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

19  Open the Build Events tab and check the path to Paint.NET is correct.  This copies the built effect directly to the Paint.NET/effects directory.  FOR FUTURE REFERENCE >> In between builds you need to delete the old *.dll file and close Paint.NET. 

If you add /y to the end of the Post build event the old dll will be overwritten instead of having to delete it after closing Paint.NET, e.g. copy "$(TargetPath)" "C:\Program Files\Paint.NET\Effects" /y.

 

Regarding step 11 closing and reopening the project shoud not be necessary. :)

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Link to comment
Share on other sites

If you add /y to the end of the Post build event the old dll will be overwritten instead of having to delete it after closing Paint.NET, e.g. copy "$(TargetPath)" "C:\Program Files\Paint.NET\Effects" /y.

 

Regarding step 11 closing and reopening the project shoud not be necessary. :)

 

re: /y  great suggestion.  Thank you.

 

re: 11.  I wrote that step because I was asked to close and reopen when changing the target framework.  VS 2010 Express demanded it.

 

I think we can further tweak the template.  I would have added more commented-out menus - but intellisense helps you out so well.  I'm sure there are lots of comments we could include to help steer new users in the right direction.

Link to comment
Share on other sites

I love you guys, thanks a lot!

 

EDIT: yes, I too think these instructions should be stickied. Starting PDN development, I thought the VS integration had been done many years ago, and as I see now... it was left out a little in the late years. If I were to be better, I could try to maintain the VS aspect of Plugins in PDN, but, I ain't that good :)

Edited by qwertyuu

borderg.png

Link to comment
Share on other sites

Anyone have any further suggestions for the template?

Link to comment
Share on other sites

  • 1 month later...

I recently started using Visual Studio for my plugin development too. Because the distort plugin I made in CodeLab, is very slow, and impossible to complete on very large pictures(~2000px). Yeah I can understand that VS version is harder to use than CodeLab but I'm still looking forwards it just to see if I run into any problems.

 

There was a suggestion I had about updating a template to include sample variables that can be manipulated by form controls, and then passed on to the bitmap result. A Scroll bar that determines the % between the black and white on the picture for example in which I managed to figure out on how to do it last night.

 

One thing I wasn't able to figure out is, placing an IndirectUI control on the form in which would be nice to see in a sample template as well, so I can get the hang on how it could be done.

 

I apologize if this thread I bumped is old. I've been using Paint.Net for a long time, and decided to start writing my own plugins for it.

Link to comment
Share on other sites

@Simon Brown wrote an excellent guide to Indirect UI rules. The guide should give you enough examples to figure out how the IndirectUI controls are implimented. Find the guide here.

Good idea to add some examples to the template. I wll do that.

Link to comment
Share on other sites

Elsewhere, @midora said....
 
 

 
 IndirectUI and PropertyBasedEffect are connected strongly.
  
... 

PropertyBasedEffect provides the method OnCreatePropertyCollection() which allows you to return properties as IndirectUi objects plus rules how these objects depend on each other.
 


Having just had a long play with the VS Effect template - I'm convinced things would be a lot clearer if there were two templates. One for effects with IndirectUI controls and another for Winform/custom UI's (basically the existing template).

 

Rather than trying to explain all about IndirectUI - I think cutting and pasting code from CodeLab is much easier (BoltBait has done a marvelous job with CodeLab's "show source" option).  So I'm thinking the IndirectUI template would be a container for the Codelab source.

 

Opinions?

Link to comment
Share on other sites

Having just had a long play with the VS Effect template - I'm convinced things would be a lot clearer if there were two templates. One for effects with IndirectUI controls and another for Winform/custom UI's (basically the existing template).

 

That's fine. Mixing PropertyBased and Basic stuff in a template will not work. You are using different classes to do the job.

 

I did once a drawing on a paper of the class hierarchy and methods. If there is time I will provide the drawings as bits and bytes ;-)

midoras signature.gif

Link to comment
Share on other sites

Thanks, I'd really like to see that.

Link to comment
Share on other sites

What I have also forgot to add is, that the fact that the Render procedure is called many times, and I palced a lot of sin/cos calculations in there too, making the results very slow. I've also discovered OnSetRenderInfo which was supposed to be ran one time only, but I'm not too sure how it works, and where it's placed.

 

I did look at source codes to other plugins, but I must assume that's it's more of an older version of the code.

Link to comment
Share on other sites

OnSetRenderInfo provides you the properties you should use to render to the destination surface.

 

You should not execute all the rendering in OnSetRenderInfo because your plugin would not profit from multi core support.

But if it is possible to split the algorithm in a pre calculation and a pixel calculation phase then it makes sense to do the pre calculation in OnSetRenderInfo and restrict the pixel calculations to the rectangle provided to Render.

midoras signature.gif

Link to comment
Share on other sites

No, OnSetRender is not obsolete - but it's something that should be used from Visual Studio as CodeLab protects it (you can't access it from your code in CodeLab).

 

Your best method of figuring out how it works is to use CodeLab to create a simple plugin then choose the option to "View Source" when you build it.  CodeLab will automatically create and populate a simple OnSetRender function.  Cut and Paste the entire source into the VS template and you should be able to figure out where and how OnSetRender works.

Link to comment
Share on other sites

  • 1 year later...

Does anyone know whether the VS template is up to date as I've been trying to use it and VS 2013 keeps giving me errors on the main EffectPlugin.cs about how certain methods can't override PDN methods as they've been set to sealed.

 

I'm a rusty C#.net programmer, and my experience with VS is limited, regardless, I had used it to code the core of my effect -- but with IndirectUI. However, I really need tab functionality as the effect has multiple elements, each with differing options. IndirectUI is just too simple a solution for the job so I really need to use windows forms for the UI; otherwise I can't finish the plugin as the UI config dialog would just be too long and hard to follow due to the default top-down "list" layout for controls.

 

I'd usually solve this on my own but I've gotten pretty fed up with it and I think I'm going to just call it a night. Maybe with a fresh start tomorrow and someone shedding some light on this, I might be able to finally get my effect plugin to compile -- probably something obvious that I've missed due to tiredness.

 

EDIT: solved this on my own.

Edited by SIC

----- sELFiNDUCEDcOMA.com

Link to comment
Share on other sites

Does anyone know whether the VS template is up to date as I've been trying to use it and VS 2013 keeps giving me errors...

 

Forget it. I just realized that I was better off seeing if I could open the template and build it as is. Runs fine in PDN, now all I have to do is add my effect code and scratch re-familiarize myself with the form UI code.

----- sELFiNDUCEDcOMA.com

Link to comment
Share on other sites

  • 4 months later...

Okay so Paint.Net 4.0 was officially released and in Visual Studio, every time I try to re-size the dialog window, it tends to fly to the lower right to a point where I can't see it anymore whenever I drag to reside window or type in a value to do it. The result seems to be the same.

 

Tried using different versions like 2010 and 2013 and the result was still the same.

 

I was either going to find an work around or just use CodeLab for now until it gets fixed.

Link to comment
Share on other sites

Something is strange with your VS setup. I'm pretty sure this is nothing to do with pdn4 as myself and quite a number of other authors have been building plugins for 4.0 without encountering this issue.

Can you post a screenshot?

Link to comment
Share on other sites

Okay here it is...

 

http://prntscr.com/3zs9it

 

The dotted lines is where the GUI is supposed to be at. Clicking and dragging the re-sizing handles on the dotted lines makes the Window go further down and right.

 

I did not have this problem when having version 3.5.11 (or the last 3.x installed) installed.

 

This is using VS2013 on Windows 8.

Edited by pcd
Link to comment
Share on other sites

It's almost like the dialog coordinates are screwed up. 

 

It's a wild guess - is there some sort of High DPI / pixel density setting in Win8 you can toggle? I bet you have it set to higher than 96ppi and VS can't handle it.

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