Jump to content

Another Problem, while writing plugins with code lap

Recommended Posts


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

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)
               for (int h=0; h<rect.Bottom; h+=Amount2)

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 :)



Link to comment
Share on other sites

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

void Render(Surface dst, Surface src, Rectangle rect)
   Rectangle selection = EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();


   // rest of code goes here

Click to play:
Download: BoltBait's Plugin Pack | CodeLab | and how about a Computer Dominos Game

Link to comment
Share on other sites

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]; 

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.

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