protected override void OnNodeAdded(Node node) { base.OnNodeAdded(node); MyNodeData data = node.Data as MyNodeData; if (data == null) { return; } // look at the node's Figure switch (data.Figure) { case NodeFigure.Input: case NodeFigure.Output: case NodeFigure.ManualOperation: { FrameworkElement leftport = node.FindPort("2", false); if (leftport != null) { SpotPanel.SetSpot(leftport, new Spot(0.05, 0.5, 1, 0)); } FrameworkElement rightport = node.FindPort("3", false); if (rightport != null) { SpotPanel.SetSpot(rightport, new Spot(0.95, 0.5, -1, 0)); } break; } default: break; } }
/// <summary> /// Call <see cref="DoResize"/> with a new bounds determined by the mouse point. /// </summary> /// <remarks> /// This determines a new resize bounds by calling /// <see cref="ComputeResize"/> with the latest mouse point /// limited by <see cref="ComputeMinSize"/> and <see cref="ComputeMaxSize"/>. /// The resulting rectangle is passed to <see cref="DoResize"/>. /// </remarks> public override void DoMouseMove() { Diagram diagram = this.Diagram; if (this.Active && diagram != null) { Size minSize = ComputeMinSize(); Size maxSize = ComputeMaxSize(); Rect newr = ComputeResize(diagram.LastMousePointInModel, SpotPanel.GetSpot(this.Handle), minSize, maxSize, true); DoResize(newr); } }
// Used in the above two methods to change the node's Tag property to a specified value. private void SetPortsVisible(UIElement uielement, bool visible) { if (Part.FindAncestor <Palette>(uielement) == null) { SpotPanel sp = uielement as SpotPanel; if (sp == null) { return; } Node n = Part.FindAncestor <Node>(sp); if (n == null) { return; } n.Tag = visible; } }
/// <summary> /// Call <see cref="DoResize"/> with a rectangle based on the most recent mouse point, /// and raise an "object resized" event before stopping the tool. /// </summary> public override void DoMouseUp() { Diagram diagram = this.Diagram; if (this.Active && diagram != null) { Size minSize = ComputeMinSize(); Size maxSize = ComputeMaxSize(); Rect newr = ComputeResize(diagram.LastMousePointInModel, SpotPanel.GetSpot(this.Handle), minSize, maxSize, true); DoResize(newr); diagram.Panel.UpdateDiagramBounds(); // set the EditResult before raising event, in case it changes the result or cancels the tool this.TransactionResult = ToolCategory; RaiseEvent(Diagram.NodeResizedEvent, new DiagramEventArgs(this.AdornedNode, this.AdornedElement)); } StopTool(); }
private void SetResizeCursor(FrameworkElement h, double angle) { Spot spot = SpotPanel.GetSpot(h); if (spot.IsNoSpot) { spot = Spot.Center; } double a = angle; if (spot.X <= 0) // left { if (spot.Y <= 0) // top-left { a += 225; } else if (spot.Y >= 1) // bottom-left { a += 135; } else // middle-left { a += 180; } } else if (spot.X >= 1) // right { if (spot.Y <= 0) // top-right { a += 315; } else if (spot.Y >= 1) // bottom-right { a += 45; } else // middle-right // a += 0; { } } else // middle-X { if (spot.Y <= 0) // top-middle { a += 270; } else if (spot.Y >= 1) // bottom-middle { a += 90; } else { // handle is in the middle-middle -- don't do anything return; } } if (a < 0) { a += 360; } else if (a >= 360) { a -= 360; } if (a < 22.5f) { h.Cursor = Part.SizeWECursor; } else if (a < 67.5f) { h.Cursor = Part.SizeNWSECursor; } else if (a < 112.5f) { h.Cursor = Part.SizeNSCursor; } else if (a < 157.5f) { h.Cursor = Part.SizeNESWCursor; } else if (a < 202.5f) { h.Cursor = Part.SizeWECursor; } else if (a < 247.5f) { h.Cursor = Part.SizeNWSECursor; } else if (a < 292.5f) { h.Cursor = Part.SizeNSCursor; } else if (a < 337.5f) { h.Cursor = Part.SizeNESWCursor; } else { h.Cursor = Part.SizeWECursor; } }