/// <summary> /// Helper method: Update the icon of the Shape button. /// </summary> private void UpdateShape() { //skip updating if shape is unchanged and already has an icon if (this.shape == ccMainForm.Shape && this.shapeBtn.BackgroundImage != null) { return; } //change display to current shape this.shape = this.ccMainForm.Shape; string shapeIconPath = ""; switch (this.shape) { case CCMainForm.DrawingShape.Circle: shapeIconPath = "Icons/Circle.png"; break; case CCMainForm.DrawingShape.FilledCircle: shapeIconPath = "Icons/FilledCircle.png"; break; case CCMainForm.DrawingShape.FilledRectangle: shapeIconPath = "Icons/FilledRectangle.png"; break; case CCMainForm.DrawingShape.Line: shapeIconPath = "Icons/Line.png"; break; case CCMainForm.DrawingShape.Pencil: shapeIconPath = "Icons/Pencil.png"; break; case CCMainForm.DrawingShape.Rectangle: shapeIconPath = "Icons/Rectangle.png"; break; default: break; }//end switch if (shapeIconPath != "") { this.shapeBtn.SetIcon(shapeIconPath); } //hide the thickness display if shape does not have thickness if (this.shape == CCMainForm.DrawingShape.FilledCircle || this.shape == CCMainForm.DrawingShape.FilledRectangle) { this.thicknessBtn.Hide(); } else { this.thicknessBtn.Show(); } }
void shapeActionEvent(CCMainForm.DrawingShape shape) { //ccMainForm.ShowMessage("Click on screen to draw"); ccMainForm.Shape = shape; ccMainForm.State = CCMainForm.CCFormState.DrawingWait; ccToolbar.RemoveCurrentToolbarButtons(); //ccMainForm.DrawingDisplay.SetToolIcon(this.enabledIconPath); //TODO refactor ccMainForm.UpdateDrawingDisplay(); }
/// <summary> /// Draw a shape with given color, thickness at start and end points. /// </summary> /// <param name="color"></param> /// <param name="lineThickness"></param> /// <param name="startPoint"></param> /// <param name="endPoint"></param> /// <param name="shape"></param> public void DrawShape(Color color, float lineThickness, Point startPoint, Point endPoint, CCMainForm.DrawingShape shape) { if (loaded == true) { Graphics g = Graphics.FromImage((System.Drawing.Image)imageBitmap); Pen pen = new Pen(color, lineThickness); //for un-filled shapes and line Brush brush = new SolidBrush(color); //for filled shapes Rectangle shapeAreaRect = new Rectangle( Math.Min(startPoint.X, endPoint.X), Math.Min(startPoint.Y, endPoint.Y), Math.Abs(endPoint.X - startPoint.X), Math.Abs(endPoint.Y - startPoint.Y)); switch (shape) { case CCMainForm.DrawingShape.Circle: g.DrawEllipse(pen, shapeAreaRect); break; case CCMainForm.DrawingShape.Fill: // TODO Console.WriteLine("Need to implement Fill tool"); break; case CCMainForm.DrawingShape.FilledCircle: g.FillEllipse(brush, shapeAreaRect); break; case CCMainForm.DrawingShape.FilledRectangle: g.FillRectangle(brush, shapeAreaRect); break; case CCMainForm.DrawingShape.Line: g.DrawLine(pen, startPoint, endPoint); break; case CCMainForm.DrawingShape.Rectangle: g.DrawRectangle(pen, shapeAreaRect); break; default: break; } // end switch } // end if }