Sign in to follow this  
Followers 0
Illnab1024

Grid Maker Plugin v3.0 - Updated July 2, 2014

69 posts in this topic

For those who need it, from those who give it, is a grid maker plug-in, allowing you to choose the size of the grid, and the ability to preserve the background of your selection.

Updated for Paint.NET 4.0

Download DLL here:

GridCheckerboard.zip

Install the normal way. If that doesn't work, post your troubles here.

GridCheckerboardUI.png

For those that are curious, here is the CodeLab source for the effect:

// Title: BoltBait's Grid Maker v3.0
// Author: BoltBait
// Submenu: Render
// Name: Grid / Checkerboard
// URL: http://www.BoltBait.com/pdn
// Keywords: grid|checker|checkerboard|lines
// Desc: Draw a grid or checkerboard
#region UICode
int Amount1 = 10; // [1,1000] Grid size
int Amount2 = 1; // [1,100] Line width
bool Amount3 = false; // [0,1] Checker board
ColorBgra Amount4 = ColorBgra.FromBgr(0, 0, 0); // Primary color
int Amount5 = 255; // [0,255] Primary alpha
bool Amount6 = true; // [0,1] Use source canvas for secondary color
ColorBgra Amount7 = ColorBgra.FromBgr(255, 255, 255); // Secondary color
int Amount8 = 255; // [0,255] Secondary alpha
#endregion

unsafe void Render(Surface dst, Surface src, Rectangle rect)
{
    bool Odd = false;
    for (int y = rect.Top; y < rect.Bottom; y++)
    {
        if (IsCancelRequested) return;
        ColorBgra* srcPtr = src.GetPointAddressUnchecked(rect.Left, y);
        ColorBgra* dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);
        for (int x = rect.Left; x < rect.Right; x++)
        {
            ColorBgra CurrentPixel = *srcPtr;

            if (Amount3)
            {
                // We're making a checker board
                Odd = true;
                if (((x / Amount1) % 2) == 0) Odd = false;
                if (((y / Amount1) % 2) == 0) Odd = !Odd;
                if (Odd)
                {
                    CurrentPixel = Amount4;
                    CurrentPixel.A = (byte)Amount5;
                }
                else
                {
                    if (!Amount6)
                    {
                        CurrentPixel = Amount7;
                        CurrentPixel.A = (byte)Amount8;
                    }
                }
            }
            else
            {
                // We're making a grid
                Odd = false;
                for (int t = 0; t < Amount2; t++)
                {
                    if ((((x - t) % Amount1) == 0) || (((y - t) % Amount1) == 0)) Odd = true;
                    if (Odd)
                    {
                        CurrentPixel = Amount4;
                        CurrentPixel.A = (byte)Amount5;
                    }
                    else
                    {
                        if (!Amount6)
                        {
                            CurrentPixel = Amount7;
                            CurrentPixel.A = (byte)Amount8;
                        }
                    }
                }
            }

            *dstPtr = CurrentPixel;
            srcPtr++;
            dstPtr++;
        }
    }
}
Paint.NET 3.x users, look here:

Hidden Content:
Download DLL v2.0: GridMaker.dll

Download Source v1.1: GridSRC.zip

Download Source v2.0: GridSRC_2_0.zip

GridPreview.png

BoltBait is again responsible for the Render Function, whereas I did the niceties of a UI.

Edited by BoltBait
Updated for Paint.NET 4.0
0

Share this post


Link to post
Share on other sites

One quick idea: On the dialog it says "Plugin coded by ...", but hey why not use a LinkLabel control and give a link to this forum post where users can download it? That also helps so that if someone gives the plugin to a friend, they can find it and get updates easily (and maybe grab other plugins too, in the process).

0

Share this post


Link to post
Share on other sites

What if you move your forum?

0

Share this post


Link to post
Share on other sites

Clicking the link doesn't work ... are you using PaintDotNet.SystemLayer.Shell.OpenURL() in the appropriate Click handler? (it should be in the 2.xx codebase as well as 3.0)

0

Share this post


Link to post
Share on other sites

I got stupid and never put the EventHandler in...

EDIT: And it ain't showing up with 2.72 systemlayers dll's... :(

Edit2: Nevermind, wrong case... Okay, it's all good

0

Share this post


Link to post
Share on other sites

I've been itching for Paint.NET to have a grid generator, but what I need is a checkerboard of the primary and secondary colors.

I suppose I could just whip that up in CodeLab... :P

-Austin Spafford

0

Share this post


Link to post
Share on other sites

I have a question. What controls the thickness of the bars in the grid? Is it the brush thickness. I know that the UI controls the spacing of the bars...

0

Share this post


Link to post
Share on other sites

I set it at 1 and that's where its going to stay.

Austin Spafford, I have made the code changes to support making checker boards. I will see if Illnab1024 has time to modify the UI and rebuild the DLL.

0

Share this post


Link to post
Share on other sites

Gridgod(er...BoltBait), Would there be a way to add an adjustment that effected pixel thickness or maybe even a thickness percentage?

0

Share this post


Link to post
Share on other sites

barkbark00, I'll see if I have access to Brush Width...

0

Share this post


Link to post
Share on other sites

OK, got it.

Changes include:

* Support for grids OR checker boards

* Support for brush width (or the default size of 1)

I sent the code to Illnab1024 for an update.

0

Share this post


Link to post
Share on other sites

Excellent!

Now the only issue is of defaults, but that's relatively minor. (optimal for me would be if I could start with two garish colors and a 32z32 grid)

Thank you for the tweak! Since my stab at a hacky-script in CodeLab failed for some bizarre reason, I'm going to go with this plugin. :)

Extra Credit: Does anyone know why on earth this script would only draw columns?

(DISCLAIMER: First C# code I've written, and the differences between it and C++ were learned through compiler errors :razz:)

const int GRID_SIZE = 32;

void Render (Surface dst, Surface src, Rectangle rect) {

   bool rowIsToggled    = false;
   int  rowsUntilToggle = 0;
   for (int y = rect.Top; y < rect.Bottom; ++y) {

       if (0 == rowsUntilToggle) {
           rowIsToggled    = !rowIsToggled;
           rowsUntilToggle = GRID_SIZE;
       }

       bool columnIsToggled    = false;
       int  columnsUntilToggle = 0;
       for (int x = rect.Left; x < rect.Right; ++x) {

           if (0 == columnsUntilToggle) {
               columnIsToggled    = !columnIsToggled;
               columnsUntilToggle = GRID_SIZE;
           }

           ColorBgra color;
           if (rowIsToggled != columnIsToggled)
               color = ColorBgra.FromBgr(220, 20, 20);
           else
               color = ColorBgra.FromBgr(20, 20, 220);

           dst[x, y] = color;

           --columnsUntilToggle;
       }

       --rowsUntilToggle;
   }

}

This is going to make manipulating icon artwork a lot more convenient at work.

Thank you!

-Austin Spafford

0

Share this post


Link to post
Share on other sites

Austin, I'm not really sure about your code, but if you want, here is my codelab script:

void Render(Surface dst, Surface src, Rectangle rect)
{
   // User Interface elements
   int GridSize = 10;
   bool AlphaOnly = false;
   bool ForegroundOnly = false;
   bool SwapColors = false;
   bool UseBrushWidth = false;
   int GridType = 0;               // 0=grid, 1=checker

   // Other variables
   PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   ColorBgra CurrentPixel;
   ColorBgra PrimaryColor;
   ColorBgra SecondaryColor;
   bool Odd = false;

   // Get the current brush width for grids
   int w = (int)EnvironmentParameters.BrushWidth;
   if (!UseBrushWidth) w = 1;

   // Grab the primary and secondary colors (swapping if specified in the UI)
   if (SwapColors) {
       PrimaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
       SecondaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
   } else {
       PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
       SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
   }

   // Loop through all the pixels
   for(int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           // Only work with a pixel if it is selected 
           // (this handles convex & concave selections)
           if (selectionRegion.IsVisible(x, y))
           {
               // Get the source pixel
               CurrentPixel = src[x,y];

               switch(GridType) {
                   // We are making a grid
                   case 0:
                   	 Odd = false;
                       for (int t=0; t<w; t++)
                       {
                           if ((((x-t) % GridSize) == 0) || (((y-t) % GridSize) == 0)) 
                               Odd = true;
                       }
                       if ( Odd ) 
                       {
                           if (!AlphaOnly)
                           {
                               CurrentPixel.R = (byte)PrimaryColor.R;
                               CurrentPixel.G = (byte)PrimaryColor.G;
                               CurrentPixel.B = (byte)PrimaryColor.B;
                           }
                           CurrentPixel.A = (byte)PrimaryColor.A;
                       } 
                       else 
                       {
                           if (!ForegroundOnly)
                           {
                               if (!AlphaOnly)
                               {
                                   CurrentPixel.R = (byte)SecondaryColor.R;
                                   CurrentPixel.G = (byte)SecondaryColor.G;
                                   CurrentPixel.B = (byte)SecondaryColor.B;
                               }
                               CurrentPixel.A = (byte)SecondaryColor.A;
                           }
                       }
                       break;
                   // We are making a checkerboard
                   case 1:
                       Odd = true;
                       if ( ((x/GridSize) % 2) == 0) Odd = false;
                       if ( ((y/GridSize) % 2) == 0) Odd = !Odd;
                       if ( Odd ) 
                       {
                           if (!AlphaOnly)
                           {
                               CurrentPixel.R = (byte)PrimaryColor.R;
                               CurrentPixel.G = (byte)PrimaryColor.G;
                               CurrentPixel.B = (byte)PrimaryColor.B;
                           }
                           CurrentPixel.A = (byte)PrimaryColor.A;
                       } 
                       else 
                       {
                           if (!ForegroundOnly)
                           {
                               if (!AlphaOnly)
                               {
                                   CurrentPixel.R = (byte)SecondaryColor.R;
                                   CurrentPixel.G = (byte)SecondaryColor.G;
                                   CurrentPixel.B = (byte)SecondaryColor.B;
                               }
                               CurrentPixel.A = (byte)SecondaryColor.A;
                           }
                       }
                       break;
                   default:
                       break;
               }
               // Save the (modified?) pixel
               dst[x,y] = CurrentPixel;
           }
       }
   }
}

The real key in making a checkerboard is in these two lines:

Odd = true;

if ( ((x/GridSize) % 2) == 0) Odd = false;

if ( ((y/GridSize) % 2) == 0) Odd = !Odd;

That is to say... every even horizontal square (x) is not colored,

but swap that for every even row (y).

That will determine if you need to use the primary or secondary color (black square vs. white square).

**Where % is the remainder of the division function (mod).

So, to simply the code down to just what you need, it would look like this:

void Render(Surface dst, Surface src, Rectangle rect) 
{ 
   int GridSize = 32; 

   PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds); 
   for(int y = rect.Top; y < rect.Bottom; y++) 
   { 
       for (int x = rect.Left; x < rect.Right; x++) 
       { 
           if (selectionRegion.IsVisible(x, y)) 
           { 
               bool Odd = true; 
               if ( ((x/GridSize) % 2) == 0) Odd = false; 
               if ( ((y/GridSize) % 2) == 0) Odd = !Odd; 
               if ( Odd ) dst[x,y] = EnvironmentParameters.PrimaryColor; 
           } 
       } 
   } 
}

0

Share this post


Link to post
Share on other sites

I downloaded 6 new plugins today with no problems. I've had no problem downloading or finding them later, however I can't download this grid maker. Does it go into the effects folder like most plugins do? I've tried all three links. The first one, Download DLL v2.0: GridMaker.dll cannot open because windows doesn't know who created it.

The second and third one, Download Source v1.1: GridSRC.zip and Download Source v2.0: GridSRC_2_0.zip can't be opened by winzip because of this error message:

"Message WZ50

An error occurred opening, writing to, closing, or deleting the specified file. Possible causes include a misspelled filename, a full disk, a read-only or locked disk, a read-only or locked file, or exceeding system limits. The operation in progress will be cancelled. Another dialog box with more specific information may be displayed.

This message may also be displayed because of an invalid archive. For example, if an archive is damaged (possibly due to line noise while downloading from an online service) it may contain invalid data."

What do I need to do to get this plugin? Thanks for your help.

0

Share this post


Link to post
Share on other sites
cannot open because windows doesn't know who created it

Seems like a Internet Explorer security warning.

Right click on the dll file, select Properties, and Press the "Unlock" button at the bottom.

Now OK. That's it. I hope.

0

Share this post


Link to post
Share on other sites

Thanks Bob. I can't find the dll in the effects folder. There are eight gridmaker files in there, but none of them are a dll.

There's one file that's zipped, but I can't open it. Something about the archive being invalid.

This is the only plugin I've had any trouble with, so I'm just going to leave this one alone for now.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0