public void Execute() { textShape = new ShapeTextDecorator(shape); if (shape.GetType() == typeof(ShapeComposite)) { ShapeComposite temp = (ShapeComposite)shape; textShape = new ShapeTextDecorator(temp.GetChildren()[0]); textShape.AddText(text, textPos); temp.GetChildren()[temp.GetChildren().FindIndex(ind => ind.Equals(temp.GetChildren()[0]))] = textShape; playground.AddShape(temp); playground.RemoveShape(shape); } else { textShape.AddText(text, textPos); playground.AddShape(textShape); playground.RemoveShape(shape); } }
public void Undo() { playground.AddShape(deletedShape); }
public void Execute() { playground.AddShape(currentShape); }
public void Update() { if (textBox != null) { textBox.Update(); } /*TODO: Move to 'UI' or/and keyboard shortcut*/ if (InputManager.IsKeyPressed(Keys.B)) { foreach (mCanvas c in playground.Canvases) { c.ForAllShapes((aShape shape) => { if (shape.Selected) { shape.DrawBorder = !shape.DrawBorder; } }); } } if (InputManager.IsKeyDown(Keys.LeftControl) && InputManager.IsKeyPressed(Keys.G)) { List <aShape> selectedShapes = getSelectedShapes(); ShapeComposite firstGroup = isGroupInSelection(selectedShapes); if (firstGroup != null) { selectedShapes.Remove(firstGroup); } ShapeComposite group = null; if (selectedShapes.Count > 1) { group = new ShapeComposite(); foreach (aShape s in selectedShapes) { group.Add(s); } } if (group != null) { deleteShapes(selectedShapes); if (firstGroup != null) { firstGroup.Add(group); } else { playground.AddShape(group); } } Reset(); } if (leftClicked && !selecting && InputManager.IsKeyDown(Keys.LeftControl)) { selecting = true; int mX = InputManager.CurrentMouseState.X; int mY = InputManager.CurrentMouseState.Y; selectionRect.X = mX; selectionRect.Y = mY; } else if (leftClicked && selecting && InputManager.IsKeyDown(Keys.LeftControl)) { int newWidth = Util.Clamp(InputManager.CurrentMouseState.X - selectionRect.X, 1, playground.Width); int newHeight = Util.Clamp(InputManager.CurrentMouseState.Y - selectionRect.Y, 1, playground.Height); Console.WriteLine("Width: " + newWidth); selectionRect.Width = newWidth; selectionRect.Height = newHeight; selectionRect.Load(); } else if (!leftClicked && selecting && InputManager.IsKeyDown(Keys.LeftControl)) { selecting = false; foreach (mCanvas c in playground.Canvases) { c.ForAllShapes((aShape iShape) => { if (selectionRect.Intersects(iShape)) { iShape.Selected = true; } }); } if (selectionRect.Width > 0) { selectionRect.Width = 1; selectionRect.Height = 1; selectionRect.Load(); } } else { foreach (mCanvas c in playground.Canvases) { c.ForAllShapes(SelectShape); } } if (!typing) { //For adding text if (InputManager.IsKeyPressed(Keys.Up)) { typing = true; AddText(TextPos.Top); } else if (InputManager.IsKeyPressed(Keys.Left)) { typing = true; AddText(TextPos.Left); } else if (InputManager.IsKeyPressed(Keys.Down)) { typing = true; AddText(TextPos.Bottom); } else if (InputManager.IsKeyPressed(Keys.Right)) { typing = true; AddText(TextPos.Right); } } if (!typing && (InputManager.IsKeyPressed(Keys.Delete) || InputManager.IsKeyPressed(Keys.Back))) { deleteShapes(); } if (InputManager.IsPressed(MouseInput.LeftButton)) { leftClicked = true; } if (InputManager.IsReleased(Input.MouseInput.LeftButton)) { leftClicked = false; } }