Popular Post toe_head2001 Posted March 13, 2016 Popular Post Share Posted March 13, 2016 (edited) Ruler Effects -> Render-> Ruler Description This will create a ruler of arbitrary length. This will NOT measure anything and will NOT convert pixel length to another unit of length. Change Log v1.0 (March 12, 2016) Initial release Download Ruler.zip Spoiler <--- Icon GPLv3 // Name: Ruler // Submenu: Render // Author: toe_head2001 // Title: // Version: 1.0 // Desc: // Keywords: // URL: // Help: #region UICode byte Amount1 = 0; // Unit|Inches|Feet|Yards|Micrometers|Millimeters|Centimeters|Decimeters|Meters int Amount2 = 12; // [1,100] Ruler Max (Integer) byte Amount3 = 0; // Ruler Max (Fraction)|0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15 byte Amount4 = 0; // |8th|10th|12th|16th int Amount5 = 1; // [1,100] Marker Step int Amount6 = 8; // [1,16] Marker Sub-Units double Amount7 = 1; // [0.1,1] Ruler Width (%) int Amount8 = 50; // [25,50] Ruler Height (px) byte Amount9 = 0; // [1] Position|Bottom|Top bool Amount10 = true; // [0,1] Black and White bool Amount11 = true; // [0,1] Draw Total Length #endregion void Render(Surface dst, Surface src, Rectangle rect) { Color foreColor = Amount10 ? Color.Black : (Color)EnvironmentParameters.PrimaryColor; Color backColor = Amount10 ? Color.White : (Color)EnvironmentParameters.SecondaryColor; Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); bool posTop = (Amount9 == 1); float width = selection.Width * (float)Amount7; float height = Amount8; float offsetX = selection.Left; float offsetY = posTop ? selection.Top : selection.Bottom - height; float leftEdge = offsetX; float rightEdge = leftEdge + width; string unit; switch (Amount1) { case 0: // Inches unit = "in"; break; case 1: // Feet unit = "ft"; break; case 2: //Yards unit = "yd"; break; case 3: // Micrometers unit = "μm"; break; case 4: // Millimeters unit = "mm"; break; case 5: // Centimeters unit = "cm"; break; case 6: // Decimeters unit = "dm"; break; case 7: // Meters unit = "m"; break; default: unit = "in"; break; } int rulerMaxInt = Amount2; float rulerMaxFracDividend = Amount3; float rulerMaxFracDivisor; switch (Amount4) { case 0: // 8th rulerMaxFracDivisor = 8; break; case 1: // 10th rulerMaxFracDivisor = 10; break; case 2: // 12th rulerMaxFracDivisor = 12; break; case 3: // 16th rulerMaxFracDivisor = 16; break; default: rulerMaxFracDivisor = 8; break; } float rulerMax = rulerMaxInt + rulerMaxFracDividend / rulerMaxFracDivisor; int step = Amount5; float stepLength = width / (rulerMax / step); int subUnits = Amount6; float subUnitLength = stepLength / subUnits; dst.CopySurface(src, rect.Location, rect); using (RenderArgs ra = new RenderArgs(dst)) { Graphics ruler = ra.Graphics; ruler.TextRenderingHint = TextRenderingHint.AntiAlias; ruler.Clip = new Region(rect); using (SolidBrush rulerBgBrush = new SolidBrush(backColor)) { ruler.FillRectangle(rulerBgBrush, offsetX, offsetY, width, height); } using (SolidBrush textBrush = new SolidBrush(foreColor)) using (Pen rulerPen = new Pen(foreColor, 2)) using (Font textFont = new Font("Arial", 16, FontStyle.Regular)) { rulerPen.Alignment = System.Drawing.Drawing2D.PenAlignment.Inset; // Draw Ruler Outline ruler.DrawRectangle(rulerPen, offsetX, offsetY, width, height); // Draw Unit float unitOffsetX = leftEdge; float unitOffsetY = (posTop) ? offsetY : offsetY + 1 + height - 25f; ruler.DrawString(unit, textFont, textBrush, unitOffsetX, unitOffsetY); // Draw Total Length if (Amount11) { string rulerMaxString = rulerMaxInt.ToString() + ((rulerMaxFracDividend != 0) ? " - " + rulerMaxFracDividend.ToString() + "/" + rulerMaxFracDivisor.ToString() : ""); string totalLength = "Total Length: " + rulerMaxString + " " + unit; SizeF totalLengthSize = ruler.MeasureString(totalLength, textFont); if (totalLengthSize.Width > width) { totalLength = "Length: " + rulerMaxString + " " + unit; totalLengthSize = ruler.MeasureString(totalLength, textFont); if (totalLengthSize.Width > width) { totalLength = rulerMaxString + " " + unit; totalLengthSize = ruler.MeasureString(totalLength, textFont); } } float totalLengthOffsetX = rightEdge - totalLengthSize.Width; float totalLengthOffsetY = (posTop) ? offsetY + height : offsetY - totalLengthSize.Height; // Dirty Hack to get a text outline ruler.DrawString(totalLength, textFont, textBrush, totalLengthOffsetX + 1, totalLengthOffsetY + 1); ruler.DrawString(totalLength, textFont, textBrush, totalLengthOffsetX - 1, totalLengthOffsetY - 1); ruler.DrawString(totalLength, textFont, textBrush, totalLengthOffsetX + 1, totalLengthOffsetY - 1); ruler.DrawString(totalLength, textFont, textBrush, totalLengthOffsetX - 1, totalLengthOffsetY + 1); ruler.DrawString(totalLength, textFont, textBrush, totalLengthOffsetX + 1, totalLengthOffsetY + 0); ruler.DrawString(totalLength, textFont, textBrush, totalLengthOffsetX - 1, totalLengthOffsetY - 0); ruler.DrawString(totalLength, textFont, textBrush, totalLengthOffsetX + 0, totalLengthOffsetY + 1); ruler.DrawString(totalLength, textFont, textBrush, totalLengthOffsetX - 0, totalLengthOffsetY - 1); textBrush.Color = backColor; ruler.DrawString(totalLength, textFont, textBrush, totalLengthOffsetX, totalLengthOffsetY); ruler.DrawString(totalLength, textFont, textBrush, totalLengthOffsetX, totalLengthOffsetY); textBrush.Color = foreColor; } // Draw Markers for (float i = 0; i <= rulerMax; i += step) { float startX = leftEdge + stepLength * i / step; float endX = startX; float startY = offsetY; float endY = offsetY + height; string numMarker = i.ToString(); SizeF numMarkerSize = ruler.MeasureString(numMarker, textFont); float numMarkerOffsetX = startX - numMarkerSize.Width; float numMarkerOffsetY = (posTop) ? offsetY : offsetY + 1 + height - 25f; ruler.DrawString(numMarker, textFont, textBrush, numMarkerOffsetX, numMarkerOffsetY); if (startX >= rightEdge) break; ruler.DrawLine(rulerPen, startX, startY, endX, endY); // Sub-unit markers rulerPen.Width = 1; for (float i2 = 1; i2 < subUnits; i2++) { startX += subUnitLength; if (startX >= rightEdge - 1) break; endX = startX; startY = (posTop) ? offsetY + height - 1 : offsetY; if (subUnits % 4f == 0) { if (i2 == subUnits / 4f || i2 == subUnits / 4f * 3) endY = (posTop) ? offsetY + height - height * 0.5f : offsetY + height * 0.5f; else if (i2 == subUnits / 2f) endY = (posTop) ? offsetY + height - height * 0.65f : offsetY + height * 0.65f; else endY = (posTop) ? offsetY + height - height * 0.35f : offsetY + height * 0.35f; } else if (subUnits % 2f == 0) { if (i2 == subUnits / 2f) endY = (posTop) ? offsetY + height - height * 0.65f : offsetY + height * 0.65f; else endY = (posTop) ? offsetY + height - height * 0.5f : offsetY + height * 0.5f; } else { endY = (posTop) ? offsetY + height - height * 0.5f : offsetY + height * 0.5f; } ruler.DrawLine(rulerPen, startX, startY, endX, endY); } rulerPen.Width = 2; } } } } Edited August 26, 2016 by toe_head2001 1 11 Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
lynxster4 Posted March 13, 2016 Share Posted March 13, 2016 @ toe_head2001...another interesting plugin! Quote My Art Gallery | My Shape Packs | ShapeMaker Mini Tut | Air Bubble Stained Glass Chrome Text with Reflections | Porcelain Text w/ Variegated Coloring | Realistic Knit PatternOpalescent Stained Glass | Frosted Snowman Cookie | Leather Texture | Plastic Text | Silk Embroidery Visit my Personal Website "Never, ever lose your sense of humor - you'll live longer" Link to comment Share on other sites More sharing options...
Red ochre Posted March 13, 2016 Share Posted March 13, 2016 Thanks & thanks for the codelab code too! Quote Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings Link to comment Share on other sites More sharing options...
Seerose Posted March 13, 2016 Share Posted March 13, 2016 Thanks for your plugin. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi Link to comment Share on other sites More sharing options...
xod Posted March 13, 2016 Share Posted March 13, 2016 A very useful plugin for me. Thanks toe_head2001. I tried to play a little with this code in CodeLab 2.11. But CodeLab working extremely hard even in Windows 10. It freezes for a little time then recovers and so on. I wonder if anyone has the same problem because I tried it on multiple systems with the same results. Quote Link to comment Share on other sites More sharing options...
Lloyd Posted March 13, 2016 Share Posted March 13, 2016 This will be of great use, thanks for creating it Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted March 13, 2016 Author Share Posted March 13, 2016 I tried to play a little with this code in CodeLab 2.11. But CodeLab working extremely hard even in Windows 10. It freezes for a little time then recovers and so on. I wonder if anyone has the same problem because I tried it on multiple systems with the same results. Yes, this is definitely an issue with CodeLab. For some reason CodeLab doesn't like something in the Switch statement for 'unit'; if you delete the code for that Switch, the issue goes away. I think the slow down may be caused by one of the listener events on the Scintilla control. I will try to isolate the issue, and relay my findings to BoltBait. Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Maximilian Posted March 14, 2016 Share Posted March 14, 2016 (edited) Thank you, toe_head, and also thanks for the source code! Edited March 17, 2016 by Maximilian Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted March 17, 2016 Author Share Posted March 17, 2016 Thank you, toe_head, and also thanks for the source code! Attached is a small contribution for owners of the vintage PdN. (My compilation contains a tiny spelling correction, since millimeters takes two ls ) You are free to distribute your own copy (in accordance with the GPLv3), but the official one I had posted is already compatible with paint.net 3.5.11. This was a special case; I usually don't do this. Though I had overlooked that typo. Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
Maximilian Posted March 17, 2016 Share Posted March 17, 2016 Apologies, I thought it wasn't compatible with 3.5.11 and so I compiled the source code. I've edited my previous post to remove that compilation. Quote Link to comment Share on other sites More sharing options...
toe_head2001 Posted March 26, 2016 Author Share Posted March 26, 2016 I tried to play a little with this code in CodeLab 2.11. But CodeLab working extremely hard even in Windows 10. It freezes for a little time then recovers and so on. I was able to find the root of the CodeLab issue. Contrary to my original assumptions, the issue was not caused by my contributed code in v2.11 , as the issue is in older versions too. The good news is that I sent a patch to BoltBait, so it should be resolved when he releases the next version. Quote (September 25th, 2023) Sorry about any broken images in my posts. I am aware of the issue. My Gallery | My Plugin Pack Layman's Guide to CodeLab Link to comment Share on other sites More sharing options...
BoltBait Posted March 26, 2016 Share Posted March 26, 2016 Thanks. That was a tough one to find. I'll post a new version of CodeLab tomorrow. Quote Download: BoltBait's Plugin Pack | CodeLab | and a Free Computer Dominos Game Link to comment Share on other sites More sharing options...
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.