public static void DrawImageToTarget(Graphics graphics, GerberFileInformation fileInfo, GerberUserTransform userTransform, Color foreGroundColor, Color backGroundColor) { bool invert = fileInfo.Inverted; RenderToTarget(graphics, fileInfo.Image, fileInfo.Image.GerberNetList, userTransform, foreGroundColor, backGroundColor, invert); }
private void RenderLayer(Graphics graphics, GerberProject project, RenderInformation renderInfo, int fileIndex) { GerberFileInformation fileInfo = project.FileInfo[fileIndex]; int bmWidth = 0; int bmHeight = 0; // Calculate how big to make the bitmap back buffer. if (renderInfo.ImageWidth < renderInfo.DisplayWidth) { bmWidth = (int)(renderInfo.DisplayWidth * graphics.DpiX); } else { bmWidth = (int)(renderInfo.ImageWidth * graphics.DpiX); } if (renderInfo.ImageHeight < renderInfo.DisplayHeight) { bmHeight = (int)(renderInfo.DisplayHeight * graphics.DpiY); } else { bmHeight = (int)(renderInfo.ImageHeight * graphics.DpiY); } // Create a back buffer and draw to it with no alpha level. using (Bitmap bitmap = new Bitmap(bmWidth, bmHeight, graphics)) using (Graphics backBuffer = Graphics.FromImage(bitmap)) { backBuffer.CompositingMode = CompositingMode.SourceCopy; ScaleAndTranslate(backBuffer, renderInfo); // For testing. /*BoundingBox bb = GetProjectBounds(project); * RectangleF r = new RectangleF((float)bb.Left, (float)bb.Top, (float)(bb.Right - bb.Left), (float)(bb.Top - bb.Bottom)); * GraphicsPath path = new GraphicsPath(); * path.AddLine((float)bb.Left, (float)bb.Bottom, (float)bb.Left, (float)(bb.Top)); * path.AddLine((float)bb.Left, (float)bb.Top, (float)bb.Right, (float)bb.Top); * path.AddLine((float)bb.Right, (float)bb.Top, (float)bb.Right, (float)bb.Bottom); * path.AddLine((float)bb.Right, (float)bb.Bottom, (float)bb.Left, (float)bb.Bottom); * backBuffer.DrawPath(new Pen(Color.FromArgb(117, 200, 0, 0), 0.015f), path); */ // Add transparency to the rendering color. Color foregroundColor = Color.FromArgb(fileInfo.Alpha, fileInfo.Color); GerberDraw.DrawImageToTarget(backBuffer, fileInfo, project.UserTransform, foregroundColor, backgroundColor); // Copy the back buffer to the visible surface with alpha level. graphics.CompositingMode = CompositingMode.SourceOver; graphics.DrawImage(bitmap, 0, 0); } }
/// <summary> /// Changes the order that file layers are rendered. /// </summary> /// <param name="project">project containing the file list</param> /// <param name="oldPosition">from position</param> /// <param name="newPosition">to position</param> public void ChangeLayerOrder(GerberProject project, int oldPosition, int newPosition) { GerberFileInformation tempFileInfo = project.FileInfo[oldPosition]; if (oldPosition < newPosition) { for (int index = oldPosition; index < newPosition; index++) { project.FileInfo[index] = project.FileInfo[index + 1]; } } else { for (int index = oldPosition; index > newPosition; index--) { project.FileInfo[index] = project.FileInfo[index - 1]; } } project.FileInfo[newPosition] = tempFileInfo; }