Skip to content

Commit 2ca7d3c

Browse files
committed
Added property 'Color' in IShape interface. Also added loading and saving of colors in the IO
1 parent e3c649b commit 2ca7d3c

5 files changed

Lines changed: 38 additions & 38 deletions

File tree

Form1.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ private Color PaintColor
2727
return;
2828

2929
paintColor = value;
30-
31-
brush = new SolidBrush(paintColor);
3230
}
3331
}
3432

@@ -52,8 +50,6 @@ private ToolItem CurrentTool
5250
}
5351
}
5452

55-
private SolidBrush brush;
56-
5753
private Point dragMouseLocation = new Point(0, 0);
5854
private Rectangle previousShapeBounds = new Rectangle();
5955
private Rectangle newShapeBounds = new Rectangle();
@@ -68,7 +64,6 @@ public Form()
6864
{
6965
InitializeComponent();
7066

71-
brush = new SolidBrush(PaintColor);
7267
commandHandler = new CommandHandler();
7368
CurrentTool = ToolItem.None;
7469

@@ -241,7 +236,7 @@ private void Picturebox_DrawArea_MouseDown(object sender, MouseEventArgs e)
241236
{
242237
case ToolItem.Rectangle:
243238

244-
RectangleShape rectangle = new RectangleShape(brush, e.Location, Constants.SHAPE_DEFAULT_WIDTH, Constants.SHAPE_DEFAULT_HEIGHT);
239+
RectangleShape rectangle = new RectangleShape(PaintColor, e.Location, Constants.SHAPE_DEFAULT_WIDTH, Constants.SHAPE_DEFAULT_HEIGHT);
245240

246241
commandHandler.AddCommand(new CreateShapeCommand(rectangle));
247242

@@ -250,7 +245,7 @@ private void Picturebox_DrawArea_MouseDown(object sender, MouseEventArgs e)
250245

251246
case ToolItem.Ellipse:
252247

253-
EllipseShape ellipse = new EllipseShape(brush, e.Location, Constants.SHAPE_DEFAULT_WIDTH, Constants.SHAPE_DEFAULT_HEIGHT);
248+
EllipseShape ellipse = new EllipseShape(PaintColor, e.Location, Constants.SHAPE_DEFAULT_WIDTH, Constants.SHAPE_DEFAULT_HEIGHT);
254249

255250
commandHandler.AddCommand(new CreateShapeCommand(ellipse));
256251

IO/Parser.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,13 @@ public static string ParseShapeList(List<IShape> shapeList)
157157
{
158158
string stringToAdd = "";
159159

160-
string suffix = " " + shape.Location.X + " " + shape.Location.Y + " " + shape.Bounds.Width + " " + shape.Bounds.Height + '\r';
160+
161+
string suffix = " " + shape.Location.X +
162+
" " + shape.Location.Y +
163+
" " + shape.Bounds.Width +
164+
" " + shape.Bounds.Height +
165+
" " + shape.Color.ToArgb() +
166+
'\r';
161167

162168
if (shape is RectangleShape)
163169
{
@@ -199,16 +205,19 @@ private static List<IShape> ProcessNodesIntoShapelist(Queue<BaseNode> nodes)
199205
int y = 100;
200206
int width = 100;
201207
int height = 100;
208+
int argb = 0;
209+
202210

203211
int.TryParse(splitNodeName[1], out x);
204212
int.TryParse(splitNodeName[2], out y);
205213
int.TryParse(splitNodeName[3], out width);
206214
int.TryParse(splitNodeName[4], out height);
215+
int.TryParse(splitNodeName[5], out argb);
207216

208217
if (node.Name.Contains("ellipse"))
209-
shapeToAdd = new EllipseShape(Brushes.Blue, new Point(x, y), width, height);
218+
shapeToAdd = new EllipseShape(Color.FromArgb(argb), new Point(x, y), width, height);
210219
else
211-
shapeToAdd = new RectangleShape(Brushes.Blue, new Point(x, y), width, height);
220+
shapeToAdd = new RectangleShape(Color.FromArgb(argb), new Point(x, y), width, height);
212221
}
213222

214223
if (shapeToAdd != null)

Interfaces/IShape.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public interface IShape
1010
bool WasClicked(Point p);
1111
HitStatus GetHitStatus(Point p);
1212

13+
Color Color { get; }
1314
int ID { get; set; }
1415
bool IsSelected { get; set; }
1516
Point Location { get; set; }

Shapes/EllipseShape.cs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ public Size MinimumSize
2929
}
3030
}
3131

32-
public Brush Brush
33-
{
34-
get { return brush; }
35-
set
36-
{
37-
if (value == brush) return;
38-
39-
brush = value;
40-
}
41-
}
42-
4332
public Point Location
4433
{
4534
get
@@ -102,24 +91,33 @@ public int ID
10291
}
10392
}
10493

94+
private Color color;
95+
public Color Color
96+
{
97+
get
98+
{
99+
return color;
100+
}
101+
}
102+
105103
private bool isSelected;
106104
private int id;
107105

108106
private GrabHandles grabHandles;
109107
private Rectangle bounds;
110-
private Brush brush;
111108
private Size minimumSize;
112109

113-
public EllipseShape(Brush brush, Point location, int width, int height)
110+
public EllipseShape(Color color, Point location, int width, int height)
114111
{
115112
this.Size = new Size(width, height);
116-
this.brush = brush;
113+
this.color = color;
117114
this.Location = location;
118115
this.MinimumSize = new Size(Constants.SHAPE_MINIMUM_WIDTH, Constants.SHAPE_MINIMUM_HEIGHT);
119116
}
120117

121118
public void Draw(Graphics g)
122119
{
120+
Brush brush = new SolidBrush(Color);
123121
g.FillEllipse(brush, Location.X, Location.Y, Size.Width, Size.Height);
124122

125123
if (IsSelected)

Shapes/RectangleShape.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,6 @@ public Size MinimumSize
2929
}
3030
}
3131

32-
public Brush Brush
33-
{
34-
get { return brush; }
35-
set
36-
{
37-
if (value == brush) return;
38-
39-
brush = value;
40-
}
41-
}
42-
4332
public Point Location
4433
{
4534
get
@@ -102,25 +91,33 @@ public int ID
10291
}
10392
}
10493

94+
private Color color;
95+
public Color Color
96+
{
97+
get
98+
{
99+
return color;
100+
}
101+
}
105102

106103
private bool isSelected;
107104
private int id;
108105

109106
private GrabHandles grabHandles;
110107
private Rectangle bounds;
111-
private Brush brush;
112108
private Size minimumSize;
113109

114-
public RectangleShape(Brush brush, Point location, int width, int height)
110+
public RectangleShape(Color color, Point location, int width, int height)
115111
{
116112
this.Size = new Size(width, height);
117-
this.brush = brush;
113+
this.color = color;
118114
this.Location = location;
119115
this.MinimumSize = new Size(Constants.SHAPE_MINIMUM_WIDTH, Constants.SHAPE_MINIMUM_HEIGHT);
120116
}
121117

122118
public void Draw(Graphics g)
123119
{
120+
Brush brush = new SolidBrush(Color);
124121
g.FillRectangle(brush, Location.X, Location.Y, Size.Width, Size.Height);
125122

126123
if (IsSelected)

0 commit comments

Comments
 (0)