private void _quadControl_ShapeUpdated(QuadWidgetControl sender, EventArgs arg)
        {
            //update shape of sprite

            //transform from original lionBounds to quadPolygon
            Quad2f quadCorners = _quadControl.GetQuadCorners();

            _quadCorners[0] = quadCorners.left_top_x;
            _quadCorners[1] = quadCorners.left_top_y;
            _quadCorners[2] = quadCorners.right_top_x;
            _quadCorners[3] = quadCorners.right_top_y;
            _quadCorners[4] = quadCorners.right_bottom_x;
            _quadCorners[5] = quadCorners.right_bottom_y;
            _quadCorners[6] = quadCorners.left_bottom_x;
            _quadCorners[7] = quadCorners.left_bottom_y;


            //this is bilinear transformation
            if (_useBilinear)
            {
                Bilinear txBilinear = Bilinear.RectToQuad(
                    _lionBounds.Left,
                    _lionBounds.Top,
                    _lionBounds.Right,
                    _lionBounds.Bottom,
                    _quadCorners);

                if (txBilinear.IsValid)
                {
                    SpriteShape spriteShape = _mySprite.GetSpriteShape();
                    spriteShape.ResetTransform();
                    spriteShape.ApplyTransform(txBilinear);
                }
            }
            else
            {
                Perspective perspective = new Perspective(
                    _lionBounds.Left,
                    _lionBounds.Top,
                    _lionBounds.Right,
                    _lionBounds.Bottom,
                    _quadCorners);
                if (perspective.IsValid)
                {
                    SpriteShape spriteShape = _mySprite.GetSpriteShape();
                    spriteShape.ResetTransform();
                    spriteShape.ApplyTransform(perspective);
                }
            }
        }
Beispiel #2
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);
        }