Ejemplo n.º 1
0
        public override void Init()
        {
            VgVisualElement renderVx    = VgVisualDocHelper.CreateVgVisualDocFromFile(@"Samples\lion.svg").VgRootElem;
            var             spriteShape = new SpriteShape(renderVx);

            _testSprite = new MyTestSprite(spriteShape);

            //lionFill.AutoFlipY = true;

            PixelFarm.CpuBlit.AffineMat mat = PixelFarm.CpuBlit.AffineMat.Iden();
            mat.RotateDeg(30);
            mat.Scale(2);

            _currentTx = new PixelFarm.CpuBlit.VertexProcessing.Affine(mat);
        }
Ejemplo n.º 2
0
        //
        void SetupCorner_Controller(UIControllerBox box)
        {
            Color c = KnownColors.FromKnownColor(KnownColor.Orange);

            box.BackColor = c;// new Color(200, c.R, c.G, c.B);
            box.SetLocation(200, 200);
            box.Visible = true;

            box.MouseDrag += (s, e) =>
            {
                Point  pos = box.Position;
                double x1  = pos.X;
                double y1  = pos.Y;

                if (firstTime)
                {
                    _mouseDownX = x1;
                    _mouseDownY = y1;
                    firstTime   = false;
                    //find rad of firsttime
                    _firstTimeRad    = Math.Atan2(y1, x1);
                    _rotateAngleDiff = 0;
                }
                else
                {
                    double newX = _actualX + e.XDiff;
                    double newY = _actualY + e.YDiff;

                    //find new angle
                    double thisTimeRad = Math.Atan2(newY, newX);
                    _rotateAngleDiff = thisTimeRad - _firstTimeRad;

                    x1 = _mouseDownX; //prevent rounding error
                    y1 = _mouseDownY; //prevent rounding error
                }
                //if (firstTime)
                //{
                //    _snapX1 = x1;
                //    _snapY1 = y1;
                //    firstTime = false;
                //}
                //else
                //{
                //    x1 = _snapX1;
                //    y1 = _snapY1;
                //}
                //double current_distance = Math.Sqrt(x1 * x1 + y1 * y1);

                //
                //double newX = pos.X + e.XDiff;
                //double newY = pos.Y + e.YDiff;

                //float diff = 1;

                //if (e.XDiff > 0)
                //{
                //    diff = -1;
                //}



                PixelFarm.CpuBlit.AffineMat aff = PixelFarm.CpuBlit.AffineMat.GetRotateMat(_rotateAngleDiff);

                aff.Transform(ref x1, ref y1);
                _actualX = x1;
                _actualY = y1;

                box.SetLocation((int)Math.Round(x1), (int)Math.Round(y1)); //essential to use double, prevent rounding err ***



                //var targetBox = box.TargetBox;

                ////test rotation around some axis
                ////find box center
                //if (targetBox != null)
                //{
                //    //find box center
                //    float centerX = (float)((targetBox.Width + targetBox.Left) / 2f);
                //    float centerY = (float)((targetBox.Height + targetBox.Top) / 2f);
                //    //
                //    Double angle = Math.Atan2(newY - centerY, newX - centerX);
                //    //rotate
                //    PixelFarm.CpuBlit.VertexProcessing.Affine aff = PixelFarm.CpuBlit.VertexProcessing.Affine.NewMatix(
                //       PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(-targetBox.Width / 2, -targetBox.Height / 2),
                //       PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Rotate(angle),
                //       PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(targetBox.Width / 2, targetBox.Height / 2)
                //    );
                //    //transform
                //    aff.Transform(ref x1, ref y1);
                //    box.SetLocation((int)x1, (int)y1);

                //}

                //if (targetBox != null)
                //{
                //    //move target box too
                //    targetBox.SetLocation(newX + 5, newY + 5);
                //}

                e.CancelBubbling = true;
            };
            _controls.Add(box);
        }