예제 #1
0
 protected override void OnGLRender(object sender, EventArgs args)
 {
     _pcx.SmoothMode  = SmoothMode.Smooth;
     _pcx.StrokeColor = PixelFarm.Drawing.Color.Blue;
     _pcx.ClearColorBuffer();
     //-------------------------------
     _spriteShape.Paint(_painter);
     //-------------------------------
     SwapBuffers();
 }
예제 #2
0
        static void DrawLion(Painter p, SpriteShape shape)
        {
            shape.Paint(p);

            //int j = shape.NumPaths;
            //int[] pathList = shape.PathIndexList;
            //Color[] colors = shape.Colors;
            //for (int i = 0; i < j; ++i)
            //{
            //    p.FillColor = colors[i];
            //    p.Fill(new VertexStoreSnap(myvxs, pathList[i]));
            //}
        }
예제 #3
0
        protected override void OnGLRender(object sender, EventArgs args)
        {
            _glsx.SmoothMode  = SmoothMode.Smooth;
            _glsx.StrokeColor = PixelFarm.Drawing.Color.Blue;
            _glsx.ClearColorBuffer();
            //-------------------------------

            lionShape.Paint(painter);

            //int j = lionShape.NumPaths;
            //int[] pathList = lionShape.PathIndexList;
            //Color[] colors = lionShape.Colors;
            //VertexStore myvxs = lionVxs;
            //for (int i = 0; i < j; ++i)
            //{
            //    painter.FillColor = colors[i];
            //    painter.Fill(new VertexStoreSnap(myvxs, pathList[i]));
            //}
            //-------------------------------
            SwapBuffers();
        }
예제 #4
0
        public override void Render(PixelFarm.Drawing.Painter p)
        {
            int strokeWidth = 1;
            int width       = p.Width;
            int height      = p.Height;

            Affine affTx = Affine.NewMatix(
                AffinePlan.Translate(-_spriteShape.Center.x, -_spriteShape.Center.y),
                AffinePlan.Scale(_spriteScale, _spriteScale),
                AffinePlan.Rotate(_angle + Math.PI),
                AffinePlan.Skew(_skewX / 1000.0, _skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            var p1 = p as AggPainter;

            if (p1 == null)
            {
                //TODO: review here
                _spriteShape.Paint(p, affTx);
                //int j = lionShape.NumPaths;
                //int[] pathList = lionShape.PathIndexList;
                //Drawing.Color[] colors = lionShape.Colors;
                ////graphics2D.UseSubPixelRendering = true;
                //var vxs = GetFreeVxs();
                //affTx.TransformToVxs(lionShape.Vxs, vxs);
                //p.StrokeWidth = 1;
                //for (int i = 0; i < j; ++i)
                //{
                //    p.StrokeColor = colors[i];
                //    p.Draw(new PixelFarm.Drawing.VertexStoreSnap(vxs, pathList[i]));

                //}
                ////not agg
                //Release(ref vxs);
                //return; //**
            }


            if (UseBitmapExt)
            {
                p.RenderQuality = Drawing.RenderQuality.Fast;
                p.Clear(Drawing.Color.White);
                p.StrokeWidth = 1;

                //-------------------------
                _spriteShape.DrawOutline(p);
            }
            else
            {
                p.RenderQuality = Drawing.RenderQuality.HighQuality;
            }


            //-----------------------
            AggRenderSurface aggsx = p1.RenderSurface;
            //-----------------------
            //TODO: make this reusable ...
            //
            SubBitmapBlender widgetsSubImage    = BitmapBlenderExtension.CreateSubBitmapBlender(aggsx.DestBitmapBlender, aggsx.GetClippingRect());
            SubBitmapBlender clippedSubImage    = new SubBitmapBlender(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage   imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(PixelFarm.Drawing.Color.White);

            AggPainter aggPainter = (AggPainter)p;

            if (RenderAsScanline)
            {
                //a low-level example, expose scanline rasterizer

                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);

                //lionShape.ApplyTransform(affTx);
                //---------------------

                using (VgPaintArgsPool.Borrow(aggPainter, out VgPaintArgs paintArgs))
                {
                    paintArgs._currentTx        = affTx;
                    paintArgs.PaintVisitHandler = (vxs, painterA) =>
                    {
                        //use external painter handler
                        //draw only outline with its fill-color.
                        rasterizer.Reset();
                        rasterizer.AddPath(vxs);
                        aggsx.BitmapRasterizer.RenderWithColor(
                            imageClippingProxy, rasterizer,
                            aggsx.ScanlinePacked8,
                            aggPainter.FillColor); //draw line with external drawing handler
                    };

                    _spriteShape.Paint(paintArgs);
                }

                //----------------------------
                //lionShape.ResetTransform();
            }
            else
            {
                if (UseBuiltInAggOutlineAATech)
                {
                    aggPainter.StrokeWidth       = 1;
                    aggPainter.LineRenderingTech = AggPainter.LineRenderingTechnique.OutlineAARenderer;

                    //------
                    using (VgPaintArgsPool.Borrow(aggPainter, out VgPaintArgs paintArgs))
                    {
                        paintArgs._currentTx        = affTx;
                        paintArgs.PaintVisitHandler = (vxs, painterA) =>
                        {
                            //use external painter handler
                            //draw only outline with its fill-color.
                            Drawing.Painter m_painter       = paintArgs.P;
                            Drawing.Color   prevStrokeColor = m_painter.StrokeColor;
                            m_painter.StrokeColor = m_painter.FillColor;
                            m_painter.Draw(vxs);
                            m_painter.StrokeColor = prevStrokeColor;
                        };
                        _spriteShape.Paint(paintArgs);
                    }
                }
                else
                {
                    //low-level implementation
                    aggPainter.StrokeWidth = 1;

                    //-------------------------
                    //Draw with LineProfile:
                    //LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), new GammaNone()); //with gamma

                    LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), null);
                    OutlineRenderer      outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile);
                    outlineRenderer.SetClipBox(0, 0, this.Width, this.Height);

                    OutlineAARasterizer rasterizer = new OutlineAARasterizer(outlineRenderer);
                    rasterizer.LineJoin = (RenderAccurateJoins ?
                                           OutlineAARasterizer.OutlineJoin.AccurateJoin
                        : OutlineAARasterizer.OutlineJoin.Round);
                    rasterizer.RoundCap = true;

                    //lionShape.ApplyTransform(affTx);
                    //----------------------------
                    using (VgPaintArgsPool.Borrow(aggPainter, out VgPaintArgs paintArgs))
                    {
                        paintArgs._currentTx        = affTx;
                        paintArgs.PaintVisitHandler = (vxs, painterA) =>
                        {
                            //use external painter handler
                            //draw only outline with its fill-color.
                            rasterizer.RenderVertexSnap(
                                vxs,
                                painterA.P.FillColor);
                        };

                        _spriteShape.Paint(paintArgs);
                    }

                    //----------------------------
                    //lionShape.ResetTransform();
                }
            }
        }
예제 #5
0
        public override void Draw(Painter p)
        {
            Painter painter = p;

            if (!_didInit)
            {
                _didInit = true;
                OnInitialize();
            }
            //-----------------------------------
            painter.Clear(Drawing.Color.White);
            //lionFill.Render(painter);

            //IBitmapBlender backBuffer = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect());
            //ChildImage image;
            //if (backBuffer.BitDepth == 32)
            //{
            //    image = new ChildImage(backBuffer, new PixelBlenderBGRA());
            //}
            //else
            //{
            //    if (backBuffer.BitDepth != 24)
            //    {
            //        throw new System.NotSupportedException();
            //    }
            //    image = new ChildImage(backBuffer, new PixelBlenderBGR());
            //}
            //ClipProxyImage dest = new ClipProxyImage(image);
            //gx.Clear(ColorRGBA.White);
            //gx.SetClippingRect(new RectInt(0, 0, Width, Height));
            //ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;
            //-----------------------------------


            RectD lionBound = _lionShape.Bounds;

            if (!_setQuadLion)
            {
                _quadPolygonControl.SetXN(0, lionBound.Left);
                _quadPolygonControl.SetYN(0, lionBound.Top);
                _quadPolygonControl.SetXN(1, lionBound.Right);
                _quadPolygonControl.SetYN(1, lionBound.Top);
                _quadPolygonControl.SetXN(2, lionBound.Right);
                _quadPolygonControl.SetYN(2, lionBound.Bottom);
                _quadPolygonControl.SetXN(3, lionBound.Left);
                _quadPolygonControl.SetYN(3, lionBound.Bottom);
                _setQuadLion = true;
            }
            //
            //
            //Bilinear txBilinear = Bilinear.RectToQuad(lionBound.Left,
            //        lionBound.Bottom,
            //        lionBound.Right,
            //        lionBound.Top,
            //        quadPolygonControl.GetInnerCoords());

            //Ellipse ell = new Ellipse((lionBound.Left + lionBound.Right) * 0.5,
            //                        (lionBound.Bottom + lionBound.Top) * 0.5,
            //                        (lionBound.Right - lionBound.Left) * 0.5,
            //                        (lionBound.Top - lionBound.Bottom) * 0.5,
            //                        200);

            //var v1 = new VertexStore();
            //var trans_ell = new VertexStore();
            //txBilinear.TransformToVxs(ell.MakeVxs(v1), trans_ell);
            ////ell.MakeVxs(v1);
            //painter.FillColor = ColorEx.Make(0.5f, 0.3f, 0.0f, 0.3f);
            //painter.Fill(trans_ell);

            ////outline
            //double prevStrokeWidth = painter.StrokeWidth;
            //painter.StrokeWidth = 3;
            //painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f);
            //painter.Draw(trans_ell);
            //painter.StrokeWidth = prevStrokeWidth;


            if (this.PerspectiveTransformType == Sample_Perspective.PerspectiveTransformType.Bilinear)
            {
                RectD bound = lionBound;
                //transform from original lionBounds to quadPolygon
                Bilinear txBilinear = Bilinear.RectToQuad(
                    bound.Left,
                    bound.Top,
                    bound.Right,
                    bound.Bottom,
                    _quadPolygonControl.GetInnerCoords());

                if (txBilinear.IsValid)
                {
                    using (VxsTemp.Borrow(out var trans_ell_vxs))
                        using (VectorToolBox.Borrow(out Ellipse ellipse))
                        {
                            _lionShape.Paint(painter, txBilinear); //transform before draw
                            //
                            ellipse.Set((lionBound.Left + lionBound.Right) * 0.5,
                                        (lionBound.Bottom + lionBound.Top) * 0.5,
                                        (lionBound.Right - lionBound.Left) * 0.5,
                                        (lionBound.Top - lionBound.Bottom) * 0.5);

                            //ellipse=> transform coord with tx => fill to output
                            ellipse.MakeVxs(txBilinear, trans_ell_vxs);

                            painter.FillColor = _ellipseColor;
                            painter.Fill(trans_ell_vxs);
                            //-------------------------------------------------------------
                            //outline
                            double prevStrokeWidth = painter.StrokeWidth;
                            painter.StrokeWidth = 3;
                            painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f);
                            painter.Draw(trans_ell_vxs);
                            painter.StrokeWidth = prevStrokeWidth;
                        }
                }
            }
            else
            {
                RectD r = lionBound;

                //var txPerspective = new Perspective(
                //   r.Left, r.Bottom, r.Right, r.Top,
                //    quadPolygonControl.GetInnerCoords());

                var txPerspective = new Perspective(
                    r.Left, r.Top, r.Right, r.Bottom,
                    _quadPolygonControl.GetInnerCoords());

                if (txPerspective.IsValid)
                {
                    //lionFill.Draw(p);
                    //lionShape.Paint(p, txPerspective); //transform -> paint

                    //painter.PaintSeries(txPerspective.TransformToVxs(lionShape.Vxs, v1),
                    //  lionShape.Colors,
                    //  lionShape.PathIndexList,
                    //  lionShape.NumPaths);
                    //--------------------------------------------------------------------------------------
                    //filled Ellipse
                    //1. create original fill ellipse
                    //RectD lionBound = lionShape.Bounds;

                    using (VectorToolBox.Borrow(out Ellipse filledEllipse))
                        using (VxsTemp.Borrow(out var trans_ell_vxs))
                        {
                            filledEllipse.Set((lionBound.Left + lionBound.Right) * 0.5,
                                              (lionBound.Bottom + lionBound.Top) * 0.5,
                                              (lionBound.Right - lionBound.Left) * 0.5,
                                              (lionBound.Top - lionBound.Bottom) * 0.5,
                                              200);
                            _lionShape.Paint(painter, txPerspective);

                            //ellipse=> transform coord with tx => fill to output
                            filledEllipse.MakeVxs(txPerspective, trans_ell_vxs);

                            painter.FillColor = ColorEx.Make(0.5f, 0.3f, 0.0f, 0.3f);
                            painter.Fill(trans_ell_vxs);
                            //--------------------------------------------------------
                            double prevStrokeW = painter.StrokeWidth;
                            painter.StrokeWidth = 3;
                            painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f);
                            painter.Draw(trans_ell_vxs);
                            painter.StrokeWidth = prevStrokeW;
                        }
                }
                //}

                ////--------------------------
                //// Render the "quad" tool and controls
                //painter.FillColor = ColorEx.Make(0f, 0.3f, 0.5f, 0.6f);

                //VectorToolBox.GetFreeVxs(out var v4);
                //painter.Fill(quadPolygonControl.MakeVxs(v4));
                //VectorToolBox.ReleaseVxs(ref v4);
            }
        }
예제 #6
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            int strokeWidth = 1;
            int width       = p.Width;
            int height      = p.Height;

            Affine affTx = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(spriteScale, spriteScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            var p1 = p as AggPainter;

            if (p1 == null)
            {
                //TODO: review here

                lionShape.Paint(p, affTx);
                //int j = lionShape.NumPaths;
                //int[] pathList = lionShape.PathIndexList;
                //Drawing.Color[] colors = lionShape.Colors;
                ////graphics2D.UseSubPixelRendering = true;
                //var vxs = GetFreeVxs();
                //affTx.TransformToVxs(lionShape.Vxs, vxs);
                //p.StrokeWidth = 1;
                //for (int i = 0; i < j; ++i)
                //{
                //    p.StrokeColor = colors[i];
                //    p.Draw(new PixelFarm.Drawing.VertexStoreSnap(vxs, pathList[i]));

                //}
                ////not agg
                //Release(ref vxs);
                //return; //**
            }


            if (UseBitmapExt)
            {
                p.RenderQuality = Drawing.RenderQualtity.Fast;
                p.Clear(Drawing.Color.White);
                p.StrokeWidth = 1;

                //-------------------------
                lionShape.DrawOutline(p);
            }
            else
            {
                p.RenderQuality = Drawing.RenderQualtity.HighQuality;
            }



            //-----------------------
            AggRenderSurface aggsx = p1.RenderSurface;
            //var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            //int width = widgetsSubImage.Width;
            //int height = widgetsSubImage.Height;

            SubImageRW     widgetsSubImage    = ImageHelper.CreateSubImgRW(aggsx.DestImage, aggsx.GetClippingRect());
            SubImageRW     clippedSubImage    = new SubImageRW(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(PixelFarm.Drawing.Color.White);


            if (RenderAsScanline)
            {
                ScanlineRasterizer rasterizer = aggsx.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                //Stroke stroke = new Stroke(strokeWidth);
                //stroke.LineJoin = LineJoin.Round;
                lionShape.ApplyTransform(affTx);


                DrawAsScanline(imageClippingProxy, aggsx, rasterizer, aggsx.ScanlineRasToDestBitmap);



                lionShape.ResetTransform();
            }
            else
            {
                //LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), new GammaNone());
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(strokeWidth * affTx.GetScale(), null);
                OutlineRenderer      outlineRenderer = new OutlineRenderer(imageClippingProxy, new PixelBlenderBGRA(), lineProfile);
                OutlineAARasterizer  rasterizer      = new OutlineAARasterizer(outlineRenderer);
                rasterizer.LineJoin = (RenderAccurateJoins ?
                                       OutlineAARasterizer.OutlineJoin.AccurateJoin
                    : OutlineAARasterizer.OutlineJoin.Round);
                rasterizer.RoundCap = true;

                SvgRenderVx renderVx = lionShape.GetRenderVx();

                lionShape.ApplyTransform(affTx);

                DrawWithLineProfile(rasterizer);

                lionShape.ResetTransform();
            }
            base.Draw(p);
        }
예제 #7
0
        public override void Draw(Painter p)
        {
            Painter painter = p;

            if (!didInit)
            {
                didInit = true;
                OnInitialize();
            }


            //-----------------------------------
            painter.Clear(Drawing.Color.White);
            //IImageReaderWriter backBuffer = ImageHelper.CreateChildImage(gx.DestImage, gx.GetClippingRect());
            //ChildImage image;
            //if (backBuffer.BitDepth == 32)
            //{
            //    image = new ChildImage(backBuffer, new PixelBlenderBGRA());
            //}
            //else
            //{
            //    if (backBuffer.BitDepth != 24)
            //    {
            //        throw new System.NotSupportedException();
            //    }
            //    image = new ChildImage(backBuffer, new PixelBlenderBGR());
            //}
            //ClipProxyImage dest = new ClipProxyImage(image);
            //gx.Clear(ColorRGBA.White);
            //gx.SetClippingRect(new RectInt(0, 0, Width, Height));
            //ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;

            if (this.PerspectiveTransformType == Sample_Perspective.PerspectiveTransformType.Bilinear)
            {
                var      bound      = lionShape.Bounds;
                Bilinear txBilinear = Bilinear.RectToQuad(bound.Left,
                                                          bound.Bottom,
                                                          bound.Right,
                                                          bound.Top,
                                                          quadPolygonControl.GetInnerCoords());
                if (txBilinear.IsValid)
                {
                    VectorToolBox.GetFreeVxs(out var v3);
                    lionShape.ApplyTransform(txBilinear);
                    lionShape.Paint(painter);
                    RectD   lionBound = lionShape.Bounds;
                    Ellipse ell       = new Ellipse((lionBound.Left + lionBound.Right) * 0.5,
                                                    (lionBound.Bottom + lionBound.Top) * 0.5,
                                                    (lionBound.Right - lionBound.Left) * 0.5,
                                                    (lionBound.Top - lionBound.Bottom) * 0.5,
                                                    200);
                    VectorToolBox.ReleaseVxs(ref v3);

                    //



                    VectorToolBox.GetFreeVxs(out var v1, out var trans_ell);

                    txBilinear.TransformToVxs(ell.MakeVxs(v1), trans_ell);
                    painter.FillColor = ColorEx.Make(0.5f, 0.3f, 0.0f, 0.3f);
                    painter.Fill(trans_ell);
                    //-------------------------------------------------------------
                    //outline
                    double prevStrokeWidth = painter.StrokeWidth;
                    painter.StrokeWidth = 3;
                    painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f);
                    painter.Draw(trans_ell);
                    painter.StrokeWidth = prevStrokeWidth;


                    VectorToolBox.ReleaseVxs(ref v1, ref trans_ell);
                }
            }
            else
            {
                RectD r = lionShape.Bounds;

                var txPerspective = new Perspective(
                    r.Left, r.Bottom, r.Right, r.Top,
                    quadPolygonControl.GetInnerCoords());
                if (txPerspective.IsValid)
                {
                    lionShape.Paint(p, txPerspective); //transform -> paint

                    //painter.PaintSeries(txPerspective.TransformToVxs(lionShape.Vxs, v1),
                    //  lionShape.Colors,
                    //  lionShape.PathIndexList,
                    //  lionShape.NumPaths);
                    //--------------------------------------------------------------------------------------
                    //filled Ellipse
                    //1. create original fill ellipse
                    RectD lionBound     = lionShape.Bounds;
                    var   filledEllipse = new Ellipse((lionBound.Left + lionBound.Right) * 0.5,
                                                      (lionBound.Bottom + lionBound.Top) * 0.5,
                                                      (lionBound.Right - lionBound.Left) * 0.5,
                                                      (lionBound.Top - lionBound.Bottom) * 0.5,
                                                      200);

                    VectorToolBox.GetFreeVxs(out var v2, out var transformedEll);

                    txPerspective.TransformToVxs(filledEllipse.MakeVxs(v2), transformedEll);
                    painter.FillColor = ColorEx.Make(0.5f, 0.3f, 0.0f, 0.3f);
                    painter.Fill(transformedEll);
                    //--------------------------------------------------------
                    var prevStrokeW = painter.StrokeWidth;
                    painter.StrokeWidth = 3;
                    painter.StrokeColor = ColorEx.Make(0.0f, 0.3f, 0.2f, 1.0f);
                    painter.Draw(transformedEll);
                    painter.StrokeWidth = prevStrokeW;


                    VectorToolBox.ReleaseVxs(ref v2, ref transformedEll);
                }
            }

            //--------------------------
            // Render the "quad" tool and controls
            painter.FillColor = ColorEx.Make(0f, 0.3f, 0.5f, 0.6f);

            VectorToolBox.GetFreeVxs(out var v4);
            painter.Fill(quadPolygonControl.MakeVxs(v4));
            VectorToolBox.ReleaseVxs(ref v4);
        }