本文整理汇总了C#中Canvas.DrawPolygon方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawPolygon方法的具体用法?C# Canvas.DrawPolygon怎么用?C# Canvas.DrawPolygon使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.DrawPolygon方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawTestImageRow
private void DrawTestImageRow(Canvas c, int baseX, int baseY)
{
Vector2[] polygon = new Vector2[]
{
new Vector2(0.0f, 0.0f),
new Vector2(50.0f, 0.0f),
new Vector2(50.0f, 45.0f),
new Vector2(5.0f, 50.0f),
};
int x = baseX;
int y = baseY;
// Outline Shapes
c.PushState();
{
c.DrawCircle(x, y, 25);
x += 100;
c.DrawCircleSegment(x, y, 25, 0.0f, MathF.RadAngle30 * 4, true);
x += 100;
c.DrawLine(x, y , x + 50, y + 25);
c.DrawDashLine(x, y + 25, x + 50, y + 50);
c.DrawThickLine(x, y + 50, x + 50, y + 75, 3);
x += 100;
c.DrawOval(x, y, 50, 50);
x += 100;
c.DrawOvalSegment(x, y, 50, 50, 0.0f, MathF.RadAngle30 * 4, true);
x += 100;
c.DrawPolygon(polygon, x, y);
x += 100;
c.DrawRect(x, y, 50, 50);
x += 100;
c.DrawText("Hello World", x, y, drawBackground: true);
x = baseX;
y += 100;
}
c.PopState();
// Filled Shapes
c.PushState();
{
c.FillCircle(x, y, 25);
x += 100;
c.FillCircleSegment(x, y, 0, 25, MathF.RadAngle30 * 0, MathF.RadAngle30 * 4);
c.FillCircleSegment(x, y, 0, 25, MathF.RadAngle30 * 5, MathF.RadAngle30 * 9, 10);
x += 100;
c.FillThickLine(x, y + 25, x + 50, y + 50, 3);
x += 100;
c.FillOval(x, y, 50, 50);
x += 100;
c.FillOvalSegment(x, y, 0, 50, 50, MathF.RadAngle30 * 0, MathF.RadAngle30 * 4);
c.FillOvalSegment(x, y, 0, 50, 50, MathF.RadAngle30 * 5, MathF.RadAngle30 * 9, 10);
x += 100;
c.FillPolygon(polygon, x, y);
x += 100;
c.FillRect(x, y, 50, 50);
x = baseX;
y += 100;
}
c.PopState();
}
示例2: OnCollectDrawcalls
protected internal override void OnCollectDrawcalls(Canvas canvas)
{
base.OnCollectDrawcalls(canvas);
List<RigidBody> visibleColliders = this.QueryVisibleColliders().ToList();
this.RetrieveResources();
RigidBody selectedBody = this.QuerySelectedCollider();
canvas.State.TextFont = Font.GenericMonospace10;
canvas.State.TextInvariantScale = true;
canvas.State.ZOffset = -1;
Font textFont = canvas.State.TextFont.Res;
// Draw Shape layer
foreach (RigidBody c in visibleColliders)
{
if (!c.Shapes.Any()) continue;
float colliderAlpha = c == selectedBody ? 1.0f : (selectedBody != null ? 0.25f : 0.5f);
float maxDensity = c.Shapes.Max(s => s.Density);
float minDensity = c.Shapes.Min(s => s.Density);
float avgDensity = (maxDensity + minDensity) * 0.5f;
Vector3 colliderPos = c.GameObj.Transform.Pos;
float colliderScale = c.GameObj.Transform.Scale;
int index = 0;
foreach (ShapeInfo s in c.Shapes)
{
CircleShapeInfo circle = s as CircleShapeInfo;
PolyShapeInfo poly = s as PolyShapeInfo;
// EdgeShapeInfo edge = s as EdgeShapeInfo;
LoopShapeInfo loop = s as LoopShapeInfo;
float shapeAlpha = colliderAlpha * (selectedBody == null || this.View.ActiveState.SelectedObjects.Any(sel => sel.ActualObject == s) ? 1.0f : 0.5f);
float densityRelative = MathF.Abs(maxDensity - minDensity) < 0.01f ? 1.0f : s.Density / avgDensity;
ColorRgba clr = s.IsSensor ? this.ShapeSensorColor : this.ShapeColor;
ColorRgba fontClr = this.FgColor;
Vector2 center = Vector2.Zero;
if (!c.IsAwake) clr = clr.ToHsva().WithSaturation(0.0f).ToRgba();
if (!s.IsValid) clr = this.ShapeErrorColor;
if (circle != null)
{
Vector2 circlePos = circle.Position * colliderScale;
MathF.TransformCoord(ref circlePos.X, ref circlePos.Y, c.GameObj.Transform.Angle);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr.WithAlpha((0.25f + densityRelative * 0.25f) * shapeAlpha)));
canvas.FillCircle(
colliderPos.X + circlePos.X,
colliderPos.Y + circlePos.Y,
colliderPos.Z,
circle.Radius * colliderScale);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr.WithAlpha(shapeAlpha)));
canvas.DrawCircle(
colliderPos.X + circlePos.X,
colliderPos.Y + circlePos.Y,
colliderPos.Z,
circle.Radius * colliderScale);
center = circlePos;
}
else if (poly != null)
{
Vector2[] polyVert = poly.Vertices.ToArray();
for (int i = 0; i < polyVert.Length; i++)
{
center += polyVert[i];
Vector2.Multiply(ref polyVert[i], colliderScale, out polyVert[i]);
MathF.TransformCoord(ref polyVert[i].X, ref polyVert[i].Y, c.GameObj.Transform.Angle);
}
center /= polyVert.Length;
Vector2.Multiply(ref center, colliderScale, out center);
MathF.TransformCoord(ref center.X, ref center.Y, c.GameObj.Transform.Angle);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr.WithAlpha((0.25f + densityRelative * 0.25f) * shapeAlpha)));
canvas.FillPolygon(polyVert, colliderPos.X, colliderPos.Y, colliderPos.Z);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr.WithAlpha(shapeAlpha)));
canvas.DrawPolygon(polyVert, colliderPos.X, colliderPos.Y, colliderPos.Z);
}
else if (loop != null)
{
Vector2[] loopVert = loop.Vertices.ToArray();
for (int i = 0; i < loopVert.Length; i++)
{
center += loopVert[i];
Vector2.Multiply(ref loopVert[i], colliderScale, out loopVert[i]);
MathF.TransformCoord(ref loopVert[i].X, ref loopVert[i].Y, c.GameObj.Transform.Angle);
}
center /= loopVert.Length;
Vector2.Multiply(ref center, colliderScale, out center);
MathF.TransformCoord(ref center.X, ref center.Y, c.GameObj.Transform.Angle);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr.WithAlpha(shapeAlpha)));
canvas.DrawPolygon(loopVert, colliderPos.X, colliderPos.Y, colliderPos.Z);
}
// Draw shape index
if (c == selectedBody)
{
Vector2 textSize = textFont.MeasureText(index.ToString(CultureInfo.InvariantCulture));
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, fontClr.WithAlpha((shapeAlpha + 1.0f) * 0.5f)));
//.........这里部分代码省略.........
示例3: DrawTileHighlights
//.........这里部分代码省略.........
Vector2 renderStartPos = worldOriginPos + tileGridPos.X * tileSize.X * worldAxisX + tileGridPos.Y * tileSize.Y * worldAxisY;;
Vector2 renderPos = renderStartPos;
Vector2 tileXStep = worldAxisX * tileSize.X;
Vector2 tileYStep = worldAxisY * tileSize.Y;
int lineMergeCount = 0;
int totalRects = 0;
for (int tileIndex = 0; tileIndex < renderedTileCount; tileIndex++)
{
bool current = highlight[tileGridPos.X, tileGridPos.Y];
if (current)
{
// Try to merge consecutive rects in the same line to reduce drawcalls / CPU load
bool hasNext = (tileGridPos.X + 1 < highlight.Width) && ((tileGridPos.X + 1 - cullingOut.VisibleTileStart.X) < cullingOut.VisibleTileCount.X);
bool next = hasNext ? highlight[tileGridPos.X + 1, tileGridPos.Y] : false;
if (next)
{
lineMergeCount++;
}
else
{
totalRects++;
canvas.FillRect(
transform.Pos.X + renderPos.X - lineMergeCount * tileXStep.X,
transform.Pos.Y + renderPos.Y - lineMergeCount * tileXStep.Y,
transform.Pos.Z,
tileSize.X * (1 + lineMergeCount),
tileSize.Y);
lineMergeCount = 0;
}
}
tileGridPos.X++;
renderPos += tileXStep;
if ((tileGridPos.X - cullingOut.VisibleTileStart.X) >= cullingOut.VisibleTileCount.X)
{
tileGridPos.X = cullingOut.VisibleTileStart.X;
tileGridPos.Y++;
renderPos = renderStartPos;
renderPos += tileYStep * (tileGridPos.Y - cullingOut.VisibleTileStart.Y);
}
}
}
}
// Draw highlight area outlines, unless flagged as uncertain
if (!uncertain)
{
// Determine the outlines of individual highlighted tile patches
if (outlineCache == null) outlineCache = new List<Vector2[]>();
if (outlineCache.Count == 0)
{
GetTileAreaOutlines(highlight, tileSize, ref outlineCache);
}
// Draw outlines around all highlighted tile patches
canvas.State.SetMaterial(selection ? strippleMaterial : defaultMaterial);
canvas.State.ColorTint = outlineTint;
foreach (Vector2[] outline in outlineCache)
{
// For strippled-line display, determine total length of outline
if (selection)
{
float totalLength = 0.0f;
for (int i = 1; i < outline.Length; i++)
{
totalLength += (outline[i - 1] - outline[i]).Length;
}
canvas.State.TextureCoordinateRect = new Rect(totalLength / strippledLineTex.PixelWidth, 1.0f);
}
// Draw the outline
canvas.DrawPolygon(
outline,
transform.Pos.X + worldOriginPos.X,
transform.Pos.Y + worldOriginPos.Y,
transform.Pos.Z);
}
}
// If this is an uncertain highlight, i.e. not actually reflecting the represented action,
// draw a gizmo to indicate this for the user.
if (uncertain)
{
Vector2 highlightSize = new Vector2(highlight.Width * tileSize.X, highlight.Height * tileSize.Y);
Vector2 highlightCenter = highlightSize * 0.5f;
Vector3 circlePos = transform.Pos + new Vector3(worldOriginPos + worldAxisX * highlightCenter + worldAxisY * highlightCenter);
float circleRadius = MathF.Min(tileSize.X, tileSize.Y) * 0.2f;
canvas.State.SetMaterial(defaultMaterial);
canvas.State.ColorTint = outlineTint;
canvas.FillCircle(
circlePos.X,
circlePos.Y,
circlePos.Z,
circleRadius);
}
}
canvas.PopState();
}