Esempio n. 1
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            int endX = Convert.ToInt32((e.X * 1.0) / (Width * 1.0) * 100);
            int endY = Convert.ToInt32((e.Y * 1.0) / (Height * 1.0) * 100);

            _rectStop   = new Point(endX, endY);
            _bMouseDown = false;
            if (_rectIndex > -1)
            {
                _rectStart = Point.Empty;
                _rectStop  = Point.Empty;
                if (endX > 100 || endY > 100 || endX < 0 || endY < 0)
                {
                    _configs.RemoveAt(_rectIndex);
                }
                _rectIndex = -1;
                OnBoundsChanged();
                return;
            }
            if (endX > 100)
            {
                endX = 100;
            }
            if (endY > 100)
            {
                endY = 100;
            }
            if (Math.Sqrt(Math.Pow(endX - _rectStart.X, 2) + Math.Pow(endY - _rectStart.Y, 2)) < 5)
            {
                //ignore
                _rectStart = Point.Empty;
                _rectStop  = Point.Empty;
                return;
            }
            var start = new Point();
            var stop  = new Point();

            start.X = _rectStart.X;
            if (_rectStop.X < _rectStart.X)
            {
                start.X = _rectStop.X;
            }
            start.Y = _rectStart.Y;
            if (_rectStop.Y < _rectStart.Y)
            {
                start.Y = _rectStop.Y;
            }

            stop.X = _rectStop.X;
            if (_rectStop.X < _rectStart.X)
            {
                stop.X = _rectStart.X;
            }
            stop.Y = _rectStop.Y;
            if (_rectStop.Y < _rectStart.Y)
            {
                stop.Y = _rectStart.Y;
            }

            var size = new Size(stop.X - start.X, stop.Y - start.Y);

            if (CurrentCameraID > -1)
            {
                var m = _configs.FirstOrDefault(p => p.CameraID == CurrentCameraID);
                if (m == null)
                {
                    m = new Pipconfig {
                        CameraID = CurrentCameraID, Rect = new Rectangle(start, size)
                    };
                    _configs.Add(m);
                }
                else
                {
                    m.Rect = new Rectangle(start, size);
                }
            }
            _rectStart = Point.Empty;
            _rectStop  = Point.Empty;
            OnBoundsChanged();
        }
Esempio n. 2
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            int endX = Convert.ToInt32((e.X * 1.0) / (Width * 1.0) * 100);
            int endY = Convert.ToInt32((e.Y * 1.0) / (Height * 1.0) * 100);
            
            _rectStop = new Point(endX, endY);
            _bMouseDown = false;
            if (_rectIndex>-1)
            {
                _rectStart = Point.Empty;
                _rectStop = Point.Empty;
                if (endX>100 || endY>100 || endX<0 || endY<0)
                {
                    _configs.RemoveAt(_rectIndex);
                }
                _rectIndex = -1;
                OnBoundsChanged();
                return;
            }
            if (endX > 100)
                endX = 100;
            if (endY > 100)
                endY = 100;
            if (Math.Sqrt(Math.Pow(endX - _rectStart.X, 2) + Math.Pow(endY - _rectStart.Y, 2)) < 5)
            {
                //ignore
                _rectStart = Point.Empty;
                _rectStop = Point.Empty;
                return;
            }
            var start = new Point();
            var stop = new Point();

            start.X = _rectStart.X;
            if (_rectStop.X < _rectStart.X)
                start.X = _rectStop.X;
            start.Y = _rectStart.Y;
            if (_rectStop.Y < _rectStart.Y)
                start.Y = _rectStop.Y;

            stop.X = _rectStop.X;
            if (_rectStop.X < _rectStart.X)
                stop.X = _rectStart.X;
            stop.Y = _rectStop.Y;
            if (_rectStop.Y < _rectStart.Y)
                stop.Y = _rectStart.Y;

            var size = new Size(stop.X - start.X, stop.Y - start.Y);
            if (CurrentCameraID > -1)
            {
                var m = _configs.FirstOrDefault(p => p.CameraID == CurrentCameraID);
                if (m == null)
                {
                    m = new Pipconfig {CameraID = CurrentCameraID, Rect = new Rectangle(start, size)};
                    _configs.Add(m);
                }
                else
                {
                    m.Rect = new Rectangle(start, size);
                }

            }
            _rectStart = Point.Empty;
            _rectStop = Point.Empty;
            OnBoundsChanged();
        }
Esempio n. 3
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            double wmulti = Convert.ToDouble(Width) / Convert.ToDouble(100);
            double hmulti = Convert.ToDouble(Height) / Convert.ToDouble(100);

            var p = new Point(Convert.ToInt32(e.Location.X / wmulti), Convert.ToInt32(e.Location.Y / hmulti));

            if (_bMouseDown)
            {
                if (_hoverPoint != Point.Empty)
                {
                    var r = _configs[_rectIndex];

                    Rectangle rnew = Rectangle.Empty;
                    if (_hoverPoint.X == r.Rect.Left)
                    {
                        rnew = _hoverPoint.Y == r.Rect.Top ? NormRect(new Point(p.X, p.Y), new Point(r.Rect.Right, r.Rect.Bottom)) : NormRect(new Point(p.X, r.Rect.Top), new Point(r.Rect.Right, p.Y));
                    }
                    if (_hoverPoint.X == r.Rect.Right)
                    {
                        rnew = _hoverPoint.Y == r.Rect.Top ? NormRect(new Point(r.Rect.X, p.Y), new Point(p.X, r.Rect.Bottom)) : NormRect(new Point(r.Rect.X, r.Rect.Y), new Point(p.X, p.Y));
                    }
                    _hoverPoint          = new Point(p.X, p.Y);
                    _configs[_rectIndex] = new Pipconfig {
                        CameraID = r.CameraID, Rect = rnew
                    };
                    Invalidate();
                    return;
                }
                int endX = Convert.ToInt32((e.X * 1.0) / (Width * 1.0) * 100);
                int endY = Convert.ToInt32((e.Y * 1.0) / (Height * 1.0) * 100);
                if (endX > 100)
                {
                    endX = 100;
                }
                if (endY > 100)
                {
                    endY = 100;
                }

                _rectStop = new Point(endX, endY);
                if (_rectIndex > -1)
                {
                    var mz = _configs[_rectIndex];
                    mz.Rect.X            = _rectOrig.X + (_rectStop.X - _rectStart.X);
                    mz.Rect.Y            = _rectOrig.Y + (_rectStop.Y - _rectStart.Y);
                    _configs[_rectIndex] = mz;
                }
            }
            else
            {
                _hoverPoint = Point.Empty;

                for (int i = 0; i < _configs.Count; i++)
                {
                    var r = _configs[i];
                    if (CalcDist(r.Rect.Left, r.Rect.Top, p) < 5)
                    {
                        _hoverPoint = new Point(r.Rect.Left, r.Rect.Top);
                        _rectIndex  = i;
                        break;
                    }
                    if (CalcDist(r.Rect.Right, r.Rect.Top, p) < 5)
                    {
                        _hoverPoint = new Point(r.Rect.Right, r.Rect.Top);
                        _rectIndex  = i;
                        break;
                    }
                    if (CalcDist(r.Rect.Right, r.Rect.Bottom, p) < 5)
                    {
                        _hoverPoint = new Point(r.Rect.Right, r.Rect.Bottom);
                        _rectIndex  = i;
                        break;
                    }
                    if (CalcDist(r.Rect.Left, r.Rect.Bottom, p) < 5)
                    {
                        _hoverPoint = new Point(r.Rect.Left, r.Rect.Bottom);
                        _rectIndex  = i;
                        break;
                    }
                }
            }
            Invalidate();
        }
Esempio n. 4
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            double wmulti = Convert.ToDouble(Width) / Convert.ToDouble(100);
            double hmulti = Convert.ToDouble(Height) / Convert.ToDouble(100);

            var p = new Point(Convert.ToInt32(e.Location.X / wmulti), Convert.ToInt32(e.Location.Y / hmulti));

            if (_bMouseDown)
            {
                if (_hoverPoint!=Point.Empty)
                {
                    var r = _configs[_rectIndex];

                    Rectangle rnew = Rectangle.Empty;
                    if (_hoverPoint.X==r.Rect.Left)
                    {
                        rnew = _hoverPoint.Y == r.Rect.Top ? NormRect(new Point(p.X, p.Y), new Point(r.Rect.Right, r.Rect.Bottom)) : NormRect(new Point(p.X, r.Rect.Top), new Point(r.Rect.Right, p.Y));
                    }
                    if (_hoverPoint.X == r.Rect.Right)
                    {
                        rnew = _hoverPoint.Y == r.Rect.Top ? NormRect(new Point(r.Rect.X, p.Y), new Point(p.X, r.Rect.Bottom)) : NormRect(new Point(r.Rect.X, r.Rect.Y), new Point(p.X, p.Y));                        
                    }
                    _hoverPoint = new Point(p.X,p.Y);
                    _configs[_rectIndex] = new Pipconfig {CameraID = r.CameraID, Rect = rnew};
                    Invalidate();
                    return;
                }
                int endX = Convert.ToInt32((e.X * 1.0) / (Width * 1.0) * 100);
                int endY = Convert.ToInt32((e.Y * 1.0) / (Height * 1.0) * 100);
                if (endX > 100)
                    endX = 100;
                if (endY > 100)
                    endY = 100;

                _rectStop = new Point(endX, endY);
                if (_rectIndex>-1)
                {
                    var mz = _configs[_rectIndex];
                    mz.Rect.X = _rectOrig.X + (_rectStop.X - _rectStart.X);
                    mz.Rect.Y = _rectOrig.Y + (_rectStop.Y - _rectStart.Y);
                    _configs[_rectIndex] = mz;
                }
            }
            else
            {
                _hoverPoint = Point.Empty;

                for (int i = 0; i < _configs.Count; i++)
                {
                    var r = _configs[i];
                    if (CalcDist(r.Rect.Left, r.Rect.Top, p) < 5)
                    {
                        _hoverPoint = new Point(r.Rect.Left, r.Rect.Top);
                        _rectIndex = i;
                        break;
                    }
                    if (CalcDist(r.Rect.Right, r.Rect.Top, p) < 5)
                    {
                        _hoverPoint = new Point(r.Rect.Right, r.Rect.Top);
                        _rectIndex = i;
                        break;
                    }
                    if (CalcDist(r.Rect.Right, r.Rect.Bottom, p) < 5)
                    {
                        _hoverPoint = new Point(r.Rect.Right, r.Rect.Bottom);
                        _rectIndex = i;
                        break;
                    }
                    if (CalcDist(r.Rect.Left, r.Rect.Bottom, p) < 5)
                    {
                        _hoverPoint = new Point(r.Rect.Left, r.Rect.Bottom);
                        _rectIndex = i;
                        break;
                    }
                }
            }
            Invalidate();
        }