Пример #1
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (myvxs == null)
            {
                var transform = 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)
                    );
                //create vertextStore again from origiinal path
                myvxs = transform.TransformToVxs(lionShape.Path.Vxs);
            }
            //---------------------------------------------------------------------------------------------
            {
                int         j        = lionShape.NumPaths;
                int[]       pathList = lionShape.PathIndexList;
                ColorRGBA[] colors   = lionShape.Colors;
                //graphics2D.UseSubPixelRendering = true;

                for (int i = 0; i < j; ++i)
                {
                    graphics2D.Render(new VertexStoreSnap(myvxs, pathList[i]), colors[i]);
                }
            }
            //---------------------------------------------------------------------------------------------
        }
Пример #2
0
        public override void Render(PixelFarm.Drawing.Painter p)
        {
            if (_currentTx == null)
            {
                _currentTx = 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)
                    );
            }

            if (JustMove)
            {
                float ox = p.OriginX;
                float oy = p.OriginY;

                p.SetOrigin(ox + _posX, oy + _posY);
                _spriteShape.Paint(p);
                p.SetOrigin(ox, oy);
            }
            else
            {
                _spriteShape.Paint(p, _currentTx);
            }
        }
Пример #3
0
        public void Draw(PixelFarm.DrawingGL.CanvasGL2d canvas)
        {
            if (myvxs == null)
            {
                var transform = 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)
                    );
                myvxs = transform.TransformToVxs(lionShape.Path.Vxs);
            }
            //---------------------------------------------------------------------------------------------
            {
                int         j        = lionShape.NumPaths;
                int[]       pathList = lionShape.PathIndexList;
                ColorRGBA[] colors   = lionShape.Colors;
                //graphics2D.UseSubPixelRendering = true;

                for (int i = 0; i < j; ++i)
                {
                    var color = colors[i];
                    //?
                    canvas.FillVxsSnap(
                        new PixelFarm.Drawing.Color(color.alpha, color.blue, color.green, color.red),
                        new VertexStoreSnap(myvxs, pathList[i]));
                }
            }
        }
Пример #4
0
        void DrawWithWinGdi(GdiPlusPainter p)
        {
            int w = 800, h = 600;

            p.Clear(Drawing.Color.White);
            p.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
            if (isMaskSliderValueChanged)
            {
                GenerateMaskWithWinGdiPlus(w, h);
            }

            using (System.Drawing.Bitmap background = CreateBackgroundBmp(w, h))
            {
                p.DrawImage(background, 0, 0);
            }

            //draw lion on background
            Affine transform = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(lionScale, lionScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(w / 2, h / 2));

            using (System.Drawing.Bitmap lionBmp = new System.Drawing.Bitmap(w, h))
                using (System.Drawing.Graphics lionGfx = System.Drawing.Graphics.FromImage(lionBmp))
                {
                    //lionGfx.Clear(System.Drawing.Color.White);
                    //int n = lionShape.NumPaths;
                    //int[] indexList = lionShape.PathIndexList;


                    //TODO: review here again
                    throw new NotSupportedException();

                    //Color[] colors = lionShape.Colors;
                    ////var lionVxs = lionShape.Path.Vxs;// transform.TransformToVxs(lionShape.Path.Vxs);

                    //var lionVxs = new VertexStore();
                    //transform.TransformToVxs(lionShape.Vxs, lionVxs);
                    //for (int i = 0; i < n; ++i)
                    //{
                    //    VxsHelper.FillVxsSnap(lionGfx,
                    //        new VertexStoreSnap(lionVxs, indexList[i]),
                    //        colors[i]);
                    //}
                    //using (var mergeBmp = MergeAlphaChannel(lionBmp, a_alphaBmp))
                    //{
                    //    //gx.InternalGraphics.DrawImage(this.a_alphaBmp, new System.Drawing.PointF(0, 0));
                    //    //gx.InternalGraphics.DrawImage(bmp, new System.Drawing.PointF(0, 0));
                    //    p.DrawImage(mergeBmp, 0, 0);
                    //}
                }
        }
Пример #5
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            if (myvxs == null)
            {
                var transform = 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)
                    );
                //create vertextStore again from original path
                myvxs = new VertexStore();

                transform.TransformToVxs(lionShape.Vxs, myvxs);

                if (AutoFlipY)
                {
                    //flip the lion
                    PixelFarm.Agg.Transform.Affine aff = PixelFarm.Agg.Transform.Affine.NewMatix(
                        PixelFarm.Agg.Transform.AffinePlan.Scale(-1, -1),
                        PixelFarm.Agg.Transform.AffinePlan.Translate(0, 600));
                    //
                    var v2 = new VertexStore();
                    myvxs = transform.TransformToVxs(myvxs, v2);
                }
            }
            //---------------------------------------------------------------------------------------------
            {
                int             j        = lionShape.NumPaths;
                int[]           pathList = lionShape.PathIndexList;
                Drawing.Color[] colors   = lionShape.Colors;
                //graphics2D.UseSubPixelRendering = true;
                for (int i = 0; i < j; ++i)
                {
                    p.FillColor = colors[i];
                    p.Fill(new VertexStoreSnap(myvxs, pathList[i]));
                }
            }
            //test
            if (SharpenRadius > 0)
            {
                //p.DoFilter(new RectInt(0, p.Height, p.Width, 0), 2);
                //PixelFarm.Agg.Imaging.SharpenFilterARGB.Sharpen()
            }
        }
Пример #6
0
        public override void Draw(CanvasPainter p)
        {
            if (p is GdiPlusCanvasPainter)
            {
                DrawWithWinGdi((GdiPlusCanvasPainter)p);
                return;
            }
            AggCanvasPainter p2 = (AggCanvasPainter)p;
            Graphics2D       gx = p2.Graphics;
            var widgetsSubImage = gx.DestImage;
            var scline          = gx.ScanlinePacked8;
            int width           = (int)widgetsSubImage.Width;
            int height          = (int)widgetsSubImage.Height;

            //change value ***
            if (isMaskSliderValueChanged)
            {
                generate_alpha_mask(gx.ScanlineRasToDestBitmap, gx.ScanlinePacked8, gx.ScanlineRasterizer, width, height);
                this.isMaskSliderValueChanged = false;
            }
            var rasterizer = gx.ScanlineRasterizer;

            rasterizer.SetClipBox(0, 0, width, height);
            //alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 0, width, height, width, 8, 1);

            PixelFarm.Agg.Imaging.AlphaMaskAdaptor imageAlphaMaskAdaptor = new PixelFarm.Agg.Imaging.AlphaMaskAdaptor(widgetsSubImage, alphaMask);
            ClipProxyImage alphaMaskClippingProxy = new ClipProxyImage(imageAlphaMaskAdaptor);
            ClipProxyImage clippingProxy          = new ClipProxyImage(widgetsSubImage);
            ////Affine transform = Affine.NewIdentity();
            ////transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
            ////transform *= Affine.NewScaling(lionScale, lionScale);
            ////transform *= Affine.NewRotation(angle + Math.PI);
            ////transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0);
            ////transform *= Affine.NewTranslation(Width / 2, Height / 2);
            Affine transform = Affine.NewMatix(
                AffinePlan.Translate(-lionShape.Center.x, -lionShape.Center.y),
                AffinePlan.Scale(lionScale, lionScale),
                AffinePlan.Rotate(angle + Math.PI),
                AffinePlan.Skew(skewX / 1000.0, skewY / 1000.0),
                AffinePlan.Translate(width / 2, height / 2));

            clippingProxy.Clear(Drawing.Color.White);
            ScanlineRasToDestBitmapRenderer sclineRasToBmp = gx.ScanlineRasToDestBitmap;
            // draw a background to show how the mask is working better
            int rect_w = 30;
            var v1     = GetFreeVxs();

            for (int i = 0; i < 40; i++)
            {
                for (int j = 0; j < 40; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * rect_w, j * rect_w, (i + 1) * rect_w, (j + 1) * rect_w, 0);
                        rect.NormalizeRadius();
                        // Drawing as an outline
                        rasterizer.AddPath(rect.MakeVxs(v1));
                        v1.Clear();
                        sclineRasToBmp.RenderWithColor(clippingProxy, rasterizer, scline, Drawing.Color.Make(.9f, .9f, .9f));
                    }
                }
            }
            ReleaseVxs(ref v1);
            ////int x, y;
            //// Render the lion
            ////VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);

            ////var vxlist = new System.Collections.Generic.List<VertexData>();
            ////trans.DoTransform(vxlist);

            var tmpVxs1 = new VertexStore();

            transform.TransformToVxs(lionShape.Path.Vxs, tmpVxs1);

            sclineRasToBmp.RenderSolidAllPaths(alphaMaskClippingProxy,
                                               rasterizer,
                                               scline,
                                               tmpVxs1,
                                               lionShape.Colors,
                                               lionShape.PathIndexList,
                                               lionShape.NumPaths);
            ///*
            //// Render random Bresenham lines and markers
            //agg::renderer_markers<amask_ren_type> m(r);
            //for(i = 0; i < 50; i++)
            //{
            //    m.line_color(agg::rgba8(randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            (randGenerator.Next() & 0x7F) + 0x7F));
            //    m.fill_color(agg::rgba8(randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            randGenerator.Next() & 0x7F,
            //                            (randGenerator.Next() & 0x7F) + 0x7F));

            //    m.line(m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height),
            //           m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height));

            //    m.marker(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 10 + 5,
            //             agg::marker_e(randGenerator.Next() % agg::end_of_markers));
            //}


            //// Render random anti-aliased lines
            //double w = 5.0;
            //agg::line_profile_aa profile;
            //profile.width(w);

            //typedef agg::renderer_outline_aa<amask_ren_type> renderer_type;
            //renderer_type ren(r, profile);

            //typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
            //rasterizer_type ras(ren);
            //ras.round_cap(true);

            //for(i = 0; i < 50; i++)
            //{
            //    ren.Color = agg::rgba8(randGenerator.Next() & 0x7F,
            //                         randGenerator.Next() & 0x7F,
            //                         randGenerator.Next() & 0x7F,
            //                         //255));
            //                         (randGenerator.Next() & 0x7F) + 0x7F);
            //    ras.move_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
            //    ras.line_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
            //    ras.render(false);
            //}


            //// Render random circles with gradient
            //typedef agg::gradient_linear_color<color_type> grad_color;
            //typedef agg::gradient_circle grad_func;
            //typedef agg::span_interpolator_linear<> interpolator_type;
            //typedef agg::span_gradient<color_type,
            //                          interpolator_type,
            //                          grad_func,
            //                          grad_color> span_grad_type;

            //agg::trans_affine grm;
            //grad_func grf;
            //grad_color grc(agg::rgba8(0,0,0), agg::rgba8(0,0,0));
            //agg::ellipse ell;
            //agg::span_allocator<color_type> sa;
            //interpolator_type inter(grm);
            //span_grad_type sg(inter, grf, grc, 0, 10);
            //agg::renderer_scanline_aa<amask_ren_type,
            //                          agg::span_allocator<color_type>,
            //                          span_grad_type> rg(r, sa, sg);
            //for(i = 0; i < 50; i++)
            //{
            //    x = randGenerator.Next() % width;
            //    y = randGenerator.Next() % height;
            //    double r = randGenerator.Next() % 10 + 5;
            //    grm.reset();
            //    grm *= agg::trans_affine_scaling(r / 10.0);
            //    grm *= agg::trans_affine_translation(x, y);
            //    grm.invert();
            //    grc.colors(agg::rgba8(255, 255, 255, 0),
            //               agg::rgba8(randGenerator.Next() & 0x7F,
            //                          randGenerator.Next() & 0x7F,
            //                          randGenerator.Next() & 0x7F,
            //                          255));
            //    sg.color_function(grc);
            //    ell.init(x, y, r, r, 32);
            //    g_rasterizer.add_path(ell);
            //    agg::render_scanlines(g_rasterizer, g_scanline, rg);
            //}
            // */
            ////m_num_cb.Render(g_rasterizer, g_scanline, clippingProxy);
        }
Пример #7
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();
                }
            }
        }
Пример #8
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            //freeze to bitmap ?

            if (vxStorage == null)
            {
                var transform = 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)
                    );

                //convert
                //System.Collections.Generic.List<VertexData> list = new System.Collections.Generic.List<VertexData>();
                vxStorage = transform.TransformToVxs(lionShape.Path.Vxs);
                //transformedPathStorage = new VertexSourceApplyTransform(lionShape.Path, transform);
                //transformedPathStorage.DoTransform(list);

                //vxStorage = new VertexStorage(list);
            }

            //-----------------------------------------------------------------------------------
            {
                int         j        = lionShape.NumPaths;
                int[]       pathList = lionShape.PathIndexList;
                ColorRGBA[] colors   = lionShape.Colors;
                for (int i = 0; i < j; ++i)
                {
                    graphics2D.Render(new VertexStoreSnap(vxStorage, pathList[i]), colors[i]);
                }
            }
            //-----------------------------------------------------------------------------------



            if (!IsFreezed)
            {
                //var destImage = graphics2D.DestImage;
                //var buffer = destImage.GetBuffer();
                //var w = destImage.Width;
                //var h = destImage.Height;

                ////snap to bmp
                //System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(w, h);
                //BitmapHelper.CopyToWindowsBitmap(buffer, 0,
                //    destImage.StrideInBytes(),
                //    destImage.Height,
                //    destImage.BitDepth,
                //    bmp, new RectangleInt(0, 0, w, h));

                //bmp.Save("d:\\WImageTest\\01.bmp");

                //this.Freeze();
                //var bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, w, h),
                //     System.Drawing.Imaging.ImageLockMode.ReadWrite,
                //     System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            }
            base.OnDraw(graphics2D);
        }
Пример #9
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);
        }
Пример #10
0
        public override void Draw(PixelFarm.Drawing.Painter p)
        {
            if (recreatePathAgain)
            {
                recreatePathAgain = false;

                var transform = 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)
                    );
                //create vertextStore again from original path


                //temp fix
                SvgRenderVx renderVx = _spriteShape.GetRenderVx();
                int         count    = renderVx.SvgVxCount;
                for (int i = 0; i < count; ++i)
                {
                    SvgPart vx = renderVx.GetInnerVx(i);
                    if (vx.Kind != SvgRenderVxKind.Path)
                    {
                        continue;
                    }
                    //Temp fix,
                    //TODO: review here,
                    //permanent transform each part?
                    //or create a copy.
                    vx.RestoreOrg();
                    VertexStore vxvxs  = vx.GetVxs();
                    VertexStore newVxs = new VertexStore();
                    transform.TransformToVxs(vxvxs, newVxs);
                    vx.SetVxs(newVxs);
                }
                _spriteShape.UpdateBounds();

                //if (AutoFlipY)
                //{
                //    //flip the lion
                //    PixelFarm.Agg.Transform.Affine aff = PixelFarm.Agg.Transform.Affine.NewMatix(
                //      PixelFarm.Agg.Transform.AffinePlan.Scale(-1, -1),
                //      PixelFarm.Agg.Transform.AffinePlan.Translate(0, 600));
                //    //
                //    var v2 = new VertexStore();
                //    myvxs = transform.TransformToVxs(myvxs, v2);
                //}
            }
            //---------------------------------------------------------------------------------------------
            {
                float ox = p.OriginX;
                float oy = p.OriginY;
                p.SetOrigin(ox + _posX, oy + _posY);
                _spriteShape.Paint(p);
                //#if DEBUG
                //                RectD bounds = lionShape.Bounds;
                //                bounds.Offset(_posX, _posY);
                //                //draw lion bounds
                //                var savedStrokeColor = p.StrokeColor;
                //                var savedFillColor = p.FillColor;
                //                var savedSmoothMode = p.SmoothingMode;

                //                p.SmoothingMode = SmoothingMode.HighSpeed;
                //                p.StrokeColor = Color.Black;
                //                p.DrawRect(bounds.Left, bounds.Top - bounds.Height, bounds.Width, bounds.Height);

                //                p.StrokeColor = Color.Red;
                //                p.DrawRect(_mouseDownX, _mouseDownY, 4, 4);


                //                //restore
                //                p.SmoothingMode = savedSmoothMode;
                //                p.StrokeColor = savedStrokeColor;
                //                p.FillColor = savedFillColor;


                //#endif

                p.SetOrigin(ox, oy);


                //int j = lionShape.NumPaths;
                //int[] pathList = lionShape.PathIndexList;
                //Drawing.Color[] colors = lionShape.Colors;
                ////graphics2D.UseSubPixelRendering = true;
                //for (int i = 0; i < j; ++i)
                //{
                //    p.FillColor = colors[i];
                //    p.Fill(new VertexStoreSnap(myvxs, pathList[i]));
                //}
            }
            //test
            if (SharpenRadius > 0)
            {
                //p.DoFilter(new RectInt(0, p.Height, p.Width, 0), 2);
                //PixelFarm.Agg.Imaging.SharpenFilterARGB.Sharpen()
            }
        }
Пример #11
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            //render
            var            widgetsSubImage    = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            int            width              = widgetsSubImage.Width;
            int            height             = widgetsSubImage.Height;
            int            strokeWidth        = 1;
            var            clippedSubImage    = new ChildImage(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

            imageClippingProxy.Clear(ColorRGBA.White);
            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));

            //transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
            //transform *= Affine.NewScaling(spriteScale, spriteScale);
            //transform *= Affine.NewRotation(angle + Math.PI);
            //transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0);
            //transform *= Affine.NewTranslation(width / 2, height / 2);


            if (RenderAsScanline)
            {
                var rasterizer = graphics2D.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                Stroke stroke = new Stroke(strokeWidth);
                stroke.LineJoin = LineJoin.Round;
                var vxs = affTx.TransformToVxs(lionShape.Path.Vxs);
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;
                sclineRasToBmp.RenderSolidAllPaths(
                    imageClippingProxy,
                    rasterizer,
                    graphics2D.ScanlinePacked8,
                    vxs,
                    lionShape.Colors,
                    lionShape.PathIndexList,
                    lionShape.NumPaths);
            }
            else
            {
                double w = strokeWidth * affTx.GetScale();
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(w, new GammaNone());
                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;
                //VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);
                var vxs = affTx.TransformToVxs(lionShape.Path.Vxs);// trans.DoTransformToNewVxStorage();
                int j   = lionShape.NumPaths;
                for (int i = 0; i < j; ++i)
                {
                    rasterizer.RenderVertexSnap(
                        new VertexStoreSnap(vxs,
                                            lionShape.PathIndexList[i]),
                        lionShape.Colors[i]);
                }
            }

            base.OnDraw(graphics2D);
        }
Пример #12
0
        public override void Draw(CanvasPainter 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 AggCanvasPainter;

            if (p1 == null)
            {
                int             j        = lionShape.NumPaths;
                int[]           pathList = lionShape.PathIndexList;
                Drawing.Color[] colors   = lionShape.Colors;
                //graphics2D.UseSubPixelRendering = true;
                var vxs = GetFreeVxs();
                affTx.TransformToVxs(lionShape.Path.Vxs, vxs);
                p.StrokeWidth = 1;
                for (int i = 0; i < j; ++i)
                {
                    p.StrokeColor = colors[i];
                    p.Draw(new VertexStoreSnap(vxs, pathList[i]));
                }
                //not agg
                Release(ref vxs);
                return; //**
            }

            Graphics2D graphics2D = p1.Graphics;
            //var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());
            //int width = widgetsSubImage.Width;
            //int height = widgetsSubImage.Height;
            var widgetsSubImage = ImageHelper.CreateChildImage(graphics2D.DestImage, graphics2D.GetClippingRect());

            var            clippedSubImage    = new ChildImage(widgetsSubImage, new PixelBlenderBGRA());
            ClipProxyImage imageClippingProxy = new ClipProxyImage(clippedSubImage);

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


            if (RenderAsScanline)
            {
                var rasterizer = graphics2D.ScanlineRasterizer;
                rasterizer.SetClipBox(0, 0, width, height);
                Stroke stroke = new Stroke(strokeWidth);
                stroke.LineJoin = LineJoin.Round;
                var vxs = GetFreeVxs();
                affTx.TransformToVxs(lionShape.Path.Vxs, vxs);
                ScanlineRasToDestBitmapRenderer sclineRasToBmp = graphics2D.ScanlineRasToDestBitmap;
                sclineRasToBmp.RenderSolidAllPaths(
                    imageClippingProxy,
                    rasterizer,
                    graphics2D.ScanlinePacked8,
                    vxs,
                    lionShape.Colors,
                    lionShape.PathIndexList,
                    lionShape.NumPaths);
                Release(ref vxs);
            }
            else
            {
                double w = strokeWidth * affTx.GetScale();
                LineProfileAnitAlias lineProfile     = new LineProfileAnitAlias(w, new GammaNone());
                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;
                //VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);
                var vxs = GetFreeVxs();
                affTx.TransformToVxs(lionShape.Path.Vxs, vxs);// trans.DoTransformToNewVxStorage();
                int j = lionShape.NumPaths;
                for (int i = 0; i < j; ++i)
                {
                    rasterizer.RenderVertexSnap(
                        new VertexStoreSnap(vxs,
                                            lionShape.PathIndexList[i]),
                        lionShape.Colors[i]);
                }
                Release(ref vxs);
            }
            base.Draw(p);
        }