Пример #1
0
        public System.Drawing.Rectangle DrawCached(Aurigma.GraphicsMill.Drawing.Graphics g, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion)
        {
            if (!HasActualData(zoom, renderingRegion))
            {
                return(System.Drawing.Rectangle.Empty);
            }

            System.Drawing.Rectangle intersection = System.Drawing.Rectangle.Intersect(renderingRegion, _viewport),
                                     dstRect      = intersection,
                                     srcRect      = intersection;

            srcRect.Offset(-_viewport.X, -_viewport.Y);
            dstRect.Offset(-viewport.X, -viewport.Y);

            g.DrawImage(_image, dstRect, srcRect, Aurigma.GraphicsMill.Transforms.CombineMode.Copy, 1.0f, Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.Low);
            return(intersection);
        }
Пример #2
0
        private void DrawViewportBackground(Aurigma.GraphicsMill.Bitmap canvas, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion)
        {
            using (Aurigma.GraphicsMill.Drawing.Graphics g = canvas.GetGraphics())
            {
                System.Drawing.Rectangle screenRect = renderingRegion;
                screenRect.X -= viewport.X;
                screenRect.Y -= viewport.Y;

                if (_workspaceBackgroundStyle == Aurigma.GraphicsMill.WinControls.WorkspaceBackgroundStyle.Grid)
                {
                    int gridPatternSize = 2 * bgGridCellSize;
                    int patternOffsetX  = renderingRegion.X % gridPatternSize,
                        patternOffsetY  = renderingRegion.Y % gridPatternSize;

                    CreateBackgroundGridTemplate(renderingRegion.Width + gridPatternSize);

                    System.Drawing.Rectangle srcRect = new System.Drawing.Rectangle(0, 0, _bgGridTemplate.Width, _bgGridTemplate.Height),
                                             dstRect = new System.Drawing.Rectangle(renderingRegion.Location, srcRect.Size);
                    dstRect.Offset(-viewport.X, -viewport.Y);
                    dstRect.Offset(-patternOffsetX, -patternOffsetY);

                    g.SetClip(new System.Drawing.Rectangle(renderingRegion.X - viewport.X, renderingRegion.Y - viewport.Y, renderingRegion.Width, renderingRegion.Height));
                    try
                    {
                        int templateRepeats = (int)System.Math.Ceiling((float)(renderingRegion.Height + patternOffsetY) / _bgGridTemplate.Height);
                        for (int j = 0; j < templateRepeats; j++)
                        {
                            g.DrawImage(_bgGridTemplate, dstRect, /*srcRect,*/ Aurigma.GraphicsMill.Transforms.CombineMode.Copy, 1.0f, Aurigma.GraphicsMill.Transforms.ResizeInterpolationMode.NearestNeighbour);
                            dstRect.Offset(0, _bgGridTemplate.Height);
                        }
                    }
                    finally
                    {
                        g.ResetClip();
                    }
                }
                else if (_workspaceBackgroundStyle == Aurigma.GraphicsMill.WinControls.WorkspaceBackgroundStyle.Solid)
                {
                    g.FillRectangle(new Aurigma.GraphicsMill.Drawing.SolidBrush(_workspaceBackColor1), screenRect);
                }
                else
                {
                    g.FillRectangle(new Aurigma.GraphicsMill.Drawing.SolidBrush(_backColor), screenRect);
                }
            }
        }
Пример #3
0
        private void CreateBackgroundGridTemplate(int width)
        {
            if (width < 1)
            {
                throw new System.ArgumentOutOfRangeException("width", StringResources.GetString("ExStrValueShouldBeAboveZero"));
            }
            if (_bgGridTemplate != null && _bgGridTemplate.Width >= width)
            {
                return;
            }

            if (_bgGridTemplate != null)
            {
                _bgGridTemplate.Dispose();
            }

            _bgGridTemplate = new Aurigma.GraphicsMill.Bitmap(width, 2 * bgGridCellSize, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb);

            using (Aurigma.GraphicsMill.Drawing.Graphics g = _bgGridTemplate.GetGraphics())
            {
                Aurigma.GraphicsMill.Drawing.SolidBrush brush0 = new Aurigma.GraphicsMill.Drawing.SolidBrush(_workspaceBackColor1),
                                                        brush1 = new Aurigma.GraphicsMill.Drawing.SolidBrush(_workspaceBackColor2);

                System.Drawing.Rectangle cellRect = new System.Drawing.Rectangle(0, 0, bgGridCellSize, bgGridCellSize);

                int n = (int)System.Math.Ceiling((float)width / (2.0f * bgGridCellSize));
                for (int i = 0; i < n; i++)
                {
                    g.FillRectangle(brush0, cellRect);
                    cellRect.Offset(bgGridCellSize, 0);
                    g.FillRectangle(brush1, cellRect);
                    cellRect.Offset(bgGridCellSize, 0);
                }

                cellRect.Location = new System.Drawing.Point(0, bgGridCellSize);
                for (int i = 0; i < n; i++)
                {
                    g.FillRectangle(brush1, cellRect);
                    cellRect.Offset(bgGridCellSize, 0);
                    g.FillRectangle(brush0, cellRect);
                    cellRect.Offset(bgGridCellSize, 0);
                }
            }
        }
Пример #4
0
        public void Render(Aurigma.GraphicsMill.Bitmap canvas, float zoom, System.Drawing.Rectangle viewport, System.Drawing.Rectangle renderingRegion)
        {
            if (!_layer.Visible || _layer.VObjects.Count < 1)
            {
                return;
            }

            CoordinateMapper coordinateMapper = new CoordinateMapper();

            coordinateMapper.Viewport   = viewport;
            coordinateMapper.Zoom       = zoom;
            coordinateMapper.Resolution = _renderingResolution;

            renderingRegion.X -= viewport.X;
            renderingRegion.Y -= viewport.Y;

            System.IntPtr           dc    = System.IntPtr.Zero;
            System.IntPtr           oldDc = System.IntPtr.Zero;
            System.Drawing.Graphics g     = null;
            Aurigma.GraphicsMill.Drawing.Graphics gdiGraphics = null;

            try
            {
                // Read MSDN KB article "GDI & GDI+ interoperability". We should create System.Drawing.Graphics
                // from DC, not from Bitmap to avoid getting sentinel bitmap. Otherwise we will not be able to
                // blend images using Aurigma.GraphicsMill.Bitmap.Draw(System.Drawing.Graphics g, ...) method.
                //
                // The first branch is used when we render to the screen. In this case canvas has 24bppRgb format
                // and we just use its GDI graphics (most probably it has been already created by caching renderer) to
                // obtain HDC. Second branch is used when we render control content to 32bppArgb image - in such case
                // we cannot create GDI graphics and have to manually create DC and select canvas.Handle into it.
                if (canvas.PixelFormat == PixelFormat.Format24bppRgb)
                {
                    gdiGraphics = canvas.GetGraphics();
                    g           = System.Drawing.Graphics.FromHdc(gdiGraphics.GetDC());
                }
                else
                {
                    dc = NativeMethods.CreateCompatibleDC(System.IntPtr.Zero);

                    if (dc == System.IntPtr.Zero)
                    {
                        throw new Aurigma.GraphicsMill.UnexpectedException(StringResources.GetString("Cannot create compatible DC."));
                    }

                    g = System.Drawing.Graphics.FromHdc(dc);
                }

                g.SetClip(renderingRegion);

                for (int i = 0; i < _layer.VObjects.Count; i++)
                {
                    System.Drawing.Rectangle bounds = coordinateMapper.WorkspaceToControl(_layer.VObjects[i].GetTransformedVObjectBounds(), Aurigma.GraphicsMill.Unit.Point);

                    if (bounds.IntersectsWith(renderingRegion))
                    {
                        _layer.VObjects[i].Draw(renderingRegion, g, coordinateMapper);
                    }
                }
            }
            finally
            {
                if (g != null)
                {
                    g.Dispose();
                }

                if (gdiGraphics != null)
                {
                    gdiGraphics.Dispose();
                }

                if (dc != System.IntPtr.Zero)
                {
                    NativeMethods.SelectObject(dc, oldDc);
                    NativeMethods.DeleteDC(dc);
                }
            }
        }