Rick Brewster

CodeLab v4.2 (for advanced users) Released March 18, 2019

Recommended Posts

CodeLab 1.1 has been released.

And a wonderful upgrade it is too :!:

I can't thank you enough BoltBait, particularly for the Drop-Down List Box and the BlendOp controls. I'm gonna have so much fun with these :D

[edit]

I was wondering if any of the controls can be set dynamically? Specifically the drop-down listbox. Can I populate the list at *.dll runtime (say with a list of fonts gleaned from the users PC)?

[/edit]

Share this post


Link to post
Share on other sites
[edit]

I was wondering if any of the controls can be set dynamically? Specifically the drop-down listbox. Can I populate the list at *.dll runtime (say with a list of fonts gleaned from the users PC)?

[/edit]

Paint.NET IndirectUI does not support such behavior.

HOWEVER... I might be able to give you something like that similar to the UserBlendOp control. Give me a few days... ;)

I do not understand this // Name: Effect Name stuff at all. Can you give an example?

Mike, the File > Save as DLL screen includes several fields of information that you need to fill in in order to build a DLL. It includes things like the author's name, the Effects submenu and menu text, and a support URL that is displayed to the user if your effect fails. Here's the save screen:

BuildDLL.png

It is a pain to enter that info every time you go to build a DLL, so I included a shortcut...

If you include a comment in your effect in the following form, the appropriate field will be filled in with the supplied default information.

// FIELD: default value

You can override this default before actually saving the DLL file. It is only for conveince. It has no effect on the effect at all.

Here are some examples:

// Author: BoltBait

// Submenu: Blurs

// Name: Gaussian Blur+

// URL: http://www.BoltBait.com/pdn

etc.

This is all explained on the following page of the help file: http://www.boltbait.com/pdn/codelab/hel ... ngdll.asp

Share this post


Link to post
Share on other sites
[edit]

I was wondering if any of the controls can be set dynamically? Specifically the drop-down listbox. Can I populate the list at *.dll runtime (say with a list of fonts gleaned from the users PC)?

[/edit]

Paint.NET IndirectUI does not support such behavior.

HOWEVER... I might be able to give you something like that similar to the UserBlendOp control. Give me a few days... ;)

That is not available through IndirectUI.

Sure it is. Use the StaticListChoiceProperty.

string[] fontNames = ... you figure this part out ...;
StaticListChoiceProperty fontNamesProperty = new StaticListChoiceProperty(YourPropertyName, fontNames);

Share this post


Link to post
Share on other sites

I have modified the CodeLab source to add a new FontList control. There may be many bugs as I am new to the CodeLab codebase. The source code was too large to attach, so PM me your email address for a copy (although note that I will probably not be able to get back to you within two weeks).

Share this post


Link to post
Share on other sites

Simon, you almost had it. You just forgot to wireup the OnSetRenderInfo function so the selected font was never being return to the user. My code is a little different from yours because I had already started on the problem when you had posted.

I have posted an updated CodeLab that includes the font list control.

Go get CodeLab version 1.2 here: http://www.BoltBait.com/pdn/codelab

Changes:

- Added Font List control

How to use the new control:

When the Render function starts, the Amount1 FontFamily variable contains the selected font family. The name of the font can be used this way: Amount1.Name and the font can be created this way: Font MyFont = new Font(Amount1.Name, 10); where you replace 10 with the desired font size. You probably don't want to do that inside of your render loop--do it at the top of your render function.

Thanks Ego Eram Reputo for supplying sample code for this control on this page: http://www.boltbait.com/pdn/codelab/hel ... asp#Fonts

Share this post


Link to post
Share on other sites
Thanks Ego Eram Reputo for supplying sample code for this control on this page: http://www.boltbait.com/pdn/codelab/hel ... html#Fonts

That might be my code :wink: , but the idea to draw directly to the canvas using drawing routines definitely came from MadJik when he and I were discussing a plugin which later became Random Mazes: http://paintdotnet.forumer.com/viewtopic.php?p=148303#p148303.

MadJik used g.DrawLine to draw the walls of his maze and I adapted this to work with g.DrawString. I would not have figured this out by myself and simply ran with his idea.

Share this post


Link to post
Share on other sites

Feature Request: Since CodeLab forces an Amount1, Amount2, etc for UI Elements, could you please include a find and replace feature? This would be extremely helpful for when dealing with reording of the UI Elements. Thanks!

Share this post


Link to post
Share on other sites
Feature Request: Since CodeLab forces an Amount1, Amount2, etc for UI Elements, could you please include a find and replace feature? This would be extremely helpful for when dealing with reording of the UI Elements. Thanks!

Mike have you seen PSPad? Have a look at this: http://www.pspad.com

I use this to do most of the "grunt" work (like cutting and pasting code from other source files - as you can open multiple files at once). Then I call up CodeLab to polish my code (& make it run - hopefully :roll: ). I generally start with an effect template (heavily commented) which tells me how to use the new UI features in CodeLab, so I don't have to keep logging on to figure them out :!:

Note: As CodeLab becomes more powerful I am using it more and more to write entire effects, but as you have noticed it has no find & replace (yet...,).

Just a thought...,

Share this post


Link to post
Share on other sites
Thanks Ego Eram Reputo for supplying sample code for this control on this page: http://www.boltbait.com/pdn/codelab/hel ... html#Fonts

That might be my code :wink: , but the idea to draw directly to the canvas using drawing routines definitely came from MadJik when he and I were discussing a plugin which later became Random Mazes: http://paintdotnet.forumer.com/viewtopic.php?p=148303#p148303.

MadJik used g.DrawLine to draw the walls of his maze and I adapted this to work with g.DrawString. I would not have figured this out by myself and simply ran with his idea.

That's OK. Everything MadJik knows he learned from me anyway. :P

BTW, I use Notepad++ for my external editor. I highly recommend it. But, I'll look into adding some sort of refactoring... AND search/replace to CodeLab.

Share this post


Link to post
Share on other sites

Hey BoltBait, type (not copy-paste) this line into Render in the default CodeLab script:

invertcolorseffect.Render(new Rectangle[]{rect},0,1);

now try it again but removing the indent first.

Share this post


Link to post
Share on other sites

Hmmm... Pressing } is causing a match in the wrong spot which is messing up your editor text.

My advice: don't do that.

Share this post


Link to post
Share on other sites

I noticed a tiny bug in your plug-in. First of all, I'm using v1.2, and just downloaded it from your site. When you have indented text and you have sections of code separated by "{" and "}", if you add a new line between "{" and "}", first, it will indent the text to be flush with existing text, and then add 4,8,12,16,etc. depending on how many open brackets there are...I don't think I explained that well, so here's an example.

1. First, open CodeLab, and delete whatever script is in there. There should be absolutely nothing.

2. Type "text" without the quotes, and hit enter. Repeat this step a few times.

3. Hit End on your keyboard, type "{" without the quotes, and hit enter.

4. Hit End on your keyboard, type "text" without the quotes, and hit enter. Repeat this step a few times.

5. Repeat Steps 3 and 4 a few times.

The text after the first "{" should ideally all be flush, but in the end, you have something that looks like this:

text
text
text
{
       text
           text
               text
               {
                               text
                                       text
                                               text
                                                       {
                                                                       text
                                                                                   text

Share this post


Link to post
Share on other sites

Yeah, it's a mess right now. The problem is that both Curtis and I put in code to handle indenting... ;)

Curtis already fixed that kind of stuff for the next release for me by removing his indent handling.

Give me a couple of days to finish my updates...

Share this post


Link to post
Share on other sites

I'm having trouble with CodeLabs Double Vector UI control. I have pasted the sample UI code from BoltBaits website into CodeLab, but it generates an error when I build the *.dll.

Here's the code I'm using....,

/* ========================================================================== */
/*                                                                            */
/*   UI - Double Vector.cs                                                    */
/*   Author: Curtis (via boltBaits Website)                                   */
/*                                                                            */
/*   Description:  How to use double Vector UI elements                       */
/*                                                                            */
/* ========================================================================== */

#region UICode
Pair Amount1=Pair.Create(0.0,0.0); // Position
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
  Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
  ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;

  int width = selection.Right - selection.Left;
  int height = selection.Bottom - selection.Top;

  // converts the Pair values to between 0 and 1
  // where 0 is the left/top and 1 is the right/bottom.
  double px = (Amount1.First + 1) / 2;
  double py = (Amount1.Second + 1) / 2;

  // we can now convert these to actual pixel co-ordinates.
  int column = (int)Math.Round(px * width);
  int row = (int)Math.Round(py * height);

  for (int y = rect.Top; y    {
     for (int x = rect.Left; x       {
        if (x == column || y == row)
        {
           dst[x,y] = PrimaryColor;
        }
        else
        {
           dst[x,y] = src[x,y];
        }
     }
  }
}

And the error is.....,

Error at line 119: Cannot implicitly convert type 'int' to 'PaintDotNet.Pair' (CS0029)

[edit]

Using the Interface Designer, I get this line, which works fine:

Pair Amount1 = Pair.Create( 0.0 , 0.0 ); // Control Description

But this one doesn't.

Pair Amount2=Pair.Create(0.0,0.0); // Position

Is the whitespace critical?

[/edit]

Share this post


Link to post
Share on other sites

Oops! Yup. There's a bug in CodeLab.

You can see the bug in line 119 of the source code if you "View Source", paste into Notepad++, and delete the first (comment) line. It is trying to build the control as an integer slider. That'll never work! :D

EDIT:

Yes, :oops: the space after the comma (here "Pair") is critical because CodeLab is trying to find an exact string in order to know what kind of control you want. I forgot to include possible spaces in the search string. I have fixed the example on the web site. If you use the built-in UI editor it generates the proper code.

Share this post


Link to post
Share on other sites

CodeLab 1.3 Release

- Added Radio Button List control type [HELP]

- Added Reseed Button control type [HELP]

- Improved syntax highlighting (by Curtis)

- Icons added to the editor UI (by Curtis)

- Added editor commands for commenting/uncommenting a selection

- Bug fixes

Go get it here: http://boltbait.com/pdn/codelab/

Share this post


Link to post
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.