/// <summary> /// Draws "ghost" gate for the supplied shape and sets the hoverGate (does nothing if shape is not /// a gate) /// </summary> /// <param name="gate"></param> /// <param name="pos"></param> public void DrawFeedback(Sketch.Shape shape, bool isHoverGate = false, bool drawingOneGate = true) { if (!Domain.LogicDomain.IsGate(shape.Type) || ShapeToGate.ContainsKey(shape)) { return; } KeyValuePair <List <string>, List <string> > shapeIO; ShapeToIO.TryGetValue(shape, out shapeIO); GhostGate ghostGate = new GhostGate(shape, ref sketchPanel, ref gateDrawer, gateRotated, shapeIO); ShapeToGate[shape] = ghostGate; ghostGate.SubscribeEvents(); currGhosts.Add(ghostGate); if (isHoverGate) { hoverGate = ghostGate; //if (shape.UserLabeled) // hoverGate.ShowDrawingAdvice(); } if (shape.UserLabeled) { ghostGate.ShowDrawingAdvice(); } }
/// <summary> /// Tells the gate that's currently being rotated that it's been dropped. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sketchPanel_StylusUp(object sender, System.Windows.Input.StylusEventArgs e) { if (RotateGates && activatedGate != null) { System.Windows.Point point = e.GetPosition(sketchPanel.InkCanvas); activatedGate.finish(point); RemoveGate(activatedGate); activatedGate = null; sketchPanel.UseCustomCursor = false; sketchPanel.EnableDrawing(); } }
/// <summary> /// Tells the nearby shape that it's being rotated (if there's one) and hides the others. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sketchPanel_StylusDown(object sender, System.Windows.Input.StylusDownEventArgs e) { // Remove all gates on a pen down no matter what RemoveAllGates(); // If we're erasing or not rotating gates, don't do anything else if (e.StylusDevice.Inverted || !RotateGates) { return; } // Clear past information activatedGate = null; // Get the nearest shape System.Windows.Point clickPoint = e.GetPosition(sketchPanel.InkCanvas); Shape nearbyShape = sketchPanel.Sketch.shapeAtPoint(clickPoint.X, clickPoint.Y, 100); // Only rotate AlreadyLabeled shapes if (nearbyShape == null || !nearbyShape.AlreadyLabeled) { return; } // Get the ghost gate for this shape DrawFeedback(nearbyShape, true); if (!ShapeToGate.ContainsKey(nearbyShape)) { return; } GhostGate nearbyGate = ShapeToGate[nearbyShape]; // If there was a viable gate nearby, activate it if (nearbyGate.canActivate(clickPoint)) { activatedGate = nearbyGate; activatedGate.activate(clickPoint); sketchPanel.UseCustomCursor = true; sketchPanel.Cursor = Cursors.Hand; sketchPanel.DisableDrawing(); } // Otherwise, take away the gate we just drew else { RemoveAllGates(); } }
/// <summary> /// Remove a single gate from the canvas /// </summary> /// <param name="gate"></param> private void RemoveGate(GhostGate gate) { if (gate == null) { return; } if (gate == hoverGate) { hoverGate = null; } gate.UnSubscribeEvents(); gate.unDraw(); currGhosts.Remove(gate); }
/// <summary> /// Remove a single gate from the canvas /// </summary> /// <param name="gate"></param> private void RemoveGate(GhostGate gate) { if (gate == null) { return; } if (gate == hoverGate) { hoverGate = null; } gate.remove(); currGhosts.Remove(gate); ShapeToGate.Remove(gate.Shape); }
/// <summary> /// Draws "ghost" gate for the supplied shape /// </summary> /// <param name="gate"></param> /// <param name="pos"></param> public void DrawFeedback(Sketch.Shape shape, bool isHoverGate = false) { if (!Domain.LogicDomain.IsGate(shape.Type)) { return; } GhostGate ghostGate = new GhostGate(shape, ref sketchPanel, ref gateDrawer); ghostGate.SubscribeEvents(); currGhosts.Add(ghostGate); if (isHoverGate) { hoverGate = ghostGate; } if (shape.UserLabeled) { ghostGate.ShowDrawingAdvice(); } }