public void ToggleOutline(bool state) { MainWindow.ins.drawCanvas.Children.Remove(outline); MainWindow.ins.drawCanvas.Children.Remove(handle); Hierarchy.GetInstance().GetTopGroup().GetAllShapes().ForEach(x => ((OrnamentDecorator)x).DisplayOrnaments(false)); if (state) { GetAllShapes().ForEach(x => ((OrnamentDecorator)x).DisplayOrnaments(true)); // calculate the transform of the outline. CalculateTransform(); // Draw it for the first time. DrawOutline(); // update the origin pos and scale of the outline. outline.UpdateOriginTransform(); // and also for the handle. handle.UpdateOriginTransform(); // update the origin pos and scale of the outline. UpdateOriginTransform(); // instantiate it. MainWindow.ins.drawCanvas.Children.Add(outline); MainWindow.ins.drawCanvas.Children.Add(handle); } else { //GetAllShapes().ForEach(x => ((OrnamentDecorator)x).DisplayOrnaments(false)); // remove it. MainWindow.ins.drawCanvas.Children.Remove(outline); MainWindow.ins.drawCanvas.Children.Remove(handle); } }
private void InitializeShortcutActions(Action <Key> onKeyDown) { onKeyDown += (key) => { switch (key) { case Key.Z: if (Keyboard.IsKeyDown(Key.LeftCtrl)) { commandManager.Undo(); } break; case Key.R: if (Keyboard.IsKeyDown(Key.LeftCtrl)) { commandManager.Redo(); } break; case Key.M: commandManager.InvokeCommand(new SwitchGroupCommand(Hierarchy.GetInstance().GetTopGroup())); break; case Key.J: if (Keyboard.IsKeyDown(Key.LeftCtrl) && Selection.GetInstance().GetChildren().Count > 0) { commandManager.InvokeCommand(new MergeCommand()); } break; } }; }
public void SaveProgramState() { if (!Hierarchy.GetInstance().GetTopGroup().GetChildren().Any()) { File.Delete(textFile); return; } File.WriteAllText(textFile, ""); // disable the outline. Selection.GetInstance().ToggleOutline(false); // get their type and transform and write it to the file. //File.AppendAllText(textFile, $"{Hierarchy.GetInstance().GetTopGroup().ToString(0)}"); File.AppendAllText(textFile, $"{Hierarchy.GetInstance().GetTopGroup().Accept(new WriteVisitor(0))}"); }
public MainWindow() { InitializeComponent(); // initialize the singleton. ins ??= this; // make te style button a toggle for the shape buttons. buttonStyle.Click += (a, b) => stylesDisplay.Visibility = stylesDisplay.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed; // initialize the clear button. buttonClear.Click += (a, b) => CommandManager.GetInstance().InvokeCommand(new ClearCommand()); // set the current newState to None. SwitchState(States.None); // assign the stack panel from the hierarchy. Hierarchy.GetInstance().SetStackPanel(selectionDisplay); // Initialize the buttons InitializeStyleButtons(); // bind the undo and redo actions to their corresponding buttons buttonUndo.Click += (a, b) => CommandManager.GetInstance().Undo(); buttonRedo.Click += (a, b) => CommandManager.GetInstance().Redo(); // als bind it to the control+z and contrl+r keys KeyDown += (a, b) => { switch (b.Key) { case Key.Z: if (Keyboard.IsKeyDown(Key.LeftCtrl)) { CommandManager.GetInstance().Undo(); } break; case Key.R: if (Keyboard.IsKeyDown(Key.LeftCtrl)) { CommandManager.GetInstance().Redo(); } break; case Key.M: CommandManager.GetInstance().InvokeCommand(new SwitchGroupCommand(Hierarchy.GetInstance().GetTopGroup())); break; case Key.J: if (Keyboard.IsKeyDown(Key.LeftCtrl) && Selection.GetInstance().GetChildren().Count > 0) { CommandManager.GetInstance().InvokeCommand(new MergeCommand()); } break; } }; // go to back to Draw newState when rmb is pressed. MouseRightButtonDown += (a, b) => { if (state == States.Select) { new ChangeShapeStyleCommand(styleIndex).Execute(); Selection.GetInstance().Clear(); Hierarchy.GetInstance().DeselectAllButtons(); } }; // click the first shape button ((Button)stylesDisplay.Children[0]).RaiseEvent(new RoutedEventArgs(System.Windows.Controls.Primitives.ButtonBase.ClickEvent)); }