Illnab1024 Posted October 9, 2006 Posted October 9, 2006 (edited) 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. 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.dllDownload Source v1.1: GridSRC.zip Download Source v2.0: GridSRC_2_0.zip BoltBait is again responsible for the Render Function, whereas I did the niceties of a UI. Edited July 3, 2014 by BoltBait Updated for Paint.NET 4.0 Quote ~~
Rick Brewster Posted October 9, 2006 Posted October 9, 2006 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). Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
Illnab1024 Posted October 9, 2006 Author Posted October 9, 2006 Good Idea! I'll get onto that right quick. Quote ~~
BoltBait Posted October 9, 2006 Posted October 9, 2006 What if you move your forum? Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
Illnab1024 Posted October 9, 2006 Author Posted October 9, 2006 I don't think that's happening anytime soon... Quote ~~
BoltBait Posted October 9, 2006 Posted October 9, 2006 Perhaps if Rick setup a redirector like: http://www.getpaint.net/plugins Or, something like that. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
Rick Brewster Posted October 9, 2006 Posted October 9, 2006 Already a step ahead of you. http://www.getpaint.net/redirect/plugins.html Just link to that. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
Illnab1024 Posted October 9, 2006 Author Posted October 9, 2006 Version 1.1 Released, Link to Plugins forum added. Quote ~~
Rick Brewster Posted October 9, 2006 Posted October 9, 2006 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) Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html
Illnab1024 Posted October 9, 2006 Author Posted October 9, 2006 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 Quote ~~
Hellfire010 Posted October 10, 2006 Posted October 10, 2006 Thanks for this, it really helped me (i'm slightly numercally challanged ) xD Quote
Austin Spafford Posted October 25, 2006 Posted October 25, 2006 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... -Austin Spafford Quote
barkbark00 Posted October 26, 2006 Posted October 26, 2006 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... Quote Take responsibility for your own intelligence. 😉 -Rick Brewster
BoltBait Posted October 26, 2006 Posted October 26, 2006 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. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
barkbark00 Posted October 26, 2006 Posted October 26, 2006 Gridgod(er...BoltBait), Would there be a way to add an adjustment that effected pixel thickness or maybe even a thickness percentage? Quote Take responsibility for your own intelligence. 😉 -Rick Brewster
BoltBait Posted October 26, 2006 Posted October 26, 2006 barkbark00, I'll see if I have access to Brush Width... Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
barkbark00 Posted October 26, 2006 Posted October 26, 2006 That would be cool! Quote Take responsibility for your own intelligence. 😉 -Rick Brewster
BoltBait Posted October 26, 2006 Posted October 26, 2006 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. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
barkbark00 Posted October 26, 2006 Posted October 26, 2006 Sweet! Quote Take responsibility for your own intelligence. 😉 -Rick Brewster
Illnab1024 Posted October 26, 2006 Author Posted October 26, 2006 Updated. Go see for yourself. 1 Quote ~~
Austin Spafford Posted October 27, 2006 Posted October 27, 2006 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 Quote
BoltBait Posted October 27, 2006 Posted October 27, 2006 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; } } } } Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game
korteck Posted January 1, 2007 Posted January 1, 2007 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. Quote
Bob Posted January 1, 2007 Posted January 1, 2007 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. Quote No. Way. I've just seen Bob. And... *poof!*—just like that—he disappears into the mist again. ~Helio
korteck Posted January 1, 2007 Posted January 1, 2007 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.