public MainWindow(ref InkToSketchWPF.InkCanvasSketch sketch, ref RecognitionInterfaces.Recognizer recog) { try { InitializeComponent(); } catch (Exception ex) { // Log error System.Console.WriteLine(ex.InnerException.Message); } // Set up inkSketch this.inkSketch = sketch; // Set up practice panel this.inkCanvas = inkSketch.InkCanvas; this.inkCanvas.Height = practiceDock.ActualHeight; this.inkCanvas.Width = practiceDock.ActualWidth; if (!practiceDock.Children.Contains(this.inkCanvas)) { practiceDock.Children.Add(this.inkCanvas); } inkCanvas.Strokes.StrokesChanged += new System.Windows.Ink.StrokeCollectionChangedEventHandler(Strokes_StrokesChanged); inkCanvas.StrokeCollected += new InkCanvasStrokeCollectedEventHandler(Strokes_StrokesCollected); inkCanvas.StrokeErasing += new InkCanvasStrokeErasingEventHandler(Strokes_StrokesErasing); // Set up gate drawing gateDrawer = new GateDrawing.GateDrawing(); gateDrawer.LockDrawingRatio = false; recognizer = recog; // Set up the list of gates defaultChoice = new ComboBoxItem(); defaultChoice.Content = "Choose a gate"; gateChooser.Items.Add(defaultChoice); gateChooser.SelectedItem = defaultChoice; foreach (ShapeType gate in LogicDomain.Gates) { if (gate == LogicDomain.SUBCIRCUIT) { continue; } ComboBoxItem item = new ComboBoxItem(); item.Content = gate.Name; gateChooser.Items.Add(item); } ComboBoxItem free = new ComboBoxItem(); free.Content = freehandString; gateChooser.Items.Add(free); }
private Popup createDrawingAdvice(ref GateDrawing.GateDrawing gateDrawer) { // Make textbox to go with the image Popup popup = new Popup(); TextBlock popupText = new TextBlock(); popupText.Text = gateDrawer.DrawingAdvice; popupText.TextWrapping = System.Windows.TextWrapping.Wrap; popupText.Background = Brushes.Pink; popupText.Foreground = Brushes.Black; popup.Child = popupText; popup.IsOpen = false; popup.AllowsTransparency = true; popup.Visibility = System.Windows.Visibility.Visible; popup.PlacementTarget = sketchPanel.InkCanvas; popup.Placement = PlacementMode.RelativePoint; popup.HorizontalOffset = 20; popup.VerticalOffset = 50; return(popup); }
/// <summary> /// The ghost gate to be drawn and added to the Sketch. The ghost gates are tracked in /// Edit Menu in currGhosts. It delegates when to draw and undraw these. The Ghosts have /// the shape that is associated with it so that it can update Orientation. /// /// Also the name Ghost gate is super cool /// </summary> /// <param name="shape"></param> /// <param name="SketchPanel"></param> public GhostGate(Sketch.Shape shape, ref SketchPanelLib.SketchPanel sketchPanel, ref GateDrawing.GateDrawing gateDrawer, GateRotatedHandler gateRotated, KeyValuePair <List <string>, List <string> > IO = new KeyValuePair <List <string>, List <string> >()) { // Initialize everything startPoint = new System.Windows.Point(); endPoint = new System.Windows.Point(); subscribed = false; this.shape = shape; this.sketchPanel = sketchPanel; this.gateDrawer = gateDrawer; this.gateRotated = gateRotated; this.SubCircuitDock = new DockPanel(); this.IO = IO; if (!Domain.LogicDomain.IsGate(shape.Type)) { return; } // It makes no sense to lock the drawing ratio if this is a subcircuit, but we need to set it back to normal after bool shouldLock = this.gateDrawer.LockDrawingRatio; if (shape.Type == Domain.LogicDomain.SUBCIRCUIT) { gateDrawer.LockDrawingRatio = false; } // Make the desired image GeometryDrawing ghostGate = gateDrawer.DrawGate(shape.Type, shape.Bounds, false, true, shape.Orientation); // Make textbox to go with the image Popup popup = new Popup(); TextBlock popupText = new TextBlock(); popupText.Text = gateDrawer.DrawingAdvice; popupText.TextWrapping = System.Windows.TextWrapping.Wrap; popupText.Background = Brushes.Pink; popupText.Foreground = Brushes.Black; popup.Child = popupText; popup.IsOpen = false; popup.AllowsTransparency = true; popup.Visibility = System.Windows.Visibility.Visible; popup.PlacementTarget = sketchPanel.InkCanvas; popup.Placement = PlacementMode.RelativePoint; popup.HorizontalOffset = 20; popup.VerticalOffset = 50; drawingAdvice = popup; gateDrawer.LockDrawingRatio = shouldLock; DrawingImage drawingImage = new DrawingImage(ghostGate); relabelImage = new System.Windows.Controls.Image(); relabelImage.Source = drawingImage; relabelImage.Width = drawingImage.Width; relabelImage.Height = drawingImage.Height; // Actually add the image InkCanvas.SetLeft(relabelImage, shape.Bounds.Left); InkCanvas.SetTop(relabelImage, shape.Bounds.Top); // If it's a subcircuit we need to display the name and where inputs/ouputs should be if (shape.Type == Domain.LogicDomain.SUBCIRCUIT) { addIO(shape.Orientation); } sketchPanel.InkCanvas.Children.Add(relabelImage); sketchPanel.InkCanvas.Children.Add(drawingAdvice); }
/// <summary> /// The ghost gate to be drawn and added to the Sketch. The ghost gates are tracked in /// Edit Menu in currGhosts. It delegates when to draw and undraw these. The Ghosts have /// the shape that is associated with it so that it can update Orientation. /// /// Also the name Ghost gate is super cool /// </summary> /// <param name="shape"></param> /// <param name="SketchPanel"></param> public GhostGate(Sketch.Shape shape, ref SketchPanelLib.SketchPanel SketchPanel, ref GateDrawing.GateDrawing gateDrawer) { //initialize everything startPoint = new System.Windows.Point(); endPoint = new System.Windows.Point(); subscribed = false; if (!Domain.LogicDomain.IsGate(shape.Type)) { return; } myShape = shape; // Make the desired image GeometryDrawing ghostGate = gateDrawer.DrawGate(myShape.Type, myShape.Bounds, false, true, myShape.Orientation); System.Windows.Media.DrawingImage drawingImage = new System.Windows.Media.DrawingImage(ghostGate); relabelImage = new System.Windows.Controls.Image(); relabelImage.Source = drawingImage; sketchPanel = SketchPanel; drawingAdvice = createDrawingAdvice(ref gateDrawer); //Actual adding of the image InkCanvas.SetLeft(relabelImage, myShape.Bounds.Left); InkCanvas.SetTop(relabelImage, myShape.Bounds.Top); sketchPanel.InkCanvas.Children.Add(relabelImage); sketchPanel.InkCanvas.Children.Add(drawingAdvice); }