AhmedElyamani Posted December 6, 2011 Share Posted December 6, 2011 Hello, I've been writing plugins with Code Lap , to learn more and to practice.. any way i wrote these Lines To Render Gird lines.. #region UICode int Amount1 = 10; // [0,100] Width int Amount2 = 10; // [0,100] Height ColorBgra Amount3 = ColorBgra.FromBgr(0,0,0); // Color #endregion void Render(Surface dst, Surface src, Rectangle rect) { // Declerations Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); Graphics g = new RenderArgs(dst).Graphics; System.Drawing.Pen mypen= new System.Drawing.Pen(Amount3); //Grid Lines for (int w=0; w<rect.Right; w+=Amount1) g.DrawLine(mypen,w,0,w,rect.Bottom); for (int h=0; h<rect.Bottom; h+=Amount2) g.DrawLine(mypen,0,h,rect.Right,h); } Simple code, Any way it renders fine , for the first time , but when i edit the Settings it renders again above the old one, and so on What i need is to render these lines only once, when the user edits the settings it shall only edit the current lines not render other lines, Got me? I know this may be a stupid question , but please be patient with me .. i'm just a beggener learning Thanks Ahmed Quote Link to comment Share on other sites More sharing options...
BoltBait Posted December 6, 2011 Share Posted December 6, 2011 You need to review the section on text: http://boltbait.com/pdn/CodeLab/help/tutorial4.asp Specifically the first part... The first thing we need to do is make sure that all pixels are copied from the source canvas to the destination canvas. We can do that with a single line of code. Just use CopySurface #region UICode #endregion void Render(Surface dst, Surface src, Rectangle rect) { Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt(); dst.CopySurface(src,rect.Location,rect); // rest of code goes here } Quote Click to play: Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game Link to comment Share on other sites More sharing options...
Ego Eram Reputo Posted December 7, 2011 Share Posted December 7, 2011 Think of the canvas as a whiteboard. You're drawing multiple times on it (each time you change the settings) without erasing the old stuff first. As BoltBait said, you need to copy the source surface to the destination surface before rendering anything new to the destination. This effectively erases any previous renderings your plugin may have done. BoltBait's suggested use of CopySurface is much more elegant than the way I used to do it: // Clear the canvas by copying existing image (source) to destination for(int y = rect.Top; y < rect.Bottom; y++) for (int x = rect.Left; x < rect.Right; x++) dst[x,y] = src[x,y]; Quote ebook: Mastering Paint.NET | resources: Plugin Index | Stereogram Tut | proud supporter of Codelab plugins: EER's Plugin Pack | Planetoid | StickMan | WhichSymbol+ | Dr Scott's Markup Renderer | CSV Filetype | dwarf horde plugins: Plugin Browser | ShapeMaker Link to comment Share on other sites More sharing options...
AhmedElyamani Posted December 7, 2011 Author Share Posted December 7, 2011 Ah, Now i got it .. Thanks A lot ! Quote Link to comment Share on other sites More sharing options...
Rick Brewster Posted December 7, 2011 Share Posted December 7, 2011 BoltBait's suggested use of CopySurface is much more elegant than the way I used to do it: :O Not to mention about 100x faster! Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html 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.