public override void Draw(Graphics g) { g.SmoothingMode = SmoothingMode.AntiAlias; Pen pen; if (DrawPen == null) { pen = new Pen(Color, PenWidth); DrawingPens.SetCurrentPen(ref pen, PenType, EndCap); } else { pen = (Pen)DrawPen.Clone(); } GraphicsPath gp = new GraphicsPath(); gp.AddLine(startPoint, endPoint); // Rotate the path about it's center if necessary if (Rotation != 0) { RectangleF pathBounds = gp.GetBounds(); Matrix m = new Matrix(); m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append); gp.Transform(m); } g.DrawPath(pen, gp); gp.Dispose(); pen.Dispose(); }
public override void Draw(Graphics g) { g.SmoothingMode = SmoothingMode.AntiAlias; Pen pen; if (DrawPen == null) { pen = new Pen(Color, PenWidth); DrawingPens.SetCurrentPen(ref pen, PenType, EndCap); } else { pen = DrawPen.Clone() as Pen; } Point[] pts = new Point[pointArray.Count]; for (int i = 0; i < pointArray.Count; i++) { Point px = (Point)pointArray[i]; pts[i] = px; } byte[] types = new byte[pointArray.Count]; for (int i = 0; i < pointArray.Count; i++) { types[i] = (byte)PathPointType.Line; } GraphicsPath gp = new GraphicsPath(pts, types); // Rotate the path about it's center if necessary if (Rotation != 0) { RectangleF pathBounds = gp.GetBounds(); Matrix m = new Matrix(); m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append); gp.Transform(m); } g.DrawPath(pen, gp); //g.DrawCurve(pen, pts); gp.Dispose(); if (pen != null) { pen.Dispose(); } }
/// <summary> /// Draw rectangle /// </summary> /// <param name="g"></param> public override void Draw(Graphics g) { Pen pen; Brush b = new SolidBrush(FillColor); if (DrawPen == null) { pen = new Pen(Color, PenWidth); DrawingPens.SetCurrentPen(ref pen, PenType, EndCap); } else { pen = (Pen)DrawPen.Clone(); } GraphicsPath gp = new GraphicsPath(); gp.AddRectangle(GetNormalizedRectangle(Rectangle)); // Rotate the path about it's center if necessary if (Rotation != 0) { RectangleF pathBounds = gp.GetBounds(); Matrix m = new Matrix(); m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append); gp.Transform(m); } if (Filled) { g.FillPath(b, gp); } g.DrawPath(pen, gp); gp.Dispose(); pen.Dispose(); b.Dispose(); }
/// <summary> /// Set state of controls. /// Function is called at idle time. /// </summary> public void SetStateOfControls() { // Select active tool toolStripButtonPointer.Checked = !drawArea.Panning && (drawArea.ActiveTool == DrawArea.DrawToolType.Pointer); toolStripButtonRectangle.Checked = (drawArea.ActiveTool == DrawArea.DrawToolType.Rectangle); toolStripButtonEllipse.Checked = (drawArea.ActiveTool == DrawArea.DrawToolType.Ellipse); toolStripButtonArrow.Checked = drawArea.EndCap == LineCap.ArrowAnchor && (drawArea.ActiveTool == DrawArea.DrawToolType.Line); toolStripButtonLine.Checked = drawArea.EndCap != LineCap.ArrowAnchor && (drawArea.ActiveTool == DrawArea.DrawToolType.Line); toolStripButtonPencil.Checked = (drawArea.ActiveTool == DrawArea.DrawToolType.Polygon); pointerToolStripMenuItem.Checked = (drawArea.ActiveTool == DrawArea.DrawToolType.Pointer); rectangleToolStripMenuItem.Checked = (drawArea.ActiveTool == DrawArea.DrawToolType.Rectangle); ellipseToolStripMenuItem.Checked = (drawArea.ActiveTool == DrawArea.DrawToolType.Ellipse); lineToolStripMenuItem.Checked = (drawArea.ActiveTool == DrawArea.DrawToolType.Line); pencilToolStripMenuItem.Checked = (drawArea.ActiveTool == DrawArea.DrawToolType.Polygon); switch (drawArea.LineWidth) { case -1: this.toolStripDropDownButtonLineThickness.Text = "Thinnest"; break; case 2: this.toolStripDropDownButtonLineThickness.Text = "Thin"; break; case 5: this.toolStripDropDownButtonLineThickness.Text = "Thick"; break; case 10: this.toolStripDropDownButtonLineThickness.Text = "Thicker"; break; case 15: this.toolStripDropDownButtonLineThickness.Text = "Thickest"; break; } this.toolStripDropDownButtonPenType.Text = DrawingPens.GetPenTypeAsString(drawArea.PenType); tsbLineColor.BackColor = drawArea.LineColor; tsbFillColor.BackColor = drawArea.FillColor; int x = drawArea.TheLayers.ActiveLayerIndex; bool objects = (drawArea.TheLayers[x].Graphics.Count > 0); bool selectedObjects = (drawArea.TheLayers[x].Graphics.SelectionCount > 0); // File operations saveToolStripMenuItem.Enabled = objects; //toolStripButtonSave.Enabled = objects; saveAsToolStripMenuItem.Enabled = objects; // Edit operations deleteToolStripMenuItem.Enabled = selectedObjects; deleteAllToolStripMenuItem.Enabled = objects; selectAllToolStripMenuItem.Enabled = objects; unselectAllToolStripMenuItem.Enabled = objects; moveToFrontToolStripMenuItem.Enabled = selectedObjects; moveToBackToolStripMenuItem.Enabled = selectedObjects; propertiesToolStripMenuItem.Enabled = selectedObjects; // Undo, Redo undoToolStripMenuItem.Enabled = drawArea.CanUndo; toolStripButtonUndo.Enabled = drawArea.CanUndo; redoToolStripMenuItem.Enabled = drawArea.CanRedo; toolStripButtonRedo.Enabled = drawArea.CanRedo; // Status Strip //tslCurrentLayer.Text = drawArea.TheLayers[x].LayerName; //tslNumberOfObjects.Text = drawArea.TheLayers[x].Graphics.Count.ToString(); //tslPanPosition.Text = drawArea.PanX + ", " + drawArea.PanY; //tslRotation.Text = drawArea.Rotation + " deg"; //tslZoomLevel.Text = (Math.Round(drawArea.Zoom * 100)) + " %"; // Pan button tsbPanMode.Checked = drawArea.Panning; }
public override void Draw(Graphics g) { g.SmoothingMode = SmoothingMode.AntiAlias; Pen pen; if (DrawPen == null) { pen = new Pen(Color, PenWidth); DrawingPens.SetCurrentPen(ref pen, PenType, EndCap); } else { pen = DrawPen.Clone() as Pen; } // Convert the array of points to a GraphicsPath object so lines are mitered correctly at the intersections // (not to mention the object is drawn faster then drawing individual lines) Point[] pts = new Point[pointArray.Count]; for (int i = 0; i < pointArray.Count; i++) { Point px = (Point)pointArray[i]; pts[i] = px; } byte[] types = new byte[pointArray.Count]; for (int i = 0; i < pointArray.Count; i++) { types[i] = (byte)PathPointType.Line; } GraphicsPath gp = new GraphicsPath(pts, types); // Rotate the path about it's center if necessary if (Rotation != 0) { RectangleF pathBounds = gp.GetBounds(); Matrix m = new Matrix(); m.RotateAt(Rotation, new PointF(pathBounds.Left + (pathBounds.Width / 2), pathBounds.Top + (pathBounds.Height / 2)), MatrixOrder.Append); gp.Transform(m); } g.DrawPath(pen, gp); //g.DrawCurve(pen, pts); // //// For DrawBeziers() to work, the pts array must have a minimum of 4 points. //// The pts array may have more than 4 points, but if so, then after the first 4 points, remaining points must be in sets of 3 for the call to work. //// The following code will adjust the pts array to properly fit these requirements. //int numPoints = pts.Length; //if (numPoints - 4 <= 0) //{ // // Cannot call DrawBeziers() so return, drawing nothing. // gp.Dispose(); // pen.Dispose(); // return; //} //while ((numPoints - 4) % 3 != 0 && numPoints - 4 > 0) //{ // // Chop off the last point from the pts array // numPoints--; // Array.Resize(ref pts, numPoints); //} //g.DrawBeziers(pen, pts); gp.Dispose(); if (pen != null) { pen.Dispose(); } }