Develop a primitive graphic editor for drawing on canvases of various shapes with brushes with a pen of the same shape, for example, on a round canvas - a round pen (a window shape can have several canvases, each of which uses its own pen). Provide for the possibility of using several types of canvases, for example, round and rectangular.
I wrote this code so far but I don't know how to implement here the creation of canvases and brushes of a certain shape.
// abstract class - brush
abstract class Brush
{
public abstract void Move ();
}
// abstract class canvas
abstract class Canvas
{
public abstract void Draw ();
}
// class round brush stroke
class RoundBrush: Brush
{
public override void Move ()
{
// paint with a round brush
}
}
// square brush stroke
class SquareBrush: Brush
{
public override void Move ()
{
// Draw with a square brush
}
}
// create a round canvas
class RoundForm: Canvas
{
public override void Draw ()
{
// Draw a round canvas (pictureBox)
}
}
// create a square canvas
class SquareForm: Canvas
{
public override void Draw ()
{
// Draw a square canvas (pictureBox)
}
}
// abstract factory class
abstract class EditorFactory
{
public abstract Brush CreateBrush ();
public abstract Canvas CreateCanvas ();
}
// Factory to create a round canvas with a round brush
class RoundFactory: EditorFactory
{
public override Brush CreateBrush ()
{
return new RoundBrush ();
}
public override Canvas CreateCanvas ()
{
return new RoundForm ();
}
}
// Factory to create a square canvas with a square brush
class SquareFactory: EditorFactory
{
public override Brush CreateBrush ()
{
return new SquareBrush ();
}
public override Canvas CreateCanvas ()
{
return new SquareForm ();
}
}
// client
class Editor
{
private Brush brush;
private Canvas canvas;
public Editor (EditorFactory factory)
{
brush = factory.CreateBrush ();
canvas = factory.CreateCanvas ();
}
public void Move ()
{
brush.Move ();
}
public void Draw ()
{
canvas.Draw ();
}
}
private void Form1_Shown (object sender, EventArgs e)
{
Editor newEditor = new Editor (new RoundFactory ());
newEditor.Move ();
newEditor.Draw ();
Editor editor = new Editor (new SquareFactory ());
editor.Move ();
editor.Draw ();
}
Aucun commentaire:
Enregistrer un commentaire