/// <summary> /// Creates a mode and registers it as the /// <see cref="CanvasControl.InputMode"/>. /// </summary> protected virtual void InitializeInputModes() { // Create a multiplexing input mode and that uses a MoveViewportInputMode and add a // wait input mode that will be used by the animator to block user input during // animations automatically. MultiplexingInputMode multiplexingInputMode = new MultiplexingInputMode(); multiplexingInputMode.Add(new WaitInputMode { Priority = 0 }); multiplexingInputMode.Add(new MoveViewportInputMode { Priority = 5 }); graphControl.InputMode = multiplexingInputMode; }
/// <summary> /// Adds the input modes that handle the resizing and movement of the rectangular area. /// </summary> /// <param name="inputMode"></param> private void AddClearRectInputModes(MultiplexingInputMode inputMode) { // create handles for interactively resizing the rectangle var rectangleHandles = new RectangleReshapeHandleProvider(clearRect) { MinimumSize = new SizeD(10, 10) }; // create a mode that deals with the handles var handleInputMode = new HandleInputMode { Priority = 1 }; // add it to the graph editor mode inputMode.Add(handleInputMode); // now the handles var inputModeContext = Contexts.CreateInputModeContext(handleInputMode); handleInputMode.Handles = new DefaultObservableCollection <IHandle> { rectangleHandles.GetHandle(inputModeContext, HandlePositions.NorthEast), rectangleHandles.GetHandle(inputModeContext, HandlePositions.NorthWest), rectangleHandles.GetHandle(inputModeContext, HandlePositions.SouthEast), rectangleHandles.GetHandle(inputModeContext, HandlePositions.SouthWest), }; // create a mode that allows for dragging the rectangle at the sides var moveInputMode = new MoveInputMode { PositionHandler = new RectanglePositionHandler(clearRect), HitTestable = HitTestables.Create((context, location) => clearRect.Contains(location)), Priority = 41 }; // handle dragging the rectangle moveInputMode.DragStarting += OnDragStarting; moveInputMode.Dragged += OnDragged; moveInputMode.DragCanceled += OnDragCanceled; moveInputMode.DragFinished += OnDragFinished; // handle resizing the rectangle handleInputMode.DragStarting += OnDragStarting; handleInputMode.Dragged += OnDragged; handleInputMode.DragCanceled += OnDragCanceled; handleInputMode.DragFinished += OnDragFinished; // add it to the edit mode inputMode.Add(moveInputMode); }
/// <summary> /// Helper method that allows for reusing this window in other applications. /// </summary> /// <param name="graphControl">The graph control.</param> public void ShowGraph(GraphControl graphControl) { this.graphControl.Graph = graphControl.Graph; this.graphControl.Selection.Clear(); // or possibly: = graphControl.Selection; this.graphControl.ContentRect = graphControl.ContentRect.GetEnlarged(20); // show all of the contents this.graphControl.FitContent(); // or possibly the same viewport // this.graphControl.Zoom = graphControl.Zoom; // this.graphControl.ViewPoint = graphControl.ViewPoint; var inputMode = new MultiplexingInputMode(); // set the whole content rect as the export rectangle exportRect.Reshape(graphControl.ContentRect); // or possibly just the visible viewport //exportRect.Set(graphControl.Viewport); // create mode which supports moving the viewport by pressing ctrl var moveViewportInputMode = new MoveViewportInputMode { PressedRecognizer = (source, args) => MouseEventRecognizers.LeftPressed(source, args) && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control }; inputMode.Add(moveViewportInputMode); AddExportRectInputModes(inputMode); this.graphControl.InputMode = inputMode; }
/// <summary> /// Adds the view modes that handle the resizing and movement of the export rectangle. /// </summary> /// <param name="inputMode"></param> private void AddExportRectInputModes(MultiplexingInputMode inputMode) { // create handles for interactivel resizing the export rectangle var rectangleHandles = new RectangleReshapeHandleProvider(exportRect) { MinimumSize = new SizeD(1, 1) }; // create a mode that deals with the handles var exportHandleInputMode = new HandleInputMode { Priority = 1 }; // add it to the graph editor mode inputMode.Add(exportHandleInputMode); // now the handles var inputModeContext = Contexts.CreateInputModeContext(exportHandleInputMode); exportHandleInputMode.Handles = new DefaultObservableCollection <IHandle> { rectangleHandles.GetHandle(inputModeContext, HandlePositions.NorthEast), rectangleHandles.GetHandle(inputModeContext, HandlePositions.NorthWest), rectangleHandles.GetHandle(inputModeContext, HandlePositions.SouthEast), rectangleHandles.GetHandle(inputModeContext, HandlePositions.SouthWest), }; // create a mode that allows for dragging the export rectangle at the sides var moveInputMode = new MoveInputMode { PositionHandler = new ExportRectanglePositionHandler(exportRect), HitTestable = HitTestables.Create( (context, location) => { var path = new GeneralPath(5); path.AppendRectangle(exportRect, false); return(path.PathContains(location, context.HitTestRadius)); }), Priority = 41 }; // add it to the edit mode inputMode.Add(moveInputMode); }
public static void AddConcurrent(this MultiplexingInputMode mux, IInputMode mode) { mux.Add(mode); }