// Draws a single point private void DrawPoint(Graphics g, DrawablePoint pt) { Pen pen = new Pen(pt.color, 2); Point pt1 = new Point(pt.x - 2, pt.y - 2); Rectangle r = new Rectangle(pt1, new Size(4, 4)); g.DrawRectangle(pen, r); }
// Draws all vertices in the polygon private void DrawVertices(Graphics g) { foreach (DPoint dp in mPolygon.Vertices) { DrawablePoint drawable = new DrawablePoint(dp); DrawPoint(g, drawable); } }
// Updates the free point state if polygon's vertices change private void UpdateFreePointState() { for (int i = 0; i < mFreePoints.Count; ++i) { DrawablePoint drawable = mFreePoints[i]; DPoint dp = new DPoint(drawable.x, drawable.y); drawable.color = (mPolygon.isPointInside(dp)) ? sColorPointInsidePolygon: sColorPointOutsidePolygon; } }
private void OnMouseClickDrawing(object sender, MouseEventArgs e) { DPoint pt = new DPoint((double)e.X, (double)e.Y); if (mCurrentMode == Mode.InsertPolygonNode) { mPolygon.AddVertice(pt); UpdateFreePointState(); mUndoStack.Push(ActionType.VerticeAdded); } else { Color color = (mPolygon.isPointInside(pt)) ? sColorPointInsidePolygon : sColorPointOutsidePolygon; DrawablePoint dp = new DrawablePoint(pt, color); mFreePoints.Add(dp); mUndoStack.Push(ActionType.PointAdded); } DrawObjects(); }