Merge pull request #10271 from RoosterDragon/point-sequencing
Support sending sequences of points when drawing lines
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenRA.Graphics
|
namespace OpenRA.Graphics
|
||||||
{
|
{
|
||||||
@@ -113,6 +114,23 @@ namespace OpenRA.Graphics
|
|||||||
return new float2(x, y) / d;
|
return new float2(x, y) / d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawDisconnectedLine(IEnumerable<float2> points, float width, Color color)
|
||||||
|
{
|
||||||
|
using (var e = points.GetEnumerator())
|
||||||
|
{
|
||||||
|
if (!e.MoveNext())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var lastPoint = e.Current;
|
||||||
|
while (e.MoveNext())
|
||||||
|
{
|
||||||
|
var point = e.Current;
|
||||||
|
DrawLine(lastPoint, point, width, color);
|
||||||
|
lastPoint = point;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DrawConnectedLine(float2[] points, float width, Color color, bool closed)
|
void DrawConnectedLine(float2[] points, float width, Color color, bool closed)
|
||||||
{
|
{
|
||||||
// Not a line
|
// Not a line
|
||||||
@@ -184,18 +202,12 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawLine(float2[] points, float width, Color color, bool connectSegments = false)
|
public void DrawLine(IEnumerable<float2> points, float width, Color color, bool connectSegments = false)
|
||||||
{
|
{
|
||||||
if (!connectSegments)
|
if (!connectSegments)
|
||||||
{
|
DrawDisconnectedLine(points, width, color);
|
||||||
if (points.Length < 2)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (var i = 1; i < points.Length; i++)
|
|
||||||
DrawLine(points[i - 1], points[i], width, color);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
DrawConnectedLine(points, width, color, false);
|
DrawConnectedLine(points as float2[] ?? points.ToArray(), width, color, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawPolygon(float2[] vertices, float width, Color color)
|
public void DrawPolygon(float2[] vertices, float width, Color color)
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
lastX = x;
|
lastX = x;
|
||||||
lastPoint = point;
|
lastPoint = point;
|
||||||
return origin + new float2(x * xStep, -point * scale);
|
return origin + new float2(x * xStep, -point * scale);
|
||||||
}).ToArray(), 1, color);
|
}), 1, color);
|
||||||
|
|
||||||
if (lastPoint != 0f)
|
if (lastPoint != 0f)
|
||||||
tiny.DrawText(GetValueFormat().F(lastPoint), origin + new float2(lastX * xStep, -lastPoint * scale - 2), color);
|
tiny.DrawText(GetValueFormat().F(lastPoint), origin + new float2(lastX * xStep, -lastPoint * scale - 2), color);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
foreach (var item in PerfHistory.Items.Values)
|
foreach (var item in PerfHistory.Items.Values)
|
||||||
{
|
{
|
||||||
cr.DrawLine(item.Samples()
|
cr.DrawLine(item.Samples()
|
||||||
.Select((sample, i) => origin + new float2(i, (float)sample) * basis).ToArray(),
|
.Select((sample, i) => origin + new float2(i, (float)sample) * basis),
|
||||||
1, item.C);
|
1, item.C);
|
||||||
|
|
||||||
var u = new float2(rect.Left, rect.Top);
|
var u = new float2(rect.Left, rect.Top);
|
||||||
|
|||||||
Reference in New Issue
Block a user