Beispiel #1
0
        private void BoxView_MouseUp(object sender, MouseEventArgs e)
        {
            if (mode == EidtMode.MoveBox)
            {
                if (snap_gird)
                {
                    if (_selected_box != null)
                    {
                        Vector2 newPos = Snap(_selected_box.a);
                        Vector2 offset = newPos - _selected_box.a;
                        _selected_box.a  = newPos;
                        _selected_box.b += offset;
                        _selected_box.c += offset;
                        _selected_box.d += offset;
                    }
                }
            }
            else if (mode == EidtMode.CreateBox)
            {
                if (snap_gird)
                {
                    if (_selected_box != null)
                    {
                        _selected_box.a = Snap(_selected_box.a);
                        _selected_box.b = Snap(_selected_box.b);
                        _selected_box.c = Snap(_selected_box.c);
                        _selected_box.d = Snap(_selected_box.d);
                    }
                }

                //忽略面积太小的BOX
                Vector2 range = _selected_box.c - _selected_box.a;
                if (Math.Abs(range.x * range.y) > 0.01f)
                {
                    _boxList.Add(_selected_box);
                    if (listener != null)
                    {
                        listener.onAddBox(this);
                    }
                }
            }
            else if (mode == EidtMode.EditBox)
            {
                if (snap_gird)
                {
                    if (_selected_box != null)
                    {
                        _selected_box.a = Snap(_selected_box.a);
                        _selected_box.b = Snap(_selected_box.b);
                        _selected_box.c = Snap(_selected_box.c);
                        _selected_box.d = Snap(_selected_box.d);
                    }
                }

                //删除面积太小的BOX
                Vector2 range = _selected_box.c - _selected_box.a;
                if (Math.Abs(range.x * range.y) <= 0.01f)
                {
                    _boxList.Remove(_selected_box);
                    if (listener != null)
                    {
                        listener.onRemoveBox(this);
                    }
                }
                else
                {
                    if (listener != null)
                    {
                        listener.onBoxChanged(this, _selected_box);
                    }
                }
            }


            mode          = EidtMode.None;
            _selected_box = null;
            Refresh();
        }
Beispiel #2
0
        private void BoxView_MouseDown(object sender, MouseEventArgs e)
        {
            if (listener == null)
            {
                return;
            }

            //查找BOX
            Vector2 pt = ViewPointToUnityPoint(e.Location);

            foreach (var box in _boxList.ToArray())
            {
                if (box.PointIn(pt))
                {
                    //左键移动
                    if (e.Button == System.Windows.Forms.MouseButtons.Left)
                    {
                        _selected_box = box;
                        if ((Control.ModifierKeys & Keys.Control) == Keys.Control)  //判断Ctrl键
                        {
                            mode = EidtMode.EditBox;
                        }
                        else
                        {
                            mode = EidtMode.MoveBox;
                        }

                        _lastMosePoint = e.Location;
                        Refresh();
                        return;
                    }
                    //右键删除
                    else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                    {
                        _boxList.Remove(box);
                        if (listener != null)
                        {
                            listener.onRemoveBox(this);
                        }
                        Refresh();
                        return;
                    }
                }
            }



            //创建BOX
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                mode            = EidtMode.CreateBox;
                _lastMosePoint  = e.Location;
                _selected_box   = new Quad();
                _selected_box.a = ViewPointToUnityPoint(e.Location);
                _selected_box.b = ViewPointToUnityPoint(e.Location);
                _selected_box.c = ViewPointToUnityPoint(e.Location);
                _selected_box.d = ViewPointToUnityPoint(e.Location);
            }
            else if (e.Button == System.Windows.Forms.MouseButtons.Middle)
            {
                mode           = EidtMode.MoveView;
                _lastMosePoint = e.Location;
            }
        }