/// <summary> /// Updates the position of the node within the control. /// </summary> /// <param name="nodePresenter">The node to update.</param> /// <param name="forceVector">The force on the node.</param> /// <param name="coefficientOfDampening">The system dampening force.</param> /// <param name="frameRate">The system frame rate.</param> /// <param name="parentCenter">The center of the parent control.</param> /// <returns>A value indicating whether any updates took place.</returns> private static bool UpdateNodePositions(NodePresenter nodePresenter, Vector forceVector, double coefficientOfDampening, double frameRate, Point parentCenter) { bool parentCenterChanged = (nodePresenter.ParentCenter != parentCenter); if (parentCenterChanged) { nodePresenter.ParentCenter = parentCenter; } // add system drag & force nodePresenter.Velocity *= 1 - (coefficientOfDampening * frameRate); nodePresenter.Velocity += (forceVector * frameRate); // apply terminalVelocity if (nodePresenter.Velocity.Length > TerminalVelocity) { nodePresenter.Velocity *= (TerminalVelocity / nodePresenter.Velocity.Length); } if (nodePresenter.Velocity.Length > MinVelocity && forceVector.Length > MinVelocity) { nodePresenter.Location += (nodePresenter.Velocity * frameRate); return(true); } else { nodePresenter.Velocity = new Vector(); return(parentCenterChanged); } }
private void OnConnectionPointSelected(NodePresenter nodePresenter, PortPresenter portPresenter) { if (_selectedNodePresenter != null && _selectedNodePresenter.Id != nodePresenter.Id) { var selectedConnectionPointPresenter = _selectedPointPresenter; var connectionBetweenNodes = new LinkPresenter(new LinkView(), new LinkData()); connectionBetweenNodes.SetFrom(selectedConnectionPointPresenter, _selectedNodePresenter.Id); connectionBetweenNodes.SetTo(portPresenter, nodePresenter.Id); _selectedNodePresenter.AddNextNode(nodePresenter); _connectionPresenters.Add(connectionBetweenNodes); _vntData.AddConnectionData(connectionBetweenNodes.LinkData); _selectedNodePresenter = null; return; } _selectedNodePresenter = nodePresenter; _selectedPointPresenter = portPresenter; }
/// <summary> /// Creates a new animation to hide the provided node. /// </summary> /// <param name="node">The node to hide.</param> /// <param name="owner">The PhotoExplorerControl containing the node.</param> /// <returns>A new DoubleAnimation that hides the provided node.</returns> private static DoubleAnimation GetNewHideAnimation(NodePresenter node, PhotoExplorerControl owner) { DoubleAnimation hideAnimation = new DoubleAnimation(0, NodeHideAnimationDuration); hideAnimation.FillBehavior = FillBehavior.Stop; HideAnimationManager hideAnimationManager = new HideAnimationManager(owner, node); hideAnimation.Completed += new EventHandler(hideAnimationManager.CompletedHandler); hideAnimation.Freeze(); return(hideAnimation); }
/// <summary> /// Removes a node from the photo explorer control. /// </summary> /// <param name="nodePresenter">The node to remove.</param> /// <param name="nodeIsCenterNode">Whether or not this node used to be the center node.</param> private void RemoveNode(NodePresenter nodePresenter, bool nodeIsCenterNode) { this.InvalidateVisual(); this.fadingNodeList.Add(nodePresenter); nodePresenter.IsHitTestVisible = false; if (nodeIsCenterNode) { nodePresenter.WasCenter = true; } DoubleAnimation nodeAnimation = GetNewHideAnimation(nodePresenter, this); nodePresenter.ScaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, nodeAnimation); nodePresenter.ScaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, nodeAnimation); nodePresenter.BeginAnimation(OpacityProperty, nodeAnimation); }
private void DrawToolPanel() { var createNewButton = new ToolPanelButton("Create"); var loadButton = new ToolPanelButton("Load"); var saveButton = new ToolPanelButton("Save"); createNewButton.Clicked += () => { foreach (var nodePresenter in _nodePresenters) { nodePresenter.ConnectionPointSelected -= OnConnectionPointSelected; nodePresenter.ConnectionPointUnSelected -= OnConnectionPointUnSelected; } _nodePresenters.Clear(); _connectionPresenters.Clear(); _selectedNodePresenter = null; _selectedPointPresenter = null; }; loadButton.Clicked += () => { }; saveButton.Clicked += () => { var saveFileDialog = new SaveFileDialog(); saveFileDialog.ShowDialog(); if (saveFileDialog.Result) { var path = saveFileDialog.Path; XmlReadWriter.Write <VntData>(path, _vntData); } }; var toolPanelButtons = new List <ToolPanelButton>() { createNewButton, loadButton, saveButton }; _vntView.DrawToolPanel(toolPanelButtons); }
/// <summary> /// Updates the nodes being displayed when the center node or the nodes related to it change. /// </summary> private void UpdateDisplayedNodes() { // Clean up all of the old nodes; if the center node was on screen previously, we can reuse it instead. NodePresenter newCenterPresenter = null; foreach (NodePresenter nodePresenter in this.nodePresenters) { if (nodePresenter.Content == this.CenterNode) { newCenterPresenter = nodePresenter; } else { this.RemoveNode(nodePresenter, false); } } this.nodePresenters.Clear(); if (this.centerNodePresenter != null) { this.RemoveNode(this.centerNodePresenter, true); } // If we weren't able to reuse the center node presenter, generate a new one. if (newCenterPresenter == null) { newCenterPresenter = new NodePresenter(this.CenterNode, true); this.AddVisualChild(newCenterPresenter); } this.centerNodePresenter = newCenterPresenter; // Add presenters for all of the new nodes. foreach (PhotoExplorerBaseNode node in this.CenterNode.RelatedNodes) { NodePresenter nodePresenter = new NodePresenter(node, false); this.AddVisualChild(nodePresenter); this.nodePresenters.Add(nodePresenter); } }
private void OnConnectionPointSelected(NodePresenter nodePresenter, ConnectionPointPresenter connectionPointPresenter) { if (_selectedNodePresenter != null && _selectedNodePresenter.Id != nodePresenter.Id) { var selectedConnectionPointPresenter = _selectedPointPresenter; var connectionBetweenNodes = new ConnectionPresenter(new ConnectionView(), new ConnectionModel()) { ConnectionPointFrom = selectedConnectionPointPresenter, ConnectionPointTo = connectionPointPresenter }; _selectedNodePresenter.AddNextNode(nodePresenter); _connectionPresenters.Add(connectionBetweenNodes); _selectedNodePresenter = null; return; } _selectedNodePresenter = nodePresenter; _selectedPointPresenter = connectionPointPresenter; }
/// <summary> /// Initializes a new instance of the HideAnimationManager class. /// </summary> /// <param name="owner">The owning PhotoExplorerControl.</param> /// <param name="nodePresenter">The NodePresenter being hidden.</param> public HideAnimationManager(PhotoExplorerControl owner, NodePresenter nodePresenter) { this.owner = owner; this.nodePresenter = nodePresenter; }
/// <summary> /// Disposes of the node and its presenter when the hide animation completes. /// </summary> /// <param name="nodePresenter">The node to clean up.</param> private void CleanUpNode(NodePresenter nodePresenter) { this.RemoveVisualChild(nodePresenter); this.fadingNodeList.Remove(nodePresenter); }
/// <summary> /// When the framework renders a visual frame, use a physics engine to update the positions of the nodes on screen. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="args">Arguments describing the event.</param> private void OnCompositionTargetRendering(object sender, EventArgs args) { if (this.nodePresenters != null && this.centerNodePresenter != null) { if (this.springForces == null) { this.springForces = SetupForceVectors(this.nodePresenters.Count); } else if (this.springForces.GetLowerBound(0) != this.nodePresenters.Count) { this.springForces = SetupForceVectors(this.nodePresenters.Count); } bool somethingInvalid = false; if (this.measureInvalidated || this.stillMoving) { if (this.measureInvalidated) { this.ticksOfLastMeasureUpdate = Environment.TickCount; } // Update the center node if (this.centerNodePresenter != null) { if (this.centerNodePresenter.NewNode) { this.centerNodePresenter.ParentCenter = this.controlCenter; this.centerNodePresenter.NewNode = false; somethingInvalid = true; } else { Vector forceVector = GetAttractionForce(EnsureNonzeroVector((Vector)this.centerNodePresenter.Location)); if (UpdateNodePositions(this.centerNodePresenter, forceVector, this.CoefficientOfDampening, this.FrameRate, this.controlCenter)) { somethingInvalid = true; } } } // Update the other nodes for (int i = 0; i < this.nodePresenters.Count; i++) { NodePresenter nodePresenter = this.nodePresenters[i]; if (nodePresenter.NewNode) { nodePresenter.NewNode = false; somethingInvalid = true; } for (int j = (i + 1); j < this.nodePresenters.Count; j++) { Vector distance = EnsureNonzeroVector(nodePresenter.Location - this.nodePresenters[j].Location); Vector repulsiveForce = GetRepulsiveForce(distance); this.springForces[i, j] = repulsiveForce; } } for (int i = 0; i < this.nodePresenters.Count; i++) { Vector forceVector = new Vector(); forceVector += GetVectorSum(i, this.nodePresenters.Count, this.springForces); forceVector += GetSpringForce(EnsureNonzeroVector(this.nodePresenters[i].Location - this.centerNodePresenter.Location)); forceVector += GetWallForce(this.RenderSize, this.nodePresenters[i].Location); if (UpdateNodePositions(this.nodePresenters[i], forceVector, this.CoefficientOfDampening, this.FrameRate, this.controlCenter)) { somethingInvalid = true; } } // Animate away the fading nodes for (int i = 0; i < this.fadingNodeList.Count; i++) { if (!this.fadingNodeList[i].WasCenter) { Vector centerDiff = EnsureNonzeroVector(this.fadingNodeList[i].Location - this.centerNodePresenter.Location); centerDiff.Normalize(); centerDiff *= 20; if (UpdateNodePositions(this.fadingNodeList[i], centerDiff, this.CoefficientOfDampening, this.FrameRate, this.controlCenter)) { somethingInvalid = true; } } } // If we've moved nodes this round (and we've still got time to shuffle more nodes), invalidate the visual so that we'll // get a chance to update again in the near future. if (somethingInvalid && this.BelowMaxSettleTime()) { this.stillMoving = true; InvalidateVisual(); } else { this.stillMoving = false; this.DisconnectFromCompositionTargetRendering(); } this.measureInvalidated = false; } } }
private void OnConnectionPointUnSelected(NodePresenter nodePresenter, ConnectionPointPresenter connectionPointPresenter) { _selectedNodePresenter = null; _selectedPointPresenter = null; }
private void OnNodeSelected(NodePresenter nodePresenter) { Selection.activeObject = nodePresenter.NodeData; }