Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();

            ImageEditor imageEditor = new ImageEditor();

            imageEditor.Dock = DockStyle.Fill;
            this.Controls.Add(imageEditor);

            imageEditor.Add(Image.FromFile("./1.png"));
            imageEditor.Add(Image.FromFile("./2.png"));
        }
Exemplo n.º 2
0
            public void ScaleTo(Point start, Point end)
            {
                if (this._width == 0 || this._height == 0)
                {
                    return;
                }
                Matrix matrix = _matrix.Clone();

                matrix.Invert();
                Point[] points = new Point[2] {
                    start, end
                };
                matrix.TransformPoints(points);

                var vector = ImageEditor.MeasureVector(points[0], points[1]);

                /////matrix.Invert();
                float centerx = this.Bound.Left + this.Bound.Width / 2;
                float centery = this.Bound.Top + this.Bound.Height / 2;


                if (start.X > centerx)
                {
                    _width += vector.X;
                }
                else
                {
                    _width  -= vector.X;
                    Location = new Point(Location.X + vector.X, Location.Y);
                }

                if (start.Y > centery)
                {
                    _height += vector.Y;
                }
                else
                {
                    _height -= vector.Y;
                    Location = new Point(Location.X, Location.Y + vector.Y);
                }
                ///////_matrix.Reset();
                //float xScale = vector.X*1.0f / this._width+1;
                //float yScale = vector.Y*1.0f / this._height+1;
                //_matrix.Scale(xScale,yScale,MatrixOrder.Prepend);


                ////_matrix.Translate(-1*vector.X,-1* vector.Y);
                //matrix.Invert();
                /////_matrix.Multiply(matrix);
                ///_matrix.Multiply(matrix);
                UpdateTransformArray();
            }
Exemplo n.º 3
0
            public void Pan(Point start, Point end)
            {
                Matrix matrix = _matrix.Clone();

                matrix.Invert();
                Point[] points = new Point[2] {
                    start, end
                };
                matrix.TransformPoints(points);

                var vector = ImageEditor.MeasureVector(points[0], points[1]);

                //Matrix matrix = new Matrix();
                //matrix.Translate(vector.X, vector.Y);
                _matrix.Translate(vector.X, vector.Y);
                ////_matrix.Translate(vector.X, vector.Y);
                UpdateTransformArray();
            }
Exemplo n.º 4
0
        public virtual void OnMouseMove(MouseEventArgs e)
        {
            Cursor cursor = Cursors.Arrow;

            foreach (var item in _items)
            {
                if (item.Status == Status.None)
                {
                    continue;
                }
                if (item.Status != Status.None)
                {
                    if (_isMouseDown)
                    {
                        ////Console.WriteLine($"{e.Location.X},{e.Location.Y};{item.Bound}");
                        if (item.Status == Status.Resize)
                        {
                            //set mouse
                            /////item.Status = Status.Resize;
                            cursor = Cursors.SizeNWSE;

                            //resize
                            if (_isMouseDown)
                            {
                                var vector = ImageEditor.MeasureVector(_lastMousePoint, e.Location);
                                item.ScaleTo(_lastMousePoint, e.Location);
                                //resize
                            }
                        }
                        else if (item.Status == Status.Pan)
                        {
                            ///item.Status = Status.Pan;
                            cursor = Cursors.SizeAll;

                            if (_isMouseDown)
                            {
                                var vector = ImageEditor.MeasureVector(_lastMousePoint, e.Location);
                                item.Pan(_lastMousePoint, e.Location);
                                //resize
                            }
                        }
                        else if (item.Status == Status.Rotate)
                        {
                            /////item.Status = Status.Rotate;
                            cursor = Cursors.AppStarting;
                        }
                        else
                        {
                            item.Status = Status.Selected;
                        }
                    }
                    else
                    {
                        ////Console.WriteLine($"{e.Location.X},{e.Location.Y};{item.Bound}");
                        if (item.IsAroundJiao(e.Location))
                        {
                            //set mouse
                            item.Status = Status.Resize;
                            cursor      = Cursors.SizeNWSE;

                            //resize
                            if (_isMouseDown)
                            {
                                var vector = ImageEditor.MeasureVector(_lastMousePoint, e.Location);

                                //resize
                            }
                        }
                        else if (item.IsOnCenter(e.Location))
                        {
                            item.Status = Status.Pan;
                            cursor      = Cursors.SizeAll;

                            if (_isMouseDown)
                            {
                                var vector = ImageEditor.MeasureVector(_lastMousePoint, e.Location);
                                item.Pan(_lastMousePoint, e.Location);
                                //resize
                            }
                        }
                        else if (item.IsOnLineCenter(e.Location))
                        {
                            item.Status = Status.Rotate;
                            cursor      = Cursors.AppStarting;
                        }
                        else
                        {
                            ////item.Status = Status.Selected;
                        }
                    }
                }
            }
            _lastMousePoint = e.Location;
            CursorChanged?.Invoke(this, new CursorChangedEvenrArgs(cursor));
        }