Rick Brewster

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

Recommended Posts

36 minutes ago, Chas said:

I get the error message: Full error message: System.ArgumentException: Font 'Verdana' does not support style 'Regular'

 

Install the Verdana font?

 

https://www.google.com/search?q=verdana+font+download

 

Verdana is one of the fonts that comes with Windows.  Are you running Windows in a language other than English?

 

Share this post


Link to post
Share on other sites

That's pretty strange. CodeLab should only fallback to the Verdana font if none of the other fonts (Consolas, Courier New, ect.) are available.

Given that Consolas, Courier New, and Verdana are all included with Windows 7, those fonts must have been uninstalled from your computer at some point.

Share this post


Link to post
Share on other sites

CodeLab 4.2 Released

This is only for Paint.NET 4.1.6+!

 

Big update today...

 

Changes:

▪ New Icons! (toe_head2001)

▪ Improved the 'unsaved changes' dialog for when there's only one tab open, and also changed the wording in the dialog when there's multiple tabs open, to be less confusing (toe_head2001)

▪ The search box (in Find & Replace) now turns red when there are no matches (toe_head2001)

▪ When using Save As, the "//Name: " comment is now parsed to try to create a default filename. If it's unsuccessful, it will fall back to "MyScript.cs" (toe_head2001)

▪ Minor fixes to Format Document (toe_head2001)

▪ Files (with .cs extension) can now be dropped (drag and drop) into CodeLab to open them. (toe_head2001)

▪ Options to use force SingleRenderCall and Legacy ROI when Building DLL (toe_head2001 and BoltBait)

▪ Added three additional menu items to the Effects menu to start CodeLab with specific parameters (EffectsFlags, EffectRendingSchedule). (toe_head2001)

▪ Scripts with "//Submenu: Adjustments" will be put in the Adjustments menu instead of the Effects menu (BoltBait)

▪ If your effect has a sample image for The Plugin Browser, it will be shown on the Build to DLL form (BoltBait)

▪ Added a new high res icon for when CodeLab is running higher than 96dpi (BoltBait)

▪ Added new build options (Legacy ROI, Single Render Call) to File New template screen (BoltBait)

▪ Added the following script comments to control build options: (BoltBait)
// Force Legacy ROI
// Force Single Render Call

▪ CodeLab can now be installed to the Store version of Paint.NET. However, when running the Store version you can not create a Visual Studio project from your CodeLab script. Building a DLL still works fine. (toe_head2001 and BoltBait)

▪ Assortment of bugfixes, cleanups, refactorings (toe_head2001 and BoltBait)

 

Grab the CodeLab DLL here:

 

http://www.boltbait.com/pdn/CodeLab/

 

Screenshots:

 

New icons:

NewIcons.png

 

When developing a CodeLab script that utilizes special rendering commands, CodeLab now has the ability to run under those conditions while you are developing your script:

CodeLabMenu.png

 

There are some new options on the File New screen:

FileNew.png

 

Here are the new features of the Save as DLL screen:

BuildingDLL.png

 

You can now install CodeLab when using the Microsoft Store version of Paint.NET.  The only limitation is that you can't generate a Visual Studio solution of your CodeLab script.  If you click the button, nothing bad happens, it just tells you of the limitation.

 

New Options:

 

Legacy ROI... Here is a good description of how the ROI's work:

https://forums.getpaint.net/topic/113917-effectoptions/?do=findComment&comment=555790

 

Single Threaded vs. Single Render Call...

SingleThreaded only uses 1 thread to make calls into Render. It'll still be called many, many times, just like if you didn't use the flag, but without any multithreading. Progress bar still works here.

SingleRenderCall only calls Render once, and it's done with 1 array with all of the roi's. That this is effectively SingleThreaded is just a corollary. You won't see any progress bar updating here because the progress bar is updated as each Render call finishes, and there's no side-channel for reporting progress.

 

 

 

  • Like 3
  • Upvote 3

Share this post


Link to post
Share on other sites
Quote

New Icons! (toe_head2001) 

 

I didn't get around to adding larger icons for HiDPI, but I plan to do so in the near future.

Share this post


Link to post
Share on other sites

Thanks for your hard work.
Is there any chance to Format Document and Find/Replace icons to be added to the toolbar?
 

Share this post


Link to post
Share on other sites
1 hour ago, xod said:

Thanks for your hard work.

 

You're welcome!

 

1 hour ago, xod said:

Is there any chance to Format Document

 

Easy.  Do you really use it that often?

 

1 hour ago, xod said:

and Find/Replace icons to be added to the toolbar?

 

Hmmm... not as easy.  We would need to highlight the icon if the Find window is open and close the window if clicked again...

 

 

Share this post


Link to post
Share on other sites
14 minutes ago, BoltBait said:

We would need to highlight the icon if the Find window is open and close the window if clicked again...

 

Would we though? Most programs don't do that with their find buttons.

 

Share this post


Link to post
Share on other sites
1 hour ago, BoltBait said:

Easy.  Do you really use it that often?

 

Yes, I use it very often. But I think I could get used to the CTRL + Q combination.

 

Now, CodeLab became very confuse for me. What version I need to use?


ARWrKPN.png
 

Share this post


Link to post
Share on other sites

Normally, you would just start CodeLab using the top entry, "CodeLab...".  However,

 

On 3/18/2019 at 9:59 PM, BoltBait said:

When developing a CodeLab script that utilizes special rendering commands, CodeLab now has the ability to run under those conditions while you are developing your script:

CodeLabMenu.png

 

Share this post


Link to post
Share on other sites
1 hour ago, toe_head2001 said:

 

Would we though? Most programs don't do that with their find buttons.

 

 

It's not absolutely necessary.

 

Are we as good as everyone else... or are we BETTER? :D 

  • Upvote 1

Share this post


Link to post
Share on other sites

If I run older scripts in Single Render Call or Legacy ROI mode, CodeLab freezes and I'm forced to close Paint.Net from Task Manager.

 

Edit:

Sorry, there was something wrong with my script.
CodeLab works perfectly.

Edited by xod

Share this post


Link to post
Share on other sites
1 hour ago, xod said:

If I run older scripts in Single Render Call or Legacy ROI mode, CodeLab freezes and I'm forced to close Paint.Net from Task Manager.

 

You'll need to give us more information.  I'm not seeing any lockups.  I am able to run older scripts in all 4 of the CodeLab modes.

 

EDIT:  How old is "older"?  I mean, you can't run scripts designed for CodeLab 1.0... but, more modern previous versions (CodeLab 2.0+) should be fine.

Share this post


Link to post
Share on other sites

CodeLab 4.2 in Russian

 

You can find the new version of CodeLab in Russian here.

Вы можете найти новую версию CodeLab на русском языке здесь.

Share this post


Link to post
Share on other sites
On 3/20/2019 at 8:40 PM, xod said:

If I run older scripts in Single Render Call or Legacy ROI mode, CodeLab freezes and I'm forced to close Paint.Net from Task Manager.

 

Edit:

Sorry, there was something wrong with my script.

 

If your script is causing CodeLab to freeze, that's an issue.

Can you share the script with us, so we can investigate?

Share this post


Link to post
Share on other sites
On 3/25/2019 at 7:37 PM, toe_head2001 said:

 

If your script is causing CodeLab to freeze, that's an issue.

Can you share the script with us, so we can investigate?

 

Spoiler

// Name: Test
// Author: 
// Submenu: 
// URL:
// Title: 

#region UICode
ListBoxControl Amount1 = 0; // Options|Move X, Y|Diagonals
IntSliderControl Amount2 = 20; // [0,800] {Amount1} X
IntSliderControl Amount3 = 20; // [0,800] {Amount1} Y
IntSliderControl Amount4 = 20; // [0,800] {!Amount1} Step
CheckboxControl Amount5 = false; // [0,1] {Amount1} Show coordinates
#endregion

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

    float selTop = selection.Top;
    float selBot = selection.Bottom;
    float selLeft = selection.Left;
    float selRight = selection.Right;
    int step = Amount4;
    float fontSize = selection.Right/100;

    using (RenderArgs ra = new RenderArgs(dst))
    {
        Graphics gr = ra.Graphics;
        gr.Clip = new Region(rect);
        gr.SmoothingMode = SmoothingMode.AntiAlias;

        StringFormat format = new StringFormat();
        using(Pen pen = new Pen(Color.Black,1))
        using (Font txtFont = new Font("Tahoma", fontSize, FontStyle.Regular))
        using (SolidBrush txtBrush = new SolidBrush(Color.Blue))
        {
            switch(Amount1)
            {
                case 0: // Move Lines
                    PointF left = new PointF(selLeft - 1f, selTop + Amount2);
                    PointF rite = new PointF(selRight, selTop + Amount2);
                    PointF top = new PointF(Amount3 + selLeft, selTop - 1f);
                    PointF bot = new PointF(Amount3 + selLeft, selBot);
                    gr.DrawLine(pen, top, bot);
                    gr.DrawLine(pen, left, rite);
                    if (Amount5)
                    {
                        txtBrush.Color = Color.Blue;
                        format.Alignment = StringAlignment.Near;
                        format.LineAlignment = StringAlignment.Far;
                        gr.DrawString(Amount2.ToString(), txtFont, txtBrush, selLeft, selTop + Amount2, format);
                        txtBrush.Color = Color.Red;
                        format.Alignment = StringAlignment.Far;
                        format.LineAlignment = StringAlignment.Center;
                        gr.DrawString(Amount3.ToString(), txtFont, txtBrush, selLeft + Amount3, selTop + fontSize, format);
                    }
                    break;
                case 1: // Diagonals
                    for (int i = 1; i < selRight; i+=step) // if step (Amount4) = 0 CodeLab freezes. Logic Amount4 must be > 0. [1,800]
                    {
                        PointF topleft = new PointF(selLeft, selTop - i + 1f);
                        PointF botrite = new PointF(selRight + i - 1f, selBot);
                        gr.DrawLine(pen, topleft, botrite);
                        PointF topleft2 = new PointF(selLeft - i + 1f, selTop);
                        PointF botrite2 = new PointF(selRight, selBot + i - 1f );
                        gr.DrawLine(pen, topleft2, botrite2);
                    }
                    break;
            }
        }
    }
}

 

 

Edited by xod

Share this post


Link to post
Share on other sites
44 minutes ago, xod said:

if step (Amount4) = 0 CodeLab freezes.

 

Well, of course it does--you've created an endless loop.

Share this post


Link to post
Share on other sites

Here's a little sneak peek of what I'm working on.

Disclaimer: It's half broken, and a work-in-progress.

 

vs2019-colors.png

 

Visual Studio 2019 colors:

Yellow for Methods

Aquamarine for Structs

Purple for certain Keywords

Light Blue for Parameters and Local Variables

  • Like 1
  • Upvote 3

Share this post


Link to post
Share on other sites
17 minutes ago, xod said:

Is it possible in CodeLab to have more validation conditions?

 

The way the readonlyproperty system is designed, no.  Sorry, this is not possible.

Share this post


Link to post
Share on other sites

Wrong alignment for braces when I try to format document because the statement is in line with 'if' keyword.

 

Spoiler

// Name: TextWarp
// Submenu:
// Author: xod
// Title: TextWarp
// Version: 1.0.0
// Desc:
// Keywords:
// URL:
// Help:

#region UICode
MultiLineTextboxControl Amount1 = "Text Warp"; // [1,32767]
FontFamily Amount2 = new FontFamily("Arial"); // Font
IntSliderControl Amount3 = 50; // [3,800] Font size
PanSliderControl Amount4 = Pair.Create(-1.000,-1.000); //
PanSliderControl Amount5 = Pair.Create(1.000,-1.000); //
PanSliderControl Amount6 = Pair.Create(-1.000,1.000); //
PanSliderControl Amount7 = Pair.Create(1.000,1.000); //
IntSliderControl Amount8 = 0; // [0,360] Rotate
CheckboxControl Amount9 = false; // [0,1] Shape
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    Rectangle sel = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
    Color PrimaryColor = EnvironmentParameters.PrimaryColor;

    float x1 = (float)Math.Round((Amount4.First + 1) * sel.Width / 2);
    float y1 = (float)Math.Round((Amount4.Second + 1) * sel.Height / 2);

    float x2 = (float)Math.Round((Amount5.First + 1) * sel.Width / 2);
    float y2 = (float)Math.Round((Amount5.Second + 1) * sel.Height / 2);

    float x3 = (float)Math.Round((Amount6.First + 1) * sel.Width / 2);
    float y3 = (float)Math.Round((Amount6.Second + 1) * sel.Height / 2);

    float x4 = (float)Math.Round((Amount7.First + 1) * sel.Width / 2);
    float y4 = (float)Math.Round((Amount7.Second + 1) * sel.Height / 2);

    string text = Amount1;
    int font_size = Amount3;
    FontStyle font_style = FontStyle.Regular;

    dst.CopySurface(src, rect.Location, rect);

    using (RenderArgs ra = new RenderArgs(dst))
    using (Pen pen = new Pen(PrimaryColor, 1))
    using (GraphicsPath path = new GraphicsPath())
    using (SolidBrush brush = new SolidBrush(PrimaryColor))
    using (FontFamily font_family = new FontFamily(Amount2.Name))
    using (Font font = new Font(font_family, font_size, font_style))
    using (StringFormat string_format = new StringFormat())
    {
        string_format.Alignment = StringAlignment.Near;
        string_format.LineAlignment = StringAlignment.Near;
        Graphics g = ra.Graphics;
        g.Clip = new Region(rect);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

        // Create a rectangle.
        RectangleF srcRect = new RectangleF(0, 0, sel.Width, sel.Height);

        PointF p1 = new PointF(x1, y1);
        PointF p2 = new PointF(x2, y2);
        PointF p3 = new PointF(x3, y3);
        PointF p4 = new PointF(x4, y4);

        if(Amount9) path.AddRectangle(srcRect);
            path.AddString(text, font_family, (int)font_style, g.DpiY * font_size / 72, new PointF(0, 0), string_format);

        // Create a destination for the warped rectangle.
        PointF[] destPoints = {p1, p2, p3, p4};

        // Create a translation matrix.
        Matrix matrix = new Matrix();
        matrix.Translate(0, 0);
        if (Amount8 > 0)
        {
            // Move TopLeft corner to center of the canvas then rotate.
            matrix.Translate(sel.Width / 2, sel.Height / 2);
            matrix.Rotate(Amount8);
        }

        // Warp the source path.
        path.Warp(destPoints, srcRect, matrix, WarpMode.Perspective, 0.5f);

        // Draw the warped path to the screen.
        g.DrawPath(pen, path);
        if(!Amount9) g.FillPath(brush, path);
            }//Wrong alignment for braces when I try to format document
             //because the statement is in line with 'if' keyword
    }

 

 

Share this post


Link to post
Share on other sites
1 hour ago, xod said:

Wrong alignment for braces when I try to format document because the statement is in line with 'if' keyword.

 

I think this might already be fixed for the next version. If not, I'll take a look at fixing it in the coming days.

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, toe_head2001 said:

 

I think this might already be fixed for the next version. If not, I'll take a look at fixing it in the coming days.

 

While there are some fixes for both quick format and for typing, this is not fixed.

 

You can even see it with the default script:

 

The line after:

if (IsCancelRequested) return;

becomes indented improperly after pressing Ctrl+Q for Quick reformat.

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.