Beispiel #1
0
        public override void drawNode(BaseNode node, int nodeId, NodeDrawState drawState)
        {
            drawNodeLabel(node, nodeId, drawState);

            switch (Event.current.type)
            {
            case EventType.Repaint:
            {
                handleNodeRepaint(node, nodeId, drawState);
                break;
            }

            case EventType.MouseDown:
            {
                handleNodeMouseDown(node, nodeId, drawState);
                break;
            }

            case EventType.MouseUp:
            {
                handleNodeMouseUp(node, nodeId, drawState);
                break;
            }
            }
        }
Beispiel #2
0
 internal static string DrawLabelEdit(BaseNode selectedNode, NodeDrawState drawState, string labelValue)
 {
     return(EditorGUI.TextField(new Rect(
                                    new Vector2(NodeWindowSizeBuffer, 0) +
                                    selectedNode.nodePosition + drawState.guiOffset + drawState.scrollOffset,
                                    new Vector2(NodeWindowWidth, NodeWindowLabelHeight)),
                                labelValue));
 }
Beispiel #3
0
 protected void drawNodeInputs(BaseNode node, int nodeId, NodeDrawState drawState)
 {
     for (int i = 0; i < node.inputs.Count; i++)
     {
         var inputPos = InputStartOffset + (InputIncrementOffset * i);
         var rect     = new Rect(inputPos, ConnectorSize);
         EditorGUI.DrawPreviewTexture(rect, drawState.inputConnectionTexture, drawState.uiMat);
     }
 }
Beispiel #4
0
 protected void drawNodeOutputs(BaseNode node, int nodeId, NodeDrawState drawState)
 {
     if (!(node is RootNode))
     {
         var outputPos = new Vector2(getNodeSize(node).width, 0) + OutputStartOffset;
         var rect      = new Rect(outputPos, ConnectorSize);
         EditorGUI.DrawPreviewTexture(rect, drawState.outputConnectionTexture, drawState.uiMat);
     }
 }
Beispiel #5
0
 protected virtual void drawNodeLabel(BaseNode node, int nodeId, NodeDrawState drawState)
 {
     if ((node != drawState.SelectedNode) || (node is RootNode))
     {
         EditorGUI.LabelField(new Rect(new Vector2(NodeWindowSizeBuffer, 0),
                                       new Vector2(NodeWindowWidth, NodeWindowLabelHeight)),
                              node.nodeName);
     }
 }
Beispiel #6
0
        public override void drawNode(BaseNode node, int nodeId, NodeDrawState drawState)
        {
            drawNodeLabel(node, nodeId, drawState);

            switch (Event.current.type)
            {
            case EventType.Repaint:
            {
                drawNodeBackground(node, nodeId, drawState);
                drawNodeInputs(node, nodeId, drawState);

                if (!(node is RootNode))
                {
                    var outputPos = new Vector2(getNodeSize(node).width, 0) + OutputStartOffset;
                    var rect      = new Rect(outputPos, ConnectorSize);
                    EditorGUI.DrawPreviewTexture(rect, output_r, drawState.uiMat);

                    outputPos += new Vector2(0, NodeWindowOutputHeight);
                    rect       = new Rect(outputPos, ConnectorSize);
                    EditorGUI.DrawPreviewTexture(rect, output_g, drawState.uiMat);

                    outputPos += new Vector2(0, NodeWindowOutputHeight);
                    rect       = new Rect(outputPos, ConnectorSize);
                    EditorGUI.DrawPreviewTexture(rect, output_b, drawState.uiMat);

                    outputPos += new Vector2(0, NodeWindowOutputHeight);
                    rect       = new Rect(outputPos, ConnectorSize);
                    EditorGUI.DrawPreviewTexture(rect, output_a, drawState.uiMat);
                }
                break;
            }

            case EventType.MouseDown:
            {
                handleNodeMouseDown(node, nodeId, drawState);
                break;
            }

            case EventType.MouseUp:
            {
                handleNodeMouseUp(node, nodeId, drawState);
                break;
            }
            }
        }
Beispiel #7
0
        protected virtual void handleNodeMouseDown(BaseNode node, int nodeId, NodeDrawState drawState)
        {
            for (int i = 0; i < node.inputs.Count; i++)
            {
                var inputPos = InputStartOffset + (InputIncrementOffset * i);
                var rect     = new Rect(inputPos, ConnectorSize);

                if (rect.Contains(drawState.screenPos))
                {
                    if (!drawState.drawCurve)
                    {
                        drawState.drawCurve = true;
                        NodeDrawState.WindowData d = drawState.windowData[nodeId];
                        drawState.curveStart                     = d.pos + Event.current.mousePosition;
                        drawState.connectionInfo.input           = true;
                        drawState.connectionInfo.nodeIndex       = nodeId;
                        drawState.connectionInfo.connectionIndex = i;
                        Event.current.Use();
                    }
                }
            }

            if (!(node is RootNode))
            {
                for (int i = 0; i < node.outputCount; i++)
                {
                    var outputPos = new Vector2(getNodeSize(node).width, 0) + OutputStartOffset + (InputIncrementOffset * i);
                    var rect      = new Rect(outputPos, ConnectorSize);

                    if (rect.Contains(drawState.screenPos))
                    {
                        if (!drawState.drawCurve)
                        {
                            drawState.drawCurve = true;
                            NodeDrawState.WindowData d = drawState.windowData[nodeId];
                            drawState.curveStart                     = d.pos + Event.current.mousePosition;
                            drawState.connectionInfo.input           = false;
                            drawState.connectionInfo.nodeIndex       = nodeId;
                            drawState.connectionInfo.connectionIndex = i;
                            Event.current.Use();
                        }
                    }
                }
            }
        }
Beispiel #8
0
        protected Color getNodeColor(BaseNode node, int nodeId, NodeDrawState drawState)
        {
            Color nodeColor = Color.gray;

            if (node is RootNode)
            {
                nodeColor = Color.blue;
            }
            if (node == drawState.SelectedNode)
            {
                nodeColor.a = SelectedNodeAlpha;
            }
            else
            {
                nodeColor.a = NodeAlpha;
            }
            return(nodeColor);
        }
Beispiel #9
0
        public override void drawNode(BaseNode node, int nodeId, NodeDrawState drawState)
        {
            drawNodeLabel(node, nodeId, drawState);

            switch (Event.current.type)
            {
            case EventType.Repaint:
            {
                drawNodeBackground(node, nodeId, drawState);

                var inputPos = InputStartOffset;
                var rect     = new Rect(inputPos, ConnectorSize);
                EditorGUI.DrawPreviewTexture(rect, input_r, drawState.uiMat);

                inputPos += InputIncrementOffset;
                rect      = new Rect(inputPos, ConnectorSize);
                EditorGUI.DrawPreviewTexture(rect, input_g, drawState.uiMat);

                inputPos += InputIncrementOffset;
                rect      = new Rect(inputPos, ConnectorSize);
                EditorGUI.DrawPreviewTexture(rect, input_b, drawState.uiMat);

                inputPos += InputIncrementOffset;
                rect      = new Rect(inputPos, ConnectorSize);
                EditorGUI.DrawPreviewTexture(rect, input_a, drawState.uiMat);

                drawNodeOutputs(node, nodeId, drawState);
                break;
            }

            case EventType.MouseDown:
            {
                handleNodeMouseDown(node, nodeId, drawState);
                break;
            }

            case EventType.MouseUp:
            {
                handleNodeMouseUp(node, nodeId, drawState);
                break;
            }
            }
        }
        protected override void DrawNodeLabel(Graphics graphics, String label, Rectangle rect,
                                              NodeDrawState nodeState, NodeDrawPos nodePos,
                                              Font nodeFont, Object itemData)
        {
            var taskItem = (itemData as MindMapTaskItem);
            var realItem = GetRealTaskItem(taskItem);

            bool      isSelected = (nodeState != NodeDrawState.None);
            Rectangle iconRect   = Rectangle.Empty;

            if (taskItem.IsTask) // not root
            {
                // Checkbox
                Rectangle checkRect = CalcCheckboxRect(rect);

                if (m_ShowCompletionCheckboxes)
                {
                    CheckBoxRenderer.DrawCheckBox(graphics, checkRect.Location, GetItemCheckboxState(realItem));
                }

                // Task icon
                if (TaskHasIcon(realItem))
                {
                    iconRect = CalcIconRect(rect);

                    if (m_TaskIcons.Get(realItem.ID))
                    {
                        m_TaskIcons.Draw(graphics, iconRect.X, iconRect.Y);
                    }

                    rect.Width = (rect.Right - iconRect.Right - 2);
                    rect.X     = iconRect.Right + 2;
                }
                else if (m_ShowCompletionCheckboxes)
                {
                    rect.Width = (rect.Right - checkRect.Right - 2);
                    rect.X     = checkRect.Right + 2;
                }
            }

            // Text Colour
            Color textColor = SystemColors.WindowText;

            if (!taskItem.TextColor.IsEmpty)
            {
                if (m_TaskColorIsBkgnd && !isSelected && !realItem.IsDone(true))
                {
                    textColor = DrawingColor.GetBestTextColor(taskItem.TextColor);
                }
                else if (isSelected)
                {
                    textColor = DrawingColor.SetLuminance(taskItem.TextColor, 0.3f);
                }
                else
                {
                    textColor = taskItem.TextColor;
                }
            }

            switch (nodeState)
            {
            case NodeDrawState.Selected:
                UIExtension.SelectionRect.Draw(this.Handle, graphics, rect.X, rect.Y, rect.Width, rect.Height, this.Focused, false);     // opaque
                break;

            case NodeDrawState.DropTarget:
                UIExtension.SelectionRect.Draw(this.Handle, graphics, rect.X, rect.Y, rect.Width, rect.Height, false, false);     // opaque
                break;

            case NodeDrawState.None:
                if (DebugMode())
                {
                    graphics.DrawRectangle(new Pen(Color.Green), rect);
                }
                break;
            }

            // Text
            var format = DefaultLabelFormat(nodePos, isSelected);

            graphics.DrawString(label, nodeFont, new SolidBrush(textColor), rect, format);

            // Draw Windows shortcut icon if task is a reference
            if (taskItem.IsReference)
            {
                if (iconRect == Rectangle.Empty)
                {
                    iconRect = rect;
                }
                else
                {
                    iconRect.Y = (rect.Bottom - iconRect.Height);                     // don't want shortcut icon centred vertically
                }
                UIExtension.ShortcutOverlay.Draw(graphics, iconRect.X, iconRect.Y, iconRect.Width, iconRect.Height);
            }
        }
Beispiel #11
0
        protected override void DrawNodeLabel(Graphics graphics, String label, Rectangle rect,
                                              NodeDrawState nodeState, NodeDrawPos nodePos,
                                              Font nodeFont, Object itemData)
        {
            var  taskItem   = (itemData as MindMapTaskItem);
            bool isSelected = (nodeState != NodeDrawState.None);

            if (taskItem.IsTask) // real task
            {
                // Checkbox
                Rectangle checkRect = CalcCheckboxRect(rect);

                if (m_ShowCompletionCheckboxes)
                {
                    CheckBoxRenderer.DrawCheckBox(graphics, checkRect.Location, GetItemCheckboxState(taskItem));
                }

                // Task icon
                if (TaskHasIcon(taskItem))
                {
                    Rectangle iconRect = CalcIconRect(rect);

                    if (m_TaskIcons.Get(taskItem.ID))
                    {
                        m_TaskIcons.Draw(graphics, iconRect.X, iconRect.Y);
                    }

                    rect.Width = (rect.Right - iconRect.Right - 2);
                    rect.X     = iconRect.Right + 2;
                }
                else if (m_ShowCompletionCheckboxes)
                {
                    rect.Width = (rect.Right - checkRect.Right - 2);
                    rect.X     = checkRect.Right + 2;
                }
            }

            // Text background
            Brush textColor = SystemBrushes.WindowText;
            Brush backColor = null;
            Color taskColor = taskItem.TextColor;

            if (!taskColor.IsEmpty)
            {
                if (m_TaskColorIsBkgnd && !isSelected && !taskItem.IsDone(true))
                {
                    backColor = new SolidBrush(taskColor);
                    textColor = new SolidBrush(DrawingColor.GetBestTextColor(taskColor));
                }
                else
                {
                    if (nodeState != MindMapControl.NodeDrawState.None)
                    {
                        taskColor = DrawingColor.SetLuminance(taskColor, 0.3f);
                    }

                    textColor = new SolidBrush(taskColor);
                }
            }

            switch (nodeState)
            {
            case NodeDrawState.Selected:
                m_SelectionRect.Draw(graphics, rect.X, rect.Y, rect.Width, rect.Height, this.Focused);
                break;

            case NodeDrawState.DropTarget:
                m_SelectionRect.Draw(graphics, rect.X, rect.Y, rect.Width, rect.Height, false);
                break;

            case NodeDrawState.None:
            {
                if (backColor != null)
                {
                    var prevSmoothing = graphics.SmoothingMode;
                    graphics.SmoothingMode = SmoothingMode.None;

                    graphics.FillRectangle(backColor, rect);
                    graphics.SmoothingMode = prevSmoothing;
                }

                if (DebugMode())
                {
                    graphics.DrawRectangle(new Pen(Color.Green), rect);
                }
            }
            break;
            }

            // Text
            var format = DefaultLabelFormat(nodePos, isSelected);

            graphics.DrawString(label, nodeFont, textColor, rect, format);
        }
Beispiel #12
0
 public abstract void drawNode(BaseNode node, int nodeId, NodeDrawState drawState);
Beispiel #13
0
 protected void drawNodeBackground(BaseNode node, int nodeId, NodeDrawState drawState)
 {
     EditorGUI.DrawRect(new Rect(NodeWindowSizeBuffer, NodeWindowLabelHeight, NodeWindowWidth, NodeWindowHeight),
                        getNodeColor(node, nodeId, drawState));
 }
Beispiel #14
0
 protected virtual void handleNodeRepaint(BaseNode node, int nodeId, NodeDrawState drawState)
 {
     drawNodeBackground(node, nodeId, drawState);
     drawNodeInputs(node, nodeId, drawState);
     drawNodeOutputs(node, nodeId, drawState);
 }
Beispiel #15
0
        protected virtual void handleNodeMouseUp(BaseNode node, int nodeId, NodeDrawState drawState)
        {
            for (int i = 0; i < node.inputs.Count; i++)
            {
                var inputPos = InputStartOffset + (InputIncrementOffset * i);
                var rect     = new Rect(inputPos, ConnectorSize);

                if (rect.Contains(drawState.screenPos))
                {
                    if (Event.current.type == EventType.MouseUp)
                    {
                        drawState.drawCurve = false;
                        //connect?
                        if (!drawState.connectionInfo.input)
                        {
                            if (drawState.connectionInfo.nodeIndex != nodeId)
                            {
                                //output to input
                                var inputNode  = drawState.layerObject.nodes[nodeId];
                                var outputNode = drawState.layerObject.nodes[drawState.connectionInfo.nodeIndex];
                                var nodeInput  = inputNode.inputs[i];
                                nodeInput.inputNode   = outputNode;
                                nodeInput.outputIndex = drawState.connectionInfo.connectionIndex;

                                inputNode.inputs[i] = nodeInput;
                                Event.current.Use();

                                drawState.connectivityChange = true;
                            }
                        }
                    }
                }
            }

            if (!(node is RootNode))
            {
                var outputPos = new Vector2(getNodeSize(node).width, 0) + OutputStartOffset;
                var rect      = new Rect(outputPos, ConnectorSize);

                if (rect.Contains(drawState.screenPos))
                {
                    if (Event.current.type == EventType.MouseUp)
                    {
                        drawState.drawCurve = false;
                        //connect?
                        if (drawState.connectionInfo.nodeIndex != nodeId)
                        {
                            //input to output
                            var outputNode = drawState.layerObject.nodes[nodeId];
                            var inputNode  = drawState.layerObject.nodes[drawState.connectionInfo.nodeIndex];
                            var nodeInput  = inputNode.inputs[drawState.connectionInfo.connectionIndex];
                            nodeInput.inputNode   = outputNode;
                            nodeInput.outputIndex = drawState.connectionInfo.connectionIndex;

                            inputNode.inputs[drawState.connectionInfo.connectionIndex] = nodeInput;
                            Event.current.Use();

                            drawState.connectivityChange = true;
                        }
                    }
                }
            }
        }