private void selectRowNode(DataGridViewRow row) { Debug.Check(row != null); if (row != null) { row.Selected = true; string behaviorFilename = (string)row.Cells["BehaviorFilename"].Value; BehaviorTreeView behaviorTreeView = UIUtilities.ShowBehaviorTree(behaviorFilename); if (behaviorTreeView != null) { string nodeId = (string)row.Cells["NodeId"].Value; NodeViewData nvd = behaviorTreeView.RootNodeView.FindNodeViewData(nodeId); if (nvd != null) { behaviorTreeView.SelectedNode = nvd; //if (behaviorTreeView.ClickNode != null) // behaviorTreeView.ClickNode(nvd); behaviorTreeView.Invalidate(); } } } }
/// <summary> /// Registeres a connector. /// </summary> /// <param name="connector">The connector which will be registered.</param> public void RegisterConnector(Connector connector) { // check if this connector has already been registered. The identifier must be unique on the node. foreach (Connector conn in _connectors) { if (conn.Identifier == connector.Identifier) { throw new Exception(Resources.ExceptionDuplicatedConnectorIdentifier); } } // add the connector and queue and update of the child list _connectors.Add(connector); _requiresRebuild = true; // add the visual subitems for the connector NodeViewData nvd = _owner as NodeViewData; if (nvd != null) { for (int i = 0; i < connector.MinCount; ++i) { nvd.AddSubItem(new NodeViewData.SubItemConnector(connector, null, i)); } } }
public override void Draw(Graphics graphics, NodeViewData nvd, RectangleF boundingBox) { // use a different brush depending on if the event is reacted to or blocked. //_labelBrush= _event.BlockEvent ? Brushes.Orange : Brushes.White; base.Draw(graphics, nvd, boundingBox); }
/// <summary> /// Searches a list for NodeViewData for this node. Internal use only. /// </summary> /// <param name="list">The list which is searched for the NodeViewData.</param> /// <returns>Returns null if no fitting NodeViewData could be found.</returns> public override NodeViewData FindNodeViewData(List <NodeViewData> list) { foreach (NodeViewData nvd in list) { if (nvd.Node is ReferencedBehavior) { ReferencedBehavior refnode = (ReferencedBehavior)nvd.Node; // if both nodes reference the same behaviour we copy the view related data if (_referencedBehavior != null && refnode.ReferenceBehaviorNode == _referencedBehavior) { NodeViewData nvdrb = (NodeViewData)nvd; NodeViewData newdata = (NodeViewData)CreateNodeViewData(nvd.Parent, nvd.RootBehavior); // copy data newdata.IsExpanded = nvdrb.IsExpanded; // return new data return(newdata); } } if (nvd.Node == this) { return(nvd); } } return(null); }
private void listView_Click(object sender, EventArgs e) { // check if there is an item selected if (listView.SelectedItems.Count < 1) { return; } // check if this item has a node connected to it. The no-errors message doesn't Nodes.Node node = listView.SelectedItems[0].Tag as Nodes.Node; if (node == null) { return; } // show the behaviour and select the node. NodeViewData nvd = _behaviorTreeList.ShowNode(node); Debug.Check(nvd != null); _behaviorTreeView.SelectedNode = nvd; _behaviorTreeView.ShowNode(nvd); PropertiesDock.InspectObject(nvd.RootBehavior, nvd.Node); }
public override void Draw(Graphics graphics, NodeViewData nvd, RectangleF boundingBox) { // render background DrawBackground(graphics, nvd, this.BackgroundBrush); // render the label PointF center = new PointF(boundingBox.Left + boundingBox.Width * 0.5f, boundingBox.Top + boundingBox.Height * 0.5f); SizeF labelSize = MeasureDisplayStringWidth(graphics, this.DisplayLabel, _labelFont); // draw text switch (_alignment) { case (Alignment.Left): graphics.DrawString(this.DisplayLabel, _labelFont, _labelBrush, boundingBox.Left + 6.0f, center.Y - labelSize.Height * 0.5f); break; case (Alignment.Center): graphics.DrawString(this.DisplayLabel, _labelFont, _labelBrush, center.X - labelSize.Width * 0.5f, center.Y - labelSize.Height * 0.5f); break; case (Alignment.Right): graphics.DrawString(this.DisplayLabel, _labelFont, _labelBrush, boundingBox.Right - labelSize.Width - 6.0f, center.Y - labelSize.Height * 0.5f); break; } }
/// <summary> /// Draws the node's shape as the background. /// </summary> /// <param name="graphics">The graphics object used for drawing.</param> /// <param name="nvd">The node view data of the node the subitem belongs to.</param> /// <param name="brush">The brush to draw the node's shape.</param> protected void DrawBackground(Graphics graphics, NodeViewData nvd, Brush brush) { if (brush != null) { nvd.DrawShapeBackground(graphics, nvd.BoundingBox, brush); } }
/// <summary> /// Draws the text. /// </summary> /// <param name="graphics">The graphics object we render to.</param> /// <param name="nvd">The view data of this node in the current view.</param> public void DrawText(Graphics graphics, NodeViewData nvd) { if (_comment != string.Empty) { graphics.DrawString(_comment, __font, _labelBrush, nvd.LayoutRectangle.Location); } }
public override void Draw(Graphics graphics, NodeViewData nvd, RectangleF boundingBox) { // use a different brush depending on if the event is reacted to or blocked. _labelBrush= _event.BlockEvent ? Brushes.Orange : Brushes.White; base.Draw(graphics, nvd, boundingBox); }
public override NodeViewData CreateNodeViewData(NodeViewData parent, BehaviorNode rootBehavior) { NodeViewData nvd = base.CreateNodeViewData(parent, rootBehavior); nvd.ChangeShape(Behaviac.Design.NodeShape.Ellipse); return nvd; }
public override NodeViewData CreateNodeViewData(NodeViewData parent, BehaviorNode rootBehavior) { NodeViewDataStyled nvd = new NodeViewDataStyled(parent, rootBehavior, this, null, __defaultBackgroundBrush, _label, _description); nvd.ChangeShape(NodeShape.Rectangle); return(nvd); }
/// <summary> /// Draws the node's shape as the background. /// </summary> /// <param name="graphics">The graphics object used for drawing.</param> /// <param name="nvd">The node view data of the node the subitem belongs to.</param> /// <param name="brush">The brush to draw the node's shape.</param> protected void DrawBackground(Graphics graphics, NodeViewData nvd, Brush brush) { if (brush != null) { nvd.DrawShapeBackground(graphics, nvd.BoundingBox, brush); //nvd.DrawShapeBorder(graphics, nvd.GetSubItemBoundingBox(nvd.BoundingBox, nvd.GetSubItemIndex(this)), Pens.WhiteSmoke); } }
public override NodeViewData CreateNodeViewData(NodeViewData parent, BehaviorNode rootBehavior) { NodeViewData nvd = base.CreateNodeViewData(parent, rootBehavior); nvd.ChangeShape(this.IsEndState ? NodeShape.RoundedRectangle : NodeShape.Rectangle); return(nvd); }
public override NodeViewData CreateNodeViewData(NodeViewData parent, BehaviorNode rootBehavior) { NodeViewDataStyled nvd = new NodeViewDataPrecondition(parent, rootBehavior, this, null, __theBackgroundBrush, __theBackgroundBrushNeg, _label, _description); nvd.ChangeShape(NodeShape.Capsule); return(nvd); }
public override NodeViewData CreateNodeViewData(NodeViewData parent, Behaviac.Design.Nodes.BehaviorNode rootBehavior) { NodeViewData nvd = base.CreateNodeViewData(parent, rootBehavior); nvd.ChangeShape(NodeShape.Rectangle); return(nvd); }
public override NodeViewData CreateNodeViewData(NodeViewData parent, BehaviorNode rootBehavior) { NodeViewData nvd = base.CreateNodeViewData(parent, rootBehavior); nvd.ChangeShape(NodeShape.Ellipse); return(nvd); }
public NodeViewDataPrecondition(NodeViewData parent, BehaviorNode rootBehavior, Node node, Pen borderPen, Brush backgroundBrush, Brush backgroundBrushNeg, string label, string description) : base(parent, rootBehavior, node, borderPen, backgroundBrush, label, description) { _backgroundBrush = backgroundBrush; _draggedBackgroundBrush = GetDraggedBrush(backgroundBrush); _backgroundBrushNeg = backgroundBrushNeg; _draggedBackgroundBrushNeg = GetDraggedBrush(backgroundBrushNeg); }
/// <summary> /// Is called when the node was double-clicked. Used for referenced behaviours. /// </summary> /// <param name="nvd">The view data of the node in the current view.</param> /// <param name="layoutChanged">Does the layout need to be recalculated?</param> /// <returns>Returns if the node handled the double click or not.</returns> public override bool OnDoubleClick(NodeViewData nvd, out bool layoutChanged) { NodeViewDataReferencedBehavior nvdrb = (NodeViewDataReferencedBehavior)nvd; nvdrb.IsExpanded = !nvdrb.IsExpanded; layoutChanged = true; return(true); }
/// <summary> /// Draws the text. /// </summary> /// <param name="dc">The graphics object we render to.</param> /// <param name="nvd">The view data of this node in the current view.</param> public void DrawText(DrawingContext dc, NodeViewData nvd) { if (_comment != string.Empty) { FormattedText formattedText = __font.FormatText(_comment, _labelBrush); dc.DrawText(formattedText, nvd.LayoutRectangle.Location); } }
/// <summary> /// Creates a new NodeLayoutManager. /// </summary> /// <param name="edgePen">The pen which is used to draw the edges connecting the nodes.</param> /// <param name="edgePenSubReferenced">The pen which is used to draw the edges connecting sub-referenced nodes.</param> /// <param name="skipLabels">Defines if labels are drawn or not.</param> /// <param name="rootNode">The root of the nodes shown in the view.</param> internal NodeLayoutManager(NodeViewData rootNode, Pen edgePen, Pen edgePenHighlight, Pen edgePenUpdate, Pen edgePenSubReferenced, bool skipLabels) { _rootNodeLayout = rootNode; _edgePen = edgePen; _edgePenHighLight = edgePenHighlight; _edgePenUpdate = edgePenUpdate; _edgePenReadOnly = edgePenSubReferenced; _skipLabels = skipLabels; }
public NodeViewDataCompoundTask(NodeViewData parent, BehaviorNode rootBehavior, Node node, Pen borderPen, Brush backgroundBrush, string label, string description) : base(parent, rootBehavior, node, borderPen, backgroundBrush, label, description) { Nodes.CompoundTask compoundTask = (Nodes.CompoundTask)_node; _usedMethodType = compoundTask.MethodType; // register to any method changes so our list is always up-to-date Nodes.Method.MethodWasModified += Method_MethodWasModified; }
/// <summary> /// Draws the background. /// </summary> /// <param name="dc">The graphics object we render to.</param> /// <param name="nvd">The view data of this node in the current view.</param> /// <param name="renderDepth">The depth which is still rendered.</param> /// <param name="padding">The padding between the nodes.</param> public void DrawBackground(DrawingContext dc, NodeViewData nvd, int renderDepth, Size padding) { Size size = nvd.GetTotalSize(padding.Width, renderDepth); if (_backgroundColor != CommentColor.NoColor) { double commentPadding = Math.Min(padding.Height, padding.Width) * 0.75; dc.DrawRoundedRectangle(_backgroundBrush, null, new Rect(nvd.LayoutRectangle.X - commentPadding * 0.5, nvd.LayoutRectangle.Y - commentPadding * 0.5, size.Width + commentPadding, size.Height + commentPadding), 6.0, 6.0); } }
public static bool SetExpandedNode(NodeViewData nvd, bool isExpanded) { Debug.Check(nvd != null && nvd.Node != null); Nodes.BehaviorNode behavior = nvd.Node.Behavior; if (behavior != null && !string.IsNullOrEmpty(behavior.Filename)) { return(SetExpandedNode(behavior.RelativePath, nvd.Node.Id.ToString(), isExpanded)); } return(false); }
public static bool IsExpandedNode(NodeViewData nvd) { Debug.Check(nvd != null && nvd.Node != null); if (nvd != null && nvd.Node != null) { bool defaultExpanded = !(nvd.Node is Nodes.ReferencedBehavior); if (defaultExpanded) { //if there is a leaf node, collapse it foreach (NodeViewData child in nvd.Children) { if (!child.CanBeExpanded()) { //leaf node can't be expanded, there is a leaf node! defaultExpanded = false; break; } } } Nodes.Behavior behavior = nvd.Node.Behavior as Nodes.Behavior; if (behavior != null) { behavior = behavior.GetTopBehavior(); } string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; if (!string.IsNullOrEmpty(filename) && _expandedNodeDict.ContainsKey(filename)) { Dictionary <string, ExpandedDatum> expandedNodes = _expandedNodeDict[filename]; string id = nvd.FullId; if (!expandedNodes.ContainsKey(id)) { return(defaultExpanded); } return(expandedNodes[id].isExpanded); } else { //defaultExpanded = true; } return(defaultExpanded); } return(false); }
/// <summary> /// Draws the background. /// </summary> /// <param name="graphics">The graphics object we render to.</param> /// <param name="nvd">The view data of this node in the current view.</param> /// <param name="renderDepth">The depth which is still rendered.</param> /// <param name="padding">The padding between the nodes.</param> public void DrawBackground(Graphics graphics, NodeViewData nvd, int renderDepth, SizeF padding) { SizeF size = nvd.GetTotalSize(padding.Width, renderDepth); if (_backgroundColor != CommentColor.NoColor) { float commentPadding = Math.Min(padding.Height, padding.Width) * 0.75f; ExtendedGraphics extended = new ExtendedGraphics(graphics); extended.FillRoundRectangle(_backgroundBrush, nvd.LayoutRectangle.X - commentPadding * 0.5f, nvd.LayoutRectangle.Y - commentPadding * 0.5f, size.Width + commentPadding, size.Height + commentPadding, 6.0f); } }
/// <summary> /// Adds nodes to the referenced behaviour which represent sub-referenced behaviours. /// </summary> /// <param name="processedBehaviors">A list of processed behaviours to handle circular references.</param> /// <param name="parent">The node the sub-referenced behaviours will be added to.</param> /// <param name="node">The current node we are checking.</param> protected void GenerateReferencedBehaviorsTree(ProcessedBehaviors processedBehaviors, NodeViewData parent, Node node) { if (!processedBehaviors.MayProcess(node)) { return; } // check if this is a referenced behaviour if (node is ReferencedBehaviorNode) { // create the dummy node and add it without marking the behaviour as being modified as these are no REAL nodes. NodeViewData rb = node.CreateNodeViewData(parent, _rootBehavior); #if DEBUG rb.IsSubreferencedGraphNode(); #endif rb.DoSynchronizeWithNode(processedBehaviors); Connector conn = parent.GetConnector("Tasks"); Debug.Check(conn != null); Connector rbconn = parent.GetConnector("Tasks"); Debug.Check(rbconn != null); parent.AddChildNotModified(conn, rb); // we have a circular reference here. Skip the children if (((ReferencedBehaviorNode)node).Reference == _rootBehavior) { rbconn.IsReadOnly = true; return; } // do the same for all the children foreach (Node child in node.Children) { GenerateReferencedBehaviorsTree(processedBehaviors.Branch(child), rb, child); } rbconn.IsReadOnly = true; } else { // do the same for all the children foreach (Node child in node.Children) { GenerateReferencedBehaviorsTree(processedBehaviors.Branch(child), parent, child); } } }
public NodeViewDataStyled(NodeViewData parent, BehaviorNode rootBehavior, Node node, Pen borderPen, Brush backgroundBrush, Brush draggedBackgroundBrush, string label, string description, int minWidth = 120, int minHeight = 35) : base(parent, rootBehavior, node, NodeShape.RoundedRectangle, new Style(backgroundBrush, null, Brushes.White), new Style(null, DefaultCurrentBorderPen, null), new Style(null, __defaultSelectedBorderPen, null), new Style(draggedBackgroundBrush, null, null), new Style(null, __highlightedBorderPen, null), new Style(null, __updatedBorderPen, null), new Style(null, __prefabBorderPen, null), label, __defaultLabelFont, __profileLabelFont, __profileLabelBoldFont, minWidth, minHeight, description) { }
public override void Draw(Graphics graphics, NodeViewData nvd, bool isCurrent, bool isSelected, bool isDragged, PointF graphMousePos) { Brush defBrush = _defaultStyle.Background; if (_genericChildren.IsReadOnly) { _defaultStyle.Background = _defaultBrushSub; } base.Draw(graphics, nvd, isCurrent, isSelected, isDragged, graphMousePos); _defaultStyle.Background = defBrush; }
/// <summary> /// Generates a list of connector subitems. /// </summary> /// <param name="firstIndex">The first connector subitem found on the node.</param> /// <returns>Returns alist of all connector subitems.</returns> protected List <NodeViewData.SubItemConnector> CollectSubItems(out int firstIndex) { if (!(_connectedChildren.Owner is NodeViewData)) { throw new Exception(Resources.ExceptionIsNotNodeViewData); } List <NodeViewData.SubItemConnector> list = new List <NodeViewData.SubItemConnector>(); firstIndex = -1; NodeViewData nvd = (NodeViewData)_connectedChildren.Owner; // for each subitem... for (int i = 0; i < nvd.SubItems.Count; ++i) { // check if it is a connector subitem NodeViewData.SubItemConnector subconn = nvd.SubItems[i] as NodeViewData.SubItemConnector; if (subconn != null && subconn.Connector == this) { // remember the index of the first connector subitem found if (firstIndex == -1) { firstIndex = i; } // add subitem to list list.Add(subconn); } else { // subitems of a connector must be next to each other if (firstIndex >= 0) { break; } } } // check if we have found any subitems if (list.Count < 1) { throw new Exception(Resources.ExceptionNoSubItemForConnector); } // check that we have found enough of them and not too many Debug.Check(list.Count >= _minCount && list.Count <= _maxCount); return(list); }
public static bool HasSetExpandedNodes(NodeViewData nvd) { Debug.Check(nvd != null && nvd.Node != null); Nodes.BehaviorNode behavior = nvd.Node.Behavior; string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; if (!string.IsNullOrEmpty(filename) && _expandedNodeDict.ContainsKey(filename)) { return(true); } return(false); }
public static bool IsExpandedConnector(NodeViewData nvd, string connector) { Debug.Check(nvd != null && nvd.Node != null); Nodes.Behavior behavior = nvd.Node.Behavior as Nodes.Behavior; if (behavior != null) { behavior = behavior.GetTopBehavior(); } string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; return(IsExpandedConnector(filename, nvd.Node.Id.ToString(), connector)); }
/// <summary> /// Draws the graph. /// </summary> /// <param name="graphics">The graphics object we want to draw to.</param> /// <param name="currentNode">The node the mouse is currently hovering over.</param> /// <param name="selectedNode">The node which is currently selected.</param> /// <param name="graphMousePos">The mouse's position in the graph.</param> internal void DrawGraph(Graphics graphics, PointF graphMousePos, NodeViewData currentNode = null, NodeViewData selectedNode = null, List <string> highlightedNodeIds = null, List <string> updatedNodeIds = null, List <string> highligltedTransitionIds = null, HighlightBreakPoint highlightBreakPoint = null, Dictionary <string, FrameStatePool.NodeProfileInfos.ProfileInfo> profileInfos = null) { // draw the node count of the root node if (_rootNodeLayout.RootBehavior == _rootNodeLayout.Node) { _rootNodeLayout.DrawCount(graphics); } // setup drawing graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear; graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; graphics.Transform = new System.Drawing.Drawing2D.Matrix(_scale, 0.0f, 0.0f, _scale, _offset.X, _offset.Y); // update display bounding boxes _rootNodeLayout.UpdateDisplay(_offset.X, _offset.Y, _scale); // draw comment backgrounds if (!_skipLabels) { _rootNodeLayout.DrawCommentBackground(graphics, _renderDepth, _padding); } // draw the edges if (_edgePen != null && _renderDepth > 0) { _rootNodeLayout.DrawEdges(graphics, highlightedNodeIds, updatedNodeIds, highligltedTransitionIds, _edgePen, _edgePenSelected, _edgePenHighLighted, _edgePenUpdate, _edgePenReadOnly, _renderDepth - 1); } // draw the nodes _rootNodeLayout.Draw(graphics, _skipLabels, graphMousePos, _renderDepth, currentNode, selectedNode, highlightedNodeIds, updatedNodeIds, highlightBreakPoint, profileInfos); // draw comment text if (!_skipLabels) { _rootNodeLayout.DrawCommentText(graphics, _renderDepth); } // draw last mouse pos //e.Graphics.DrawRectangle(Pens.Red, graphMousePos.X -1.0f, graphMousePos.Y -1.0f, 2.0f, 2.0f); }
//find the last recent parent which contains state data if the current one has no data public PlanningState GetLastNode(NodeViewData nvd) { while (nvd != null && !_states.ContainsKey(nvd.FullId)) { nvd = nvd.Parent; } if (nvd != null && _states.ContainsKey(nvd.FullId)) { PlanningState ps = _states[nvd.FullId]; while (ps != null && ps._agents.Count == 0) { ps = ps._parent; } return ps; } return null; }
public static bool HasSetExpandedNodes(NodeViewData nvd) { Debug.Check(nvd != null && nvd.Node != null); Nodes.Behavior behavior = nvd.Node.Behavior as Nodes.Behavior; if (behavior != null) { behavior = behavior.GetTopBehavior(); } string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; if (!string.IsNullOrEmpty(filename) && _expandedNodeDict.ContainsKey(filename)) { return true; } return false; }
public static bool IsExpandedNode(NodeViewData nvd) { Debug.Check(nvd != null && nvd.Node != null); bool defaultExpanded = !(nvd.Node is Nodes.ReferencedBehavior); if (defaultExpanded) { //if there is a leaf node, collapse it foreach(NodeViewData child in nvd.Children) { if (!child.CanBeExpanded()) { //leaf node can't be expanded, there is a leaf node! defaultExpanded = false; break; } } } Nodes.Behavior behavior = nvd.Node.Behavior as Nodes.Behavior; if (behavior != null) { behavior = behavior.GetTopBehavior(); } string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; if (!string.IsNullOrEmpty(filename) && _expandedNodeDict.ContainsKey(filename)) { Dictionary<string, ExpandedDatum> expandedNodes = _expandedNodeDict[filename]; string id = nvd.FullId; if (!expandedNodes.ContainsKey(id)) { return defaultExpanded; } return expandedNodes[id].isExpanded; } else { //defaultExpanded = true; } return defaultExpanded; }
/// <summary> /// Draws the node to the graph. /// </summary> /// <param name="graphics">The graphics object we render to.</param> /// <param name="nvd">The view data of this node for drawing.</param> /// <param name="isCurrent">Determines if the node is currently hovered over.</param> /// <param name="isSelected">Determines if the node is selected.</param> /// <param name="isDragged">Determines if the node is currently being dragged.</param> /// <param name="graphMousePos">The mouse position in the untransformed graph.</param> public virtual void Draw(Graphics graphics, NodeViewData nvd, bool isCurrent, bool isSelected, bool isDragged, PointF graphMousePos) { #if DEBUG //ensure consistency DebugCheckIntegrity(); #endif RectangleF boundingBox= nvd.BoundingBox; // assemble the correct style Style style= _defaultStyle; if(isDragged) style+= _draggedStyle; else if(isCurrent) style+= _currentStyle; else if(isSelected) style+= _selectedStyle; if(style.Background !=null) DrawShapeBackground(graphics, boundingBox, style.Background); // if the node is dragged, do not render the events if(!isDragged) { // if this node is not selected, deselect the event if(!isSelected && _selectedSubItem !=null) { _selectedSubItem.IsSelected= false; _selectedSubItem= null; } if(_subItems.Count >0) { Region prevreg= graphics.Clip; // draw non parallel subitems first for(int i= 0; i <_subItems.Count; ++i) { if(!_subItems[i].ShowParallelToLabel) { // get the bounding box of the event RectangleF newclip= GetSubItemBoundingBox(boundingBox, i); graphics.Clip= new Region(newclip); _subItems[i].Draw(graphics, nvd, newclip); } } // draw parallel subitems second for(int i= 0; i <_subItems.Count; ++i) { if(_subItems[i].ShowParallelToLabel) { // get the bounding box of the event RectangleF newclip= GetSubItemBoundingBox(boundingBox, i); graphics.Clip= new Region(newclip); _subItems[i].Draw(graphics, nvd, newclip); } } // restore rendering area graphics.Clip= prevreg; } // draw the label of the node if(style.Label !=null) { // calculate the height of all non-parallel subitems so we can correctly center the label float subItemsHeight= 0.0f; foreach(SubItem sub in _subItems) { if(!sub.ShowParallelToLabel) subItemsHeight+= sub.Height; } float x= boundingBox.Left + (boundingBox.Width - _subItemParallelWidth) *0.5f - _realLabelSize.Width *0.5f; float y= boundingBox.Top + boundingBox.Height *0.5f - subItemsHeight *0.5f - _realLabelSize.Height *0.5f; graphics.DrawString(_label, _font, style.Label, x, y); //graphics.DrawRectangle(Pens.Red, boundingBox.X, boundingBox.Y, boundingBox.Width, boundingBox.Height); //graphics.DrawRectangle(Pens.Red, x, y, _realLabelSize.Width, _realLabelSize.Height); //graphics.DrawRectangle(Pens.Green, x, y, _labelSize.Width, _labelSize.Height); } } // draw the nodes border if(style.Border !=null) DrawShapeBorder(graphics, boundingBox, style.Border); //graphics.DrawRectangle(Pens.Red, nvd.LayoutRectangle.X, nvd.LayoutRectangle.Y, nvd.LayoutRectangle.Width, nvd.LayoutRectangle.Height); }
/// <summary> /// Creates a view for this node. Allows you to return your own class and store additional data. /// </summary> /// <param name="rootBehavior">The root of the graph of the current view.</param> /// <param name="parent">The parent of the NodeViewData created.</param> /// <returns>Returns a new NodeViewData object for this node.</returns> public virtual NodeViewData CreateNodeViewData(NodeViewData parent, BehaviorNode rootBehavior) { return new NodeViewData(parent, rootBehavior, this); }
/// <summary> /// This method is called before the layout gets updated so you can add new children or remove some. Used by referenced behaviour nodes. /// </summary> /// <param name="nvd">Thew NodeViewData of the node in the current view. Children can be invalid!</param> public virtual void PreLayoutUpdate(NodeViewData nvd) { }
/// <summary> /// Draws the node's shape as the background. /// </summary> /// <param name="graphics">The graphics object used for drawing.</param> /// <param name="nvd">The node view data of the node the subitem belongs to.</param> /// <param name="brush">The brush to draw the node's shape.</param> protected void DrawBackground(Graphics graphics, NodeViewData nvd, Brush brush) { if(brush !=null) nvd.Node.DrawShapeBackground(graphics, nvd.BoundingBox, brush); }
/// <summary> /// Creates a view for this node. Allows you to return your own class and store additional data. /// </summary> /// <param name="rootBehavior">The root of the graph of the current view.</param> /// <param name="parent">The parent of the NodeViewData created.</param> /// <returns>Returns a new NodeViewData object for this node.</returns> public override NodeViewData CreateNodeViewData(NodeViewData parent, BehaviorNode rootBehavior) { return new NodeViewDataReferencedBehavior(parent, rootBehavior, this, null, BackgroundBrush, Label, Description); }
public static bool IsExpandedConnector(NodeViewData nvd, string connector) { Debug.Check(nvd != null && nvd.Node != null); Nodes.Behavior behavior = nvd.Node.Behavior as Nodes.Behavior; if (behavior != null) { behavior = behavior.GetTopBehavior(); } string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; return IsExpandedConnector(filename, nvd.Node.Id.ToString(), connector); }
public override NodeViewData CreateNodeViewData(NodeViewData parent, BehaviorNode rootBehavior) { NodeViewData nvd = base.CreateNodeViewData(parent, rootBehavior); nvd.ChangeShape(NodeShape.Rectangle); return nvd; }
public static bool SetExpandedNode(NodeViewData nvd, bool isExpanded) { Debug.Check(nvd != null && nvd.Node != null); Nodes.Behavior b = nvd.Node.Behavior as Nodes.Behavior; if (b != null) { b = b.GetTopBehavior(); Debug.Check(b != null); if (!string.IsNullOrEmpty(b.Filename)) { return SetExpandedNode(b.RelativePath, nvd.FullId, isExpanded); } } return false; }
public override void Draw(Graphics graphics, NodeViewData nvd, bool isCurrent, bool isSelected, bool isDragged, PointF graphMousePos) { Brush defBrush= _defaultStyle.Background; NodeViewDataReferencedBehavior nvdrb= (NodeViewDataReferencedBehavior) nvd; if(_genericChildren.IsReadOnly) _defaultStyle.Background= _defaultBrushCollapsed; base.Draw(graphics, nvd, isCurrent, isSelected, isDragged, graphMousePos); _defaultStyle.Background= defBrush; }
public override void PreLayoutUpdate(NodeViewData nvd) { // check if we must update the children NodeViewDataReferencedBehavior nvdrb= (NodeViewDataReferencedBehavior) nvd; if( nvdrb.RebuildChildren || _referencedBehavior !=null && !nvdrb.IsExpanded && nvdrb.ReferencedBehaviorLastModification !=_referencedBehavior.ModificationID ) { nvdrb.RebuildChildren= false; ExpandNode(nvdrb); if(_referencedBehavior !=null) nvdrb.ReferencedBehaviorLastModification= _referencedBehavior.ModificationID; } base.PreLayoutUpdate(nvd); }
/// <summary> /// Creates a view for this node. Allows you to return your own class and store additional data. /// </summary> /// <param name="rootBehavior">The root of the graph of the current view.</param> /// <param name="parent">The parent of the NodeViewData created.</param> /// <returns>Returns a new NodeViewData object for this node.</returns> public override NodeViewData CreateNodeViewData(NodeViewData parent, BehaviorNode rootBehavior) { return new NodeViewDataReferencedBehavior(parent, rootBehavior, this); }
/// <summary> /// Is called when the node was double-clicked. Used for referenced behaviours. /// </summary> /// <param name="nvd">The view data of the node in the current view.</param> /// <param name="layoutChanged">Does the layout need to be recalculated?</param> /// <returns>Returns if the node handled the double click or not.</returns> public override bool OnDoubleClick(NodeViewData nvd, out bool layoutChanged) { NodeViewDataReferencedBehavior nvdrb= (NodeViewDataReferencedBehavior) nvd; nvdrb.IsExpanded= !nvdrb.IsExpanded; nvdrb.RebuildChildren= true; layoutChanged= true; return true; }
/// <summary> /// Called when the node is drawn. /// </summary> /// <param name="graphics">The graphics object used to draw the subitem.</param> /// <param name="nvd">The node view data of the node the subitem belongs to.</param> /// <param name="boundingBox">The bounding box of the subitem. Drawing is clipped to this.</param> public abstract void Draw(Graphics graphics, NodeViewData nvd, RectangleF boundingBox);
/// <summary> /// Draws the background. /// </summary> /// <param name="graphics">The graphics object we render to.</param> /// <param name="nvd">The view data of this node in the current view.</param> /// <param name="renderDepth">The depth which is still rendered.</param> /// <param name="padding">The padding between the nodes.</param> public void DrawBackground(Graphics graphics, NodeViewData nvd, int renderDepth, SizeF padding) { SizeF size = nvd.GetTotalSize(padding.Width, renderDepth); if (_backgroundColor != CommentColor.NoColor) { float commentPadding = Math.Min(padding.Height, padding.Width) * 0.75f; ExtendedGraphics extended = new ExtendedGraphics(graphics); extended.FillRoundRectangle(_backgroundBrush, nvd.LayoutRectangle.X - commentPadding * 0.5f, nvd.LayoutRectangle.Y - commentPadding * 0.5f, size.Width + commentPadding, size.Height + commentPadding, 0.05f); } }
/// <summary> /// Draws the text of the comment. /// </summary> /// <param name="graphics">The graphics object we render to.</param> /// <param name="nvd">The view data of this node in the current view.</param> public void DrawCommentText(Graphics graphics, NodeViewData nvd) { if(_comment !=null) _comment.DrawText(graphics, nvd); }
public static bool SetExpandedConnector(NodeViewData nvd, string connector, bool isConnectorExpanded) { Debug.Check(nvd != null && nvd.Node != null); Nodes.Behavior behavior = nvd.Node.Behavior as Nodes.Behavior; if (behavior != null) { behavior = behavior.GetTopBehavior(); } if (behavior != null && !string.IsNullOrEmpty(behavior.Filename)) { return SetExpandedConnector(behavior.RelativePath, nvd.Node.Id.ToString(), connector, isConnectorExpanded); } return false; }
/// <summary> /// Is called when the node was double-clicked. Used for referenced behaviours. /// </summary> /// <param name="nvd">The view data of the node in the current view.</param> /// <param name="layoutChanged">Does the layout need to be recalculated?</param> /// <returns>Returns if the node handled the double click or not.</returns> public virtual bool OnDoubleClick(NodeViewData nvd, out bool layoutChanged) { layoutChanged= false; return false; }
/// <summary> /// Creates a view for this node. Allows you to return your own class and store additional data. /// </summary> /// <param name="rootBehavior">The root of the graph of the current view.</param> /// <param name="parent">The parent of the NodeViewData created.</param> /// <returns>Returns a new NodeViewData object for this node.</returns> public virtual NodeViewData CreateNodeViewData(NodeViewData parent, BehaviorNode rootBehavior) { return new NodeViewDataStyled(parent, rootBehavior, this, null, BackgroundBrush, _label, _description); }
/// <summary> /// Is called when a possible selection of an event occured. /// </summary> /// <param name="nvd">The view data of the node in the current view.</param> /// <param name="graphMousePos">The mouse position in the untransformed graph.</param> public virtual void ClickEvent(NodeViewData nvd, PointF graphMousePos) { SubItem newsub= null; for(int i= 0; i <_subItems.Count; ++i) { if(_subItems[i].SelectableObject !=null) { RectangleF bbox= GetSubItemBoundingBox(nvd.BoundingBox, i); if(bbox.Contains(graphMousePos)) { newsub= _subItems[i]; break; } } } SelectedSubItem= newsub; }
/// <summary> /// Draws the edges connecting the nodes. /// </summary> /// <param name="graphics">The graphics object we render to.</param> /// <param name="nvd">The view data of this node in the current view.</param> /// <param name="edgePen">The pen used for normal connectors.</param> /// <param name="edgePenReadOnly">The pen used for read-only connectors.</param> public virtual void DrawEdges(Graphics graphics, NodeViewData nvd, Pen edgePen, Pen edgePenReadOnly) { RectangleF boundingBox= nvd.BoundingBox; // calculate an offset so we cannot see the end or beginning of the rendered edge float edgePenHalfWidth= edgePen.Width *0.5f; foreach(NodeViewData node in nvd.Children) { RectangleF nodeBoundingBox= node.BoundingBox; // calculate the centre between both nodes and of the edge float middle= boundingBox.Right + (nodeBoundingBox.Left - boundingBox.Right) *0.5f; // end at the middle of the other node float nodeHeight= nodeBoundingBox.Top + nodeBoundingBox.Height *0.5f; // find the correct connector for this node for(int i= 0; i <_subItems.Count; ++i) { SubItemConnector conn= _subItems[i] as SubItemConnector; if(conn !=null && conn.Child ==node.Node) { // get the bounding box of the event RectangleF subitemBoundingBox= GetSubItemBoundingBox(boundingBox, i); // start at the middle of the connector float connectorHeight= subitemBoundingBox.Top + subitemBoundingBox.Height *0.5f; graphics.DrawBezier(conn.Connector.IsReadOnly ? edgePenReadOnly : edgePen, boundingBox.Right - edgePenHalfWidth, connectorHeight, middle, connectorHeight, middle, nodeHeight, nodeBoundingBox.Left + edgePenHalfWidth, nodeHeight); break; } } } }
/// <summary> /// Draws the text. /// </summary> /// <param name="graphics">The graphics object we render to.</param> /// <param name="nvd">The view data of this node in the current view.</param> public void DrawText(Graphics graphics, NodeViewData nvd) { if (_comment != string.Empty) { graphics.DrawString(_comment, __font, _labelBrush, nvd.LayoutRectangle.Location.X + 25, nvd.LayoutRectangle.Location.Y); } }
/// <summary> /// Draws the background of the comment. /// </summary> /// <param name="graphics">The graphics object we render to.</param> /// <param name="nvd">The view data of this node in the current view.</param> /// <param name="renderDepth">The depth which is still rendered.</param> /// <param name="padding">The padding between the nodes.</param> public void DrawCommentBackground(Graphics graphics, NodeViewData nvd, int renderDepth, SizeF padding) { if(_comment !=null) _comment.DrawBackground(graphics, nvd, renderDepth, padding); }
public override void Draw(Graphics graphics, NodeViewData nvd, RectangleF boundingBox) { // render background DrawBackground(graphics, nvd, _selected ? _backgroundSelected : _backgroundNormal); // render the label PointF center= new PointF(boundingBox.Left + boundingBox.Width *0.5f, boundingBox.Top + boundingBox.Height *0.5f); SizeF labelSize= MeasureDisplayStringWidth(graphics, Label, _labelFont); // draw text switch(_alignment) { case(Alignment.Left): graphics.DrawString(Label, _labelFont, _labelBrush, boundingBox.Left + 6.0f, center.Y - labelSize.Height *0.5f); break; case(Alignment.Center): graphics.DrawString(Label, _labelFont, _labelBrush, center.X - labelSize.Width *0.5f, center.Y - labelSize.Height *0.5f); break; case(Alignment.Right): graphics.DrawString(Label, _labelFont, _labelBrush, boundingBox.Right - labelSize.Width -6.0f, center.Y - labelSize.Height *0.5f); break; } //graphics.DrawRectangle(Pens.Red, boundingBox.X, boundingBox.Y, boundingBox.Width, boundingBox.Height); }