// 將 json 字串轉為 shapes
        public void ConvertToShapes(string text)
        {
            Debug.WriteLine(text);
            _shapes = new List <Shape>();
            List <ShapeFormat> shapeFormats = JsonSerializer.Deserialize <List <ShapeFormat> >(text);

            foreach (ShapeFormat shapeFormat in shapeFormats)
            {
                Shape shape = new ShapeFactory().CreateShape((ShapeType)shapeFormat.ShapeType);
                shape.SetStartPoint(shapeFormat.StartPointLeft, shapeFormat.StartPointTop);
                shape.SetEndPoint(shapeFormat.EndPointLeft, shapeFormat.EndPointTop);
                shape.IsReverse = shapeFormat.IsReverse;
                Debug.WriteLine(shape.IsReverse);
                _shapes.Add(shape);
            }
        }
        /// <summary>   Pointer pressed. </summary>
        ///
        /// <param name="pointX">   The x coordinate. </param>
        /// <param name="pointY">   The y coordinate. </param>

        public void PressPointer(double pointX, double pointY)
        {
            if (pointX > 0 && pointY > 0)
            {
                _firstPointX = pointX;
                _firstPointY = pointY;
                if (_drawType == DrawType.Line)
                {
                    _shape = ShapeFactory.GetLine(_firstPointX, _firstPointY, 0, 0);
                }
                else if (_drawType == DrawType.Diamond)
                {
                    _shape = ShapeFactory.GetDiamond(_firstPointX, _firstPointY, 0, 0);
                }
                else if (_drawType == DrawType.Ellipse)
                {
                    _shape = ShapeFactory.GetEllipse(_firstPointX, _firstPointY, 0, 0);
                }
                _isPressed = true;
            }
        }
        /// <summary>   Releases the shape. </summary>
        ///
        /// <exception cref="KeyNotFoundException"> Thrown when a Key Not Found error condition occurs. </exception>
        ///
        /// <param name="pointX">   The x coordinate. </param>
        /// <param name="pointY">   The y coordinate. </param>

        private void ReleaseShape(double pointX, double pointY)
        {
            IShape shape;

            if (_drawType == DrawType.Line)
            {
                shape = ShapeFactory.GetLine(_firstPointX, _firstPointY, pointX, pointY);
            }
            else if (_drawType == DrawType.Diamond)
            {
                shape = ShapeFactory.GetDiamond(_firstPointX, _firstPointY, pointX, pointY);
            }
            else if (_drawType == DrawType.Ellipse)
            {
                shape = ShapeFactory.GetEllipse(_firstPointX, _firstPointY, pointX, pointY);
            }
            else
            {
                return;
            }
            ICommand newCommand = new DrawCommand(this, shape);

            _commandManager.ExecuteNewCommand(newCommand);
        }
Exemple #4
0
 public PointerState(Model model)
 {
     _model        = model;
     _shapeFactory = new ShapeFactory();
 }
Exemple #5
0
 public Model()
 {
     _shapes         = new List <IShape>();
     _commandManager = new CommandManager();
     _shapeFactory   = new ShapeFactory();
 }