예제 #1
0
        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);
                }
        }
예제 #2
0
        /// <summary>
        /// Draw the user selection layer;
        /// </summary>
        /// <param name="graphics">surface to render the image</param>
        /// <param name="project">project containing the files to render</param>
        /// <param name="renderInfo">information for positioning, scaling and translating</param>
        /// <param name="selectionInfo">information about the users selection</param>
        public void RenderSelectionLayer(Graphics graphics, GerberProject project, RenderInformation renderInfo, SelectionInformation selectionInfo)
        {
            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.SourceOver;
                    ScaleAndTranslate(backBuffer, renderInfo);
                    Color foregroundColor = Color.FromArgb(177, Color.White);
                    GerberDraw.DrawImageToTarget(backBuffer, selectionInfo, project.UserTransform, foregroundColor, backgroundColor);
                    // Copy the back buffer to the visible surface with alpha level.
                    graphics.CompositingMode = CompositingMode.SourceOver;
                    graphics.DrawImage(bitmap, 0, 0);
                }
        }