I have some Graphical Classes whose public member are manipulated by user at runtime.
I want to access these class through polymorphism. The classes public parameters will differ (i.e; some properties match such as width, height , etc and others donot match)
The following is my code so far. Please help me throughly.
public interface GraphicsObject
{
int Width { get; set; }
int Height { get; set; }
int Repetation { get; set; }
int RepetationMin { get; set; }
int RepetationMax { get; set; }
bool IsRepetationRandom { get; set; }
bool IsTop { get; set; }
bool IsBtm { get; set; }
bool IsOffset { get; set; }
LineType LineType { get; set; }
bool IsLineTypeRandom { get; set; }
Shapes Shapes { get; set; }
bool IsShapesRandom { get; set; }
GraphicsPath[] Draw();
}
My Graphical Classes:
public class FallingLines : GraphicsObject
{
#region Properties
public int Width { get; set; }
public int Height { get; set; }
public int Repetation { get; set; }
public int RepetationMax { get; set; }
public int RepetationMin { get; set; }
public bool IsRepetationRandom { get; set; }
public bool IsTop { get; set; }
public bool IsBtm { get; set; }
public bool IsOffset { get; set; }
public LineType LineType { get; set; }
public bool IsLineTypeRandom { get; set; }
#endregion
#region Constructor
public FallingLines(int width, int height)
{
this.Width = width;
this.Height = height;
this.Repetation = 10;
this.RepetationMin = 8;
this.RepetationMax = 10;
this.IsRepetationRandom = true;
this.IsTop = true;
this.IsBtm = false;
this.IsOffset = true;
this.LineType = GraphicalDesigns.LineType.Irregular;
this.IsLineTypeRandom = false;
}
#endregion
#region Function
public GraphicsPath[] Draw()
{
}
private Rectangle[] GetRectangle(int randomOffset)
{
}
private GraphicsPath GetPath(int x, int y, int width, int height)
{
}
private Point[] GetPoints(int count)
{
}
private Point[] DrawWave(Point top, Point btm, int cntWave)
{
}
private GraphicsPath DrawIrregularity(Point[] points, int width)
{
}
private Point[] GetRandomPointInLine(Point[] points, int curveCnt)
{
}
private Point[] DrawIrregularWave(Point top, Point btm, int width)
{
}
}
public enum LineType
{
Straight,
SineCurve,
Irregular
}
public class GeometricalShapes : GraphicsObject
{
#region Properties
public int Width { get; set; }
public int Height { get; set; }
public int Repetation { get; set; }
public int RepetationMax { get; set; }
public int RepetationMin { get; set; }
public bool IsRepetationRandom { get; set; }
public bool IsOffset { get; set; }
public Shapes Shapes { get; set; }
public bool IsShapesRandom { get; set; }
#endregion
public GeometricalShapes(int width, int height)
{
this.Width = width;
this.Height = height;
this.Repetation = 6;
this.RepetationMax = 10;
this.RepetationMin = 4;
this.IsRepetationRandom = true;
this.IsOffset = true;
this.Shapes = GraphicalDesigns.Shapes.Circle;
this.IsShapesRandom = true;
}
public GraphicsPath[] Draw()
{
}
private int[] GetIncBoxSize(int repetation)
{
}
private GraphicsPath GetPath(int x, int y, int wt, int ht)
{
}
}
public enum Shapes
{
Triangle,
Square,
Rectangle,
Circle,
Oval,
Pentagon,
Hexagon,
Octagon
}
For Controlling through the main Form:
private GraphicsPath[] gPath = null;
public GraphicsPath[] GPath
{
get { return this.gPath; }
}
private PointF[] points = null;
public PointF[] Points
{
get { return points; }
}
public GraphicsMode mode;
public int Width { get; set; }
public int Height { get; set; }
public int Repetation { get; set; }
public int RepetationMin { get; set; }
public int RepetationMax { get; set; }
public bool IsRepetationRandom { get; set; }
public bool IsTop { get; set; }
public bool IsBtm { get; set; }
public bool IsOffset { get; set; }
public LineType LineType { get; set; }
public bool IsLineTypeRandom { get; set; }
public Shapes Shapes { get; set; }
public bool IsShapesRandom { get; set; }
public GraphicsObject gObject;
public ModelGraphics(int width, int height)
{
this.Width = width;
this.Height = height;
}
public void SetGraphicalObject(GraphicsMode mode)
{
this.mode = mode;
switch (mode)
{
case GraphicsMode.GeometricalShape:
gObject = new GeometricalShapes(this.Width,this.Height);
this.Repetation = gObject.Repetation;
this.RepetationMax = gObject.RepetationMax;
this.RepetationMin = gObject.RepetationMin;
this.IsRepetationRandom = gObject.IsRepetationRandom;
this.IsOffset = gObject.IsOffset;
this.Shapes = gObject.Shapes;
this.IsShapesRandom = gObject.IsShapesRandom;
break;
case GraphicsMode.FallingLine:
gObject = new FallingLines(this.Width,this.Height);
this.Repetation = gObject.Repetation;
this.RepetationMax = gObject.RepetationMax;
this.RepetationMin = gObject.RepetationMin;
this.IsRepetationRandom = gObject.IsRepetationRandom;
this.IsTop = gObject.IsTop;
this.IsBtm = gObject.IsBtm;
this.IsOffset = gObject.IsOffset;
this.LineType = gObject.LineType;
this.IsLineTypeRandom = gObject.IsLineTypeRandom;
break;
}
}
public void GetGraphicalObject()
{
gPath = (GraphicsPath[])gObject.Draw().Clone();
}
How do i set the values from mainForm to graphical classes and vice-versa.
I know the concept of OOP doesnot match. Please help me understand and help me figure out my structure for ease when i have more graphical classes such as FallingLines and GeometricalShapes
Thankyou