Пример #1
0
        /// <summary>
        /// Show Properties dialog. Return true if list is changed
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public bool ShowPropertiesDialog(MkaDocument parent)
        {
            if (SelectionCount < 1)
            {
                return(false);
            }

            MkaMokkanInfo      info       = new MkaMokkanInfo();
            GraphicsProperties properties = new GraphicsProperties();
            bool multi = (SelectionCount > 1);

            // get properties from selected object
            GetProperties(ref info, ref properties);

            MkaPropertiesMokkan dlg = new MkaPropertiesMokkan(this, info, properties, multi);
            CommandChange       c   = new CommandChange(this);

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

            if (ApplyProperties(dlg.MokkanProperty, dlg.Properties))
            {
                c.NewState(this);
                parent.AddCommandToHistory(c);
                return(true);
            }

            return(false);
        }
Пример #2
0
        /// <summary>
        /// Mouse move - resize new polygon
        /// </summary>
        public override void OnMouseMove(MkaDocument docArea, MouseEventArgs e)
        {
            docArea.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;
            }

            docArea.Refresh();
        }
Пример #3
0
        /// <summary>
        /// Right mouse button is released
        /// </summary>
        public override void OnMouseUp(MkaDocument docArea, MouseEventArgs e)
        {
            if (selectMode == SelectionMode.NetSelection)
            {
                // Remove old selection rectangle
                ControlPaint.DrawReversibleFrame(
                    docArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);

                // Make group selection
                docArea.MokkanList.SelectInRectangle(
                    DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint));

                selectMode = SelectionMode.None;
            }

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

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

            if (commandChangeState != null && wasMove)
            {
                // Keep state after moving/resizing and add command to history
                commandChangeState.NewState(docArea.MokkanList);
                docArea.AddCommandToHistory(commandChangeState);
                commandChangeState = null;
            }
        }
Пример #4
0
 /// <summary>
 /// Left mouse button is pressed
 /// </summary>
 public override void OnMouseDown(MkaDocument docArea, 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(docArea, newPolygon);
     lastX = e.X;
     lastY = e.Y;
 }
Пример #5
0
        /// <summary>
        /// Mouse is moved, left mouse button is pressed or none button is pressed
        /// </summary>
        public override void OnMouseMove(MkaDocument docArea, MouseEventArgs e)
        {
            docArea.Cursor = Cursor;

            if (e.Button == MouseButtons.Left)
            {
                Point point = new Point(e.X, e.Y);
                docArea.MokkanList[0].MoveHandleTo(point, 5);
                docArea.Refresh();
            }
        }
Пример #6
0
        /// <summary>
        /// Left mouse is released.
        /// New object is created and resized.
        /// </summary>
        public override void OnMouseUp(MkaDocument docArea, MouseEventArgs e)
        {
            docArea.MokkanList[0].Normalize();
            List <DrawObject> list = new List <DrawObject>();

            list.Add(docArea.MokkanList[0]);
            docArea.AddCommandToHistory(new CommandAdd(list));
            docArea.ActiveTool = ToolType.Pointer;

            docArea.Capture = false;
            docArea.Refresh();
        }
Пример #7
0
        /// <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>
        protected void AddNewObject(MkaDocument docArea, DrawObject o)
        {
            docArea.MokkanList.UnselectAll();

            o.Selected = true;
            docArea.MokkanList.Add(o);
            docArea.MokkanList[0].MokkanInfo.RBangou = docArea.MokkanList.GetNextRBangou(docArea.MokkanList[0].MokkanInfo.RBangou, 1);
            MkaMokkanInfo.LastRBangou = docArea.MokkanList.GetNextRBangou(MkaMokkanInfo.LastRBangou + 1, 0);
            docArea.Capture           = true;
            docArea.Refresh();

            docArea.SetDirty();
        }
Пример #8
0
        /// <summary>
        /// Left mouse button is released
        /// </summary>
        public override void OnMouseUp(MkaDocument docArea, MouseEventArgs e)
        {
            newPolygon = null;

            base.OnMouseUp(docArea, e);
        }
Пример #9
0
 /// <summary>
 /// Left mouse button is pressed
 /// </summary>
 public override void OnMouseDown(MkaDocument docArea, MouseEventArgs e)
 {
     AddNewObject(docArea, new DrawEllipse(e.X, e.Y, 1, 1));
 }
Пример #10
0
 /// <summary>
 /// Left mouse button is released
 /// </summary>
 public virtual void OnMouseUp(MkaDocument docArea, MouseEventArgs e)
 {
 }
Пример #11
0
        /// <summary>
        /// Left mouse button is pressed
        /// </summary>
        public override void OnMouseDown(MkaDocument docArea, 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 docArea.MokkanList.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
                    docArea.MokkanList.UnselectAll();
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(docArea.MokkanList);

                    break;
                }
            }

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

                for (int i = 0; i < n1; i++)
                {
                    if (docArea.MokkanList[i].HitTest(point) == 0)
                    {
                        o = docArea.MokkanList[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)
                    {
                        docArea.MokkanList.UnselectAll();
                    }

                    // Select clicked object
                    o.Selected = true;

                    commandChangeState = new CommandChangeState(docArea.MokkanList);

                    docArea.Cursor = Cursors.SizeAll;
                }
            }

            // Net selection
            if (selectMode == SelectionMode.None)
            {
                // click on background
                if ((Control.ModifierKeys & Keys.Control) == 0)
                {
                    docArea.MokkanList.UnselectAll();
                }

                selectMode = SelectionMode.NetSelection;
            }

            lastPoint.X  = e.X;
            lastPoint.Y  = e.Y;
            startPoint.X = e.X;
            startPoint.Y = e.Y;

            docArea.Capture = true;

            docArea.Refresh();

            if (selectMode == SelectionMode.NetSelection)
            {
                // Draw selection rectangle in initial position
                ControlPaint.DrawReversibleFrame(
                    docArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, lastPoint)),
                    Color.Black,
                    FrameStyle.Dashed);
            }
        }
Пример #12
0
        /// <summary>
        /// Mouse is moved.
        /// None button is pressed, or left button is pressed.
        /// </summary>
        public override void OnMouseMove(MkaDocument docArea, 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 < docArea.MokkanList.Count; i++)
                {
                    int n = docArea.MokkanList[i].HitTest(point);

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

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

                docArea.Cursor = cursor;

                return;
            }

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

            /// Left button is pressed

            // 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);
                    docArea.SetDirty();
                    docArea.Refresh();
                }
            }

            // move
            if (selectMode == SelectionMode.Move)
            {
                foreach (DrawObject o in docArea.MokkanList.Selection)
                {
                    o.Move(dx, dy);
                }

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

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

                // Draw new selection rectangle
                ControlPaint.DrawReversibleFrame(
                    docArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, point)),
                    Color.Black,
                    FrameStyle.Dashed);

                return;
            }
        }