/// <summary> /// TODO: Implement proper clipping to improve performance with alot of objects /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GraphEditorClass_Paint(object sender, PaintEventArgs e) { if (DesignMode) { GraphNode node = new GraphNodeRoundedRectangle(Guid.NewGuid(), new RectangleF(10.0f, 10.0f, 100.0f, 50.0f), 0.0f, Color.AliceBlue, Color.Black, Color.Red, Color.Black, Color.Black); node.Label = "DEMO1"; var g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; if (DrawDropShadow) { node.DrawDropShadow(g, DropShadowOffsetX, DropShadowOffsetY); } node.Draw(g, this.Font, false); } else { Graphics g = e.Graphics; List <GraphNode> drawNodes = new List <GraphNode>(_nodes); List <GraphLine> drawLines = new List <GraphLine>(_lines); List <GraphLinkLine> drawLinkLines = new List <GraphLinkLine>(_linkLines); g.SmoothingMode = SmoothingMode.AntiAlias; g.TranslateTransform(-_scrollPosition.X, -_scrollPosition.Y); if (DrawDropShadow) { foreach (var n in drawNodes) { n.DrawDropShadow(g, DropShadowOffsetX, DropShadowOffsetY); } } foreach (var l in drawLinkLines) { l.Draw(g); } foreach (var l in drawLines) { if (l != _selectedObject) { l.Draw(g, this.Font, false); } } foreach (var s in drawNodes) { s.Draw(g, this.Font, s == _selectedObject); } // Always draw a selected line above everything if (_selectedObject is GraphLine) { GraphLine l = _selectedObject as GraphLine; l.Draw(g, this.Font, true); } // We are dragging a line from a graph node if ((_draggingMode == DraggingMode.DrawLine) && (_selectedObject != null) && (_selectedObject is GraphNode)) { Pen p = null; GraphNode node = _selectedObject as GraphNode; try { p = new Pen(Brushes.Black); g.DrawLine(p, node.Center, _lastDragPoint); } finally { if (p != null) { p.Dispose(); } } } } }
/// <summary> /// TODO: Implement proper clipping to improve performance with alot of objects /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GraphEditorClass_Paint(object sender, PaintEventArgs e) { if (DesignMode) { GraphNode node = new GraphNodeRoundedRectangle(Guid.NewGuid(), new RectangleF(10.0f, 10.0f, 100.0f, 50.0f), 0.0f, Color.AliceBlue, Color.Black, Color.Red, Color.Black, Color.Black); node.Label = "DEMO1"; var g = e.Graphics; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (DrawDropShadow) { node.DrawDropShadow(g, DropShadowOffsetX, DropShadowOffsetY); } node.Draw(g, this.Font, false); } else { Graphics g = e.Graphics; //List<GraphNode> drawNodes = new List<GraphNode>(); //List<GraphLine> drawLines = new List<GraphLine>(); List <GraphNode> drawNodes = new List <GraphNode>(_nodes); List <GraphLine> drawLines = new List <GraphLine>(_lines); List <GraphLinkLine> drawLinkLines = new List <GraphLinkLine>(_linkLines); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.ScaleTransform(_zoom, _zoom); g.TranslateTransform(-_scrollPosition.X, -_scrollPosition.Y); //g.ScaleTransform(_zoom, _zoom); //g.TranslateTransform(-_scrollPosition.X, -_scrollPosition.Y); //foreach (GraphNode n in _nodes) //{ // RectangleF boundary = n.Boundary; // if (DrawDropShadow) // { // boundary = new RectangleF(boundary.Location, new SizeF(boundary.Width + DropShadowOffsetX, boundary.Height + DropShadowOffsetY)); // } // if (g.Clip.IsVisible(boundary)) // { // drawNodes.Add(n); // } //} //foreach (GraphLine l in _lines) //{ // if (g.Clip.IsVisible(GraphUtils.GetLineBoundingBox(l.SourceShape.Center, l.DestShape.Center))) // { // drawLines.Add(l); // } //} if (DrawDropShadow) { foreach (var n in drawNodes) { n.DrawDropShadow(g, DropShadowOffsetX, DropShadowOffsetY); } } foreach (var l in drawLinkLines) { l.Draw(g); } foreach (var l in drawLines) { if (l != _selectedObject) { l.Draw(g, this.Font, false); } } foreach (var s in drawNodes) { s.Draw(g, this.Font, s == _selectedObject); } // Always draw a selected line above everything if (_selectedObject is GraphLine) { GraphLine l = _selectedObject as GraphLine; l.Draw(g, this.Font, true); } // We are dragging a line from a graph node if ((_draggingMode == DraggingMode.DrawLine) && (_selectedObject != null) && (_selectedObject is GraphNode)) { Pen p = null; GraphNode node = _selectedObject as GraphNode; try { p = new Pen(Brushes.Black); g.DrawLine(p, node.Center, _lastDragPoint); } finally { if (p != null) { p.Dispose(); } } } } }
/// <summary> /// TODO: Implement proper clipping to improve performance with alot of objects /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GraphEditorClass_Paint(object sender, PaintEventArgs e) { if (DesignMode) { GraphNode node = new GraphNodeRoundedRectangle(Guid.NewGuid(), new RectangleF(10.0f, 10.0f, 100.0f, 50.0f), 0.0f, Color.AliceBlue, Color.Black, Color.Red, Color.Black, Color.Black); node.Label = "DEMO1"; var g = e.Graphics; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (DrawDropShadow) { node.DrawDropShadow(g, DropShadowOffsetX, DropShadowOffsetY); } node.Draw(g, this.Font, false); } else { Graphics g = e.Graphics; //List<GraphNode> drawNodes = new List<GraphNode>(); //List<GraphLine> drawLines = new List<GraphLine>(); List<GraphNode> drawNodes = new List<GraphNode>(_nodes); List<GraphLine> drawLines = new List<GraphLine>(_lines); List<GraphLinkLine> drawLinkLines = new List<GraphLinkLine>(_linkLines); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; g.ScaleTransform(_zoom, _zoom); g.TranslateTransform(-_scrollPosition.X, -_scrollPosition.Y); //g.ScaleTransform(_zoom, _zoom); //g.TranslateTransform(-_scrollPosition.X, -_scrollPosition.Y); //foreach (GraphNode n in _nodes) //{ // RectangleF boundary = n.Boundary; // if (DrawDropShadow) // { // boundary = new RectangleF(boundary.Location, new SizeF(boundary.Width + DropShadowOffsetX, boundary.Height + DropShadowOffsetY)); // } // if (g.Clip.IsVisible(boundary)) // { // drawNodes.Add(n); // } //} //foreach (GraphLine l in _lines) //{ // if (g.Clip.IsVisible(GraphUtils.GetLineBoundingBox(l.SourceShape.Center, l.DestShape.Center))) // { // drawLines.Add(l); // } //} if (DrawDropShadow) { foreach (var n in drawNodes) { n.DrawDropShadow(g, DropShadowOffsetX, DropShadowOffsetY); } } foreach (var l in drawLinkLines) { l.Draw(g); } foreach (var l in drawLines) { if (l != _selectedObject) { l.Draw(g, this.Font, false); } } foreach (var s in drawNodes) { s.Draw(g, this.Font, s == _selectedObject); } // Always draw a selected line above everything if (_selectedObject is GraphLine) { GraphLine l = _selectedObject as GraphLine; l.Draw(g, this.Font, true); } // We are dragging a line from a graph node if ((_draggingMode == DraggingMode.DrawLine) && (_selectedObject != null) && (_selectedObject is GraphNode)) { Pen p = null; GraphNode node = _selectedObject as GraphNode; try { p = new Pen(Brushes.Black); g.DrawLine(p, node.Center, _lastDragPoint); } finally { if (p != null) { p.Dispose(); } } } } }