Пример #1
0
        void SetupControllerBoxProperties(UIControllerBox controllerBox)
        {
            //for controller box
            controllerBox.MouseDrag += (s, e) =>
            {
                Point pos  = controllerBox.Position;
                int   newX = pos.X + e.XDiff;
                int   newY = pos.Y + e.YDiff;

                //also move controller box?
                int j = _controls.Count;
                for (int i = 0; i < j; ++i)
                {
                    UIControllerBox corner = _controls[i];
                    Point           p2     = corner.Position;
                    int             newX2  = p2.X + e.XDiff;
                    int             newY2  = p2.Y + e.YDiff;
                    corner.SetLocation(newX2, newY2);
                }
                var targetBox = controllerBox.TargetBox;
                if (targetBox != null)
                {
                    //move target box too
                    targetBox.SetLocation(newX + 5, newY + 5);
                }

                e.CancelBubbling = true;
            };
        }
Пример #2
0
        void SetupCornerProperties(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;

                //---------------------------------
                _simpleBox.InvalidateOuterGraphics();
                foreach (var ctrl in _controls)
                {
                    ctrl.InvalidateOuterGraphics();
                }

                //then update the vxs shape
                VertexStore vxs = _svgPath.GetVxs();
                vxs.ReplaceVertex(cornerBox.Index, newX, newY);
                PixelFarm.Agg.SvgPart.SetResolvedObject(_svgPath, null);//clear

                _ui.HandleElementUpdate();
            };
        }
Пример #3
0
        public void UpdateControlPoints(PixelFarm.Agg.SvgPart svgPath)
        {
            //1. we remove existing point from root

            _svgPath = svgPath;
            VertexStore vxs = svgPath.GetVxs();

            int m = _controls.Count;

            for (int n = 0; n < m; ++n)
            {
                _controls[n].RemoveSelf();
            }
            _controls.Clear(); //***
            _points.Clear();

            //2. create new control points...

            int j = vxs.Count;

            for (int i = 0; i < j; ++i)
            {
                var cmd = vxs.GetVertex(i, out double x, out double y);
                switch (cmd)
                {
                case PixelFarm.Agg.VertexCmd.MoveTo:
                {
                    var ctrlPoint = new UIControllerBox(8, 8);
                    ctrlPoint.Index = i;
                    ctrlPoint.SetLocation((int)x, (int)y);
                    SetupCornerBoxController(ctrlPoint);
                    _controls.Add(ctrlPoint);
                    _simpleBox.AddChild(ctrlPoint);
                }
                break;

                case PixelFarm.Agg.VertexCmd.LineTo:
                {
                    var ctrlPoint = new UIControllerBox(8, 8);
                    ctrlPoint.Index = i;
                    ctrlPoint.SetLocation((int)x, (int)y);
                    SetupCornerBoxController(ctrlPoint);
                    _controls.Add(ctrlPoint);
                    _simpleBox.AddChild(ctrlPoint);
                }
                break;

                case PixelFarm.Agg.VertexCmd.Close:
                    break;
                }
            }
        }
Пример #4
0
        void SetupCornerBoxController(UIControllerBox box)
        {
            Color c = KnownColors.FromKnownColor(KnownColor.Orange);

            box.BackColor = new Color(100, c.R, c.G, c.B);

            //controllerBox1.dbugTag = 3;
            box.Visible = true;
            SetupCornerProperties(box);
            //viewport.AddContent(box);
            //
            _controls.Add(box);
        }
Пример #5
0
        void SetupEdge_Controller(UIControllerBox box)
        {
            Color c = KnownColors.FromKnownColor(KnownColor.Blue);

            box.BackColor = c;// new Color(200, c.R, c.G, c.B);
            box.SetLocation(200, 200);
            box.Visible = true;
            switch (box.MoveDirection)
            {
            case MoveDirection.XAxis:
            {
                box.MouseDrag += (s, e) =>
                {
                    Point pos = box.Position;
                    box.SetLocation(pos.X + e.XDiff, pos.Y);
                    //var targetBox = cornerBox.TargetBox;
                    //if (targetBox != null)
                    //{
                    //    //move target box too
                    //    targetBox.SetLocation(newX + 5, newY + 5);
                    //}

                    e.CancelBubbling = true;
                };
            }
            break;

            case MoveDirection.YAxis:
            {
                box.MouseDrag += (s, e) =>
                {
                    Point pos = box.Position;
                    box.SetLocation(pos.X, pos.Y + e.YDiff);
                    //var targetBox = cornerBox.TargetBox;
                    //if (targetBox != null)
                    //{
                    //    //move target box too
                    //    targetBox.SetLocation(newX + 5, newY + 5);
                    //}

                    e.CancelBubbling = true;
                };
            }
            break;
            }

            _controls.Add(box);
        }
Пример #6
0
 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;
     };
 }
Пример #7
0
 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();
     //------------
 }
Пример #8
0
        public void UpdateControllerBoxes(LayoutFarm.UI.UIBox box)
        {
            //move controller here
            controllerBox1.SetLocationAndSize(box.Left - 5, box.Top - 5,
                                              box.Width + 10, box.Height + 10);
            controllerBox1.Visible   = true;
            controllerBox1.TargetBox = box;


            {
                //left-top
                UIControllerBox ctrlBox = _boxLeftTop;
                ctrlBox.SetLocationAndSize(box.Left - 5, box.Top - 5, 5, 5);
                ctrlBox.TargetBox = box;
                ctrlBox.Visible   = true;
            }
            {
                //right-top
                UIControllerBox ctrlBox = _boxRightTop;
                ctrlBox.SetLocationAndSize(box.Left + box.Width, box.Top - 5, 5, 5);
                ctrlBox.TargetBox = box;
                ctrlBox.Visible   = true;
            }
            {
                //left-bottom
                UIControllerBox ctrlBox = _boxLeftBottom;
                ctrlBox.SetLocationAndSize(box.Left - 5, box.Top + box.Height, 5, 5);
                ctrlBox.TargetBox = box;
                ctrlBox.Visible   = true;
            }
            {
                //right-bottom
                UIControllerBox ctrlBox = _boxRightBottom;
                ctrlBox.SetLocationAndSize(box.Left + box.Width, box.Top + box.Height, 5, 5);
                ctrlBox.TargetBox = box;
                ctrlBox.Visible   = true;
            }
        }
Пример #9
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;
                //}

                //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);
        }
Пример #10
0
        void InitEdgeControlBoxes()
        {
            _midLeftSide = new UIControllerBox(20, 20)
            {
                MoveDirection = MoveDirection.XAxis, BackColor = Color.Blue, Visible = false
            };
            SetupEdge_Controller(_midLeftSide);
            _midLeftSide.MouseDrag += (s1, e1) =>
            {
                //move other boxes ...
                AbstractRectUI target1 = _boxLeftTop.TargetBox;
                //update target
                if (target1 != null)
                {
                    //change left side x and width
                    int xdiff = _midLeftSide.Right - target1.Left;
                    target1.SetLocationAndSize(
                        target1.Left + xdiff,
                        target1.Top,
                        target1.Width - xdiff,
                        target1.Height);
                    //update other controller
                    UpdateControllerBoxes(target1);
                }
            };
            _groundBox.Add(_midLeftSide);
            //------------
            _midRightSide = new UIControllerBox(20, 20)
            {
                MoveDirection = MoveDirection.XAxis, BackColor = Color.Blue, Visible = false
            };
            SetupEdge_Controller(_midRightSide);
            _midRightSide.MouseDrag += (s1, e1) =>
            {
                AbstractRectUI target1 = _boxLeftTop.TargetBox;
                //change left side x and width
                int xdiff = _midRightSide.Left - target1.Right;
                target1.SetLocationAndSize(
                    target1.Left,
                    target1.Top,
                    target1.Width + xdiff,
                    target1.Height);

                //update other controller
                UpdateControllerBoxes(target1);
            };
            _groundBox.Add(_midRightSide);
            //------------

            _midTop = new UIControllerBox(20, 20)
            {
                MoveDirection = MoveDirection.YAxis, BackColor = Color.Blue, Visible = false
            };
            SetupEdge_Controller(_midTop);
            _midTop.MouseDrag += (s1, e1) =>
            {
                AbstractRectUI target1 = _boxLeftTop.TargetBox;
                int            ydiff   = target1.Top - _midTop.Bottom;
                target1.SetLocationAndSize(
                    target1.Left,
                    target1.Top - ydiff,
                    target1.Width,
                    target1.Height + ydiff);
                //update other controller
                UpdateControllerBoxes(target1);
            };
            _groundBox.Add(_midTop);

            //------------
            _midBottom = new UIControllerBox(20, 20)
            {
                MoveDirection = MoveDirection.YAxis, BackColor = Color.Blue, Visible = false
            };
            SetupEdge_Controller(_midBottom);
            _midBottom.MouseDrag += (s1, e1) =>
            {
                AbstractRectUI target1 = _boxLeftTop.TargetBox;
                int            ydiff   = _midBottom.Top - target1.Bottom;

                target1.SetLocationAndSize(
                    target1.Left,
                    target1.Top,
                    target1.Width,
                    target1.Height + ydiff);
                //update other controller
                UpdateControllerBoxes(target1);
            };
            _groundBox.Add(_midBottom);
            //------------
        }
Пример #11
0
        void InitCornerControlBoxes()
        {
            _boxLeftTop = new UIControllerBox(20, 20)
            {
                BackColor = Color.Yellow, Visible = false
            };
            SetupCorner_Controller(_boxLeftTop);
            _boxLeftTop.MouseDrag += (s1, e1) =>
            {
                //move other boxes ...
                AbstractRectUI target1 = _boxLeftTop.TargetBox;
                //update target
                if (target1 != null)
                {
                    target1.SetLocationAndSize(
                        _boxLeftTop.Right,
                        _boxLeftTop.Bottom,
                        _boxRightTop.Left - _boxLeftTop.Right,
                        _boxRightBottom.Top - _boxLeftTop.Bottom);
                    //update other controller
                    UpdateControllerBoxes(target1);
                }
            };
            _groundBox.Add(_boxLeftTop);
            //------------
            _boxLeftBottom = new UIControllerBox(20, 20)
            {
                BackColor = Color.Yellow, Visible = false
            };
            SetupCorner_Controller(_boxLeftBottom);
            _boxLeftBottom.MouseDrag += (s1, e1) =>
            {
                AbstractRectUI target1 = _boxLeftBottom.TargetBox;
                //update target
                if (target1 != null)
                {
                    target1.SetLocationAndSize(_boxLeftBottom.Right,
                                               _boxLeftTop.Bottom,
                                               _boxRightTop.Left - _boxLeftBottom.Right,
                                               _boxLeftBottom.Top - _boxLeftTop.Bottom);
                    //update other controller
                    UpdateControllerBoxes(target1);
                }
            };
            _groundBox.Add(_boxLeftBottom);
            //------------

            _boxRightTop = new UIControllerBox(20, 20)
            {
                BackColor = Color.Yellow, Visible = false
            };
            SetupCorner_Controller(_boxRightTop);
            _boxRightTop.MouseDrag += (s1, e1) =>
            {
                AbstractRectUI target1 = _boxRightTop.TargetBox;
                //update target
                if (target1 != null)
                {
                    target1.SetLocationAndSize(
                        _boxLeftTop.Right,
                        _boxRightTop.Bottom,
                        _boxRightTop.Left - _boxLeftTop.Right,
                        _boxRightBottom.Top - _boxRightTop.Bottom);
                    //update other controllers
                    UpdateControllerBoxes(target1);
                }
            };
            _groundBox.Add(_boxRightTop);

            //------------
            _boxRightBottom = new UIControllerBox(20, 20)
            {
                BackColor = Color.Yellow, Visible = false
            };
            SetupCorner_Controller(_boxRightBottom);
            _boxRightBottom.MouseDrag += (s1, e1) =>
            {
                OnUpdateShape();
                //rotate all other control points
                //AbstractRectUI target1 = _boxRightBottom.TargetBox;



                ////update target
                //if (target1 != null)
                //{
                //    target1.SetLocationAndSize(_boxLeftTop.Right,
                //                      _boxLeftTop.Bottom,
                //                      _boxRightBottom.Left - _boxLeftTop.Right,
                //                      _boxRightBottom.Top - _boxLeftTop.Bottom);
                //    //update other controllers
                //    UpdateControllerBoxes(target1);
                //}
            };
            _groundBox.Add(_boxRightBottom);
            //------------
        }
Пример #12
0
        public void UpdateControllerBoxes(LayoutFarm.UI.AbstractRectUI targetBox)
        {
            //move controller here
            _centralBox.SetLocationAndSize(
                targetBox.Left - 5, targetBox.Top - 5,
                targetBox.Width + 10, targetBox.Height + 10);
            _centralBox.Visible   = true;
            _centralBox.TargetBox = targetBox;
            //------------
            //corners
            //------------
            {
                //left-top
                UIControllerBox ctrlBox = _boxLeftTop;
                ctrlBox.SetLocationAndSize(targetBox.Left - 5, targetBox.Top - 5, 5, 5);
                ctrlBox.TargetBox = targetBox;
                ctrlBox.Visible   = true;
            }
            {
                //right-top
                UIControllerBox ctrlBox = _boxRightTop;
                ctrlBox.SetLocationAndSize(targetBox.Left + targetBox.Width, targetBox.Top - 5, 5, 5);
                ctrlBox.TargetBox = targetBox;
                ctrlBox.Visible   = true;
            }
            {
                //left-bottom
                UIControllerBox ctrlBox = _boxLeftBottom;
                ctrlBox.SetLocationAndSize(targetBox.Left - 5, targetBox.Top + targetBox.Height, 5, 5);
                ctrlBox.TargetBox = targetBox;
                ctrlBox.Visible   = true;
            }
            {
                //right-bottom
                UIControllerBox ctrlBox = _boxRightBottom;
                ctrlBox.SetLocationAndSize(targetBox.Left + targetBox.Width, targetBox.Top + targetBox.Height, 5, 5);
                ctrlBox.TargetBox = targetBox;
                ctrlBox.Visible   = true;
            }


            //------------
            //mid-edges
            //------------
            {
                //left
                UIControllerBox ctrlBox = _midLeftSide;
                ctrlBox.SetLocationAndSize(targetBox.Left - 5, (targetBox.Top - 5) + (targetBox.Height / 2), 5, 5);
                ctrlBox.TargetBox = targetBox;
                ctrlBox.Visible   = true;
            }
            {
                //right
                UIControllerBox ctrlBox = _midRightSide;
                ctrlBox.SetLocationAndSize(targetBox.Left + targetBox.Width, targetBox.Top - 5 + (targetBox.Height / 2), 5, 5);
                ctrlBox.TargetBox = targetBox;
                ctrlBox.Visible   = true;
            }
            {
                //top
                UIControllerBox ctrlBox = _midTop;
                ctrlBox.SetLocationAndSize(targetBox.Left - 5 + (targetBox.Width / 2), targetBox.Top - 5, 5, 5);
                ctrlBox.TargetBox = targetBox;
                ctrlBox.Visible   = true;
            }
            {
                // bottom
                UIControllerBox ctrlBox = _midBottom;
                ctrlBox.SetLocationAndSize(targetBox.Left + (targetBox.Width / 2), targetBox.Bottom, 5, 5);
                ctrlBox.TargetBox = targetBox;
                ctrlBox.Visible   = true;
            }
            OnUpdateShape();
        }
Пример #13
0
        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);
        }