コード例 #1
0
        /// <summary>
        ///   Mouse move - resize new polygon
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseMove(TransparentCanvas drawArea, MouseEventArgs e)
        {
            drawArea.Cursor = Cursor;

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            if (_newPolygon == null)
            {
                return; // precaution
            }

            Point point    = new Point(e.X, e.Y);
            int   distance = (e.X - _lastX) * (e.X - _lastX) + (e.Y - _lastY) * (e.Y - _lastY);

            if (distance < _minDistance)
            {
                // Distance between last two points is less than minimum -
                // move last point
                _newPolygon.MoveHandleTo(point, _newPolygon.HandleCount);
            }
            else
            {
                // Add new point
                _newPolygon.AddPoint(point);
                _lastX = e.X;
                _lastY = e.Y;
            }

            drawArea.Refresh();
        }
コード例 #2
0
        /// <summary>
        ///   Right mouse button is released
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseUp(TransparentCanvas drawArea, MouseEventArgs e)
        {
            if (_selectMode == SelectionMode.NetSelection)
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(_startPoint, _lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                // Make group selection
                drawArea.GraphicsList.SelectInRectangle(
                    DrawRectangle.GetNormalizedRectangle(_startPoint, _lastPoint));

                _selectMode = SelectionMode.None;
            }

            if (_resizedObject != null)
            {
                // after resizing
                _resizedObject.Normalize();
                _resizedObject = null;
            }

            drawArea.Capture = false;
            drawArea.Refresh();

            if (_commandChangeState != null && _wasMove)
            {
                // Keep state after moving/resizing and add command to history
                _commandChangeState.NewState(drawArea.GraphicsList);
                drawArea.AddCommandToHistory(_commandChangeState);
                _commandChangeState = null;
            }
        }
コード例 #3
0
ファイル: ToolPolygon.cs プロジェクト: gitter-badger/UROCare
        /// <summary>
        ///   Mouse move - resize new polygon
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseMove(TransparentCanvas drawArea, MouseEventArgs e)
        {
            drawArea.Cursor = Cursor;

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            if (_newPolygon == null)
            {
                return; // precaution
            }

            Point point = new Point(e.X, e.Y);
            int distance = (e.X - _lastX)*(e.X - _lastX) + (e.Y - _lastY)*(e.Y - _lastY);

            if (distance < _minDistance)
            {
                // Distance between last two points is less than minimum -
                // move last point
                _newPolygon.MoveHandleTo(point, _newPolygon.HandleCount);
            }
            else
            {
                // Add new point
                _newPolygon.AddPoint(point);
                _lastX = e.X;
                _lastY = e.Y;
            }

            drawArea.Refresh();
        }
コード例 #4
0
ファイル: GraphicsList.cs プロジェクト: gitter-badger/UROCare
        /// <summary>
        ///   Show Properties dialog. Return true if list is changed
        /// </summary>
        /// <param name="parent"> </param>
        /// <returns> </returns>
        public bool ShowPropertiesDialog(TransparentCanvas parent)
        {
            if (SelectionCount < 1)
            {
                return(false);
            }

            GraphicsProperties properties = GetProperties();
//            var dlg = new PropertiesDialog();
//            dlg.Properties = properties;
//
            var c = new CommandChangeState(this);

//
//            if (dlg.ShowDialog(parent) != DialogResult.OK)
//            {
//                return false;
//            }

            if (ApplyProperties(properties))
            {
                c.NewState(this);
                parent.AddCommandToHistory(c);
            }

            return(true);
        }
コード例 #5
0
ファイル: ToolObject.cs プロジェクト: gitter-badger/UROCare
        /// <summary>
        ///   Left mouse is released. New object is created and resized.
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseUp(TransparentCanvas drawArea, MouseEventArgs e)
        {
            drawArea.GraphicsList[0].Normalize();
            drawArea.AddCommandToHistory(new CommandAdd(drawArea.GraphicsList[0]));
            drawArea.ActiveTool = TransparentCanvas.DrawToolType.Pointer;

            drawArea.Capture = false;
            drawArea.Refresh();
        }
コード例 #6
0
ファイル: ToolPolygon.cs プロジェクト: gitter-badger/UROCare
 /// <summary>
 ///   Left nouse button is pressed
 /// </summary>
 /// <param name="drawArea"> </param>
 /// <param name="e"> </param>
 public override void OnMouseDown(TransparentCanvas drawArea, MouseEventArgs e)
 {
     // Create new polygon, add it to the list
     // and keep reference to it
     _newPolygon = new DrawPolygon(e.X, e.Y, e.X + 1, e.Y + 1);
     AddNewObject(drawArea, _newPolygon);
     _lastX = e.X;
     _lastY = e.Y;
 }
コード例 #7
0
ファイル: ToolObject.cs プロジェクト: gitter-badger/UROCare
        /// <summary>
        ///   Left mouse is released. New object is created and resized.
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseUp(TransparentCanvas drawArea, MouseEventArgs e)
        {
            drawArea.GraphicsList[0].Normalize();
            drawArea.AddCommandToHistory(new CommandAdd(drawArea.GraphicsList[0]));
            drawArea.ActiveTool = TransparentCanvas.DrawToolType.Pointer;

            drawArea.Capture = false;
            drawArea.Refresh();
        }
コード例 #8
0
 /// <summary>
 ///   Left nouse button is pressed
 /// </summary>
 /// <param name="drawArea"> </param>
 /// <param name="e"> </param>
 public override void OnMouseDown(TransparentCanvas drawArea, MouseEventArgs e)
 {
     // Create new polygon, add it to the list
     // and keep reference to it
     _newPolygon = new DrawPolygon(e.X, e.Y, e.X + 1, e.Y + 1);
     AddNewObject(drawArea, _newPolygon);
     _lastX = e.X;
     _lastY = e.Y;
 }
コード例 #9
0
        /// <summary>
        ///   Mouse is moved, left mouse button is pressed or none button is pressed
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseMove(TransparentCanvas drawArea, MouseEventArgs e)
        {
            drawArea.Cursor = Cursor;

            if (e.Button == MouseButtons.Left)
            {
                var point = new Point(e.X, e.Y);
                drawArea.GraphicsList[0].MoveHandleTo(point, 5);
                drawArea.Refresh();
            }
        }
コード例 #10
0
        /// <summary>
        ///   Mouse is moved, left mouse button is pressed or none button is pressed
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseMove(TransparentCanvas drawArea, MouseEventArgs e)
        {
            drawArea.Cursor = Cursor;

            if (e.Button == MouseButtons.Left)
            {
                var point = new Point(e.X, e.Y);
                drawArea.GraphicsList[0].MoveHandleTo(point, 5);
                drawArea.Refresh();
            }
        }
コード例 #11
0
ファイル: ToolObject.cs プロジェクト: gitter-badger/UROCare
        /// <summary>
        ///   Add new object to draw area. Function is called when user left-clicks draw area, and one of ToolObject-derived tools is active.
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="o"> </param>
        protected void AddNewObject(TransparentCanvas drawArea, DrawObject o)
        {
            drawArea.GraphicsList.UnselectAll();

            o.Selected = true;
            drawArea.GraphicsList.Add(o);

            drawArea.Capture = true;
            drawArea.Refresh();

            drawArea.SetDirty();
        }
コード例 #12
0
ファイル: ToolObject.cs プロジェクト: gitter-badger/UROCare
        /// <summary>
        ///   Add new object to draw area. Function is called when user left-clicks draw area, and one of ToolObject-derived tools is active.
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="o"> </param>
        protected void AddNewObject(TransparentCanvas drawArea, DrawObject o)
        {
            drawArea.GraphicsList.UnselectAll();

            o.Selected = true;
            drawArea.GraphicsList.Add(o);

            drawArea.Capture = true;
            drawArea.Refresh();

            drawArea.SetDirty();
        }
コード例 #13
0
ファイル: ToolPointer.cs プロジェクト: gitter-badger/UROCare
        /// <summary>
        ///   Left mouse button is pressed
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseDown(TransparentCanvas drawArea, MouseEventArgs e)
        {
            _commandChangeState = null;
            _wasMove = false;

            _selectMode = SelectionMode.None;
            Point point = new Point(e.X, e.Y);

            // Test for resizing (only if control is selected, cursor is on the handle)
            foreach (DrawObject o in drawArea.GraphicsList.Selection)
            {
                int handleNumber = o.HitTest(point);

                if (handleNumber > 0)
                {
                    _selectMode = SelectionMode.Size;

                    // keep resized object in class member
                    _resizedObject = o;
                    _resizedObjectHandle = handleNumber;

                    // Since we want to resize only one object, unselect all other objects
                    drawArea.GraphicsList.UnselectAll();
                    o.Selected = true;

                    _commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    break;
                }
            }

            // Test for move (cursor is on the object)
            if (_selectMode == SelectionMode.None)
            {
                int n1 = drawArea.GraphicsList.Count;
                DrawObject o = null;

                for (int i = 0; i < n1; i++)
                {
                    if (drawArea.GraphicsList[i].HitTest(point) == 0)
                    {
                        o = drawArea.GraphicsList[i];
                        break;
                    }
                }

                if (o != null)
                {
                    _selectMode = SelectionMode.Move;

                    // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        drawArea.GraphicsList.UnselectAll();
                    }

                    // Select clicked object
                    o.Selected = true;

                    _commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            // Net selection
            if (_selectMode == SelectionMode.None)
            {
                // click on background
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.GraphicsList.UnselectAll();
                }

                _selectMode = SelectionMode.NetSelection;
            }

            _lastPoint.X = e.X;
            _lastPoint.Y = e.Y;
            _startPoint.X = e.X;
            _startPoint.Y = e.Y;

            drawArea.Capture = true;

            drawArea.Refresh();

            if (_selectMode == SelectionMode.NetSelection)
            {
                // Draw selection rectangle in initial position
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(_startPoint, _lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
コード例 #14
0
ファイル: ToolPointer.cs プロジェクト: gitter-badger/UROCare
        /// <summary>
        ///   Right mouse button is released
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseUp(TransparentCanvas drawArea, MouseEventArgs e)
        {
            if (_selectMode == SelectionMode.NetSelection)
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(_startPoint, _lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                // Make group selection
                drawArea.GraphicsList.SelectInRectangle(
                    DrawRectangle.GetNormalizedRectangle(_startPoint, _lastPoint));

                _selectMode = SelectionMode.None;
            }

            if (_resizedObject != null)
            {
                // after resizing
                _resizedObject.Normalize();
                _resizedObject = null;
            }

            drawArea.Capture = false;
            drawArea.Refresh();

            if (_commandChangeState != null && _wasMove)
            {
                // Keep state after moving/resizing and add command to history
                _commandChangeState.NewState(drawArea.GraphicsList);
                drawArea.AddCommandToHistory(_commandChangeState);
                _commandChangeState = null;
            }
        }
コード例 #15
0
ファイル: ToolPointer.cs プロジェクト: gitter-badger/UROCare
        /// <summary>
        ///   Mouse is moved. None button is pressed, or left button is pressed.
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseMove(TransparentCanvas drawArea, MouseEventArgs e)
        {
            Point point = new Point(e.X, e.Y);
            Point oldPoint = _lastPoint;

            _wasMove = true;

            // set cursor when mouse button is not pressed
            if (e.Button == MouseButtons.None)
            {
                Cursor cursor = null;

                for (int i = 0; i < drawArea.GraphicsList.Count; i++)
                {
                    int n = drawArea.GraphicsList[i].HitTest(point);

                    if (n > 0)
                    {
                        cursor = drawArea.GraphicsList[i].GetHandleCursor(n);
                        break;
                    }
                }

                if (cursor == null)
                {
                    cursor = Cursors.Default;
                }

                drawArea.Cursor = cursor;

                return;
            }

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            // Find difference between previous and current position
            int dx = e.X - _lastPoint.X;
            int dy = e.Y - _lastPoint.Y;

            _lastPoint.X = e.X;
            _lastPoint.Y = e.Y;

            // resize
            if (_selectMode == SelectionMode.Size)
            {
                if (_resizedObject != null)
                {
                    _resizedObject.MoveHandleTo(point, _resizedObjectHandle);
                    drawArea.SetDirty();
                    drawArea.Refresh();
                }
            }

            // move
            if (_selectMode == SelectionMode.Move)
            {
                foreach (DrawObject o in drawArea.GraphicsList.Selection)
                {
                    o.Move(dx, dy);
                }

                drawArea.Cursor = Cursors.SizeAll;
                drawArea.SetDirty();
                drawArea.Refresh();
            }

            if (_selectMode == SelectionMode.NetSelection)
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(_startPoint, oldPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                // Draw new selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(_startPoint, point)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
コード例 #16
0
ファイル: Tool.cs プロジェクト: gitter-badger/UROCare
 /// <summary>
 ///   Left mouse button is released
 /// </summary>
 /// <param name="drawArea"> </param>
 /// <param name="e"> </param>
 public virtual void OnMouseUp(TransparentCanvas drawArea, MouseEventArgs e)
 {
 }
コード例 #17
0
ファイル: ToolPolygon.cs プロジェクト: gitter-badger/UROCare
        public override void OnMouseUp(TransparentCanvas drawArea, MouseEventArgs e)
        {
            _newPolygon = null;

            base.OnMouseUp(drawArea, e);
        }
コード例 #18
0
        public override void OnMouseUp(TransparentCanvas drawArea, MouseEventArgs e)
        {
            _newPolygon = null;

            base.OnMouseUp(drawArea, e);
        }
コード例 #19
0
        /// <summary>
        ///   Left mouse button is pressed
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseDown(TransparentCanvas drawArea, MouseEventArgs e)
        {
            _commandChangeState = null;
            _wasMove            = false;

            _selectMode = SelectionMode.None;
            Point point = new Point(e.X, e.Y);

            // Test for resizing (only if control is selected, cursor is on the handle)
            foreach (DrawObject o in drawArea.GraphicsList.Selection)
            {
                int handleNumber = o.HitTest(point);

                if (handleNumber > 0)
                {
                    _selectMode = SelectionMode.Size;

                    // keep resized object in class member
                    _resizedObject       = o;
                    _resizedObjectHandle = handleNumber;

                    // Since we want to resize only one object, unselect all other objects
                    drawArea.GraphicsList.UnselectAll();
                    o.Selected = true;

                    _commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    break;
                }
            }

            // Test for move (cursor is on the object)
            if (_selectMode == SelectionMode.None)
            {
                int        n1 = drawArea.GraphicsList.Count;
                DrawObject o  = null;

                for (int i = 0; i < n1; i++)
                {
                    if (drawArea.GraphicsList[i].HitTest(point) == 0)
                    {
                        o = drawArea.GraphicsList[i];
                        break;
                    }
                }

                if (o != null)
                {
                    _selectMode = SelectionMode.Move;

                    // Unselect all if Ctrl is not pressed and clicked object is not selected yet
                    if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected)
                    {
                        drawArea.GraphicsList.UnselectAll();
                    }

                    // Select clicked object
                    o.Selected = true;

                    _commandChangeState = new CommandChangeState(drawArea.GraphicsList);

                    drawArea.Cursor = Cursors.SizeAll;
                }
            }

            // Net selection
            if (_selectMode == SelectionMode.None)
            {
                // click on background
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    drawArea.GraphicsList.UnselectAll();
                }

                _selectMode = SelectionMode.NetSelection;
            }

            _lastPoint.X  = e.X;
            _lastPoint.Y  = e.Y;
            _startPoint.X = e.X;
            _startPoint.Y = e.Y;

            drawArea.Capture = true;

            drawArea.Refresh();

            if (_selectMode == SelectionMode.NetSelection)
            {
                // Draw selection rectangle in initial position
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(_startPoint, _lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
コード例 #20
0
ファイル: ToolLine.cs プロジェクト: gitter-badger/UROCare
 public override void OnMouseDown(TransparentCanvas drawArea, MouseEventArgs e)
 {
     AddNewObject(drawArea, new DrawLine(e.X, e.Y, e.X + 1, e.Y + 1));
 }
コード例 #21
0
        /// <summary>
        ///   Mouse is moved. None button is pressed, or left button is pressed.
        /// </summary>
        /// <param name="drawArea"> </param>
        /// <param name="e"> </param>
        public override void OnMouseMove(TransparentCanvas drawArea, MouseEventArgs e)
        {
            Point point    = new Point(e.X, e.Y);
            Point oldPoint = _lastPoint;

            _wasMove = true;

            // set cursor when mouse button is not pressed
            if (e.Button == MouseButtons.None)
            {
                Cursor cursor = null;

                for (int i = 0; i < drawArea.GraphicsList.Count; i++)
                {
                    int n = drawArea.GraphicsList[i].HitTest(point);

                    if (n > 0)
                    {
                        cursor = drawArea.GraphicsList[i].GetHandleCursor(n);
                        break;
                    }
                }

                if (cursor == null)
                {
                    cursor = Cursors.Default;
                }

                drawArea.Cursor = cursor;

                return;
            }

            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            // Find difference between previous and current position
            int dx = e.X - _lastPoint.X;
            int dy = e.Y - _lastPoint.Y;

            _lastPoint.X = e.X;
            _lastPoint.Y = e.Y;

            // resize
            if (_selectMode == SelectionMode.Size)
            {
                if (_resizedObject != null)
                {
                    _resizedObject.MoveHandleTo(point, _resizedObjectHandle);
                    drawArea.SetDirty();
                    drawArea.Refresh();
                }
            }

            // move
            if (_selectMode == SelectionMode.Move)
            {
                foreach (DrawObject o in drawArea.GraphicsList.Selection)
                {
                    o.Move(dx, dy);
                }

                drawArea.Cursor = Cursors.SizeAll;
                drawArea.SetDirty();
                drawArea.Refresh();
            }

            if (_selectMode == SelectionMode.NetSelection)
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(_startPoint, oldPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                // Draw new selection rectangle
                ControlPaint.DrawReversibleFrame(
                    drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(_startPoint, point)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
コード例 #22
0
ファイル: ToolLine.cs プロジェクト: gitter-badger/UROCare
 public override void OnMouseDown(TransparentCanvas drawArea, MouseEventArgs e)
 {
     AddNewObject(drawArea, new DrawLine(e.X, e.Y, e.X + 1, e.Y + 1));
 }
コード例 #23
0
 /// <summary>
 ///   Left nous button is pressed
 /// </summary>
 /// <param name="drawArea"> </param>
 /// <param name="e"> </param>
 public override void OnMouseDown(TransparentCanvas drawArea, MouseEventArgs e)
 {
     AddNewObject(drawArea, new DrawRectangle(e.X, e.Y, 1, 1));
 }
コード例 #24
0
 /// <summary>
 ///   Left nous button is pressed
 /// </summary>
 /// <param name="drawArea"> </param>
 /// <param name="e"> </param>
 public override void OnMouseDown(TransparentCanvas drawArea, MouseEventArgs e)
 {
     AddNewObject(drawArea, new DrawRectangle(e.X, e.Y, 1, 1));
 }
コード例 #25
0
ファイル: GraphicsList.cs プロジェクト: gitter-badger/UROCare
        /// <summary>
        ///   Show Properties dialog. Return true if list is changed
        /// </summary>
        /// <param name="parent"> </param>
        /// <returns> </returns>
        public bool ShowPropertiesDialog(TransparentCanvas parent)
        {
            if (SelectionCount < 1)
            {
                return false;
            }

            GraphicsProperties properties = GetProperties();
//            var dlg = new PropertiesDialog();
//            dlg.Properties = properties;
//
            var c = new CommandChangeState(this);
//
//            if (dlg.ShowDialog(parent) != DialogResult.OK)
//            {
//                return false;
//            }

            if (ApplyProperties(properties))
            {
                c.NewState(this);
                parent.AddCommandToHistory(c);
            }

            return true;
        }
コード例 #26
0
ファイル: Tool.cs プロジェクト: gitter-badger/UROCare
 /// <summary>
 ///   Left mouse button is released
 /// </summary>
 /// <param name="drawArea"> </param>
 /// <param name="e"> </param>
 public virtual void OnMouseUp(TransparentCanvas drawArea, MouseEventArgs e)
 {
 }