پیاده سازی پروژه نقاشی (Paint) به صورت شی گرا 6#
نویسنده: صابر فتح الهی
تاریخ: ۱۳۹۱/۱۲/۰۵ ۰:۵
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
using System.Drawing;
namespace PWS.ObjectOrientedPaint.Models
{
/// <summary>
/// Ellipse Draw
/// </summary>
public class Ellipse : Shape
{
#region Constructors (2)
/// <summary>
/// Initializes a new instance of the <see cref="Ellipse" /> class.
/// </summary>
/// <param name="startPoint">The start point.</param>
/// <param name="endPoint">The end point.</param>
/// <param name="zIndex">Index of the z.</param>
/// <param name="foreColor">Color of the fore.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="isFill">if set to <c>true</c> [is fill].</param>
/// <param name="backgroundColor">Color of the background.</param>
public Ellipse(PointF startPoint, PointF endPoint, int zIndex, Color foreColor, byte thickness, bool isFill, Color backgroundColor)
: base(startPoint, endPoint, zIndex, foreColor, thickness, isFill, backgroundColor)
{
ShapeType = ShapeType.Ellipse;
}
/// <summary>
/// Initializes a new instance of the <see cref="Ellipse" /> class.
/// </summary>
public Ellipse()
{
ShapeType = ShapeType.Ellipse;
}
#endregion Constructors
#region Methods (1)
// Public Methods (1)
/// <summary>
/// Draws the specified g.
/// </summary>
/// <param name="g">The g.</param>
public override void Draw(Graphics g)
{
if (IsFill)
g.FillEllipse(BackgroundBrush, StartPoint.X, StartPoint.Y, Width, Height);
g.DrawEllipse(Pen, StartPoint.X, StartPoint.Y, Width, Height);
base.Draw(g);
}
#endregion Methods
}
}using System;
using System.Drawing;
namespace PWS.ObjectOrientedPaint.Models
{
/// <summary>
/// Circle
/// </summary>
public class Circle : Ellipse
{
#region Constructors (2)
/// <summary>
/// Initializes a new instance of the <see cref="Circle" /> class.
/// </summary>
/// <param name="startPoint">The start point.</param>
/// <param name="endPoint">The end point.</param>
/// <param name="zIndex">Index of the z.</param>
/// <param name="foreColor">Color of the fore.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="isFill">if set to <c>true</c> [is fill].</param>
/// <param name="backgroundColor">Color of the background.</param>
public Circle(PointF startPoint, PointF endPoint, int zIndex, Color foreColor, byte thickness, bool isFill, Color backgroundColor)
{
float x = 0, y = 0;
float width = Math.Abs(endPoint.X - startPoint.X);
float height = Math.Abs(endPoint.Y - startPoint.Y);
if (startPoint.X <= endPoint.X && startPoint.Y <= endPoint.Y)
{
x = startPoint.X;
y = startPoint.Y;
}
else if (startPoint.X >= endPoint.X && startPoint.Y >= endPoint.Y)
{
x = endPoint.X;
y = endPoint.Y;
}
else if (startPoint.X >= endPoint.X && startPoint.Y <= endPoint.Y)
{
x = endPoint.X;
y = startPoint.Y;
}
else if (startPoint.X <= endPoint.X && startPoint.Y >= endPoint.Y)
{
x = startPoint.X;
y = endPoint.Y;
}
StartPoint = new PointF(x, y);
var side = Math.Max(width, height);
EndPoint = new PointF(x + side, y + side);
ShapeType = ShapeType.Circle;
Zindex = zIndex;
ForeColor = foreColor;
Thickness = thickness;
BackgroundColor = backgroundColor;
IsFill = isFill;
}
/// <summary>
/// Initializes a new instance of the <see cref="Circle" /> class.
/// </summary>
public Circle()
{
ShapeType = ShapeType.Circle;
}
#endregion Constructors
#region Methods (1)
// Public Methods (1)
/// <summary>
/// Points the in sahpe.
/// </summary>
/// <param name="point">The point.</param>
/// <param name="tolerance">The tolerance.</param>
/// <returns>
/// <c>true</c> if [has point in sahpe] [the specified point]; otherwise, <c>false</c>.
/// </returns>
public override bool HasPointInSahpe(PointF point, byte tolerance = 5)
{
float width = Math.Abs(EndPoint.X+tolerance - StartPoint.X-tolerance);
float height = Math.Abs(EndPoint.Y+tolerance - StartPoint.Y-tolerance);
float diagonal = Math.Max(height, width);
float raduis = diagonal / 2;
float dx = Math.Abs(point.X - (X + Width / 2));
float dy = Math.Abs(point.Y - (Y + height / 2));
return (dx + dy <= raduis);
}
#endregion Methods
}
}