private void Window1_EditFull_KeyDown(object sender, KeyEventArgs e) { // delete all selected gates if (e.Key == Key.Delete) { gateCanvas.UndoProvider.Add(gateCanvas.DeleteSelectedGates()); } if (e.Key == Key.Escape) { DragDrop.DragDropHelper.Cancel(); } if (Keyboard.Modifiers == ModifierKeys.Control) { // the control shortcuts // because our toolbar are image not text if (e.Key == Key.N && MyEditLevel == EditLevel.FULL) { btnNew_Click(sender, e); } if (e.Key == Key.O && MyEditLevel == EditLevel.FULL) { btnOpen_Click(sender, e); } if (e.Key == Key.S && MyEditLevel == EditLevel.FULL) { if (btnSave.IsEnabled) { btnSave_Click(sender, e); } else { btnSave_As_Click(sender, e); } } if (e.Key == Key.X && btnCut.IsEnabled) { btnCut_Click(sender, e); } if (e.Key == Key.C && btnCopy.IsEnabled) { btnCopy_Click(sender, e); } if (e.Key == Key.V && btnPaste.IsEnabled) { btnPaste_Click(sender, e); } if (e.Key == Key.Z && btnUndo.IsEnabled) { btnUndo_Click(sender, e); } if (e.Key == Key.Y && btnRedo.IsEnabled) { btnRedo_Click(sender, e); } if (!gateCanvas.EndUserMode) { if (e.Key == Key.A) { gateCanvas.SelectAll(); } // gate rotation if (e.Key == Key.Right) { KeyRotateGates(90); } if (e.Key == Key.Left) { KeyRotateGates(-90); } } } else { // not using ctrl if (!gateCanvas.EndUserMode) { if ((e.Key == Key.Right || e.Key == Key.Left || e.Key == Key.Down || e.Key == Key.Up) && gateCanvas.selected.Count > 0 && moves == null) { moves = new UndoRedo.Transaction("Move " + (gateCanvas.selected.Count == 1 ? "Gate" : gateCanvas.selected.Count.ToString() + " Gates")); } // moving gates if (e.Key == Key.Right) { KeyMoveGates(1, 0); } if (e.Key == Key.Left) { KeyMoveGates(-1, 0); } if (e.Key == Key.Up) { KeyMoveGates(0, -1); } if (e.Key == Key.Down) { KeyMoveGates(0, 1); } } } }
protected Window1(EditLevel e) { InitializeComponent(); _myEditLevel = e; EventDispatcher.BatchDispatcher = Dispatcher; gateCanvas.Circuit.Start(); // Everybody gets zoom sbZoom = new ShadowBox(); sbZoom.Margin = new Thickness(20); Grid1.Children.Remove(spZoom); sbZoom.Children.Add(spZoom); spZoom.Background = Brushes.Transparent; sbZoom.VerticalAlignment = VerticalAlignment.Top; sbZoom.HorizontalAlignment = HorizontalAlignment.Right; Grid1.Children.Add(sbZoom); Grid.SetColumn(sbZoom, 1); Grid.SetRow(sbZoom, 1); // everybody gets view keys this.PreviewKeyDown += new KeyEventHandler(Window1_View_KeyDown); Grid1.Children.Remove(spGates); if (e == EditLevel.FULL || e == EditLevel.EDIT) { // delete for edit or full this.PreviewKeyDown += new KeyEventHandler(Window1_EditFull_KeyDown); this.PreviewKeyUp += (s2, e2) => { // add moves if needed if (moves != null) { ((UndoRedo.UndoManager)Resources["undoManager"]).Add(moves); } moves = null; }; // drag/drop for edit or full DragDrop.DragDropHelper.ItemDropped += new EventHandler <DragDrop.DragDropEventArgs>(DragDropHelper_ItemDropped); // gates for edit or full sbGates = new ShadowBox(); sbGates.Margin = new Thickness(20, 20, 20, 20); sbGates.Children.Add(spGates); spGates.Background = Brushes.Transparent; sbGates.VerticalAlignment = VerticalAlignment.Center; sbGates.HorizontalAlignment = HorizontalAlignment.Left; Grid1.Children.Add(sbGates); Grid.SetColumn(sbGates, 1); Grid.SetRow(sbGates, 1); // edit or full get undo and edit tbUndo.Visibility = Visibility.Visible; tbEdit.Visibility = Visibility.Visible; // monitor the clipboard to provide cut/copy/paste visibility gateCanvas.selected.ListChanged += (s2, e2) => { btnCopy.IsEnabled = gateCanvas.selected.Count > 0; btnCut.IsEnabled = gateCanvas.selected.Count > 0; btnCopyAsImage.IsEnabled = gateCanvas.selected.Count > 0; }; this.Activated += (s2, e2) => { btnPaste.IsEnabled = Clipboard.ContainsData("IC"); }; } Grid1.Children.Remove(spSpeed); if (e == EditLevel.FULL) { // speed only for the main window sbSpeed = new ShadowBox(); sbSpeed.Margin = new Thickness(20, 20, 175, 20); sbSpeed.Children.Add(spSpeed); spSpeed.Background = Brushes.Transparent; sbSpeed.VerticalAlignment = VerticalAlignment.Top; sbSpeed.HorizontalAlignment = HorizontalAlignment.Right; Grid1.Children.Add(sbSpeed); Grid.SetColumn(sbSpeed, 1); Grid.SetRow(sbSpeed, 1); // otherwise the defaults mess it up when you open a new window slSpeed.ValueChanged += (sender2, e2) => { Gates.PropagationThread.SLEEP_TIME = (int)slSpeed.Value; }; // full also gets file and ic tbFile.Visibility = Visibility.Visible; tbIC.Visibility = Visibility.Visible; } if (e == EditLevel.EDIT) { // can't edit the user gates in this view spGates.IsReadOnly = true; } this.Loaded += (sender2, e2) => { ((UndoRedo.UndoManager)Resources["undoManager"]).SetSavePoint(); UpdateTitle(); lblAppTitle.Text = APP_TITLE; lblAppVersion.Text = APP_VERSION; lblAppCopyright.Text = APP_COPYRIGHT; }; // green team: added if statement to determine if ctrl keys are pressed // then fires mouse wheel zoom event this.PreviewMouseWheel += (sender, e2) => { if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) { gateCanvas.UseZoomCenter = true; double centerX = (Mouse.GetPosition(this).X + gateCanvas.GCScroller.HorizontalOffset) / gateCanvas.Zoom; double centerY = (Mouse.GetPosition(this).Y + gateCanvas.GCScroller.VerticalOffset) / gateCanvas.Zoom; gateCanvas.ZoomCenter = new Point(centerX, centerY); if (e2.Delta > 0) { slZoom.Value += 0.1; } else { slZoom.Value -= 0.1; } e2.Handled = true; } }; ((UndoRedo.UndoManager)Resources["undoManager"]).PropertyChanged += (sender2, e2) => { UpdateTitle(); // look for modified or not }; InfoLine.GetInstance().PropertyChanged += InfoLine_PropertyChanged; }