Ejemplo n.º 1
0
        public bool HitTestOnSubPart(float x, float y)
        {
            int partCount = _svgRenderVx.SvgVxCount;

            _selectedVxs = null;//reset
            for (int i = partCount - 1; i >= 0; --i)
            {
                //we do hittest top to bottom => (so => iter backward)

                SvgPart vx = _svgRenderVx.GetInnerVx(i);
                if (vx.Kind != SvgRenderVxKind.Path)
                {
                    continue;
                }
                VertexStore innerVxs = vx.GetVxs();
                //fine tune
                //hit test ***
                if (VertexHitTester.IsPointInVxs(innerVxs, x, y))
                {
                    if (_selectedVxs != null)
                    {
                        //de-selected this first
                    }


                    _selectedVxs = innerVxs;
                    vx.FillColor = Color.Black;
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        public RectD GetBounds()
        {
            //find bound
            //TODO: review here
            if (_needBoundUpdate)
            {
                int partCount = _vxList.Length;

                for (int i = 0; i < partCount; ++i)
                {
                    SvgPart vx = _vxList[i];
                    if (vx.Kind != SvgRenderVxKind.Path)
                    {
                        continue;
                    }

                    RectD       rectTotal = new RectD();
                    VertexStore innerVxs  = vx.GetVxs();
                    BoundingRect.GetBoundingRect(new VertexStoreSnap(innerVxs), ref rectTotal);

                    _boundRect.ExpandToInclude(rectTotal);
                }

                _needBoundUpdate = false;
            }
            return(_boundRect);
        }
Ejemplo n.º 3
0
        static VertexStore GetStrokeVxsOrCreateNew(SvgPart s, Painter p, float strokeW)
        {
            VertexStore strokeVxs = s.StrokeVxs;

            if (strokeVxs != null && s.StrokeWidth == strokeW)
            {
                return(strokeVxs);
            }

            var new_output = new VertexStore();

            p.VectorTool.CreateStroke(s.GetVxs(), strokeW, new_output);
            s.StrokeVxs = new_output;

            return(new_output);
        }
Ejemplo n.º 4
0
        public void UpdateBounds()
        {
            //find bound
            //TODO: review here
            int   partCount = _svgRenderVx.SvgVxCount;
            RectD rectTotal = new RectD();

            for (int i = 0; i < partCount; ++i)
            {
                SvgPart vx = _svgRenderVx.GetInnerVx(i);
                if (vx.Kind != SvgRenderVxKind.Path)
                {
                    continue;
                }
                VertexStore innerVxs = vx.GetVxs();
                PixelFarm.Agg.BoundingRect.GetBoundingRect(new VertexStoreSnap(innerVxs), ref rectTotal);
            }
            this.boundingRect = rectTotal;
        }
Ejemplo n.º 5
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()
            }
        }
Ejemplo n.º 6
0
        public void Render(Painter p)
        {
            //
            if (HasBitmapSnapshot)
            {
                p.DrawImage(_backimg, X, Y);
                return;
            }

            PixelFarm.Agg.Transform.Affine currentTx = null;

            var renderState = new TempRenderState();

            renderState.strokeColor = p.StrokeColor;
            renderState.strokeWidth = (float)p.StrokeWidth;
            renderState.fillColor   = p.FillColor;
            renderState.affineTx    = currentTx;

            //------------------
            VertexStore tempVxs = p.GetTempVxsStore();

            int j = _vxList.Length;

            for (int i = 0; i < j; ++i)
            {
                SvgPart vx = _vxList[i];
                switch (vx.Kind)
                {
                case SvgRenderVxKind.BeginGroup:
                {
                    //1. save current state before enter new state
                    p.StackPushUserObject(renderState);

                    //2. enter new px context
                    if (vx.HasFillColor)
                    {
                        p.FillColor = renderState.fillColor = vx.FillColor;
                    }
                    if (vx.HasStrokeColor)
                    {
                        p.StrokeColor = renderState.strokeColor = vx.StrokeColor;
                    }
                    if (vx.HasStrokeWidth)
                    {
                        p.StrokeWidth = renderState.strokeWidth = vx.StrokeWidth;
                    }
                    if (vx.AffineTx != null)
                    {
                        //apply this to current tx
                        if (currentTx != null)
                        {
                            currentTx = currentTx * vx.AffineTx;
                        }
                        else
                        {
                            currentTx = vx.AffineTx;
                        }
                        renderState.affineTx = currentTx;
                    }
                }
                break;

                case SvgRenderVxKind.EndGroup:
                {
                    //restore to prev state
                    renderState   = (TempRenderState)p.StackPopUserObject();
                    p.FillColor   = renderState.fillColor;
                    p.StrokeColor = renderState.strokeColor;
                    p.StrokeWidth = renderState.strokeWidth;
                    currentTx     = renderState.affineTx;
                }
                break;

                case SvgRenderVxKind.Path:
                {
                    VertexStore vxs = vx.GetVxs();
                    if (vx.HasFillColor)
                    {
                        //has specific fill color
                        if (vx.FillColor.A > 0)
                        {
                            if (currentTx == null)
                            {
                                p.Fill(vxs, vx.FillColor);
                            }
                            else
                            {
                                //have some tx
                                tempVxs.Clear();
                                currentTx.TransformToVxs(vxs, tempVxs);
                                p.Fill(tempVxs, vx.FillColor);
                            }
                        }
                    }
                    else
                    {
                        if (p.FillColor.A > 0)
                        {
                            if (currentTx == null)
                            {
                                p.Fill(vxs);
                            }
                            else
                            {
                                //have some tx
                                tempVxs.Clear();
                                currentTx.TransformToVxs(vxs, tempVxs);
                                p.Fill(tempVxs);
                            }
                        }
                    }

                    if (p.StrokeWidth > 0)
                    {
                        //check if we have a stroke version of this render vx
                        //if not then request a new one
                        if (vx.HasStrokeColor)
                        {
                            //has specific stroke color
                            p.StrokeWidth = vx.StrokeWidth;
                            VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);

                            if (currentTx == null)
                            {
                                p.Fill(strokeVxs, vx.StrokeColor);
                            }
                            else
                            {
                                //have some tx
                                tempVxs.Clear();
                                currentTx.TransformToVxs(strokeVxs, tempVxs);
                                p.Fill(tempVxs, vx.StrokeColor);
                            }
                        }
                        else if (p.StrokeColor.A > 0)
                        {
                            VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);
                            if (currentTx == null)
                            {
                                p.Fill(strokeVxs, p.StrokeColor);
                            }
                            else
                            {
                                tempVxs.Clear();
                                currentTx.TransformToVxs(strokeVxs, tempVxs);
                                p.Fill(tempVxs, p.StrokeColor);
                            }
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        if (vx.HasStrokeColor)
                        {
                            VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);
                            p.Fill(strokeVxs);
                        }
                        else if (p.StrokeColor.A > 0)
                        {
                            VertexStore strokeVxs = GetStrokeVxsOrCreateNew(vx, p, (float)p.StrokeWidth);
                            p.Fill(strokeVxs, p.StrokeColor);
                        }
                    }
                }
                break;
                }
            }


            p.ReleaseTempVxsStore(tempVxs);
        }