/// <summary>
 /// Adds a round rectangle to the graphics path where the integer radius specified determines how rounded the rectangle should become.
 /// This can be thought of rounded arcs connected by straight lines.
 /// </summary>
 /// <param name="self"></param>
 /// <param name="bounds"></param>
 /// <param name="radius"></param>
 public static void AddRoundedRectangle(this GraphicsPath self, Rectangle bounds, int radius)
 {
     if (radius * 2 > bounds.Width)
     {
         self.AddEllipse(bounds);
         return;
     }
     if (radius <= 0)
     {
         self.AddRectangle(bounds);
         return;
     }
     int w = radius * 2;
     Rectangle br = new Rectangle(bounds.Right - w, bounds.Bottom - w, w, w);
     Rectangle bl = new Rectangle(bounds.Left, bounds.Bottom - w, w, w);
     Rectangle tl = new Rectangle(bounds.Left, bounds.Top, w, w);
     Rectangle tr = new Rectangle(bounds.Right - w, bounds.Top, w, w);
     self.AddArc(br, 0, 90F);
     self.AddLine(new Point(bounds.Right - radius, bounds.Bottom), new Point(bounds.Left + radius, bounds.Bottom));
     self.AddArc(bl, 90F, 90F);
     self.AddLine(new Point(bounds.Left, bounds.Bottom - radius), new Point(bounds.Left, bounds.Top + radius));
     self.AddArc(tl, 180F, 90F);
     self.AddLine(new Point(bounds.Left + radius, bounds.Top), new Point(bounds.Right - radius, bounds.Top));
     self.AddArc(tr, 270F, 90F);
     self.AddLine(new Point(bounds.Right, bounds.Top + radius), new Point(bounds.Right, bounds.Bottom - radius));
     self.CloseFigure();
 }
        /// <summary>
        /// Adds a rectangle with round corners to the current GraphicsPath.
        /// </summary>
        /// <param name="gp">The current GraphicsPath object.</param>
        /// <param name="point">The coordinates of the upper left corner.</param>
        /// <param name="size">The dimension of the rectangle.</param>
        /// <param name="radius">The radius of the different corners starting with the upper left corner.</param>
        /// <returns>The current GraphicsPath object.</returns>
        public static GraphicsPath AddRoundRectangle(this GraphicsPath gp, PointF point, SizeF size, params float[] radius)
        {
            var r = new float[4];
            var d = new float[4];
            var bottom = point.Y + size.Height;
            var right = point.X + size.Width;

            for (int i = 0; i < r.Length; i++)
            {
                r[i] = radius.Length > 0 ? radius[i % radius.Length] : 0f;
                d[i] = 2f * r[i];
            }

            if (r[0] > 0f)
                gp.AddArc(new RectangleF(point.X, point.Y, d[0], d[0]), 180, 90);

            gp.AddLine(new PointF(point.X + r[0], point.Y), new PointF(right - r[1], point.Y));

            if (r[1] > 0f)
                gp.AddArc(new RectangleF(right - d[1], point.Y, d[1], d[1]), 270, 90);

            gp.AddLine(new PointF(right, point.Y + r[1]), new PointF(right, bottom - r[2]));

            if (r[2] > 0f)
                gp.AddArc(new RectangleF(right - d[2], bottom - d[2], d[2], d[2]), 0, 90);

            gp.AddLine(new PointF(right - r[2], bottom), new PointF(point.X + r[3], bottom));

            if (r[3] > 0f)
                gp.AddArc(new RectangleF(point.X, bottom - d[3], d[3], d[3]), 90, 90);

            gp.AddLine(new PointF(point.X, bottom - r[3]), new PointF(point.X, point.Y + r[0]));
            gp.CloseFigure();
            return gp;
        }
 /// <summary>
 /// Adds the unclosed set of lines that are the top and left of the shape
 /// </summary>
 /// <param name="self"></param>
 /// <param name="bounds"></param>
 /// <param name="radius"></param>
 public static void AddRoundedRectangleTopLeft(this GraphicsPath self, Rectangle bounds, int radius)
 {
     if (radius * 2 > bounds.Width)
     {
         self.AddArc(bounds, 180F, 90F);
         return;
     }
     int w = radius * 2;
     Rectangle tl = new Rectangle(bounds.Left, bounds.Top, w, w);
     self.AddLine(new Point(bounds.Left, bounds.Bottom - radius), new Point(bounds.Left, bounds.Top + radius));
     self.AddArc(tl, 180F, 90F);
     self.AddLine(new Point(bounds.Left + radius, bounds.Top), new Point(bounds.Right - radius, bounds.Top));
 }
 public static void DrawMesh(this DrawingDesc desc, Mesh mesh, Pen pen)
 {
     foreach (var item in mesh.Lines)
     {
         desc.AddLine((float)item.P1.X1, (float)item.P1.X2, (float)item.P2.X1, (float)item.P2.X2, pen);
     }
 }
        public static void AddAxis(
            this DebugRenderer debugRenderer,
            string renderPass, float size = 50f)
        {
            Rgba32 AxisColourX = Rgba32.Red;
            Rgba32 AxisColourY = Rgba32.Green;
            Rgba32 AxisColourZ = Rgba32.Blue;

            debugRenderer.AddLine(
                renderPass,
                new Vector3(-size, 0, 0),
                new Vector3(0, 0, 0),
                Rgba32.White);

            debugRenderer.AddLine(
                renderPass,
                new Vector3(0, -size, 0),
                new Vector3(0, 0, 0),
                Rgba32.White);

            debugRenderer.AddLine(
                renderPass,
                new Vector3(0, 0, -size),
                new Vector3(0, 0, 0),
                Rgba32.White);

            debugRenderer.AddLine(
                renderPass,
                new Vector3(0, 0, 0),
                new Vector3(size, 0, 0),
                AxisColourX);

            debugRenderer.AddLine(
                renderPass,
                new Vector3(0, 0, 0),
                new Vector3(0, size, 0),
                AxisColourY);

            debugRenderer.AddLine(
                renderPass,
                new Vector3(0, 0, 0),
                new Vector3(0, 0, size),
                AxisColourZ);
        }
        public static void AddRoundedRectangle(this GraphicsPath path, RectangleF rect, int cornerRadius)
        {
            if (cornerRadius > 0)
            {
                path.StartFigure();
                path.AddArc(rect.X, rect.Y, cornerRadius * 2, cornerRadius * 2, 180, 90);
                path.AddLine(rect.X + cornerRadius, rect.Y, rect.Right - cornerRadius * 2, rect.Y);
                path.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y, cornerRadius * 2, cornerRadius * 2, 270, 90);
                path.AddLine(rect.Right, rect.Y + cornerRadius * 2, rect.Right, rect.Y + rect.Height - cornerRadius * 2);

                path.AddArc(rect.X + rect.Width - cornerRadius * 2, rect.Y + rect.Height - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 0, 90);

                path.AddLine(rect.Right - cornerRadius * 2, rect.Bottom, rect.X + cornerRadius * 2, rect.Bottom);
                path.AddArc(rect.X, rect.Bottom - cornerRadius * 2, cornerRadius * 2, cornerRadius * 2, 90, 90);
                path.AddLine(rect.X, rect.Bottom - cornerRadius * 2, rect.X, rect.Y + cornerRadius * 2);
                path.CloseFigure();
            }
            else
            {
                path.AddRectangle(rect);
            }
        }
        public static ILine GenerateIdealLine(this Graph graph, DateTime start,
                                             IEnumerable<KeyValuePair<DateTime, float>> staffingPercentages)
        {
            staffingPercentages = staffingPercentages.OrderBy(kv => kv.Key);

            var intervals = GenerateIntervals(start, staffingPercentages.ToArray()).ToArray();
            var totalPersonMinutes = intervals.Sum(i => i.PersonMinutes);

            var remainingPercentage = 1.0;
            var percentages = intervals
                .Select(i => new {i.Start, i.End, Percentage = i.PersonMinutes/totalPersonMinutes})
                .Select(x =>
                    {
                        remainingPercentage -= x.Percentage;
                        if (Math.Abs(remainingPercentage) < 0.0001) remainingPercentage = 0.0;
                        return new {x.Start, x.End, Percentage = (float) remainingPercentage};
                    });

            var ideal = graph.AddLine("Ideal");
            ideal.AddPoint((float) 1.0, start);
            percentages.ToList().ForEach(x => ideal.AddPoint(x.Percentage, x.End));

            return ideal;
        }
        public static void AddPathFigureSegment(
            this D2D.GeometrySink sink, Jupiter.Media.PathSegment segment)
        {
            var bezierSegment = segment as BezierSegment;

            if (bezierSegment != null)
            {
                sink.AddBezier(
                    new D2D.BezierSegment
                    {
                        Point1 = bezierSegment.Point1.ToSharpDX(),
                        Point2 = bezierSegment.Point2.ToSharpDX(),
                        Point3 = bezierSegment.Point3.ToSharpDX()
                    });
                return;
            }

            var lineSegment = segment as LineSegment;

            if (lineSegment != null)
            {
                sink.AddLine(
                    lineSegment.Point.ToSharpDX());
                return;
            }

            var polyBezierSegment = segment as PolyBezierSegment;

            if (polyBezierSegment != null)
            {
                var beziers = new D2D.BezierSegment[polyBezierSegment.Points.Count / 3];

                for (int i = 0; i < beziers.Length; i++)
                {
                    beziers[i].Point1 = polyBezierSegment.Points[i * 3].ToSharpDX();
                    beziers[i].Point2 = polyBezierSegment.Points[i * 3 + 1].ToSharpDX();
                    beziers[i].Point3 = polyBezierSegment.Points[i * 3 + 2].ToSharpDX();
                }

                sink.AddBeziers(beziers);
                return;
            }

            var polyLineSegment = segment as PolyLineSegment;

            if (polyLineSegment != null)
            {
                var lines = new SharpDX.DrawingPointF[polyLineSegment.Points.Count];

                for (int i = 0; i < lines.Length; i++)
                {
                    lines[i] = polyLineSegment.Points[i].ToSharpDX();
                }

                sink.AddLines(lines);
                return;
            }

            var quadraticBezierSegment = segment as QuadraticBezierSegment;

            if (quadraticBezierSegment != null)
            {
                sink.AddQuadraticBezier(
                    new D2D.QuadraticBezierSegment
                    {
                        Point1 = quadraticBezierSegment.Point1.ToSharpDX(),
                        Point2 = quadraticBezierSegment.Point2.ToSharpDX()
                    });
                return;
            }

            var polyQuadraticBezierSegment = segment as PolyQuadraticBezierSegment;

            if (polyQuadraticBezierSegment != null)
            {
                var quadraticBeziers = new D2D.QuadraticBezierSegment[polyBezierSegment.Points.Count / 2];

                for (int i = 0; i < quadraticBeziers.Length; i++)
                {
                    quadraticBeziers[i].Point1 = polyBezierSegment.Points[i * 2].ToSharpDX();
                    quadraticBeziers[i].Point2 = polyBezierSegment.Points[i * 2 + 1].ToSharpDX();
                }

                sink.AddQuadraticBeziers(quadraticBeziers);
                return;
            }

            var arcSegment = segment as ArcSegment;

            if (arcSegment != null)
            {
                sink.AddArc(
                    new D2D.ArcSegment
                    {
                        Point = arcSegment.Point.ToSharpDX(),
                        Size = arcSegment.Size.ToSharpDX(),
                        RotationAngle = (float)arcSegment.RotationAngle,
                        SweepDirection = arcSegment.SweepDirection.ToSharpDX(),
                        ArcSize = arcSegment.IsLargeArc ? D2D.ArcSize.Large : D2D.ArcSize.Small
                    });
                return;
            }
        }
 public static void AddLineGeometry(
     this D2D.GeometrySink sink, Jupiter.Media.LineGeometry lineGeometry)
 {
     sink.BeginFigure(
         lineGeometry.StartPoint.ToSharpDX(),
         D2D.FigureBegin.Hollow);
     sink.AddLine(
         lineGeometry.EndPoint.ToSharpDX());
     sink.EndFigure(D2D.FigureEnd.Open);
 }
        public static void AddGrid(
            this DebugRenderer debugRenderer,
            string renderPass, float gridSquareSize = 0.50f, int numberOfGridSquares = 10,
            bool ShowXZPlane = true, bool ShowXYPlane = false, bool ShowYZPlane = false)
        {
            Rgba32 AxisColourX = Rgba32.Red;
            Rgba32 AxisColourY = Rgba32.Green;
            Rgba32 AxisColourZ = Rgba32.Blue;
            Rgba32 gridColour = Rgba32.LightGrey;

            float length = numberOfGridSquares * 2 * gridSquareSize;
            float halfLength = length / 2;

            if( ShowXZPlane )
            {
                for (int i = 0; i < (numberOfGridSquares * 2 + 1); i++)
                {
                    if (i * gridSquareSize - halfLength == 0)
                        continue;

                    debugRenderer.AddLine(
                        renderPass,
                        new Vector3(-halfLength, 0.0f, i * gridSquareSize - halfLength),
                        new Vector3(halfLength, 0.0f, i * gridSquareSize - halfLength),
                        gridColour);

                    debugRenderer.AddLine(
                        renderPass,
                        new Vector3(i * gridSquareSize - halfLength, 0.0f, -halfLength),
                        new Vector3(i * gridSquareSize - halfLength, 0.0f, halfLength),
                        gridColour);
                }
            }

            if( ShowXYPlane )
            {
                for (int i = 0; i < (numberOfGridSquares * 2 + 1); i++)
                {
                    if (i * gridSquareSize - halfLength == 0)
                        continue;

                    debugRenderer.AddLine(
                        renderPass,
                        new Vector3(-halfLength, i * gridSquareSize - halfLength, 0f),
                        new Vector3(halfLength, i * gridSquareSize - halfLength, 0f),
                        gridColour);

                    debugRenderer.AddLine(
                        renderPass,
                        new Vector3(i * gridSquareSize - halfLength, -halfLength, 0f),
                        new Vector3(i * gridSquareSize - halfLength, halfLength, 0f),
                        gridColour);
                }
            }

            if( ShowYZPlane )
            {
                for (int i = 0; i < (numberOfGridSquares * 2 + 1); i++)
                {
                    if (i * gridSquareSize - halfLength == 0)
                        continue;

                    debugRenderer.AddLine(
                        renderPass,
                        new Vector3(0f, -halfLength, i * gridSquareSize - halfLength),
                        new Vector3(0f, halfLength, i * gridSquareSize - halfLength),
                        gridColour);

                    debugRenderer.AddLine(
                        renderPass,
                        new Vector3(0f, i * gridSquareSize - halfLength, -halfLength),
                        new Vector3(0f, i * gridSquareSize - halfLength, halfLength),
                        gridColour);
                }
            }

            if( ShowXYPlane )
            {
                for (int i = 0; i < (numberOfGridSquares * 2 + 1); i++)
                {
                    if (i * gridSquareSize - halfLength == 0)
                        continue;

                    debugRenderer.AddLine(
                        renderPass,
                        new Vector3(-halfLength, i * gridSquareSize - halfLength, 0f),
                        new Vector3(halfLength, i * gridSquareSize - halfLength, 0f),
                        gridColour);

                    debugRenderer.AddLine(
                        renderPass,
                        new Vector3(i * gridSquareSize - halfLength, -halfLength, 0f),
                        new Vector3(i * gridSquareSize - halfLength, halfLength, 0f),
                        gridColour);
                }
            }

            AddAxis (debugRenderer, renderPass, numberOfGridSquares * gridSquareSize);
        }
 public static void AddOneLineFigure(this CanvasPathBuilder builder, float x1, float y1, float x2, float y2)
 {
     builder.BeginFigure(x1, y1);
     builder.AddLine(x2, y2);
     builder.EndFigure(CanvasFigureLoop.Open);
 }
 public static void StartMethod(this CodeFileBuilder builder, string prefix, string methodBody)
 {
     builder.AddLine(prefix + methodBody);
     builder.Indent();
 }
Exemple #13
0
 public static void AddLineExt(this Log log, LogLevel level, string Source, string Desc, params object[] arg)
 {
     if (log != null)
         log.AddLine(level, Source, Desc, arg);
 }
Exemple #14
0
		/// <summary>
		/// Adds a line to the path
		/// </summary>
		/// <param name="path">Path to add the line to</param>
		/// <param name="start">Starting point for the line</param>
		/// <param name="end">Ending point for the line</param>
		public static void AddLine (this IGraphicsPath path, PointF start, PointF end)
		{
			path.AddLine (start.X, start.Y, end.X, end.Y);
		}
        /// <summary>
        /// Adds the unclosed set of lines that are the bottom and right of the shape
        /// </summary>
        /// <param name="self"></param>
        /// <param name="bounds"></param>
        /// <param name="radius"></param>
        public static void AddRoundedRectangleBottomRight(this GraphicsPath self, Rectangle bounds, int radius)
        {
            if (radius * 2 > bounds.Width)
            {
                self.AddArc(bounds, 0F, 90F);
            }
            int w = radius * 2;
            Rectangle br = new Rectangle(bounds.Right - w, bounds.Bottom - w, w, w);
            self.AddLine(new Point(bounds.Right, bounds.Top + radius), new Point(bounds.Right, bounds.Bottom - radius));
            self.AddArc(br, 0, 90F);
            self.AddLine(new Point(bounds.Right - radius, bounds.Bottom), new Point(bounds.Left + radius, bounds.Bottom));

        }
        public static void AddLines(this TextBox textBox, ConcurrentQueue<string> texts)
        {
            var counter = 0;
            Count += texts.Count;
            ++Calls;
            while (texts.Count > 0)
            {
                string name = "";
                texts.TryDequeue(out name);

                textBox.AddLine(name);

                if (++counter > 10)
                {
                    new System.Threading.Timer((_) =>
                                               textBox.BeginInvoke(new Action(() => textBox.AddLines(texts))), null, 200,
                                               0);
                    return;
                }

            }
        }