private int _yOffset; //移動前後Y差值 #endregion Fields #region Constructors //建構元 public MoveShapeCommand(Model model, Shape shape,int xOffset,int yOffset) { this._model = model; this._targetShape = shape; this._xOffset = xOffset; this._yOffset = yOffset; }
//加入圖形 public void AddShape(int mode, Point locationOfTopPoint) { Shape newShape = _shapeFactory.CreateShpae(mode, locationOfTopPoint); _shapes.Add(newShape); _focusShape = newShape; _focusShape.IsFocus = true; }
public void Initialize() { Point startPoint = new Point(10, 10); Point endPoint = new Point(20, 20); _rectangle = ShapeFactory.CreatShape(Mode.Rectangle, startPoint, endPoint); _moveShapeCommandTarget = new MoveShapeCommand_Accessor(_rectangle, new Point(10, 10)); }
public ResizeShapeCommand(Shape shape, Point differentPoint, Point resize) { _resizeShape = shape; _startPoint = shape.StartPosition; _differentPoint = differentPoint; _resize = resize; }
// 按下滑鼠 public override void PressMouse(Point point) { _startPosition = point; _mousePressed = true; _drawingShape = ShapeFactory.CreatShape(_shapeModel.SelectedMode, _startPosition, _startPosition); _drawingShape.IsSelect = true; }
Point _oldPoint; //舊點 #endregion Fields #region Constructors //建構元 public ResizeShapeCommand(Model model, Shape shape, Shape.ChangePoint changePoint, Point newPoint,Point oldPoint) { _model = model; _targetShape = shape; _changePoint = changePoint; _newPoint = newPoint; _oldPoint = oldPoint; }
public void Initialize() { Point startPoint = new Point(10, 10); Point endPoint = new Point(20, 20); _rectangle = ShapeFactory.CreatShape(Mode.Rectangle, startPoint, endPoint); _shapeModel = new ShapeModel(); _deleteCommandTarget = new DeleteShapeCommand_Accessor(_rectangle, _shapeModel); _shapeModel.CursorChange += InvokeTest; _shapeModel.ScreenChange += InvokeTest; _shapeModel.StripChange += InvokeTest; }
//增加Shape命令 public void AddShape(Shape targetShape,int shapeIndex) { if (!targetShape.IsAPoint) //可形成圖形 則新增命令 { NewCommandExcute(); _commands.Add(new AddShapeCommand(_model, targetShape, shapeIndex)); targetShape.ResetLocationOfPaintPoint(); } else //無法形成圖形 刪除點 { _model.DeleteShape(shapeIndex); } }
//找尋被選取的圖形 public void FindFocusShape(int mouseX, int mouseY) { if (_focusShape != null) DisposeFocusShape(); for (int i = _shapes.Count() - 1; i >= 0; i--) { if (_shapes[i].ContainsInShape(mouseX, mouseY)) { _focusShape = _shapes[i]; _focusShape.IsFocus = true; break; } } }
// 放開滑鼠 public override void ReleaseMouse(Point point) { if (_drawingShape != null) { Command command = new AddShapeCommand(_drawingShape, _shapeModel); if (_drawingShape.Width != 0 & _drawingShape.Height != 0) { _shapeModel.DoCommand(command); } _drawingShape.IsSelect = false; } _drawingShape = null; _mousePressed = false; }
//按下滑鼠左鍵的事件 public override void PressMouse(Point locationOfTopPoint) { if (_model.FocusShape != null && !_isPressing) //在案壓住並且有Shape被選中 { _timer.Start(); //開始計數 _FirstPressPoint = locationOfTopPoint; _isPressing = true; _focusShape = _model.FocusShape; if (IsPressOnControlPoint(locationOfTopPoint)) { _isResizing = true; } else if (_focusShape.ContainsInShape(locationOfTopPoint.X, locationOfTopPoint.Y)) { _isMoving = true; } else { _model.DisPoseFocusShape(); } } }
//Resize命令 public void ResizeShape(Shape targetShape, Point oldPoint, Point newPoint, Shape.ChangePoint changePoint) { NewCommandExcute(); _commands.Add(new ResizeShapeCommand(_model, targetShape, changePoint, newPoint, oldPoint)); }
private Model _model; // Model #endregion Fields #region Constructors //建構元 public DeleteShapeCommand(Model model,Shape shape,int shapeIndex) { this._model = model; this._shapeIndex = shapeIndex; this._targetShape = shape; }
public AddShapeCommand(Shape shape, ShapeModel shapeModel) { _shape = shape; _shapeModel = shapeModel; }
//增加ReSize命令 public void CommandResizeShape(Point oldPoint, Point newPoint, Shape.ChangePoint changePoint) { _commandManager.ResizeShape(FocusShape, oldPoint, newPoint, changePoint); }
public void Initialize() { _target = ShapeFactory.CreatShape(Mode.Line, new Point(10, 10), new Point(20, 20)); }
public void Initialize() { Point start = new Point(10, 10); Point end= new Point(20, 20); _target = ShapeFactory.CreatShape(Mode.Rectangle, start, end); }
//取消選取狀態 public void DisPoseFocusShape() { _shapes.DisposeFocusShape(); _focusShape = null; }
public MoveShapeCommand(Shape shape, Point point) { _shape = shape; _point = point; _startPoint = _shape.StartPosition; }
//找尋目前鼠標所指的圖形 public void FindFocusShape(int mouseX, int mouseY) { _shapes.FindFocusShape(mouseX, mouseY); if (_focusShape != _shapes.FocusShape) NotifyObserver(); _focusShape = _shapes.FocusShape; }
//插入Shape public void InsertShape(Shape shape,int index) { _shapes.InsertShape(index, shape); }
public DeleteShapeCommand(Shape shape, ShapeModel shapeModel) { _shape = shape; _shapeModel = shapeModel; }
//增加圖形 public void AddShape(Point locationOfTopPoint) { _shapes.AddShape((int)_shapeType, locationOfTopPoint); _focusShape = _shapes.FocusShape; }
//插入圖形 public void InsertShape(int index, Shape shape) { _shapes.Insert(index, shape); }
//刪除圖形命令 public void DeleteShape(Shape targetShape, int shapeIndex) { NewCommandExcute(); _model.DeleteShape(shapeIndex); _model.DisPoseFocusShape(); _commands.Add(new DeleteShapeCommand(_model,targetShape,shapeIndex)); }
//取消選取 public void DisposeFocusShape() { if (_focusShape != null) _focusShape.IsFocus = false; _focusShape = null; }
//移動圖形命令 public void MoveShape(Shape targetShape,int xOffset,int yOffset) { NewCommandExcute(); _commands.Add(new MoveShapeCommand(_model,targetShape,xOffset,yOffset)); }
//找尋圖形Index public int FindShapeInedx(Shape targetShape) { for (int i = 0; i < _shapes.Count; i++) { if (_shapes[i] == targetShape) return i; } return -1; //not found }
private Model _model; //Model #endregion Fields #region Constructors //建構元 public AddShapeCommand(Model model, Shape targetShape, int shapeIndex) { this._model = model; this._targetShape = targetShape; this._shapeIndex = shapeIndex; }