/// <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; } }
/// <summary> /// Draw rectangle /// </summary> /// <param name="g"></param> public override void Draw(Graphics g) { Pen pen = Properties.GetPen(); SolidBrush brush = Properties.GetBrush(); // draw rectangle Rectangle rec = DrawRectangle.GetNormalizedRectangle(Rectangle); rec.X = (int)Math.Round(rec.X * Ratio); rec.Y = (int)Math.Round(rec.Y * Ratio); rec.Width = (int)Math.Round(rec.Width * Ratio); rec.Height = (int)Math.Round(rec.Height * Ratio); g.DrawRectangle(pen, rec); g.FillRectangle(brush, rec); // draw remain id if (RShow) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; Font font = new Font(MkaDefine.RDefaultFontName, this.Properties.RFontSize * Ratio); SizeF measure = g.MeasureString(MokkanInfo.RBangou.ToString(), font); PointF showPnt; if (Properties.RShowPosition == ShowPosition.Top) { showPnt = new PointF(this.Properties.RShowLocation.X * Ratio, this.Properties.RShowLocation.Y * Ratio - measure.Height / 2.0f); } else { showPnt = new PointF(this.Properties.RShowLocation.X * Ratio, this.Properties.RShowLocation.Y * Ratio + measure.Height / 2.0f); } g.DrawString(MokkanInfo.RBangou.ToString(), font, MkaDefine.PrintTextBrush, showPnt, sf); } pen.Dispose(); brush.Dispose(); }
/// <summary> /// Normalize rectangle /// </summary> public override void Normalize() { rectangle = DrawRectangle.GetNormalizedRectangle(rectangle); }
/// <summary> /// Get handle point by 1-based number /// </summary> /// <param name="handleNumber"></param> /// <returns></returns> public override Point GetHandle(int handleNumber) { int x, y, xCenter, yCenter; Rectangle rectangle = DrawRectangle.GetNormalizedRectangle(Rectangle); rectangle.X = (int)Math.Round(rectangle.X * Ratio); rectangle.Y = (int)Math.Round(rectangle.Y * Ratio); rectangle.Width = (int)Math.Round(rectangle.Width * Ratio); rectangle.Height = (int)Math.Round(rectangle.Height * Ratio); xCenter = rectangle.X + rectangle.Width / 2; yCenter = rectangle.Y + rectangle.Height / 2; x = rectangle.X; y = rectangle.Y; switch (handleNumber) { case 1: x = rectangle.X; y = rectangle.Y; break; case 2: x = xCenter; y = rectangle.Y; break; case 3: x = rectangle.Right; y = rectangle.Y; break; case 4: x = rectangle.Right; y = yCenter; break; case 5: x = rectangle.Right; y = rectangle.Bottom; break; case 6: x = xCenter; y = rectangle.Bottom; break; case 7: x = rectangle.X; y = rectangle.Bottom; break; case 8: x = rectangle.X; y = yCenter; break; } return(new Point(x, y)); }
/// <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); } }
/// <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; } }