public void Undo(InternalCanvas canvas) { shapeComponent.Width = oldWidth; shapeComponent.Height = oldHeight; shapeComponent.Location = oldLocation; canvas.SetNewShape(shapeComponent, oldLocation.X, oldLocation.Y); }
public void Redo(InternalCanvas canvas) { canvas.Shapes.Add(TextOrnament); canvas.Children.Add(TextOrnament); canvas.Shapes.Remove(OldShapeComponent); canvas.Children.Remove(OldShapeComponent); }
private Point GetNewLocationAndSize(InternalCanvas canvas, double offset_x, double offset_y) { double new_x = shapeComponent.Location.X; double new_y = shapeComponent.Location.Y; newWidth = shapeComponent.ActualWidth; newHeight = shapeComponent.ActualHeight; // Update the rectangle. switch (shapeComponent.MousePosition) { case MousePositionType.Body: new_x += offset_x; new_y += offset_y; break; case MousePositionType.UL: new_x += offset_x; new_y += offset_y; newWidth -= offset_x; newHeight -= offset_y; break; case MousePositionType.UR: new_y += offset_y; newWidth += offset_x; newHeight -= offset_y; break; case MousePositionType.DR: newWidth += offset_x; newHeight += offset_y; break; case MousePositionType.DL: new_x += offset_x; newWidth -= offset_x; newHeight += offset_y; break; case MousePositionType.L: new_x += offset_x; newWidth -= offset_x; break; case MousePositionType.R: newWidth += offset_x; break; case MousePositionType.B: newHeight += offset_y; break; case MousePositionType.T: new_y += offset_y; newHeight -= offset_y; break; } return(new Point(SetLeftOfShape(canvas, shapeComponent, new_x), SetTopOfShape(canvas, shapeComponent, new_y))); }
private void ExecuteMouseMove(InternalCanvas canvas) { // See how much the mouse has moved. Point point = Mouse.GetPosition(canvas); double offset_x = point.X - mousePosition.X; double offset_y = point.Y - mousePosition.Y; // Get the rectangle's current position. Point newPosition = GetNewLocationAndSize(canvas, offset_x, offset_y); // Don't use negative width or height. if ((newWidth > 0) && (newHeight > 0)) { // Update the rectangle. shapeComponent.Move(new MoveVisitor(new Point(newPosition.X - newLocation.X, newPosition.Y - newLocation.Y))); //canvas.SetNewShape(shapeComponent, newPosition.X, newPosition.Y); canvas.SetNewShape(shapeComponent, shapeComponent.Location.X, shapeComponent.Location.Y); shapeComponent.Resize(new ResizeVisitor(((offset_x + shapeComponent.ActualWidth) / shapeComponent.ActualWidth), ((offset_y + shapeComponent.ActualHeight) / shapeComponent.ActualHeight), shapeComponent.MousePosition)); //shapeComponent.Width = newWidth; //shapeComponent.Height = newHeight; // Save the mouse's new location. mousePosition = point; } newLocation = canvas.GetPositionOfShapeInCanvas(shapeComponent); shapeComponent.Location = newLocation; //SetMouseCursor(shape); }
private void ExecuteMouseMove(InternalCanvas canvas) { // See how much the mouse has moved. Point point = Mouse.GetPosition(canvas); double offset_x = point.X - mousePosition.X; double offset_y = point.Y - mousePosition.Y; // Get the rectangle's current position. double new_x, new_y; GetNewLocationAndSize(shape, offset_x, offset_y, out new_x, out new_y, out newWidth, out newHeight); // Don't use negative width or height. if ((newWidth > 0) && (newHeight > 0)) { // Update the rectangle. //SetLeftOfShape(canvas, shape, new_x); //SetTopOfShape(canvas, shape, new_y); canvas.SetNewShape(shape, SetLeftOfShape(canvas, shape, new_x), SetTopOfShape(canvas, shape, new_y)); shape.Width = newWidth; shape.Height = newHeight; // Save the mouse's new location. mousePosition = point; } newLocation = canvas.GetPositionOfShapeInCanvas(shape); shape.Location = newLocation; //SetMouseCursor(shape); }
public void ExecuteMouseDown(InternalCanvas canvas) { startPoint = Mouse.GetPosition(canvas); newshape = GetShape(); canvas.SetNewShape(newshape, startPoint.X, startPoint.Y); canvas.Children.Add(newshape); }
public void Redo(InternalCanvas canvas) { shapeComponent.Width = newWidth; shapeComponent.Height = newHeight; shapeComponent.Location = newLocation; canvas.SetNewShape(shapeComponent, newLocation.X, newLocation.Y); }
public void Execute(InternalCanvas canvas) { if (commands.Count > 0 && !commands.Last().IsCompleted) { commands.Last().Execute(canvas); redocommands.Clear(); } }
public void Redo(InternalCanvas canvas) { canvas.Shapes.Add(group); canvas.Children.Add(group); foreach (ShapeComponent component in oldShapeComponents) { canvas.Shapes.Remove(component); canvas.Children.Remove(component); } }
public void Undo(InternalCanvas canvas) { if (commands.Count > 0) { Command oldcommand = commands.Last(); commands.Remove(oldcommand); oldcommand.Undo(canvas); redocommands.Add(oldcommand); } }
public void Redo(InternalCanvas canvas) { if (redocommands.Count > 0) { Command redocommand = redocommands.Last(); redocommand.Redo(canvas); commands.Add(redocommand); redocommands.Remove(redocommand); } }
public void AddGroupToCanvas(InternalCanvas canvas) { canvas.Shapes.Add(group); canvas.Children.Add(group); canvas.SetNewShape(group, group.Location.X, group.Location.Y); foreach (ShapeComponent component in oldShapeComponents) { canvas.Shapes.Remove(component); canvas.Children.Remove(component); } IsCompleted = true; }
public void Execute(InternalCanvas canvas) { //Key.LeftCtrl == KeyStates.Down if (Mouse.LeftButton == MouseButtonState.Pressed) { ExecuteMouseDown(canvas); } else if (Keyboard.IsKeyDown(Key.LeftCtrl) && group.Shapes.Count() > 0) { AddGroupToCanvas(canvas); } }
public void Redo(InternalCanvas canvas) { if (!(OldShapeComponent is TextDecorator)) { canvas.Shapes.Add(TextOrnament); canvas.Children.Add(TextOrnament); canvas.Shapes.Remove(OldShapeComponent); canvas.Children.Remove(OldShapeComponent); } else if (OldShapeComponent is TextDecorator textshape) { throw new NotImplementedException(); } }
private double SetTopOfShape(InternalCanvas canvas, ShapeComponent shape, double new_y) { if (new_y < 0) { return(0); } else if (new_y > (canvas.ActualHeight - shape.ActualHeight)) { return(canvas.ActualHeight - shape.ActualHeight); } else { return(new_y); } }
public void ExecuteMouseMove(InternalCanvas canvas) { var pos = Mouse.GetPosition(canvas); var x = Math.Min(pos.X, startPoint.X); var y = Math.Min(pos.Y, startPoint.Y); var w = Math.Max(pos.X, startPoint.X) - x; var h = Math.Max(pos.Y, startPoint.Y) - y; newshape.Width = w; newshape.Height = h; canvas.SetNewShape(newshape, x, y); }
private double SetLeftOfShape(InternalCanvas canvas, ShapeComponent shape, double new_x) { if (new_x < 0) { return(0); } else if (new_x > (canvas.ActualWidth - shape.ActualWidth)) { return(canvas.ActualWidth - shape.ActualWidth); } else { return(new_x); } }
public void Execute(InternalCanvas canvas) { if (Mouse.LeftButton == MouseButtonState.Pressed && newshape == null) { ExecuteMouseDown(canvas); } else if (Mouse.LeftButton == MouseButtonState.Pressed && newshape != null) { ExecuteMouseMove(canvas); } else if (Mouse.LeftButton == MouseButtonState.Released && newshape != null) { ExecuteMouseUp(canvas); } }
private void AddTextDecorator(InternalCanvas canvas, ShapeComponent canvasshape) { InputDialog inputDialog = new InputDialog(); if (inputDialog.ShowDialog() == true) { TextOrnament = new TextDecorator(canvasshape, inputDialog.Texts); canvas.Shapes.Remove(canvasshape); canvas.Children.Remove(canvasshape); canvas.Shapes.Add(TextOrnament); canvas.Children.Add(TextOrnament); canvas.SetNewShape(TextOrnament, TextOrnament.ShapeComponent.Location.X, TextOrnament.ShapeComponent.Location.Y); } }
public override void Execute(InternalCanvas canvas) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Text file (*.txt)|*.txt|C# file (*.cs)|*.cs"; if (saveFileDialog.ShowDialog() == true) { SaveVisitor save = new SaveVisitor(); foreach (ShapeComponent shape in canvas.Shapes) { shape.Save(save); } File.WriteAllText(saveFileDialog.FileName, save.stringBuilder.ToString()); } IsCompleted = true; }
private void ExecuteMouseDown(InternalCanvas canvas) { mousePosition = Mouse.GetPosition(canvas); foreach (ShapeComponent canvasshape in canvas.Shapes) { if (canvasshape.IsMouseOver) { canvasshape.MousePosition = canvasshape.GetMousePositionType(mousePosition); shape = canvasshape; oldLocation = canvas.GetPositionOfShapeInCanvas(shape); oldHeight = shape.Height; oldWidth = shape.Width; shape.Stroke = Brushes.DarkBlue; break; } } }
public override void Execute(InternalCanvas canvas) { LoadedShapes = new List <ShapeComponent>(); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { string fileContent = File.ReadAllText(openFileDialog.FileName); ReadedLines = FileContentToList(fileContent); LoadedShapes = ReadedLinesToShapes(); } canvas.Reset(); foreach (ShapeComponent loadedshape in LoadedShapes) { canvas.AddShape(loadedshape); } IsCompleted = true; }
public void Execute(InternalCanvas canvas) { foreach (ShapeComponent canvasshape in canvas.Shapes) { if (canvasshape.IsMouseOver) { OldShapeComponent = canvasshape; if (!(canvasshape is TextDecorator)) { AddTextDecorator(canvas, canvasshape); } else if (canvasshape is TextDecorator textshape) { ModifyTextDecorator(textshape); } IsCompleted = true; break; } } }
public MainViewmodel() { Coordinates = new Test("car"); Actions = new Actions(); Setting = CurrentSetting.Selection; Canvas = InternalCanvas.getInstance(); SelectedShapes = new List <ShapeComponent>(); RectangleCommand = new RelayCommand(x => SetSetting(CurrentSetting.Rectangle)); CircleCommand = new RelayCommand(x => SetSetting(CurrentSetting.Circle)); SelectCommand = new RelayCommand(x => SetSetting(CurrentSetting.Selection)); GroupCommand = new RelayCommand(x => SetSetting(CurrentSetting.Group)); TextCommand = new RelayCommand(x => SetSetting(CurrentSetting.Text)); MouseDownCommand = new RelayCommand(MouseDown); MouseUpCommand = new RelayCommand(MouseUp); MouseMoveCommand = new RelayCommand(MouseMove); SaveCommand = new RelayCommand(SaveFile); LoadCommand = new RelayCommand(LoadFile); UndoCommand = new RelayCommand(Undo); RedoCommand = new RelayCommand(Redo); }
public void ExecuteMouseDown(InternalCanvas canvas) { foreach (ShapeComponent canvasshape in canvas.Shapes) { if (canvasshape.IsMouseOver) { if (group.Contains(canvasshape)) { group.Remove(canvasshape); oldShapeComponents.Remove(canvasshape); canvasshape.Stroke = Brushes.LightBlue; } else { group.Add(canvasshape); oldShapeComponents.Add(canvasshape); canvasshape.Stroke = Brushes.Red; } } } }
public void Redo(InternalCanvas canvas) { canvas.Children.Add(newshape); canvas.Shapes.Add(newshape); }
public void Undo(InternalCanvas canvas) { canvas.Children.Remove(newshape); canvas.Shapes.Remove(newshape); }
public void ExecuteMouseUp(InternalCanvas canvas) { newshape.Location = canvas.GetPositionOfShapeInCanvas(newshape); canvas.AddNewShape(newshape); IsCompleted = true; }
private void ExecuteMouseUp(InternalCanvas canvas) { //shape.Selected = false; shapeComponent.Stroke = null; //Cursor = Cursors.Arrow; }
void Command.Undo(InternalCanvas canvas) { }