Jump to content
How to Install Plugins ×

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


Recommended Posts

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

~~

Link to comment
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).

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
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)

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
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; 
           } 
       } 
   } 
}

Link to comment
Share on other sites

  • 2 months later...

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.

KORTECKGOLDGIFSIG455x100.gif
Link to comment
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.

No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio

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

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