public void TestDefaultCheckIsSelected() { Shape shape = new Shape(); shape.SetPoints(new Point(20, 30), new Point(30, 40)); Assert.IsTrue(shape.CheckIsSelected(new Point(25, 35))); Assert.IsFalse(shape.CheckIsSelected(new Point(19, 35))); Assert.IsFalse(shape.CheckIsSelected(new Point(25, 41))); Assert.IsFalse(shape.CheckIsSelected(new Point(19, 41))); }
public void TestSetPoints() { Shape shape = new Shape(); shape.SetPoints(new Point(20, 30), new Point(30, 40)); Assert.AreEqual(20, shape.TopLeftPoint.X); Assert.AreEqual(30, shape.TopLeftPoint.Y); Assert.AreEqual(30, shape.BottomRightPoint.X); Assert.AreEqual(40, shape.BottomRightPoint.Y); }
public void TestBottomRightPoint() { Shape shape = new Shape(); shape.SetPoints(new Point(20, 30), new Point(30, 40)); Assert.AreEqual(30, shape.BottomRightPoint.X); Assert.AreEqual(40, shape.BottomRightPoint.Y); shape.SetPoints(new Point(80, 30), new Point(30, 40)); Assert.AreEqual(80, shape.BottomRightPoint.X); Assert.AreEqual(40, shape.BottomRightPoint.Y); shape.SetPoints(new Point(80, 80), new Point(30, 40)); Assert.AreEqual(80, shape.BottomRightPoint.X); Assert.AreEqual(80, shape.BottomRightPoint.Y); shape.SetPoints(new Point(20, 70), new Point(30, 40)); Assert.AreEqual(30, shape.BottomRightPoint.X); Assert.AreEqual(70, shape.BottomRightPoint.Y); }
public void TestTopLeftPoint() { Shape shape = new Shape(); shape.SetPoints(new Point(20, 30), new Point(30, 40)); Assert.AreEqual(20, shape.TopLeftPoint.X); Assert.AreEqual(30, shape.TopLeftPoint.Y); shape.SetPoints(new Point(80, 30), new Point(30, 40)); Assert.AreEqual(30, shape.TopLeftPoint.X); Assert.AreEqual(30, shape.TopLeftPoint.Y); shape.SetPoints(new Point(80, 80), new Point(30, 40)); Assert.AreEqual(30, shape.TopLeftPoint.X); Assert.AreEqual(40, shape.TopLeftPoint.Y); shape.SetPoints(new Point(20, 70), new Point(30, 40)); Assert.AreEqual(20, shape.TopLeftPoint.X); Assert.AreEqual(40, shape.TopLeftPoint.Y); }
public void TestSetPointsByList() { Shape shape = new Shape(); List<Point> points = new List<Point>(); points.Add(new Point(20, 30)); points.Add(new Point(30, 40)); shape.SetPoints(points); Assert.AreEqual(20, shape.TopLeftPoint.X); Assert.AreEqual(30, shape.TopLeftPoint.Y); Assert.AreEqual(30, shape.BottomRightPoint.X); Assert.AreEqual(40, shape.BottomRightPoint.Y); }
//stop resize shape public void EndCreateShape(Point point) { operationShape.SetPoints(startPoint, point); Add(operationShape); operationShape = null; }
//constructor of paint model public PaintModel() { Shapes = new List<Shape>(); operationShape = null; }
//add a shape into shape list public void Add(Shape shape) { Shapes.Add(shape); ChangeModel(); }
private Point SetOperationShapePosition(Shape shape, Point point) { Point movePoint; movePoint.X = point.X - startPoint.X; movePoint.Y = point.Y - startPoint.Y; Point newTopLeftPoint; newTopLeftPoint.X = shapeOriginTopLeftPoint.X + movePoint.X; newTopLeftPoint.Y = shapeOriginTopLeftPoint.Y + movePoint.Y; Point newBottomRightPoint; newBottomRightPoint.X = shapeOriginBottomRightPoint.X + movePoint.X; newBottomRightPoint.Y = shapeOriginBottomRightPoint.Y + movePoint.Y; shape.SetPoints(newTopLeftPoint, newBottomRightPoint); return point; }
//start create shape public void StartCreateShape(ShapeEnum shapeEnum, Point point) { operationShape = ShapeFactory.GetShape(shapeEnum); operationShape.SetPoints(point, point); startPoint = point; ChangeModel(); }
//select shape public void SelecteShape(Point point) { foreach (Shape shape in Shapes) { if (shape.CheckIsSelected(point)) { operationShape = shape; break; } } if (operationShape != null) { startPoint = point; shapeOriginTopLeftPoint = operationShape.TopLeftPoint; shapeOriginBottomRightPoint = operationShape.BottomRightPoint; operationShape.IsSelected = true; Remove(operationShape); } }
//remove a shape from shape list public bool Remove(Shape shape) { bool removeResult = Shapes.Remove(shape); ChangeModel(); return removeResult; }
//stop moving selected shape public void EndSelecteShape(Point point) { if (operationShape != null) { point = SetOperationShapePosition(operationShape, point); operationShape.IsSelected = false; Add(operationShape); operationShape = null; } }