Ejemplo n.º 1
0
        public void DrawBuffer(IDrawingGraphics drawingGraphics)
        {
            //var dstTop = (drawingGraphics.VisibleRect.Top > 0) ? 0 : drawingGraphics.VisibleRect.Top;
            var dstTop = Math.Max(0, drawingGraphics.CalculateY(0));
            var dstLeft = drawingGraphics.CalculateX(this.Location.X);
            var srcTop = (drawingGraphics.VisibleRect.Top > 0) ? drawingGraphics.VisibleRect.Top : 0;
            var dstWidth = _buffer.Image.Width;
            var height = this.Parent.Size.Height;

            //drawingGraphics.DrawImage(_buffer.Image, 0, 0);
            //return;
            drawingGraphics.Graphics.DrawImage(_buffer.Image,
                dstLeft, dstTop,
                new Rectangle(0, srcTop, dstWidth, height), GraphicsUnit.Pixel);
            return;

            var hSrc = _buffer.Graphics.GetHdc();
            var hDst = drawingGraphics.Graphics.GetHdc();

            /*
            var blendFunction = new BlendFunction
            {
                BlendOp = (byte)BlendOperation.AcSrcOver,
                BlendFlags = (byte)BlendFlags.Zero,
                SourceConstantAlpha = 100,
                AlphaFormat = 0
            };

            DrawingAPI.AlphaBlend(hDst, 0, -drawingGraphics.VisibleRect.Top, Size.Width, Size.Height, hSrc,
                0, 0, Size.Width, Size.Height, blendFunction);

             */

            DrawingAPI.BitBlt(hDst,
                dstLeft, dstTop,
                dstWidth, height,
                hSrc,
                0, srcTop,
                DrawingAPI.SRCCOPY
                );

            //DrawingAPI.BitBlt(hDst, 0, -drawingGraphics.VisibleRect.Top, Size.Width, Size.Height,
            //    hSrc, 0, 0,
            //    DrawingAPI.SRCCOPY
            //    );

            /*
            BitmapData a = _buffer.Image.LockBits(new Rectangle(0, 0, Size.Width, Size.Height), ImageLockMode.ReadOnly,
                                           (PixelFormat) PixelFormatID.PixelFormat32bppARGB);
            var factory = (IImagingFactory)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("327ABDA8-072B-11D3-9D7B-0000F81EF32E")));
            IImage image;
            factory.CreateImageFromBuffer(a.Scan0, a., BufferDisposalFlag.BufferDisposalFlagNone, image);

            _buffer.Image.UnlockBits(a);
            */

            _buffer.Graphics.ReleaseHdc(hSrc);
            drawingGraphics.Graphics.ReleaseHdc(hDst);
        }
Ejemplo n.º 2
0
        public override void Draw(IDrawingGraphics drawingGraphics)
        {
            var dg = drawingGraphics;
            if (this.clipBitmap == null)
            {
                this.clipBitmap = new Bitmap(this.Size.Width.ToPixels(), this.Size.Height.ToPixels()-1); // TODO roundup errors!
            }
            if (CachePanning && panInProgress && this.clipBitmap != null)
            {
                drawingGraphics.Graphics.DrawImage(this.clipBitmap, drawingGraphics.CalculateX(this.HorizontalOffset - this.panH), drawingGraphics.CalculateY(this.VerticalOffset - this.panV));
            }else
            {
            using (var clipBitmap = drawingGraphics.GetClipBuffer(new Rectangle(0, 0, this.Size.Width, this.Size.Height), this.clipBitmap))
            {
                /* Do shadows */
                if (this.DrawShadows)
                {
                    if (TopShadow == null)
                    {
                        TopShadow = new Bitmap(this.Size.Width.ToPixels(), drawingGraphics.CalculateHeight(ShadowHeight));
                        BottomShadow = new Bitmap(this.Size.Width.ToPixels(), drawingGraphics.CalculateHeight(ShadowHeight));
                    }
                    if (this.VerticalOffset < 0)
                    {
                        drawingGraphics.GetOpaqueClipBuffer(new Rectangle(0, 0, this.Size.Width, this.ShadowHeight), TopShadow).Dispose();
                    }
                    if (this.VerticalOffset > Math.Min(0, -this.Content.Size.Height + this.Size.Height))
                    {
                        drawingGraphics.GetOpaqueClipBuffer(new Rectangle(0, this.Size.Height + 1 - ShadowHeight,
                                                                          this.Size.Width, ShadowHeight), BottomShadow).Dispose();
                    }
                }

                this.Content.Draw(clipBitmap.DrawingGr.CreateChild(new Point(this.HorizontalOffset, this.VerticalOffset),
                                                                   this.content.TransformationScaling, this.content.TransformationCenter));
                if (this.ShowScrollbars)
                {
                    this.DrawScrollBar(clipBitmap.DrawingGr);
                }
            }
            }

            if (this.DrawShadows)
            {
                if (this.VerticalOffset < 0)
                {
                    int cheight = 0;
                    for(int s = 0; s < ShadowSteps; s++)
                    {
                        drawingGraphics.Graphics.AlphaBlend(TopShadow,
                          new Rectangle(dg.CalculateX(0), dg.CalculateY(0)+cheight, TopShadow.Width, TopShadow.Height/ShadowSteps),
                          new Rectangle(0, cheight, TopShadow.Width, TopShadow.Height/ShadowSteps), 0.95f - 1f/(ShadowSteps+2)*s);
                        cheight += TopShadow.Height/ShadowSteps;
                    }
                }
                if (this.VerticalOffset > Math.Min(0, -this.Content.Size.Height + this.Size.Height))
                {
                    int cheight = 0;
                    for(int s = 0; s < ShadowSteps; s++)
                    {
                        drawingGraphics.Graphics.AlphaBlend(BottomShadow,
                          new Rectangle(dg.CalculateX(0), dg.CalculateY(this.Size.Height-ShadowHeight)+cheight, BottomShadow.Width, BottomShadow.Height/ShadowSteps),
                          new Rectangle(0, cheight, BottomShadow.Width, BottomShadow.Height/ShadowSteps), 1f/(ShadowSteps+2)*(s+2));
                        cheight += BottomShadow.Height/ShadowSteps;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override void Draw(IDrawingGraphics drawingGraphics)
        {
            var dg = drawingGraphics;

            if (this.clipBitmap == null)
            {
                this.clipBitmap = new Bitmap(this.Size.Width.ToPixels(), this.Size.Height.ToPixels() - 1); // TODO roundup errors!
            }
            if (CachePanning && panInProgress && this.clipBitmap != null)
            {
                drawingGraphics.Graphics.DrawImage(this.clipBitmap, drawingGraphics.CalculateX(this.HorizontalOffset - this.panH), drawingGraphics.CalculateY(this.VerticalOffset - this.panV));
            }
            else
            {
                using (var clipBitmap = drawingGraphics.GetClipBuffer(new Rectangle(0, 0, this.Size.Width, this.Size.Height), this.clipBitmap))
                {
                    /* Do shadows */
                    if (this.DrawShadows)
                    {
                        if (TopShadow == null)
                        {
                            TopShadow    = new Bitmap(this.Size.Width.ToPixels(), drawingGraphics.CalculateHeight(ShadowHeight));
                            BottomShadow = new Bitmap(this.Size.Width.ToPixels(), drawingGraphics.CalculateHeight(ShadowHeight));
                        }
                        if (this.VerticalOffset < 0)
                        {
                            drawingGraphics.GetOpaqueClipBuffer(new Rectangle(0, 0, this.Size.Width, this.ShadowHeight), TopShadow).Dispose();
                        }
                        if (this.VerticalOffset > Math.Min(0, -this.Content.Size.Height + this.Size.Height))
                        {
                            drawingGraphics.GetOpaqueClipBuffer(new Rectangle(0, this.Size.Height + 1 - ShadowHeight,
                                                                              this.Size.Width, ShadowHeight), BottomShadow).Dispose();
                        }
                    }

                    this.Content.Draw(clipBitmap.DrawingGr.CreateChild(new Point(this.HorizontalOffset, this.VerticalOffset),
                                                                       this.content.TransformationScaling, this.content.TransformationCenter));
                    if (this.ShowScrollbars)
                    {
                        this.DrawScrollBar(clipBitmap.DrawingGr);
                    }
                }
            }

            if (this.DrawShadows)
            {
                if (this.VerticalOffset < 0)
                {
                    int cheight = 0;
                    for (int s = 0; s < ShadowSteps; s++)
                    {
                        drawingGraphics.Graphics.AlphaBlend(TopShadow,
                                                            new Rectangle(dg.CalculateX(0), dg.CalculateY(0) + cheight, TopShadow.Width, TopShadow.Height / ShadowSteps),
                                                            new Rectangle(0, cheight, TopShadow.Width, TopShadow.Height / ShadowSteps), 0.95f - 1f / (ShadowSteps + 2) * s);
                        cheight += TopShadow.Height / ShadowSteps;
                    }
                }
                if (this.VerticalOffset > Math.Min(0, -this.Content.Size.Height + this.Size.Height))
                {
                    int cheight = 0;
                    for (int s = 0; s < ShadowSteps; s++)
                    {
                        drawingGraphics.Graphics.AlphaBlend(BottomShadow,
                                                            new Rectangle(dg.CalculateX(0), dg.CalculateY(this.Size.Height - ShadowHeight) + cheight, BottomShadow.Width, BottomShadow.Height / ShadowSteps),
                                                            new Rectangle(0, cheight, BottomShadow.Width, BottomShadow.Height / ShadowSteps), 1f / (ShadowSteps + 2) * (s + 2));
                        cheight += BottomShadow.Height / ShadowSteps;
                    }
                }
            }
        }