DrawBezier() public method

public DrawBezier ( Pen pen, Point pt1, Point pt2, Point pt3, Point pt4 ) : void
pen Pen
pt1 Point
pt2 Point
pt3 Point
pt4 Point
return void
Example #1
0
        public static void DrawEdge( Graphics g, Edge edge )
        {
            // Line
            if( edge.IsComplex )
            {
                var old_end_cap = edge.LinePen.EndCap;
                edge.LinePen.EndCap = System.Drawing.Drawing2D.LineCap.Round;

                for( int seg_ind = 0; seg_ind < edge.Segments.Length - 1; ++seg_ind )
                {
                    var segment = edge.Segments[seg_ind];
                    if( segment.IsLinear )
                        g.DrawLine(edge.LinePen, segment.Points[0], segment.Points[1]);
                    else
                        g.DrawBezier(edge.LinePen, segment.Points[0], segment.Points[1], segment.Points[2], segment.Points[3]);
                }

                edge.LinePen.EndCap = old_end_cap;

                var last_segment = edge.Segments[edge.Segments.Length - 1];
                if( last_segment.IsLinear )
                    g.DrawLine(edge.LinePen, last_segment.Points[0], last_segment.Points[1]);
                else
                    g.DrawBezier(edge.LinePen, last_segment.Points[0], last_segment.Points[1], last_segment.Points[2], last_segment.Points[3]);
            }
            else
            {
                g.DrawLine(edge.LinePen, edge.StartPosition, edge.EndPosition);
            }

            // Label
            if( edge.LabelText != null )
                g.DrawString(edge.LabelText, edge.LabelFont, edge.LabelBrush,
                    edge.LabelPosition.X, edge.LabelPosition.Y);
        }
Example #2
0
        public override void Draw(Graphics g)
        {
            if (this.lineComponent.IsSelected)
            {
                g.DrawLine(ViewFactory.BoundingBoxPen, this.lineComponent.StartPoint.X, this.lineComponent.StartPoint.Y, this.lineComponent.ControlPoint1.X, this.lineComponent.ControlPoint1.Y);
                g.DrawLine(ViewFactory.BoundingBoxPen, this.lineComponent.EndPoint.X, this.lineComponent.EndPoint.Y, this.lineComponent.ControlPoint2.X, this.lineComponent.ControlPoint2.Y);
            }
            if (this.lineComponent.ParentMoving)
            {
                g.DrawBezier(ViewFactory.LinePen,
                    this.lineComponent.StartPoint.MakePointF(),
                    this.lineComponent.ControlPoint1.MakePointF(),
                    this.lineComponent.ControlPoint2.MakePointF(),
                    this.lineComponent.EndPoint.MakePointF());
            }
            else
            {
                g.DrawLines(ViewFactory.LinePen, this.lineComponent.points.ToArray());
                /*DrawPoint(g, new FlowChartPoint(points[points.Count/2].X,points[points.Count/2].Y), 
                    GraphicsSettings.LabelPen, GraphicsSettings.EdgeBoxWidth);*/
            }

            DrawArrow(g, this.lineComponent.EndPoint, this.lineComponent.ControlPoint2,
                ViewFactory.ArrowBrush,
                ViewFactory.ArrowPen,
                ViewFactory.ArrowLength);

            if (this.lineComponent.IsSelected)
            {
                DrawPoint(g, this.lineComponent.ControlPoint1, ViewFactory.EdgePen, ViewFactory.EdgeBoxWidth);
                DrawPoint(g, this.lineComponent.ControlPoint2, ViewFactory.EdgePen, ViewFactory.EdgeBoxWidth);
            }
            base.Draw(g);
        }
Example #3
0
        public void lines(Graphics g, int[,] A, Point[] P, Pen pen)
        {
            for (int i = 0; i < A.GetLength(0); i++)
            {
                for (int j = 0; j < A.GetLength(0); j++)
                {
                    if (A[i,j] == 1)
                    {
                        Point p1 = normDistance(P[i], P[j]);
                        Point p2 = normDistance(P[j], P[i]);

                        g.DrawLine(pen, p1,p2);

                    }
                    if (A[i,i] != 0)
                    {
                        Pen self = new Pen(Color.FromArgb(0,255,255),8);
                        int Xs = P[i].X, Ys = P[i].Y + 20;
                        int Xe = Xs, Ye = Ys;
                        int p1X = Xs - 100;
                        int p1Y = Ys + 50;
                        int p2X = Xs + 100;
                        int p2Y = Ys + 50;

                        g.DrawBezier(self, Xs, Ys, p1X, p1Y, p2X, p2Y, Xe, Ye);
                    }

                }
            }
        }
		public static void DrawLeftToRightArrow(Graphics g, int x1, int y1, int x2, int y2) 
		{
			int startLine = 7;
			int endLine = 15;
			int bezierStregth = 10;
			float arrowLength = 7.0f;
			float arrowWidth = 3.2f;
			
			// Shadow
			g.DrawLine(ArrowShadowPen,x1+1,y1+1,x1+startLine+2,y1+1);
			g.DrawLine(ArrowShadowPen,x2-endLine,y2+1,x2+1-8,y2+1);
			g.DrawBezier(ArrowShadowPen,
				x1+startLine+1,y1+1,
				x1+startLine+bezierStregth+1,y1+1,
				x2-endLine-bezierStregth+1,y2+1,
			    x2-endLine+1,y2+1);
			// Head shadow
			PointF[] arrowPointsShadow = { 
				new PointF(x2-5-arrowLength+1,y2-arrowWidth+1),
				new PointF(x2-5+1,y2+1), 
				new PointF(x2-5-arrowLength+1,y2+arrowWidth+1)
			};
			GraphicsPath arrowPathShadow = new GraphicsPath();
			arrowPathShadow.AddPolygon(arrowPointsShadow);
			g.FillPath(ArrowShadowBrush,arrowPathShadow);
			// Line
			g.DrawLine(LeftToRightArrowPen,x1,y1,x1+startLine+1,y1);
			g.DrawLine(LeftToRightArrowPen,x2-endLine-1,y2,x2-8,y2);
			g.DrawBezier(LeftToRightArrowPen,
				x1+startLine,y1,
				x1+startLine+bezierStregth,y1,
				x2-endLine-bezierStregth,y2,
				x2-endLine,y2);
			// Head
			PointF[] arrowPoints = { 
				new PointF(x2-5-arrowLength,y2-arrowWidth),
				new PointF(x2-5,y2), 
				new PointF(x2-5-arrowLength,y2+arrowWidth)
			};
			GraphicsPath arrowPath = new GraphicsPath();
			arrowPath.AddPolygon(arrowPoints);
			g.FillPath(LeftToRightArrowBrush,arrowPath);	           
		}
        public override void DrawGraphics(Graphics destination)
        {
            DrawGraphics();
            using (var pen = Style.CreatePen())
            {
                destination.DrawBezier(pen, ControlPoints[0], ControlPoints[1], ControlPoints[2], ControlPoints[3]);
            }

            EditablegeometryCue.DrawGeometry(destination);
        }
Example #6
0
		public override void Paint(Graphics graphics)
		{
			Point pointN = SupplierViewer.GetOutputLineConnectionPoint(Item);
			Point pointM = ConsumerViewer.GetInputLineConnectionPoint(Item);
			Point pointN2 = new Point(pointN.X, pointN.Y - Math.Max((int)((pointN.Y - pointM.Y) / 2), 40));
			Point pointM2 = new Point(pointM.X, pointM.Y + Math.Max((int)((pointN.Y - pointM.Y) / 2), 40));

			using (Pen pen = new Pen(DataCache.IconAverageColour(Item.Icon), 3f))
			{
				graphics.DrawBezier(pen, pointN, pointN2, pointM2, pointM);
			}
		}
Example #7
0
        private void DrawBezier(Graphics g)
        {
            // Draw a black Bezier curve.
            Pen pen = new Pen(Color.Black);
            pen.Width = 5;
            pen.DashStyle = DashStyle.Dash;

            // Specify which type of drawing must occur at the ends of the stroke
            pen.StartCap = LineCap.RoundAnchor;
            pen.EndCap = LineCap.ArrowAnchor;

            g.DrawBezier(
                pen,
                new Point(10, 30),
                new Point(30, 200),
                new Point(50, -100),
                new Point(70, 100));
        }
        private static void DrawAxons(this Network network, Graphics graphic)
        {
            foreach (Axon axon in network.Axons)
            {
                Point source = Translate(network, axon.Source).Add(5);
                Point target = Translate(network, axon.Target).Add(5);

                Point s2 = source.Shift(50, 0);
                Point t2 = target.Shift(-50, 0);

                Color color = Blend(Color.Gray, Color.Red, axon.Signal);
                float width = (float)axon.Weight*2;
                Pen axonpen = new Pen(color, width);
                
                graphic.DrawBezier(axonpen, source, s2, t2, target);
            }

        }
Example #9
0
 public static void DrawBezier(Graphics g, DiagramView view, System.Drawing.Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
 {
     if (pen != null)
     {
         g.DrawBezier(pen, x1, y1, x2, y2, x3, y3, x4, y4);
     }
 }
Example #10
0
        public override void DrawToGraphics(Graphics graphics)
        {
            Pen pen = Pens.Black;
            switch (this.CurrentState)
            {
                case ItemState.Free:
                    pen = new Pen(ColorDefinition.GetColorWhenFree());
                    break;

                case ItemState.Hover:
                    pen = new Pen(ColorDefinition.GetColorWhenHover());
                    break;

                case ItemState.Selected:
                    pen = new Pen(ColorDefinition.GetColorWhenSelected());
                    break;

                default:
                    break;
            } // switch

            List<PointF> tempNails = new List<PointF>();
            tempNails.Add(this.GetStartingPoint());
            foreach (NailItem nail in this.Nails)
                tempNails.Add(nail.Center());
            tempNails.Add(this.GetEndPoint());

            float R = NailItem.R;
            if (this.CurrentState == ItemState.Free)
                R = NailItem.R + 5;

            PointF[] points = new PointF[3];
            PointF firstNail = PointF.Empty;
            firstNail = tempNails[0];
            for (int i = 0; i < tempNails.Count - 1; i++)
            {
                points[1] = tempNails[i + 1];
                points[0] = GraphUltility.FindPointByDistance(points[1], firstNail, R);
                graphics.DrawLine(pen, firstNail, points[0]);

                if (i + 2 < tempNails.Count)
                {
                    points[2] = GraphUltility.FindPointByDistance(points[1], tempNails[i + 2], R);
                    firstNail = points[2];

                    //Make the intersection curved
                    if (this.CurrentState == ItemState.Free)
                        graphics.DrawBezier(pen, points[0], points[1], points[1], points[2]);
                }
            }
            DrawRouteWithBigArrow(graphics, pen, firstNail, tempNails[tempNails.Count - 1]);

            Label.Value = _weight;
            Label.CurrentState = this.CurrentState;
            Label.DrawToGraphics(graphics);
        }
Example #11
0
        private bool DrawItem(Graphics wa, Graph.ILaneRow row)
        {
            if (row == null || row.NodeLane == -1)
            {
                return false;
            }

            // Clip to the area we're drawing in, but draw 1 pixel past so
            // that the top/bottom of the line segment's anti-aliasing isn't
            // visible in the final rendering.
            int top = wa.RenderingOrigin.Y + _rowHeight / 2;
            var laneRect = new Rectangle(0, top, (int)wa.ClipBounds.Width, _rowHeight);
            Region oldClip = wa.Clip;
            var newClip = new Region(laneRect);
            newClip.Intersect(oldClip);
            wa.Clip = newClip;
            // wa.Clear(Color.Transparent);

            //Getting RevisionGraphDrawStyle results in call to AppSettings. This is not very cheap, cache.
            revisionGraphDrawStyleCache = RevisionGraphDrawStyle;

            //for (int r = 0; r < 2; r++)
            for (int lane = 0; lane < row.Count; lane++)
            {
                int mid = wa.RenderingOrigin.X + (int)((lane + 0.5) * _laneWidth);

                for (int item = 0; item < row.LaneInfoCount(lane); item++)
                {
                    if (item > 2)
                    {
                    }
                    Graph.LaneInfo laneInfo = row[lane, item];

                    bool highLight = (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && laneInfo.Junctions.Any(j => j.IsRelative)) ||
                                     (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.HighlightSelected && laneInfo.Junctions.Any(j => j.HighLight)) ||
                                     (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.Normal);

                    List<Color> curColors = GetJunctionColors(laneInfo.Junctions);

                    // Create the brush for drawing the line
                    Brush brushLineColor = null;
                    Pen brushLineColorPen = null;
                    try
                    {
                        bool drawBorder = highLight && AppSettings.BranchBorders; //hide border for "non-relatives"

                        if (curColors.Count == 1 || !AppSettings.StripedBranchChange)
                        {
                            if (curColors[0] != _nonRelativeColor)
                            {
                                brushLineColor = new SolidBrush(curColors[0]);
                            }
                            else if (curColors.Count > 1 && curColors[1] != _nonRelativeColor)
                            {
                                brushLineColor = new SolidBrush(curColors[1]);
                            }
                            else
                            {
                                drawBorder = false;
                                brushLineColor = new SolidBrush(_nonRelativeColor);
                            }
                        }
                        else
                        {
                            Color lastRealColor = curColors.LastOrDefault(c => c != _nonRelativeColor);

                            if (lastRealColor.IsEmpty)
                            {
                                brushLineColor = new SolidBrush(_nonRelativeColor);
                                drawBorder = false;
                            }
                            else
                            {
                                brushLineColor = new HatchBrush(HatchStyle.DarkDownwardDiagonal, curColors[0], lastRealColor);
                            }
                        }

                        // Precalculate line endpoints
                        bool singleLane = laneInfo.ConnectLane == lane;
                        int x0 = mid;
                        int y0 = top - 1;
                        int x1 = singleLane ? x0 : mid + (laneInfo.ConnectLane - lane) * _laneWidth;
                        int y1 = top + _rowHeight;

                        Point p0 = new Point(x0, y0);
                        Point p1 = new Point(x1, y1);

                        // Precalculate curve control points when needed
                        Point c0, c1;
                        if (singleLane)
                        {
                            c0 = c1 = Point.Empty;
                        }
                        else
                        {
                            // Controls the curvature of cross-lane lines (0 = straight line, 1 = 90 degree turns)
                            const float severity = 0.5f;
                            c0 = new Point(x0, (int)(y0 * (1.0f - severity) + y1 * severity));
                            c1 = new Point(x1, (int)(y1 * (1.0f - severity) + y0 * severity));
                        }

                        for (int i = drawBorder ? 0 : 2; i < 3; i++)
                        {
                            Pen penLine = null;
                            if (i == 0)
                            {
                                penLine = _whiteBorderPen;
                            }
                            else if (i == 1)
                            {
                                penLine = _blackBorderPen;
                            }
                            else
                            {
                                if (brushLineColorPen == null)
                                    brushLineColorPen = new Pen(brushLineColor, _laneLineWidth);
                                penLine = brushLineColorPen;
                            }

                            if (laneInfo.ConnectLane == lane)
                            {
                                wa.DrawLine
                                    (
                                        penLine,
                                        new Point(mid, top - 1),
                                        new Point(mid, top + _rowHeight + 2)
                                    );
                            }
                            else
                            {
                                wa.DrawBezier
                                    (
                                        penLine,
                                        new Point(mid, top - 1),
                                        new Point(mid, top + _rowHeight + 2),
                                        new Point(mid + (laneInfo.ConnectLane - lane) * _laneWidth, top - 1),
                                        new Point(mid + (laneInfo.ConnectLane - lane) * _laneWidth, top + _rowHeight + 2)
                                    );
                            }
                        }
                    }
                    finally
                    {
                        if (brushLineColorPen != null)
                            ((IDisposable)brushLineColorPen).Dispose();
                        if (brushLineColor != null)
                            ((IDisposable)brushLineColor).Dispose();
                    }
                }
            }

            // Reset the clip region
            wa.Clip = oldClip;
            {
                // Draw node
                var nodeRect = new Rectangle
                    (
                    wa.RenderingOrigin.X + (_laneWidth - _nodeDimension) / 2 + row.NodeLane * _laneWidth,
                    wa.RenderingOrigin.Y + (_rowHeight - _nodeDimension) / 2,
                    _nodeDimension,
                    _nodeDimension
                    );

                Brush nodeBrush;

                List<Color> nodeColors = GetJunctionColors(row.Node.Ancestors);

                bool highlight = (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && row.Node.Ancestors.Any(j => j.IsRelative)) ||
                                 (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.HighlightSelected && row.Node.Ancestors.Any(j => j.HighLight)) ||
                                 (revisionGraphDrawStyleCache == RevisionGraphDrawStyleEnum.Normal);

                bool drawBorder = AppSettings.BranchBorders && highlight;

                if (nodeColors.Count == 1)
                {
                    nodeBrush = new SolidBrush(highlight ? nodeColors[0] : _nonRelativeColor);
                    if (nodeColors[0] == _nonRelativeColor) drawBorder = false;
                }
                else
                {
                    nodeBrush = new LinearGradientBrush(nodeRect, nodeColors[0], nodeColors[1],
                                                        LinearGradientMode.Horizontal);
                    if (nodeColors.All(c => c == _nonRelativeColor))
                        drawBorder = false;
                }

                if (_filterMode == FilterType.Highlight && row.Node.IsFiltered)
                {
                    Rectangle highlightRect = nodeRect;
                    highlightRect.Inflate(2, 3);
                    wa.FillRectangle(Brushes.Yellow, highlightRect);
                    wa.DrawRectangle(Pens.Black, highlightRect);
                }

                if (row.Node.Data == null)
                {
                    wa.FillEllipse(Brushes.White, nodeRect);
                    using (var pen = new Pen(Color.Red, 2))
                    {
                        wa.DrawEllipse(pen, nodeRect);
                    }
                }
                else if (row.Node.IsActive)
                {
                    wa.FillRectangle(nodeBrush, nodeRect);
                    nodeRect.Inflate(1, 1);
                    using (var pen = new Pen(Color.Black, 3))
                        wa.DrawRectangle(pen, nodeRect);
                }
                else if (row.Node.IsSpecial)
                {
                    wa.FillRectangle(nodeBrush, nodeRect);
                    if (drawBorder)
                    {
                        wa.DrawRectangle(Pens.Black, nodeRect);
                    }
                }
                else
                {
                    wa.FillEllipse(nodeBrush, nodeRect);
                    if (drawBorder)
                    {
                        wa.DrawEllipse(Pens.Black, nodeRect);
                    }
                }
            }
            return true;
        }
Example #12
0
        private void DrawChildren(Graphics g, IList<INative> children)
        {
            foreach (var child in children)
            {
                if (child is IPin)
                {
                    var pin = child as IPin;
                    var color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
                    Brush brush = new SolidBrush(color);

                    double x = pin.Point.X - 4.0;
                    double y = pin.Point.Y - 4.0;
                    double width = 8.0;
                    double height = 8.0;

                    g.FillEllipse(
                        brush,
                        (float)x,
                        (float)y,
                        (float)width,
                        (float)height);

                    brush.Dispose();
                }
                else if (child is ILine)
                {
                    var line = child as ILine;
                    Pen pen = new Pen(
                        ToNativeColor(line.Stroke),
                        (float)line.StrokeThickness);

                    g.DrawLine(
                        pen,
                        (float)line.Point1.X,
                        (float)line.Point1.Y,
                        (float)line.Point2.X,
                        (float)line.Point2.Y);

                    pen.Dispose();
                }
                else if (child is IBezier)
                {
                    var bezier = child as IBezier;
                    Pen pen = new Pen(
                        ToNativeColor(bezier.Stroke),
                        (float)bezier.StrokeThickness);

                    g.DrawBezier(
                        pen,
                        (float)bezier.Start.X,
                        (float)bezier.Start.Y,
                        (float)bezier.Point1.X,
                        (float)bezier.Point1.Y,
                        (float)bezier.Point2.X,
                        (float)bezier.Point2.Y,
                        (float)bezier.Point3.X,
                        (float)bezier.Point3.Y);

                    pen.Dispose();
                }
                else if (child is IQuadraticBezier)
                {
                    var quadraticBezier = child as IQuadraticBezier;
                    Pen pen = new Pen(
                        ToNativeColor(quadraticBezier.Stroke),
                        (float)quadraticBezier.StrokeThickness);

                    double x1 = quadraticBezier.Start.X;
                    double y1 = quadraticBezier.Start.Y;
                    double x2 = quadraticBezier.Start.X + (2.0 * (quadraticBezier.Point1.X - quadraticBezier.Start.X)) / 3.0;
                    double y2 = quadraticBezier.Start.Y + (2.0 * (quadraticBezier.Point1.Y - quadraticBezier.Start.Y)) / 3.0;
                    double x3 = x2 + (quadraticBezier.Point2.X - quadraticBezier.Start.X) / 3.0;
                    double y3 = y2 + (quadraticBezier.Point2.Y - quadraticBezier.Start.Y) / 3.0;
                    double x4 = quadraticBezier.Point2.X;
                    double y4 = quadraticBezier.Point2.Y;

                    g.DrawBezier(
                        pen,
                        (float)x1,
                        (float)y1,
                        (float)x2,
                        (float)y2,
                        (float)x3,
                        (float)y3,
                        (float)x4,
                        (float)y4);

                    pen.Dispose();
                }
                else if (child is IArc)
                {
                    var arc = child as IArc;

                    double x = Math.Min(arc.Point1.X, arc.Point2.X);
                    double y = Math.Min(arc.Point1.Y, arc.Point2.Y);
                    double width = Math.Abs(arc.Point2.X - arc.Point1.X);
                    double height = Math.Abs(arc.Point2.Y - arc.Point1.Y);

                    if (width > 0.0 && height > 0.0)
                    {
                        Pen pen = new Pen(
                            ToNativeColor(arc.Stroke),
                            (float)arc.StrokeThickness);

                        g.DrawArc(
                            pen,
                            (float)x,
                            (float)y,
                            (float)width,
                            (float)height,
                            (float)arc.StartAngle,
                            (float)arc.SweepAngle);

                        pen.Dispose();
                    }
                }
                else if (child is IRectangle)
                {
                    var rectangle = child as IRectangle;
                    Pen pen = new Pen(
                        ToNativeColor(rectangle.Stroke),
                        (float)rectangle.StrokeThickness);

                    double x = Math.Min(rectangle.Point1.X, rectangle.Point2.X);
                    double y = Math.Min(rectangle.Point1.Y, rectangle.Point2.Y);
                    double width = Math.Abs(rectangle.Point2.X - rectangle.Point1.X);
                    double height = Math.Abs(rectangle.Point2.Y - rectangle.Point1.Y);

                    g.DrawRectangle(
                        pen,
                        (float)x,
                        (float)y,
                        (float)width,
                        (float)height);

                    pen.Dispose();
                }
                else if (child is IEllipse)
                {
                    var ellipse = child as IEllipse;
                    Pen pen = new Pen(
                        ToNativeColor(ellipse.Stroke),
                        (float)ellipse.StrokeThickness);

                    double x = Math.Min(ellipse.Point1.X, ellipse.Point2.X);
                    double y = Math.Min(ellipse.Point1.Y, ellipse.Point2.Y);
                    double width = Math.Abs(ellipse.Point2.X - ellipse.Point1.X);
                    double height = Math.Abs(ellipse.Point2.Y - ellipse.Point1.Y);

                    g.DrawEllipse(
                        pen,
                        (float)x,
                        (float)y,
                        (float)width,
                        (float)height);

                    pen.Dispose();
                }
                else if (child is IText)
                {
                    var text = child as IText;
                    Brush brush = new SolidBrush(ToNativeColor(text.Foreground));
                    Font font = new Font("Calibri", (float)(text.Size *  72 / 96));

                    double x = Math.Min(text.Point1.X, text.Point2.X);
                    double y = Math.Min(text.Point1.Y, text.Point2.Y);
                    double width = Math.Abs(text.Point2.X - text.Point1.X);
                    double height = Math.Abs(text.Point2.Y - text.Point1.Y);

                    g.DrawString(
                        text.Text,
                        font,
                        brush,
                        new RectangleF(
                            (float)x,
                            (float)y,
                            (float)width,
                            (float)height),
                        new StringFormat()
                        {
                            Alignment = (StringAlignment)text.HorizontalAlignment,
                            LineAlignment = (StringAlignment)text.VerticalAlignment
                        });

                    brush.Dispose();
                    font.Dispose();
                }
                else if (child is IBlock)
                {
                    var block = child as IBlock;

                    DrawChildren(g, block.Children);
                }
            }
        }
Example #13
0
        private void DrawConnectors(DiagramShapeControlBase parentShape, Graphics g, Pen pen, Brush brush, DiagramLayoutDirection direction, DiagramConnectorType connectorType)
        {
            if (parentShape.Expanded)
            {
                Point startPoint = new Point();
                Point endPoint = new Point();

                if (showExpanders)
                {
                    startPoint.X = parentShape.expander.Left + parentShape.expander.Width / 2;
                    startPoint.Y = parentShape.expander.Top + parentShape.expander.Height / 2;
                }
                else
                {
                    if (direction == DiagramLayoutDirection.Vertical)
                    {
                        startPoint.X = parentShape.Left + parentShape.Width / 2;
                        startPoint.Y = parentShape.Bottom;
                    }
                    else if (direction == DiagramLayoutDirection.Horizontal)
                    {
                        startPoint.Y = parentShape.Top + parentShape.Height / 2;
                        startPoint.X = parentShape.Right;
                    }
                }

                foreach (DiagramShapeControlBase shape in parentShape.childShapes)
                {
                    if (direction == DiagramLayoutDirection.Vertical)
                    {
                        endPoint.Y = shape.Top;
                        endPoint.X = shape.Left + (shape.Width / 2);
                    }
                    else if (direction == DiagramLayoutDirection.Horizontal)
                    {
                        endPoint.Y = shape.Top + (shape.Height / 2);
                        endPoint.X = shape.Left;
                    }

                    switch (connectorType)
                    {
                        case DiagramConnectorType.Standard:
                            g.DrawLine(pen, startPoint, endPoint);

                            break;

                        case DiagramConnectorType.Bezier:
                            Point pt1 = Point.Empty;
                            Point pt2 = Point.Empty;

                            if (direction == DiagramLayoutDirection.Vertical)
                            {
                                pt1 = new Point(startPoint.X, startPoint.Y + 20);
                                pt2 = new Point(endPoint.X, endPoint.Y - 20);
                            }
                            else if (direction == DiagramLayoutDirection.Horizontal)
                            {
                                pt1 = new Point(startPoint.X + 20, startPoint.Y);
                                pt2 = new Point(endPoint.X - 20, endPoint.Y);
                            }

                            g.DrawBezier(pen, startPoint, pt1, pt2, endPoint);

                            break;
                    }

                    // Draw arrows
                    if (drawArrows)
                    {
                        Point anglePoint = new Point(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y);
                        float angle = (float)(Math.Atan2(anglePoint.Y, anglePoint.X) * (180.0 / Math.PI));

                        if (connectorType == DiagramConnectorType.Bezier)
                        {
                            if (direction == DiagramLayoutDirection.Horizontal)
                                angle *= 0.5f;
                            else
                                angle = 90.0f + (angle - 90.0f) * 0.5f;
                        }

                        g.TranslateTransform(endPoint.X, endPoint.Y);
                        g.RotateTransform(angle);

                        g.FillPath(brush, arrowPath);

                        g.ResetTransform();
                    }

                    DrawConnectors(shape, g, pen, brush, direction, connectorType);
                }
            }
        }
        private void DrawOne(Graphics g, int xmin, int xmax, int ymin, int ymax)
        {
            var shape = Shape.Arc;
            var color = new Color();
            var randomValue = RandomProvider.RandomGenerator.NextDouble();
            foreach (var probabilitiesOfShape in ProbabilitiesOfShapes)
            {
                if (randomValue < probabilitiesOfShape.Probability)
                {
                    shape = probabilitiesOfShape.Value;
                    break;
                }
            }

            randomValue = RandomProvider.RandomGenerator.NextDouble();

            foreach (var colorProbabilityPair in colorsCDFs)
            {
                if (randomValue < colorProbabilityPair.probability)
                {
                    color = colorProbabilityPair.color;
                    break;
                }
            }

            var pen = new Pen(color);

            var x1 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1);
            var y1 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1);

            var x2 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1);
            var y2 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1);

            var x3 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1);
            var y3 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1);

            var x4 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1);
            var y4 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1);

            var w1 = RandomProvider.RandomGenerator.Next(x1, xmax + 1);
            var h1 = RandomProvider.RandomGenerator.Next(y1, ymax + 1);

            var angle1 = RandomProvider.RandomGenerator.Next(0, 360);

            switch (shape)
            {
                case Shape.Arc:
                    g.DrawArc(pen, x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360),
                        RandomProvider.RandomGenerator.Next(0, 360));
                    break;
                case Shape.Bezier:
                    g.DrawBezier(pen, x1, y1, x2, y2, x3, y3, x4, y4);
                    break;
                case Shape.ClosedCurve:
                    g.DrawClosedCurve(pen,
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.Curve:
                    g.DrawCurve(pen,
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.Ellipse:
                    g.DrawEllipse(pen, x1, y1, w1, h1);
                    break;
                case Shape.Line:
                    g.DrawLine(pen, x1, y1, x2, y2);
                    break;
                case Shape.Lines:
                    g.DrawLines(pen,
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.Pie:
                    g.DrawPie(pen, x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360),
                        RandomProvider.RandomGenerator.Next(0, 360));
                    break;
                case Shape.Polygon:
                    g.DrawPolygon(pen,
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.Rectangle:
                    g.DrawRectangle(pen, x1, y1, w1, h1);
                    break;
                case Shape.String:
                    g.DrawString(EnglishWordsDictionary.GetRandomWord(),
                        new Font("Cambria", RandomProvider.RandomGenerator.Next(1, 50)), new SolidBrush(color),
                        new PointF(x1, y1));
                    break;
                case Shape.FillClosedCurve:
                    g.FillClosedCurve(new SolidBrush(color),
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.FillEllipse:
                    g.FillEllipse(new SolidBrush(color), x1, y1, w1, h1);
                    break;
                case Shape.FillPie:
                    g.FillPie(new SolidBrush(color), x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360),
                        RandomProvider.RandomGenerator.Next(0, 360));
                    break;
                case Shape.FillPolygon:
                    g.FillPolygon(new SolidBrush(color),
                        new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)});
                    break;
                case Shape.FillRectangle:
                    g.FillRectangle(new SolidBrush(color), x1, y1, w1, h1);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
            // g.Save();
        }
Example #15
0
        private void DrawSelectedString(Graphics g)
        {
            // highlight the selected cells
            g.DrawImage(texSelected, new Point(0,0));

            // draw the wiring
            if (cellPoints.Length > 1) {
                g.DrawLines(new Pen(Color.FromArgb(80, Color.Black), 3.0f), cellPoints);
                g.DrawLines(new Pen(Color.LightYellow, 1.0f), cellPoints);
            }

            // draw the bypass diode arcs
            int ndiodes = CellString.BypassDiodes.Count;
            for (int i = 0; i < ndiodes; i++) {
                ArraySpec.BypassDiode diode = CellString.BypassDiodes[i];
                PointF pA = junctionPoints[diode.CellIxs.First];
                PointF pB = junctionPoints[diode.CellIxs.Second + 1];
                float perpX = (pB.Y - pA.Y) * 0.2f;
                float perpY = (pA.X - pB.X) * 0.2f;
                PointF pMidA = new PointF(
                    pA.X * 0.7f + pB.X * 0.3f + perpX,
                    pA.Y * 0.7f + pB.Y * 0.3f + perpY);
                PointF pMidB = new PointF(
                    pA.X * 0.3f + pB.X * 0.7f + perpX,
                    pA.Y * 0.3f + pB.Y * 0.7f + perpY);
                g.DrawBezier(new Pen(Color.FromArgb(200, Color.Black), 5f), pA, pMidA, pMidB, pB);
                g.DrawBezier(new Pen(Color.Red, 3f), pA, pMidA, pMidB, pB);
            }

            // draw the bypass diode endpoints
            foreach(int i in bypassJunctions){
                DrawJunction(g, junctionPoints[i], Brushes.Red);
            }
        }
Example #16
0
        public void Draw(Graphics g)
        {
            if (Start.IsEmpty == false)
            {
                g.FillRectangle(Brushes.Blue, Start.X - 4, Start.Y - 4, 8, 8);
            }

            if (End.IsEmpty == false)
            {
                g.FillRectangle(Brushes.Blue, End.X - 4, End.Y - 4, 8, 8);
            }

            if (CP1.IsEmpty == false)
            {
                g.FillEllipse(Brushes.Orange, CP1.X - 4, CP1.Y - 4, 8, 8);
            }

            if (CP2.IsEmpty == false)
            {
                g.FillEllipse(Brushes.Orange, CP2.X - 4, CP2.Y - 4, 8, 8);
            }

            using (Pen dashed = new Pen(Brushes.Violet, 1.5f))
            {
                dashed.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                if (Start.IsEmpty == false && CP1.IsEmpty == false)
                {
                    g.DrawLine(dashed, Start, CP1);
                }

                if (CP1.IsEmpty == false && CP2.IsEmpty == false)
                {
                    g.DrawLine(dashed, CP1, CP2);
                }

                if (CP2.IsEmpty == false && End.IsEmpty == false)
                {
                    g.DrawLine(dashed, CP2, End);
                }
            }

            if (Start.IsEmpty == false && CP1.IsEmpty == false && CP2.IsEmpty == false && End.IsEmpty == false)
            {
                g.DrawBezier(Pens.Magenta, Start, CP1, CP2, End);
            }

            if (_pointSelected.IsEmpty == false)
            {
                using (Pen pen = new Pen(Color.Violet, 3f))
                {
                    if (IsStartSelected(_pointSelected, _curveSelected) == true)
                    {
                        g.DrawRectangle(pen, _curveSelected.Start.X - 8, _curveSelected.Start.Y - 8, 16, 16);
                    }

                    if (IsCP1Selected(_pointSelected, _curveSelected) == true)
                    {
                        g.DrawEllipse(pen, _curveSelected.CP1.X - 8, _curveSelected.CP1.Y - 8, 16, 16);
                    }

                    if (IsCP2Selected(_pointSelected, _curveSelected) == true)
                    {
                        g.DrawEllipse(pen, _curveSelected.CP2.X - 8, _curveSelected.CP2.Y - 8, 16, 16);
                    }

                    if (IsEndSelected(_pointSelected, _curveSelected) == true)
                    {
                        g.DrawRectangle(pen, _curveSelected.End.X - 8, _curveSelected.End.Y - 8, 16, 16);
                    }
                }
            }
        }
Example #17
0
		public virtual void DrawConnections(Graphics g, Color outlineColor, NodePort selectedPort)
		{
			if (g == null)
			{
				throw new ArgumentNullException("g");
			}

			for (Int32 i = 0; i < InputsLength; i++)
			{
				if (GetInput(i).Connection != null)
				{
					Color color = Color.Black;

					if (Object.ReferenceEquals(GetInput(i), selectedPort))
					{
						color = outlineColor;
					}

					NodeBase currentNode = GetInput(i).Connection.Node;
					Int32 connectionIndex = 0;

					for (Int32 j = 0; j < currentNode.OutputsLength; j++)
					{
						if (Object.ReferenceEquals(currentNode.GetOutput(j), GetInput(i).Connection))
						{
							connectionIndex = j;
							break;
						}
					}

					/* Calculate extreme points. */

					Point output = new Point(
						currentNode.BodyRectangle.X + currentNode.BodyRectangle.Width
						, currentNode.BodyRectangle.Y + connectionIndex * currentNode.HeaderRectangle.Height + currentNode.HeaderRectangle.Height / 2 + 1
					);

					Point input = new Point(
						BodyRectangle.X
						, BodyRectangle.Y + i * HeaderRectangle.Height + HeaderRectangle.Height / 2 + 1
					);


					/* Draw connection shadow and the connection itself. */

					g.DrawBezier(
						_connectionPen
						, input
						, new Point(input.X - 26, input.Y + 4)
						, new Point(output.X + 34, output.Y + 4)
						, output
					);

					using (SolidBrush sb = new SolidBrush(color))
					using (Pen pen = new Pen(sb, 2f))
					{
						g.DrawBezier(pen, input, new Point(input.X - 30, input.Y), new Point(output.X + 30, output.Y), output);
						g.FillPolygon(sb, new Point[] { new Point(input.X - 5, input.Y - 5), input, new Point(input.X - 5, input.Y + 5) });
					}
				}
			}
		}
Example #18
0
		/// <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;
					}
				}
			}
		}
Example #19
0
        private void DrawBezier(Graphics graphics, Bezier bezier, Pen pen, Brush brush, bool control)
        {
            graphics.DrawBezier(pen, bezier.Point1.ToPointF(), bezier.Point2.ToPointF(), bezier.Point3.ToPointF(), bezier.Point4.ToPointF());
            if (control)
            {
                graphics.DrawLine(pen, bezier.Point1.ToPointF(), bezier.Point2.ToPointF());
                graphics.DrawLine(pen, bezier.Point4.ToPointF(), bezier.Point3.ToPointF());

                DrawPoint(graphics, bezier.Point1.X, bezier.Point1.Y, brush);
                DrawPoint(graphics, bezier.Point2.X, bezier.Point2.Y, brush);
                DrawPoint(graphics, bezier.Point3.X, bezier.Point3.Y, brush);
                DrawPoint(graphics, bezier.Point4.X, bezier.Point4.Y, brush);
            }
        }
Example #20
0
        private void DrawEdge(Edge e, Pen pen, Graphics graphics)
        {
            ICurve curve = e.Curve;
            Curve c = curve as Curve;
            if (c != null) {
                foreach (ICurve s in c.Segments) {
                    LineSegment l = s as LineSegment;
                    if (l != null)
                        graphics.DrawLine(pen, MsaglPointToDrawingPoint(l.Start), MsaglPointToDrawingPoint(l.End));
                    CubicBezierSegment cs = s as CubicBezierSegment;
                    if (cs != null)
                        graphics.DrawBezier(pen, MsaglPointToDrawingPoint(cs.B(0)), MsaglPointToDrawingPoint(cs.B(1)), MsaglPointToDrawingPoint(cs.B(2)), MsaglPointToDrawingPoint(cs.B(3)));

                }
                if (e.ArrowheadAtSource)
                    DrawArrow(e, pen, graphics, e.Curve.Start, e.EdgeGeometry.SourceArrowhead.TipPosition);
                if (e.ArrowheadAtTarget)
                    DrawArrow(e, pen, graphics, e.Curve.End, e.EdgeGeometry.TargetArrowhead.TipPosition);
            } else {
                var l=curve as LineSegment;
                if (l != null)
                    graphics.DrawLine(pen, MsaglPointToDrawingPoint(l.Start), MsaglPointToDrawingPoint(l.End));
            }
        }
Example #21
0
 /// <summary>
 /// Zeichnet das LineSegment mit dem Stift pen auf die Zeichenfläche g
 /// </summary>
 /// <param name="g">Zeichenfläche auf die gemalt werden soll</param>
 /// <param name="pen">zu benutzender Stift</param>
 public void Draw(Graphics g, Pen pen)
 {
     g.DrawBezier(pen, _p0, _p1, _p2, _p3);
 }
Example #22
0
        private void Render(Graphics g)
        {            
            Size csize = this.ClientSize;
            int w = (int)csize.Width;
            int h = (int)csize.Height;

            frmclk.Start(); // start frame timer.

            switch (m_sampleDrawing)
            {

                case SampleDrawings.FillSolidRects:
                    {
                        for (int i = 0; i < m_rects.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            g.FillRectangle(m_brush1, m_rects[i]);
                        }
                    }
                    break;

                case SampleDrawings.Draw_Rects:
                    {
                        Pen p = new Pen(Color.Red);
                        for (int i = 0; i < m_rects.Count; i++)
                        {
                            p.Color = m_colors[i];
                            g.DrawRectangle(p, m_rects[i]);
                        }
                        p.Dispose();
                    }
                    break;

                case SampleDrawings.DrawRandomLines1:
                    {

                        Pen p = new Pen(Color.Red);
                        for (int i = 0; i < m_lines.Count; i++)
                        {
                            p.Color = m_colors[i];
                            Line line = m_lines[i];
                            g.DrawLine(p, line.P1, line.P2);
                        }
                        p.Dispose();
                    }
                    break;
                case SampleDrawings.DrawRandomLines2:
                    {
                        Pen p = new Pen(Color.Red, 2.0f);
                        for (int i = 0; i < m_lines.Count; i++)
                        {
                            p.Color = m_colors[i];
                            Line line = m_lines[i];
                            g.DrawLine(p, line.P1, line.P2);
                        }
                        p.Dispose();

                    }
                    break;

                case SampleDrawings.DrawBeziers:
                    {
                        int c = 0;
                        Pen p = new Pen(Color.White, 2.0f);
                        //Pen p = new Pen(Color.White);                        
                        foreach (Bezier bz in m_beziers)
                        {
                            p.Color = m_colors[c++];
                            g.DrawBezier(p, bz.P1, bz.P2, bz.P3, bz.P4);
                        }
                        p.Dispose();
                    }
                    break;
                case SampleDrawings.DrawText:
                    {
                        RectangleF layoutrect = new RectangleF();
                        layoutrect.Size = g.MeasureString(m_drawInfo, m_info);

                        for (int i = 0; i < m_texts.Count; i++)
                        {
                            m_brush1.Color = m_colors[i];
                            layoutrect.Location = m_texts[i];
                            g.DrawString(m_drawInfo
                                , m_info, m_brush1, layoutrect, m_strFormat);
                        }
                    }

                    break;
                case SampleDrawings.DrawBitmaps:
                    {
                        Random rnd = new Random(7533);

                        RectangleF bmpRect = new RectangleF();
                        bmpRect.Size = m_bmp.Size;

                        for (int i = 0; i < 20; i++)
                        {
                            bmpRect.Location = new PointF(rnd.Next(w), rnd.Next(h));
                            g.DrawImage(m_bmp, bmpRect);
                        }
                    }
                    break;


                default:
                    break;
            }



            m_frameCount++;
            m_cumulativeTime += (float)frmclk.Elapsed;

            // compute fps and tpf every 10 frames.
            if (m_frameCount > 10)
            {
                m_fps = m_frameCount / m_cumulativeTime;
                m_cumulativeTime = 0;
                m_frameCount = 0;

                UpdateInfo();
            }
        }
		private void dibujarVehiculo(Graphics grafico, Vehiculo vehiculo)
		{
			//El punto es el centro del vehiculo
			int xInicio = (int)vehiculo.X;
			int yInicio = (int)vehiculo.Y;
			int largo = vehiculo.Largo;
			int ancho = 12;

			//Coordenada del inicio del dibujo
			int x = xInicio-(ancho/2);
			int y = yInicio-largo;
			Random a = new Random (vehiculo.Id);
			Color colorVehiculo = Color.White;
			if (vehiculo.Tipo == Vehiculo.AUTOPERSONAL) {
				colorVehiculo = Color.FromArgb(a.Next(20, 105),a.Next(30, 160),125);
			} else if (vehiculo.Tipo == Vehiculo.CAMION) {
				colorVehiculo = Color.FromArgb(a.Next(0, 120),a.Next(0, 50),0);
			} else if (vehiculo.Tipo == Vehiculo.TRASPORTEPUBLICO) {
				colorVehiculo = Color.FromArgb(a.Next(230, 255),a.Next(50, 200),0);
			}
				
			if(Modificar.eliminarVehiculos && Modificar.estaSobre(vehiculo)) {
				colorVehiculo = Configuracion.COLORRESALTAR;
			}

			Color interDerecho = Color.Gray;
			Color interIzquierdo = Color.Gray;
			Color freno = Color.Gray;

			if (vehiculo.Intermitente == Vehiculo.INTERMITENTE_DERECHA)
				interDerecho = Color.Yellow;
			else if (vehiculo.Intermitente == Vehiculo.INTERMITENTE_IZQUIERDA)
				interIzquierdo = Color.Yellow;
			if (vehiculo.LuzFreno)
				freno = Color.Red;

			if (Configuracion.mostrarBezier) {
				Bezier b = vehiculo.Conductor.Bezier;
				if (b != null)
					grafico.DrawBezier (new Pen (colorVehiculo), b.X1, b.Y1, b.X2, b.Y2, b.X3, b.Y3, b.X4, b.Y4);
			}
			//Rota el vehiculo con el angulo de giro
			Matrix m = new Matrix ();
			m.Translate (Configuracion.origenX,Configuracion.origenY);
			m.Scale (Configuracion.tamañoMapa,Configuracion.tamañoMapa);
			m.RotateAt ((int)vehiculo.Angulo, new PointF (xInicio, yInicio));
			grafico.Transform = m;
			grafico.FillRectangle (new SolidBrush (colorVehiculo), x, y, ancho, largo);
			grafico.FillRectangle (new SolidBrush (interIzquierdo), x, y+largo-2, 2, 2);
			grafico.FillRectangle (new SolidBrush (freno), x+4, y+largo-2, 4, 2);
			grafico.FillRectangle (new SolidBrush (interDerecho), x+10, y+largo-2, 2, 2);
			//grafico.FillRectangle (new SolidBrush (Color.Green), x+ancho/2, y+largo, 4, 4);
			//grafico.FillRectangle (new SolidBrush (Color.YellowGreen), x+ancho/2-4, y+largo, 4, 4);
			if (Configuracion.mostrarRadioPercepcion) {
				grafico.DrawEllipse (new Pen (colorVehiculo), xInicio - Configuracion.radioPercepcionVehiculo, yInicio-(largo/2) - Configuracion.radioPercepcionVehiculo, Configuracion.radioPercepcionVehiculo * 2, Configuracion.radioPercepcionVehiculo * 2);
				grafico.DrawEllipse (new Pen (colorVehiculo), xInicio - Configuracion.radioPercepcionSeñaletica, yInicio-(largo/2) - Configuracion.radioPercepcionSeñaletica, Configuracion.radioPercepcionSeñaletica * 2, Configuracion.radioPercepcionSeñaletica * 2);
			}
			this.dibujarID (grafico, vehiculo.Id, Elemento.VERTICAL, x+3, y);
			grafico.ResetTransform ();

			//Se reestablecen los ajustes del mapa
			grafico.TranslateTransform (Configuracion.origenX,Configuracion.origenY);
			grafico.ScaleTransform (Configuracion.tamañoMapa,Configuracion.tamañoMapa);
		}
Example #24
0
 /// <summary>
 /// This method draws a Bezier curve.
 /// </summary>
 /// <param name="graphics">It receives the Graphics instance</param>
 /// <param name="array">An array of (x,y) pairs of coordinates used to draw the curve.</param>
 public static void Bezier(Graphics graphics, int[] array)
 {
     Pen pen = Manager.GetPen(graphics);
     try
     {
         graphics.DrawBezier(pen, array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7]);
     }
     catch(IndexOutOfRangeException e)
     {
         throw new IndexOutOfRangeException(e.ToString());
     }
 }
Example #25
0
        // end drawGraph
        private bool DrawItem(Graphics wa, Graph.ILaneRow row)
        {
            if (row == null || row.NodeLane == -1)
            {
                return false;
            }

            // Clip to the area we're drawing in, but draw 1 pixel past so
            // that the top/bottom of the line segment's anti-aliasing isn't
            // visible in the final rendering.
            int top = wa.RenderingOrigin.Y + rowHeight / 2;
            var laneRect = new Rectangle(0, top, Width, rowHeight);
            Region oldClip = wa.Clip;
            var newClip = new Region(laneRect);
            newClip.Intersect(oldClip);
            wa.Clip = newClip;
            wa.Clear(Color.Transparent);

            //for (int r = 0; r < 2; r++)
                for (int lane = 0; lane < row.Count; lane++)
                {
                    int mid = wa.RenderingOrigin.X + (int)((lane + 0.5) * LANE_WIDTH);

                    for (int item = 0; item < row.LaneInfoCount(lane); item++)
                    {
                        Graph.LaneInfo laneInfo = row[lane, item];

                        bool highLight = (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && laneInfo.Junctions.Any(j => j.IsRelative)) ||
                                         (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.HighlightSelected && laneInfo.Junctions.Any(j => j.HighLight)) ||
                                         (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.Normal);

                        List<Color> curColors = GetJunctionColors(laneInfo.Junctions);

                        // Create the brush for drawing the line
                        Brush brushLineColor = null;
                        Pen brushLineColorPen = null;
                        try
                        {
                            bool drawBorder = Settings.BranchBorders && highLight; //hide border for "non-relatives"

                            if (curColors.Count == 1 || !Settings.StripedBranchChange)
                            {
                                if (curColors[0] != nonRelativeColor)
                                {
                                    brushLineColor = new SolidBrush(curColors[0]);
                                }
                                else if (curColors.Count > 1 && curColors[1] != nonRelativeColor)
                                {
                                    brushLineColor = new SolidBrush(curColors[1]);
                                }
                                else
                                {
                                    drawBorder = false;
                                    brushLineColor = new SolidBrush(nonRelativeColor);
                                }
                            }
                            else
                            {
                                Color lastRealColor = curColors.LastOrDefault(c => c != nonRelativeColor);

                                if (lastRealColor.IsEmpty)
                                {
                                    brushLineColor = new SolidBrush(nonRelativeColor);
                                    drawBorder = false;
                                }
                                else
                                {
                                    brushLineColor = new HatchBrush(HatchStyle.DarkDownwardDiagonal, curColors[0], lastRealColor);
                                }
                            }

                            for (int i = drawBorder ? 0 : 2; i < 3; i++)
                            {
                                Pen penLine = null;
                                if (i == 0)
                                {
                                    penLine = whiteBorderPen;
                                }
                                else if (i == 1)
                                {
                                    penLine = blackBorderPen;
                                }
                                else
                                {
                                    if (brushLineColorPen == null)
                                        brushLineColorPen = new Pen(brushLineColor, LANE_LINE_WIDTH);
                                    penLine = brushLineColorPen;
                                }

                                if (laneInfo.ConnectLane == lane)
                                {
                                    wa.DrawLine
                                        (
                                            penLine,
                                            new Point(mid, top - 1),
                                            new Point(mid, top + rowHeight + 2)
                                        );
                                }
                                else
                                {
                                    wa.DrawBezier
                                        (
                                            penLine,
                                            new Point(mid, top - 1),
                                            new Point(mid, top + rowHeight + 2),
                                            new Point(mid + (laneInfo.ConnectLane - lane) * LANE_WIDTH, top - 1),
                                            new Point(mid + (laneInfo.ConnectLane - lane) * LANE_WIDTH, top + rowHeight + 2)
                                        );
                                }
                            }
                        }
                        finally
                        {
                            if (brushLineColorPen != null)
                                ((IDisposable)brushLineColorPen).Dispose();
                            if (brushLineColor != null)
                                ((IDisposable)brushLineColor).Dispose();
                        }
                    }
                }

            // Reset the clip region
            wa.Clip = oldClip;
            {
                // Draw node
                var nodeRect = new Rectangle
                    (
                    wa.RenderingOrigin.X + (LANE_WIDTH - NODE_DIMENSION) / 2 + row.NodeLane * LANE_WIDTH,
                    wa.RenderingOrigin.Y + (rowHeight - NODE_DIMENSION) / 2,
                    NODE_DIMENSION,
                    NODE_DIMENSION
                    );

                Brush nodeBrush;

                List<Color> nodeColors = GetJunctionColors(row.Node.Ancestors);

                bool highlight = (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.DrawNonRelativesGray && row.Node.Ancestors.Any(j => j.IsRelative)) ||
                                 (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.HighlightSelected && row.Node.Ancestors.Any(j => j.HighLight)) ||
                                 (RevisionGraphDrawStyle == RevisionGraphDrawStyleEnum.Normal);

                bool drawBorder = Settings.BranchBorders && highlight;

                if (nodeColors.Count == 1)
                {
                    nodeBrush = new SolidBrush(highlight ? nodeColors[0] : nonRelativeColor);
                    if (nodeColors[0] == nonRelativeColor) drawBorder = false;
                }
                else
                {
                    nodeBrush = new LinearGradientBrush(nodeRect, nodeColors[0], nodeColors[1],
                                                        LinearGradientMode.Horizontal);
                    if (nodeColors.All(c => c == nonRelativeColor))
                        drawBorder = false;
                }

                if (filterMode == FilterType.Highlight && row.Node.IsFiltered)
                {
                    Rectangle highlightRect = nodeRect;
                    highlightRect.Inflate(2, 3);
                    wa.FillRectangle(Brushes.Yellow, highlightRect);
                    wa.DrawRectangle(Pens.Black, highlightRect);
                }

                if (row.Node.Data == null)
                {
                    wa.FillEllipse(Brushes.White, nodeRect);
                    using (var pen = new Pen(Color.Red, 2))
                    {
                        wa.DrawEllipse(pen, nodeRect);
                    }
                }
                else if (row.Node.IsActive)
                {
                    wa.FillRectangle(nodeBrush, nodeRect);
                    nodeRect.Inflate(1, 1);
                    using (var pen = new Pen(Color.Black, 3))
                        wa.DrawRectangle(pen, nodeRect);
                }
                else if (row.Node.IsSpecial)
                {
                    wa.FillRectangle(nodeBrush, nodeRect);
                    if (drawBorder)
                    {
                        wa.DrawRectangle(Pens.Black, nodeRect);
                    }
                }
                else
                {
                    wa.FillEllipse(nodeBrush, nodeRect);
                    if (drawBorder)
                    {
                        wa.DrawEllipse(Pens.Black, nodeRect);
                    }
                }
            }
            return true;
        }
        private Graph.LaneInfo DrawPenLoop(Graphics wa, int top, int lane, int mid, Graph.LaneInfo laneInfo, Brush brushLineColor, bool drawBorder)
        {
            for (int i = drawBorder ? 0 : 2; i < 3; i++)
            {
                Pen penLine;
                if (i == 0)
                {
                    penLine = new Pen(new SolidBrush(Color.White), LANE_LINE_WIDTH + 2);
                }
                else if (i == 1)
                {
                    penLine = new Pen(new SolidBrush(Color.Black), LANE_LINE_WIDTH + 1);
                }
                else
                {
                    penLine = new Pen(brushLineColor, LANE_LINE_WIDTH);
                }

                if (laneInfo.ConnectLane == lane)
                {
                    wa.DrawLine
                        (
                            penLine,
                            new Point(mid, top - 1),
                            new Point(mid, top + rowHeight + 2)
                        );
                }
                else
                {
                    wa.DrawBezier
                        (
                            penLine,
                            new Point(mid, top - 1),
                            new Point(mid, top + rowHeight + 2),
                            new Point(mid + (laneInfo.ConnectLane - lane) * LANE_WIDTH, top - 1),
                            new Point(mid + (laneInfo.ConnectLane - lane) * LANE_WIDTH, top + rowHeight + 2)
                        );
                }
            }
            return laneInfo;
        }
Example #27
0
        // end DrawGraph
        private bool DrawItem(Graphics wa, Graph.LaneRow row)
        {
            if (row == null || row.NodeLane == -1)
            {
                return false;
            }

            // Clip to the area we're drawing in, but draw 1 pixel past so
            // that the top/bottom of the line segment's anti-aliasing isn't
            // visible in the final rendering.
            int top = wa.RenderingOrigin.Y + _rowHeight / 2;
            var laneRect = new Rectangle(0, top, Width, _rowHeight);
            Region oldClip = wa.Clip;
            var newClip = new Region(laneRect);
            newClip.Intersect(oldClip);
            wa.Clip = newClip;
            wa.Clear(Color.Transparent);

            for (int r = 0; r < 2; r++)
                for (int lane = 0; lane < row.Count; lane++)
                {
                    int mid = wa.RenderingOrigin.X + (int)((lane + 0.5) * LaneWidth);

                    for (int item = 0; item < row.LaneInfoCount(lane); item++)
                    {
                        Graph.LaneInfo laneInfo = row[lane, item];

                        //Draw all non-relative items first, them draw
                        //all relative items on top
                        if (laneInfo.Junctions.FirstOrDefault() != null)
                            if (laneInfo.Junctions.First().IsRelative == (r == 0))
                                continue;

                        List<Color> curColors = GetJunctionColors(laneInfo.Junctions);

                        // Create the brush for drawing the line
                        Brush brushLineColor;
                        bool drawBorder = BranchBorders; //hide border for "non-relatives"
                        if (curColors.Count == 1 || !StripedBranchChange)
                        {
                            if (curColors[0] != _nonRelativeColor)
                            {
                                brushLineColor = new SolidBrush(curColors[0]);
                            }
                            else if (curColors.Count > 1 && curColors[1] != _nonRelativeColor)
                            {
                                brushLineColor = new SolidBrush(curColors[1]);
                            }
                            else
                            {
                                drawBorder = false;
                                brushLineColor = new SolidBrush(_nonRelativeColor);
                            }
                        }
                        else
                        {
                            brushLineColor = new HatchBrush(HatchStyle.DarkDownwardDiagonal, curColors[0], curColors[1]);
                            if (curColors[0] == _nonRelativeColor && curColors[1] == _nonRelativeColor) drawBorder = false;
                        }

                        for (int i = drawBorder ? 0 : 2; i < 3; i++)
                        {
                            Pen penLine;
                            if (i == 0)
                            {
                                penLine = new Pen(new SolidBrush(Color.White), LaneLineWidth + 2);
                            }
                            else if (i == 1)
                            {
                                penLine = new Pen(new SolidBrush(Color.Black), LaneLineWidth + 1);
                            }
                            else
                            {
                                penLine = new Pen(brushLineColor, LaneLineWidth);
                            }

                            if (laneInfo.ConnectLane == lane)
                            {
                                wa.DrawLine
                                    (
                                        penLine,
                                        new Point(mid, top - 1),
                                        new Point(mid, top + _rowHeight + 2)
                                    );
                            }
                            else
                            {
                                wa.DrawBezier
                                    (
                                        penLine,
                                        new Point(mid, top - 1),
                                        new Point(mid, top + _rowHeight + 2),
                                        new Point(mid + (laneInfo.ConnectLane - lane) * LaneWidth, top - 1),
                                        new Point(mid + (laneInfo.ConnectLane - lane) * LaneWidth, top + _rowHeight + 2)
                                    );
                            }
                        }
                    }
                }

            // Reset the clip region
            wa.Clip = oldClip;
            {
                // Draw node
                var nodeRect = new Rectangle
                    (
                    wa.RenderingOrigin.X + (LaneWidth - NodeDimensions) / 2 + row.NodeLane * LaneWidth,
                    wa.RenderingOrigin.Y + (_rowHeight - NodeDimensions) / 2,
                    NodeDimensions,
                    NodeDimensions
                    );

                Brush nodeBrush;
                bool drawBorder = BranchBorders;
                List<Color> nodeColors = GetJunctionColors(row.Node.Ancestors);
                if (nodeColors.Count == 1)
                {
                    nodeBrush = new SolidBrush(nodeColors[0]);
                    if (nodeColors[0] == _nonRelativeColor) drawBorder = false;
                }
                else
                {
                    nodeBrush = new LinearGradientBrush(nodeRect, nodeColors[0], nodeColors[1],
                                                        LinearGradientMode.Horizontal);
                    if (nodeColors[0] == _nonRelativeColor && nodeColors[1] == Color.LightGray) drawBorder = false;
                }

                if (_filterMode == FilterType.Highlight && row.Node.IsFiltered)
                {
                    Rectangle highlightRect = nodeRect;
                    highlightRect.Inflate(2, 3);
                    wa.FillRectangle(Brushes.Yellow, highlightRect);
                    wa.DrawRectangle(new Pen(Brushes.Black), highlightRect);
                }

                if (row.Node.Data == null)
                {
                    wa.FillEllipse(Brushes.White, nodeRect);
                    wa.DrawEllipse(new Pen(Color.Red, 2), nodeRect);
                }
                else if (row.Node.IsActive)
                {
                    wa.FillRectangle(nodeBrush, nodeRect);
                    nodeRect.Inflate(1, 1);
                    wa.DrawRectangle(new Pen(Color.Black, 3), nodeRect);
                }
                else if (row.Node.IsSpecial)
                {
                    wa.FillRectangle(nodeBrush, nodeRect);
                    if (drawBorder)
                    {
                        wa.DrawRectangle(new Pen(Color.Black, 1), nodeRect);
                    }
                }
                else
                {
                    wa.FillEllipse(nodeBrush, nodeRect);
                    if (drawBorder)
                    {
                        wa.DrawEllipse(new Pen(Color.Black, 1), nodeRect);
                    }
                }
            }
            return true;
        }
Example #28
0
		public void DrawPath(Graphics g)
		{
			//if (mBaseMovement != null)
			//	mBaseMovement.DrawPath(g);

			if (mBaseMovement != null)
				mBaseMovement.DrawPath(g);

			PointF anchor = GetAnchorPoint();

			try {

				Matrix mx = new Matrix();
				mx.RotateAt(-mMoveRotation, new PointF(anchor.X, anchor.Y));

				g.Transform = mx;

				Pen pen = new Pen(Color.White);
				pen.DashPattern = new float[] { 6.0f, 8.0f };
				pen.DashStyle = DashStyle.Custom;

				switch (mType) {
					case MovementType.VerticalCycle:
						g.DrawLine(pen, anchor.X, anchor.Y - GetYRadius(),
							anchor.X, anchor.Y + GetYRadius());
						break;
					case MovementType.HorizontalCycle:
						g.DrawLine(pen, anchor.X - GetXRadius(), anchor.Y,
							anchor.X + GetXRadius(), anchor.Y);
						break;
					case MovementType.Circle:
					case MovementType.RotateAroundCircle:
						g.DrawEllipse(pen, anchor.X - GetXRadius(), anchor.Y - GetYRadius(),
										GetXRadius() * 2, GetYRadius() * 2);
						break;
					case MovementType.HorizontalInfinity:
						g.DrawBezier(pen,
							anchor.X, anchor.Y,
							anchor.X - (GetXRadius() * 1.35f), anchor.Y - (GetYRadius() * 1.8f),
							anchor.X - (GetXRadius() * 1.35f), anchor.Y + (GetYRadius() * 1.8f),
							anchor.X, anchor.Y);
						g.DrawBezier(pen,
							anchor.X, anchor.Y,
							anchor.X + (GetXRadius() * 1.35f), anchor.Y - (GetYRadius() * 1.8f),
							anchor.X + (GetXRadius() * 1.35f), anchor.Y + (GetYRadius() * 1.8f),
							anchor.X, anchor.Y);
						break;
					case MovementType.VericalInfinity:
						g.DrawBezier(pen,
							anchor.X, anchor.Y,
							anchor.X - GetXRadius(), anchor.Y - GetYRadius(),
							anchor.X + GetXRadius(), anchor.Y - GetYRadius(),
							anchor.X, anchor.Y);
						g.DrawBezier(pen,
							anchor.X, anchor.Y,
							anchor.X - GetXRadius(), anchor.Y + GetYRadius(),
							anchor.X + GetXRadius(), anchor.Y + GetYRadius(),
							anchor.X, anchor.Y);
						break;
					case MovementType.VerticalArc:
						g.DrawArc(pen, anchor.X - GetXRadius(), anchor.Y - GetYRadius(),
							GetXRadius() * 2, GetYRadius() * 2, -90.0f, 180.0f);
						break;
					case MovementType.HorizontalArc:
						g.DrawArc(pen, anchor.X - GetXRadius(), anchor.Y - GetYRadius(),
										GetXRadius() * 2, GetYRadius() * 2, 180.0f, 180.0f);
						break;
					case MovementType.HorizontalWrap:
						if (mReverse) {
							g.DrawLine(pen, anchor.X, anchor.Y,
								anchor.X - GetXRadius(), anchor.Y);
						} else {
							g.DrawLine(pen, anchor.X, anchor.Y,
								anchor.X + GetXRadius(), anchor.Y);
						}
						break;
					case MovementType.VerticalWrap:
						if (mReverse) {
							g.DrawLine(pen, anchor.X, anchor.Y,
								anchor.X, anchor.Y + GetYRadius());
						} else {
							g.DrawLine(pen, anchor.X, anchor.Y,
								anchor.X, anchor.Y - GetYRadius());
						}
						break;
				}

			} catch {

			} finally {
				g.Transform = new Matrix();
			}
		}
        private void RenderRelativePath(VehicleState vs, Path transPath, Graphics g, WorldTransform t, bool isArbiterPath)
        {
            if((isArbiterPath && DrawingUtility.DrawArbiterLanePath) ||
                (!isArbiterPath && DrawingUtility.DrawOperationalLanePath))
            {
                // compute the rotation matrix to add in our vehicles rotation
                /*Matrix3 rotMatrix = new Matrix3(
                    Math.Cos(vs.heading.ArcTan), -Math.Sin(vs.heading.ArcTan), 0,
                    Math.Sin(vs.heading.ArcTan), Math.Cos(vs.heading.ArcTan), 0,
                    0, 0, 1);

                // compute the translation matrix to move our vehicle's location
                Matrix3 transMatrix = new Matrix3(
                    1, 0, vs.xyPosition.X,
                    0, 1, vs.xyPosition.Y,
                    0, 0, 1);

                // compute the combined transformation matrix
                Matrix3 m = rotMatrix * transMatrix;

                // clone, transform and add each segment to our path
                transPath.Transform(m);*/

                float nomPixelWidth = 2.0f;
                float penWidth = nomPixelWidth / t.Scale;
                Pen arbiterPen = new Pen(Color.FromArgb(100, DrawingUtility.ArbiterLanePath), penWidth);
                Pen operationalPen = new Pen(Color.FromArgb(100, DrawingUtility.OperationalLanePath), penWidth);

                // display path
                foreach (IPathSegment ps in transPath)
                {
                    if (ps is BezierPathSegment)
                    {
                        BezierPathSegment seg = (BezierPathSegment)ps;
                        CubicBezier cb = seg.cb;

                        if (isArbiterPath)
                        {
                            g.DrawBezier(arbiterPen, DrawingUtility.ToPointF(cb.P0), DrawingUtility.ToPointF(cb.P1), DrawingUtility.ToPointF(cb.P2), DrawingUtility.ToPointF(cb.P3));
                        }
                        else
                        {
                            g.DrawBezier(operationalPen, DrawingUtility.ToPointF(cb.P0), DrawingUtility.ToPointF(cb.P1), DrawingUtility.ToPointF(cb.P2), DrawingUtility.ToPointF(cb.P3));
                        }
                    }
                }
            }
        }
Example #30
0
        /** Draw a flat symbol.
         * @param ynote The pixel location of the top of the accidental's note.
         */
        public void DrawFlat(Graphics g, Pen pen, int ynote)
        {
            int x = SheetMusic.LineSpace/4;

            /* Draw the vertical line */
            pen.Width = 1;
            g.DrawLine(pen, x, ynote - SheetMusic.NoteHeight - SheetMusic.NoteHeight/2,
                        x, ynote + SheetMusic.NoteHeight);

            /* Draw 3 bezier curves.
             * All 3 curves start and stop at the same points.
             * Each subsequent curve bulges more and more towards
             * the topright corner, making the curve look thicker
             * towards the top-right.
             */
            g.DrawBezier(pen, x, ynote + SheetMusic.LineSpace/4,
            x + SheetMusic.LineSpace/2, ynote - SheetMusic.LineSpace/2,
            x + SheetMusic.LineSpace, ynote + SheetMusic.LineSpace/3,
            x, ynote + SheetMusic.LineSpace + SheetMusic.LineWidth + 1);

            g.DrawBezier(pen, x, ynote + SheetMusic.LineSpace/4,
            x + SheetMusic.LineSpace/2, ynote - SheetMusic.LineSpace/2,
            x + SheetMusic.LineSpace + SheetMusic.LineSpace/4,
              ynote + SheetMusic.LineSpace/3 - SheetMusic.LineSpace/4,
            x, ynote + SheetMusic.LineSpace + SheetMusic.LineWidth + 1);

            g.DrawBezier(pen, x, ynote + SheetMusic.LineSpace/4,
            x + SheetMusic.LineSpace/2, ynote - SheetMusic.LineSpace/2,
            x + SheetMusic.LineSpace + SheetMusic.LineSpace/2,
             ynote + SheetMusic.LineSpace/3 - SheetMusic.LineSpace/2,
            x, ynote + SheetMusic.LineSpace + SheetMusic.LineWidth + 1);
        }