Esempio n. 1
0
        /// <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 void Draw(Graphics graphics, NodeViewData nvd, PointF graphMousePos,
            bool isCurrent, bool isSelected, bool isDragged,
            bool isHighlighted,
            bool isUpdated,
            HighlightBreakPoint highlightBreakPoint,
            Dictionary<string, FrameStatePool.NodeProfileInfos.ProfileInfo> profileInfos)
        {
            #if DEBUG
            //ensure consistency
            DebugCheckIntegrity();
            #endif
            RectangleF boundingBox = nvd.BoundingBox;

            // assemble the correct style
            Style style = _defaultStyle;

            Behavior b = this.Node.Behavior as Behavior;

            if (b != null && b.PlanningProcess != null) {
            FrameStatePool.PlanningState nodeState = b.PlanningProcess.GetNode(this.FullId);

            if (nodeState != null) {
                if (nodeState._bOk) {
                    style += _planSucceededStyle;

                } else {
                    style += _planFailedStyle;
                }
            }
            }

            if (isDragged)
            { style += _draggedStyle; }

            else if (isSelected)
            { style += _selectedStyle; }

            else if (isCurrent)
            { style += _currentStyle; }

            else if (isHighlighted)
            { style += _highlightedStyle; }

            else if (isUpdated)
            { style += _updatedStyle; }

            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;
                y += getTopAttachmentsHeight();
                graphics.DrawString(this.DisplayLabel, _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 prefab border
            if (!string.IsNullOrEmpty(nvd.Node.PrefabName)) {
            _prefabStyle.Border.DashStyle = nvd.Node.IsPrefabDataDirty() ? System.Drawing.Drawing2D.DashStyle.Dash : System.Drawing.Drawing2D.DashStyle.Solid;
            DrawShapeBorder(graphics, boundingBox, _prefabStyle.Border);
            _prefabStyle.Border.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
            }

            // draw the nodes border
            if (style.Border != null) {
            if (isHighlighted && (isCurrent || isSelected)) {
                //highlight border
                DrawShapeBorder(graphics, boundingBox, _highlightedStyle.Border);

                //shrink it to draw the selected/current border
                RectangleF rect = boundingBox;
                rect.Inflate(-_highlightedStyle.Border.Width, -_highlightedStyle.Border.Width);

                DrawShapeBorder(graphics, rect, style.Border);

            } else {
                DrawShapeBorder(graphics, boundingBox, style.Border);
            }
            }

            // draw the profile info
            if (profileInfos != null && profileInfos.Count > 0) {
            string fullId = nvd.FullId;

            if (profileInfos.ContainsKey(fullId)) {
                FrameStatePool.NodeProfileInfos.ProfileInfo profileInfo = profileInfos[fullId];
                string timeStr = string.Format("{0:F3}", Math.Abs(profileInfo.Time));
                string avgTimeStr = (profileInfo.Count <= 0) ? "0" : string.Format("{0:F3}", profileInfo.TotalTime / profileInfo.Count);
                string info = string.Format("{0}  {1}  {2}", timeStr, avgTimeStr, profileInfo.Count);
                SizeF txtSize = MeasureDisplayStringWidth(graphics, info, _profileFont);
                float x = boundingBox.Left;
                float y = boundingBox.Top - txtSize.Height - 2;
                graphics.DrawString(info, (profileInfo.Time >= 0) ? _profileBoldFont : _profileFont, Brushes.Black, x, y);
            }
            }

            // draw the attached condition
            foreach(Node.Connector connector in nvd.Connectors) {
            if (!connector.IsAsChild) {
                PointF[] vertices = getConnectorTriangle(nvd, connector);

                Brush brush = isCurrent && nvd.IsInExpandConnectorRange(graphMousePos) ? Brushes.Yellow : Brushes.Blue;

                graphics.FillPolygon(Brushes.LightGray, vertices);

                if (this.IsExpanded && connector.ChildCount > 0) {
                    graphics.FillRectangle(brush, vertices[0].X + 0.5f, vertices[0].Y + 3.5f, 5.5f, 1.5f);

                    if (!connector.IsExpanded)
                    { graphics.FillRectangle(brush, vertices[0].X + 2.5f, vertices[0].Y + 1.5f, 1.5f, 5.5f); }
                }
            }
            }

            // draw the breakpoints
            bool isBreakpointHighlighted = false;
            const float width = 18.0f;
            BreakPointStates enterState = getBreakPointState(highlightBreakPoint, HighlightBreakPoint.kEnter);

            if (HighlightBreakPoint.ShowBreakPoint && (enterState == BreakPointStates.Normal || enterState == BreakPointStates.Disable) ||
            enterState == BreakPointStates.Highlight) {
            isBreakpointHighlighted |= (enterState == BreakPointStates.Highlight);

            float x = boundingBox.X + width * 0.1f;
            float y = boundingBox.Y + (boundingBox.Height - width) * 0.5f;

            graphics.FillEllipse(getBrush(enterState), x, y, width, width);
            }

            BreakPointStates exitState = getBreakPointState(highlightBreakPoint, HighlightBreakPoint.kExit);

            if (HighlightBreakPoint.ShowBreakPoint && (exitState == BreakPointStates.Normal || exitState == BreakPointStates.Disable) ||
            exitState == BreakPointStates.Highlight) {
            isBreakpointHighlighted |= (exitState == BreakPointStates.Highlight);

            float x = boundingBox.X + (boundingBox.Width - width) - width * 0.1f;
            float y = boundingBox.Y + (boundingBox.Height - width) * 0.5f;

            graphics.FillEllipse(getBrush(exitState), x, y, width, width);
            }

            BreakPointStates planState = getBreakPointState(highlightBreakPoint, HighlightBreakPoint.kPlanning);

            if (HighlightBreakPoint.ShowBreakPoint && (planState == BreakPointStates.Normal || planState == BreakPointStates.Disable) ||
            planState == BreakPointStates.Highlight) {
            isBreakpointHighlighted |= (planState == BreakPointStates.Highlight);

            float x = boundingBox.X + (boundingBox.Width * 0.5f) - width * 0.5f;
            float y = boundingBox.Y + (boundingBox.Height - width) * 0.5f;

            graphics.FillEllipse(getBrush(planState), x, y, width, width);
            }

            // draw the expand or collapse symbol
            if (nvd.CanBeExpanded()) {
            Brush brush = isCurrent && nvd.IsInExpandRange(graphMousePos) ? Brushes.Yellow : Brushes.LightGray;

            graphics.FillRectangle(brush, boundingBox.X + 5.0f, boundingBox.Y + 5.0f, 12.0f, 2.0f);

            if (!nvd.IsExpanded)
            { graphics.FillRectangle(brush, boundingBox.X + 10.0f, boundingBox.Y, 2.0f, 12.0f); }
            }

            // draw node id
            if (ShowNodeId) {
            graphics.DrawString(nvd.FullId, _profileFont, isBreakpointHighlighted ? Brushes.Yellow : Brushes.White, boundingBox.X, boundingBox.Y + boundingBox.Height);
            }

            //graphics.DrawRectangle(Pens.Red, nvd.LayoutRectangle.X, nvd.LayoutRectangle.Y, nvd.LayoutRectangle.Width, nvd.LayoutRectangle.Height);
        }