static void SetupControllerBoxProperties2(UIControllerBox cornerBox)
 {
     //for controller box
     cornerBox.MouseDrag += (s, e) =>
     {
         Point pos  = cornerBox.Position;
         int   newX = pos.X + e.XDiff;
         int   newY = pos.Y + e.YDiff;
         cornerBox.SetLocation(newX, newY);
         //var targetBox = cornerBox.TargetBox;
         //if (targetBox != null)
         //{
         //    //move target box too
         //    targetBox.SetLocation(newX + 5, newY + 5);
         //}
         e.CancelBubbling = true;
     };
 }
 public void Init()
 {
     //------------
     _centralBox = new UIControllerBox(40, 40);
     {
         Color c = KnownColors.FromKnownColor(KnownColor.Yellow);
         _centralBox.BackColor = new Color(100, c.R, c.G, c.B);
         _centralBox.SetLocation(200, 200);
         //controllerBox1.dbugTag = 3;
         _centralBox.Visible = false;
         SetupControllerBoxProperties(_centralBox);
         //viewport.AddChild(controllerBox1);
         _controls.Add(_centralBox);
     }
     _groundBox.Add(_centralBox);
     //------------
     InitCornerControlBoxes();
     InitEdgeControlBoxes();
     //------------
 }
        //
        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;
                //}

                //box.SetLocation((int)newX, (int)newY);
                PixelFarm.CpuBlit.VertexProcessing.Affine aff = PixelFarm.CpuBlit.VertexProcessing.Affine.New(
                    //PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(-x1, -y1),
                    PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Rotate(_rotateAngleDiff));

                //PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(x1, y1));

                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);
        }
        public void Init()
        {
            //------------
            controllerBox1 = new UIControllerBox(40, 40);
            {
                Color c = KnownColors.FromKnownColor(KnownColor.Yellow);
                controllerBox1.BackColor = new Color(100, c.R, c.G, c.B);
                controllerBox1.SetLocation(200, 200);
                //controllerBox1.dbugTag = 3;
                controllerBox1.Visible = false;
                SetupControllerBoxProperties(controllerBox1);
                //viewport.AddContent(controllerBox1);
                _controls.Add(controllerBox1);
            }
            _simpleBox.AddChild(controllerBox1);
            //------------

            _boxLeftTop = new UIControllerBox(20, 20);
            SetupCornerBoxController(_boxLeftTop);
            _boxLeftTop.MouseDrag += (s1, e1) =>
            {
                //move other boxes ...
                UIBox target1 = _boxLeftTop.TargetBox;
                //update target
                target1.SetLocationAndSize(_boxLeftTop.Right,
                                           _boxLeftTop.Bottom,
                                           _boxRightTop.Left - _boxLeftTop.Right,
                                           _boxRightBottom.Top - _boxLeftTop.Bottom);
                //update other controller
                UpdateControllerBoxes(target1);
            };
            _simpleBox.AddChild(_boxLeftTop);
            //------------
            _boxLeftBottom = new UIControllerBox(20, 20);
            SetupCornerBoxController(_boxLeftBottom);
            _boxLeftBottom.MouseDrag += (s1, e1) =>
            {
                UIBox target1 = _boxLeftBottom.TargetBox;
                //update target
                target1.SetLocationAndSize(_boxLeftBottom.Right,
                                           _boxLeftTop.Bottom,
                                           _boxRightTop.Left - _boxLeftBottom.Right,
                                           _boxLeftBottom.Top - _boxLeftTop.Bottom);
                //update other controller
                UpdateControllerBoxes(target1);
            };
            _simpleBox.AddChild(_boxLeftBottom);
            //------------

            _boxRightTop = new UIControllerBox(20, 20);
            SetupCornerBoxController(_boxRightTop);
            _boxRightTop.MouseDrag += (s1, e1) =>
            {
                UIBox target1 = _boxRightTop.TargetBox;
                //update target
                target1.SetLocationAndSize(_boxLeftTop.Right,
                                           _boxRightTop.Bottom,
                                           _boxRightTop.Left - _boxLeftTop.Right,
                                           _boxRightBottom.Top - _boxRightTop.Bottom);
                //update other controller
                UpdateControllerBoxes(target1);
            };
            _simpleBox.AddChild(_boxRightTop);

            //------------
            _boxRightBottom = new UIControllerBox(20, 20);
            SetupCornerBoxController(_boxRightBottom);
            _boxRightBottom.MouseDrag += (s1, e1) =>
            {
                UIBox target1 = _boxRightBottom.TargetBox;
                //update target
                target1.SetLocationAndSize(_boxLeftTop.Right,
                                           _boxLeftTop.Bottom,
                                           _boxRightBottom.Left - _boxLeftTop.Right,
                                           _boxRightBottom.Top - _boxLeftTop.Bottom);
                //update other controller
                UpdateControllerBoxes(target1);
            };
            _simpleBox.AddChild(_boxRightBottom);
        }