Example #1
0
 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)));
 }
Example #2
0
 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);
 }
Example #3
0
 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);
 }
Example #4
0
 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);
 }
Example #5
0
 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);
 }
Example #6
0
 //stop resize shape
 public void EndCreateShape(Point point)
 {
     operationShape.SetPoints(startPoint, point);
     Add(operationShape);
     operationShape = null;
 }
Example #7
0
 //constructor of paint model
 public PaintModel()
 {
     Shapes = new List<Shape>();
     operationShape = null;
 }
Example #8
0
 //add a shape into shape list
 public void Add(Shape shape)
 {
     Shapes.Add(shape);
     ChangeModel();
 }
Example #9
0
 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;
 }
Example #10
0
 //start create shape
 public void StartCreateShape(ShapeEnum shapeEnum, Point point)
 {
     operationShape = ShapeFactory.GetShape(shapeEnum);
     operationShape.SetPoints(point, point);
     startPoint = point;
     ChangeModel();
 }
Example #11
0
 //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);
     }
 }
Example #12
0
 //remove a shape from shape list
 public bool Remove(Shape shape)
 {
     bool removeResult = Shapes.Remove(shape);
     ChangeModel();
     return removeResult;
 }
Example #13
0
 //stop moving selected shape
 public void EndSelecteShape(Point point)
 {
     if (operationShape != null)
     {
         point = SetOperationShapePosition(operationShape, point);
         operationShape.IsSelected = false;
         Add(operationShape);
         operationShape = null;
     }
 }