Beispiel #1
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (Active)
            {
                MouseController.Draw(spriteBatch);
            }

            if (!Active)
            {
                MenuPause.Draw(spriteBatch);
            }

            base.Draw(spriteBatch);
        }
Beispiel #2
0
        private void paintDrawWindow(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            Matrix transform = GetTransform();

            var        tl     = transform.Inverse().TransformPoint(new PointF(0, 0));
            var        br     = transform.Inverse().TransformPoint(new PointF(Width, Height));
            RectangleF bounds = RectangleF.FromLTRB(tl.X, tl.Y, br.X, br.Y);

            using (g.Clip = new Region(new RectangleF(0, 0, DocumentSize.Width * GraphScale, DocumentSize.Height * GraphScale)))
            {
                var originalState = g.Save();

                DrawGrid(e);

                g.Transform = transform;

                if (CurrentFile != null)
                {
                    //var orderedUnselectedNodes = CurrentFile.Nodes.Reverse().Where(n => !m_mouseController.Selected.Nodes.Contains(n.Data.NodeId));
                    //var orderedSelectedNodes = CurrentFile.Nodes.Reverse().Where(n => m_mouseController.Selected.Nodes.Contains(n.Data.NodeId));

                    var tree  = new ZOrderedQuadTree <TNode>(SpatiallyOrderedNodes, CurrentFile.RelativePosition);
                    var nodes = tree.FindTouchingRegion(bounds).Reverse();
                    var orderedUnselectedNodes = nodes.Where(n => !m_mouseController.Selected.Nodes.Contains(n.Data.NodeId));
                    var orderedSelectedNodes   = nodes.Where(n => m_mouseController.Selected.Nodes.Contains(n.Data.NodeId));

                    //Make sure the nodes are the right size so the connectors end up in the right place
                    foreach (var node in CurrentFile.Nodes)
                    {
                        node.Renderer.UpdateArea();
                    }

                    HashSet <UnorderedTuple2 <PointF> > unselectedNodeConnections = new HashSet <UnorderedTuple2 <PointF> >();
                    HashSet <UnorderedTuple2 <PointF> > selectedNodeConnections   = new HashSet <UnorderedTuple2 <PointF> >();
                    HashSet <UnorderedTuple2 <PointF> > selectedConnections       = new HashSet <UnorderedTuple2 <PointF> >();

                    foreach (var node in orderedUnselectedNodes)
                    {
                        foreach (var t in node.Data.Connectors)
                        {
                            foreach (var connection in t.Connections)
                            {
                                PointF p1       = UIInfo(t).Area.Value.Center();
                                PointF p2       = UIInfo(connection).Area.Value.Center();
                                var    pair     = UnorderedTuple.Make(p1, p2);
                                bool   selected = m_mouseController.IsSelected(connection) || m_mouseController.IsSelected(t);

                                if (selected)
                                {
                                    unselectedNodeConnections.Remove(pair);
                                    if (!m_mouseController.DraggingLinks) //If we're dragging this connection around then let the mouse controller render it
                                    {
                                        selectedConnections.Add(pair);
                                    }
                                }
                                else
                                {
                                    unselectedNodeConnections.Add(pair);
                                }
                            }
                        }
                    }

                    foreach (var node in orderedSelectedNodes)
                    {
                        foreach (var t in node.Data.Connectors)
                        {
                            foreach (var connection in t.Connections)
                            {
                                PointF p1       = UIInfo(t).Area.Value.Center();
                                PointF p2       = UIInfo(connection).Area.Value.Center();
                                var    pair     = UnorderedTuple.Make(p1, p2);
                                bool   selected = m_mouseController.IsSelected(connection) || m_mouseController.IsSelected(t);

                                unselectedNodeConnections.Remove(pair);

                                if (selected)
                                {
                                    selectedNodeConnections.Remove(pair);
                                    if (!m_mouseController.DraggingLinks) //If we're dragging this connection around then let the mouse controller render it
                                    {
                                        selectedConnections.Add(pair);
                                    }
                                }
                                else
                                {
                                    selectedNodeConnections.Add(pair);
                                }
                            }
                        }
                    }

                    //Draw all the groups
                    foreach (NodeGroup group in CurrentFile.Groups.Reverse())
                    {
                        group.Renderer.Draw(g, m_mouseController.Selected.Groups.Contains(group), m_colorScheme);
                    }

                    //Draw all the connections for unselected nodes
                    using (ConnectionDrawer connections = new ConnectionDrawer(this.Colors))
                    {
                        foreach (var connection in unselectedNodeConnections)
                        {
                            connections.Add(connection.Item1, connection.Item2, false);
                        }
                        connections.Draw(g);
                    }

                    //Draw all the unselected nodes
                    foreach (TNode node in orderedUnselectedNodes)
                    {
                        node.Renderer.Draw(g, m_mouseController.Selected.Nodes.Contains(node.Data.NodeId), m_colorScheme);
                        foreach (var t in node.Data.Connectors)
                        {
                            bool selected = m_mouseController.IsSelected(t);
                            UIInfo(t).Draw(g, selected ? Colors.Foreground : Colors.Connectors);
                        }
                    }

                    //Draw all the connections for selected nodes
                    using (ConnectionDrawer connections = new ConnectionDrawer(this.Colors))
                    {
                        foreach (var connection in selectedNodeConnections)
                        {
                            connections.Add(connection.Item1, connection.Item2, false);
                        }
                        connections.Draw(g);
                    }

                    //Draw all the selected nodes
                    foreach (TNode node in orderedSelectedNodes)
                    {
                        node.Renderer.Draw(g, m_mouseController.Selected.Nodes.Contains(node.Data.NodeId), m_colorScheme);
                        foreach (var t in node.Data.Connectors)
                        {
                            bool selected = m_mouseController.IsSelected(t);
                            UIInfo(t).Draw(g, selected ? Colors.Foreground : Colors.Connectors);
                        }
                    }

                    //Draw all the selected connections
                    using (ConnectionDrawer connections = new ConnectionDrawer(this.Colors))
                    {
                        foreach (var connection in selectedConnections)
                        {
                            connections.Add(connection.Item1, connection.Item2, true);
                        }
                        connections.Draw(g);
                    }

                    //Draw any dynamic connections, etc
                    if (m_mouseController != null)
                    {
                        using (var connections = new ConnectionDrawer(this.Colors))
                        {
                            m_mouseController.Draw(g, connections);
                            connections.Draw(g);
                        }
                    }
                }

                g.DrawRectangle(Colors.ControlBorder, RectangleF.FromLTRB(0, 0, DocumentSize.Width - 1, DocumentSize.Height - 1));

                g.Restore(originalState);

                g.DrawRectangle(Colors.ControlBorder, Rectangle.FromLTRB(0, 0, drawWindow.Width - 1, drawWindow.Height - 1));
            }
        }