// This will draw a temporary shape as a "cursor" wherever the user moves // the mouse. This cursor is the same size as the actual shape that will // be drawn in HandleMouseDown(), so that the user can know where they are // going to be drawing if they click the mouse. private void HandleMouseMoved(object sender, MouseEventArgs e) { // We don't want to actually draw a shape here, but instead to draw a temporary cursor. // So we're going to make a new DrawLineAction or DrawCircleAction, etc., just like in // HandleMouseDown, but instead of adding it to the list of actions, we're going to set it // as the Cursor of the DrawingModel. We'll let the DrawingModel take care of the details of // drawing a cursor (a temporary image) instead of drawing a permanent shape. if (_isDrawing) { if (DrawLinesButton.Checked) { _canvasModel.Cursor = new DrawLineAction(_cursorPen, _startPoint.X, _startPoint.Y, e.Location.X, e.Location.Y); } else if (DrawCirclesButton.Checked) { int radius = MathHelpers.GetRadius(_startPoint, new Point(e.Location.X, e.Location.Y)); if (radius > 0) { _canvasModel.Cursor = new DrawCircleAction(_cursorPen, _startPoint.X, _startPoint.Y, radius); } } } // _lastKnownX = e.Location.X; // _lastKnownY = e.Location.Y; }
private IDrawAction GetAction(MouseEventArgs e, Pen pen) { if (DrawLinesButton.Checked) { return(new DrawLineAction(pen, _startPoint.X, _startPoint.Y, e.Location.X, e.Location.Y)); } if (DrawCirclesButton.Checked) { int radius = MathHelpers.GetRadius(_startPoint, new Point(e.Location.X, e.Location.Y)); if (radius == 0) { return(null); } return(new DrawCircleAction(pen, _startPoint.X, _startPoint.Y, radius)); } if (DrawRectanglesButton.Checked) { return(new DrawRectangleAction(pen, _startPoint.X, _startPoint.Y, e.Location.X, e.Location.Y)); } if (DrawXesButton.Checked) { return(new DrawXesAction(pen, _startPoint.X, e.Location.X, _startPoint.Y, e.Location.Y)); } return(null); }
private void HandleMouseUp(object sender, MouseEventArgs e) { // Here's where we actually draw the shape. We also hide the cursor (by setting it to // null) and turn off the "_isDrawing" flag value. if (DrawLinesButton.Checked) { _actions.Add(new DrawLineAction(_pen, _startPoint.X, _startPoint.Y, e.Location.X, e.Location.Y)); } else if (DrawCirclesButton.Checked) { int radius = MathHelpers.GetRadius(_startPoint, new Point(e.Location.X, e.Location.Y)); if (radius > 0) { _actions.Add(new DrawCircleAction(_pen, _startPoint.X, _startPoint.Y, radius)); } } _canvasModel.Cursor = null; _isDrawing = false; }
public void DrawSomethingFrom(Point start, Point end, bool isCursor) { if (DrawCirclesButton.Checked) { // Draw a circle whose center is start, and whose outside passes through end _canvasModel.DrawCircle(_pen, start.X, start.Y, MathHelpers.GetRadius(start, end), isCursor); } else if (DrawXesButton.Checked) { _canvasModel.DrawLine(_pen, start.X, start.Y, end.X, end.Y, isCursor); _canvasModel.DrawLine(_pen, start.X, end.Y, end.X, start.Y, isCursor); } else if (DrawRectanglesButton.Checked) { _canvasModel.DrawLine(_pen, start.X, start.Y, end.X, start.Y, isCursor); _canvasModel.DrawLine(_pen, end.X, start.Y, end.X, end.Y, isCursor); _canvasModel.DrawLine(_pen, end.X, end.Y, start.X, end.Y, isCursor); _canvasModel.DrawLine(_pen, start.X, end.Y, start.X, start.Y, isCursor); } else { _canvasModel.DrawLine(_pen, start.X, start.Y, end.X, end.Y, isCursor); } }
//should be able to pass the entire object created from xml file private IDrawAction GetActionFromSavedSession(SessionData drawObject) { // ARBG in a 32 bit integer representing the ARBG values // unable to capture the name for all the colors - use arbg values _color = Color.FromArgb(drawObject.PenColor_ARBG); _fillcolor = Color.FromArgb(drawObject.BrushColor_ARBG); //get line width _line_width = drawObject.LineWidth; //get type pen if (drawObject.IsFill) { _drawingBrush = new SolidBrush(_fillcolor); } else { _drawingPen = new Pen(_color, _line_width); } //get start and end points _startPoint.X = drawObject.StartX; _startPoint.Y = drawObject.StartY; _endPoint.X = drawObject.EndX; _endPoint.Y = drawObject.EndY; if (drawObject.NameofDrawingAction.Contains("DrawLineAction")) { return(new DrawLineAction(_drawingPen, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y)); } if (drawObject.NameofDrawingAction.Contains("DrawCircle") || drawObject.NameofDrawingAction.Contains("Oval")) { //shift key not saved state - no long depressed when action completed so it's not saved as true if (drawObject.IsShift) { if (drawObject.IsFill) { return(new DrawOvalAction(_drawingBrush, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y, true)); } else { return(new DrawOvalAction(_drawingPen, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y)); } } else { if (drawObject.IsFill) { int radius = MathHelpers.GetRadius(_startPoint, new Point(_endPoint.X, _endPoint.Y)); if (radius == 0) { return(null); } return(new DrawCircleAction(_drawingBrush, _startPoint.X, _startPoint.Y, radius, true)); } else { int radius = MathHelpers.GetRadius(_startPoint, new Point(_endPoint.X, _endPoint.Y)); if (radius == 0) { return(null); } return(new DrawCircleAction(_drawingPen, _startPoint.X, _startPoint.Y, radius)); } } } if (drawObject.NameofDrawingAction.Contains("Rectangle")) { if (drawObject.IsFill) { if (drawObject.IsShift) { //MessageBox.Show("shift key"); int diffx = Math.Abs(_startPoint.X - _endPoint.X); int samexy = _startPoint.Y + diffx; return(new DrawRectangleAction(_drawingBrush, _startPoint.X, _startPoint.Y, _endPoint.X, samexy, true)); } return(new DrawRectangleAction(_drawingBrush, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y, true)); } else { if (drawObject.IsShift) { //MessageBox.Show("shift key"); int diffx = Math.Abs(_startPoint.X - _endPoint.X); int samexy = _startPoint.Y + diffx; return(new DrawRectangleAction(_drawingPen, _startPoint.X, _startPoint.Y, _endPoint.X, samexy)); } return(new DrawRectangleAction(_drawingPen, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y)); } } if (drawObject.NameofDrawingAction.Contains("DrawX")) { return(new DrawXAction(_drawingPen, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y)); } return(null); }
private IDrawAction GetAction(MouseEventArgs e, Pen pen) { //takes mouse arg e and converts to point / adjusts all points to next 5 Sanp2Grid(e); if (DrawLinesButton.Checked) { return(new DrawLineAction(pen, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y)); } if (DrawCirclesButton.Checked) { if (Control.ModifierKeys == Keys.Shift) { _shiftKeyFlag = true; if (FillcheckBox.Checked) { return(new DrawOvalAction(_drawingBrush, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y, true)); } else { return(new DrawOvalAction(pen, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y)); } } else { if (FillcheckBox.Checked) { int radius = MathHelpers.GetRadius(_startPoint, new Point(_endPoint.X, _endPoint.Y)); if (radius == 0) { return(null); } return(new DrawCircleAction(_drawingBrush, _startPoint.X, _startPoint.Y, radius, true)); } else { int radius = MathHelpers.GetRadius(_startPoint, new Point(_endPoint.X, _endPoint.Y)); if (radius == 0) { return(null); } return(new DrawCircleAction(pen, _startPoint.X, _startPoint.Y, radius)); } } } if (DrawRectanglesButton.Checked) { if (FillcheckBox.Checked) { if (Control.ModifierKeys == Keys.Shift) { _shiftKeyFlag = true; //MessageBox.Show("shift key"); int diffx = Math.Abs(_startPoint.X - _endPoint.X); int samexy = _startPoint.Y + diffx; return(new DrawRectangleAction(_drawingBrush, _startPoint.X, _startPoint.Y, _endPoint.X, samexy, true)); } return(new DrawRectangleAction(_drawingBrush, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y, true)); } else { if (Control.ModifierKeys == Keys.Shift) { _shiftKeyFlag = true; //MessageBox.Show("shift key"); int diffx = Math.Abs(_startPoint.X - _endPoint.X); int samexy = _startPoint.Y + diffx; return(new DrawRectangleAction(pen, _startPoint.X, _startPoint.Y, _endPoint.X, samexy)); } return(new DrawRectangleAction(pen, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y)); } } if (DrawXesButton.Checked) { return(new DrawXAction(pen, _startPoint.X, _startPoint.Y, _endPoint.X, _endPoint.Y)); } return(null); }