本文整理汇总了C#中Canvas.FillPolygon方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.FillPolygon方法的具体用法?C# Canvas.FillPolygon怎么用?C# Canvas.FillPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.FillPolygon方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public void Draw(IDrawDevice device)
{
var triangles = env.Triangles;
var triangleSideLength = env.TriangleSideLength;
Canvas canvas = new Canvas(device);
Vector2[][] vectors = new Vector2[4][];
vectors[0] = new Vector2[3];
vectors[0][0] = new Vector2(-(triangleSideLength / 2), -(triangleSideLength / 2));
vectors[0][1] = new Vector2((triangleSideLength / 2), -(triangleSideLength / 2));
vectors[0][2] = new Vector2(0, 0);
vectors[1] = new Vector2[3];
vectors[1][0] = new Vector2((triangleSideLength / 2), -(triangleSideLength / 2));
vectors[1][1] = new Vector2((triangleSideLength / 2), (triangleSideLength / 2));
vectors[1][2] = new Vector2(0, 0);
vectors[2] = new Vector2[3];
vectors[2][0] = new Vector2((triangleSideLength / 2), (triangleSideLength / 2));
vectors[2][1] = new Vector2(-(triangleSideLength / 2), (triangleSideLength / 2));
vectors[2][2] = new Vector2(0, 0);
vectors[3] = new Vector2[3];
vectors[3][0] = new Vector2(-(triangleSideLength / 2), (triangleSideLength / 2));
vectors[3][1] = new Vector2(-(triangleSideLength / 2), -(triangleSideLength / 2));
vectors[3][2] = new Vector2(0, 0);
BatchInfo[] infos = new BatchInfo[4];
infos[0] = new BatchInfo(DrawTechnique.Alpha, ColorRgba.Red, null);
infos[1] = new BatchInfo(DrawTechnique.Alpha, ColorRgba.Blue, null);
infos[2] = new BatchInfo(DrawTechnique.Alpha, ColorRgba.White, null);
infos[3] = new BatchInfo(DrawTechnique.Alpha, ColorRgba.Green, null);
for (int x = 0; x < triangles.GetLength(0); x++)
{
for (int y = 0; y < triangles.GetLength(1); y++)
{
for (int i = 0; i < triangles.GetLength(2); i++)
{
canvas.State.SetMaterial(infos[i]);
if(true/*triangles[x,y,i] != null*/)
{
canvas.FillPolygon(vectors[i], triangleSideLength / 2 + triangleSideLength * x,
triangleSideLength / 2 + triangleSideLength * y);
}
}
}
}
}
示例2: Draw
public override void Draw(Canvas target, Vector3 basePos, float baseRotation, float baseScale)
{
float borderRadius = DefaultOutlineWidth;
float polyScale = 1.0f;
// Scale anti-proportional to perspective scale in order to keep a constant size
// in screen space even when actually drawing in world space.
{
float scale = 1.0f;
Vector3 posTemp = this.pos + basePos;
target.DrawDevice.PreprocessCoords(ref posTemp, ref scale);
borderRadius /= scale;
if (this.invariantScale) polyScale /= scale;
}
// Determine base position
Vector3 circlePos = this.pos;
MathF.TransformCoord(ref circlePos.X, ref circlePos.Y, baseRotation, baseScale);
circlePos += basePos;
// Draw polygon and outline
target.State.ColorTint *= this.Color;
target.State.TransformAngle = baseRotation;
target.State.TransformScale = new Vector2(baseScale, baseScale) * polyScale;
target.FillPolygon(
this.vertices,
circlePos.X,
circlePos.Y,
circlePos.Z);
if (target.DrawDevice.DepthWrite) target.State.ZOffset -= 0.1f;
target.State.ColorTint *= ColorRgba.Black;
target.FillPolygonOutline(
this.vertices,
borderRadius / polyScale,
circlePos.X,
circlePos.Y,
circlePos.Z);
}
示例3: 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)));
//.........这里部分代码省略.........
示例4: 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();
}
示例5: Draw
public override void Draw(Canvas target, Vector3 basePos, float baseRotation, float baseScale)
{
float originRadius = 5.0f;
float vectorThickness = 4.0f;
float borderRadius = DefaultOutlineWidth;
// Scale anti-proportional to perspective scale in order to keep a constant size
// in screen space even when actually drawing in world space.
{
float scale = 1.0f;
Vector3 posTemp = this.posA + basePos;
target.DrawDevice.PreprocessCoords(ref posTemp, ref scale);
originRadius /= scale;
borderRadius /= scale;
vectorThickness /= scale;
}
// Determine base and target positions
Vector3 originPos = this.posA;
Vector3 targetPos = this.posB;
MathF.TransformCoord(ref originPos.X, ref originPos.Y, baseRotation, baseScale);
MathF.TransformCoord(ref targetPos.X, ref targetPos.Y, baseRotation, baseScale);
originPos += basePos;
targetPos += basePos;
// Create connection polygon
float vectorLen = (targetPos.Xy - originPos.Xy).Length;
Vector2 dirForward = (targetPos.Xy - originPos.Xy).Normalized;
Vector2 dirLeft = dirForward.PerpendicularLeft;
Vector2 dirRight = -dirLeft;
Vector2[] connection = new Vector2[4];
connection[0] = dirLeft * vectorThickness * 0.5f;
connection[1] = dirLeft * vectorThickness * 0.5f + dirForward * vectorLen;
connection[2] = dirRight * vectorThickness * 0.5f + dirForward * vectorLen;
connection[3] = dirRight * vectorThickness * 0.5f;
// Draw vector and outline
ColorRgba areaColor = target.State.ColorTint * this.Color;
ColorRgba outlineColor = areaColor * ColorRgba.Black;
target.State.ColorTint = areaColor;
target.FillPolygon(
connection,
originPos.X,
originPos.Y,
originPos.Z);
if (target.DrawDevice.DepthWrite) target.State.ZOffset -= 0.1f;
target.State.ColorTint = outlineColor;
target.FillPolygonOutline(
connection,
borderRadius,
originPos.X,
originPos.Y,
originPos.Z);
// Draw connection points and outline
if (target.DrawDevice.DepthWrite) target.State.ZOffset -= 0.1f;
target.State.ColorTint = areaColor;
target.FillCircle(
originPos.X,
originPos.Y,
originPos.Z,
originRadius - borderRadius * 0.5f);
target.FillCircle(
targetPos.X,
targetPos.Y,
targetPos.Z,
originRadius - borderRadius * 0.5f);
if (target.DrawDevice.DepthWrite) target.State.ZOffset -= 0.1f;
target.State.ColorTint = outlineColor;
target.FillCircleSegment(
originPos.X,
originPos.Y,
originPos.Z,
originRadius,
0.0f,
MathF.RadAngle360,
borderRadius);
target.FillCircleSegment(
targetPos.X,
targetPos.Y,
targetPos.Z,
originRadius,
0.0f,
MathF.RadAngle360,
borderRadius);
}
示例6: DrawShapeArea
private void DrawShapeArea(Canvas canvas, Transform transform, LoopShapeInfo shape)
{
// LoopShapes don't have an area. Do nothing here, unless explicitly specified
if (!this.fillHollowShapes) return;
Vector3 pos = transform.Pos;
float angle = transform.Angle;
float scale = transform.Scale;
if (this.wrapTexture)
{
Rect pointBoundingRect = shape.Vertices.BoundingBox();
canvas.State.TextureCoordinateRect = new Rect(
pointBoundingRect.W / canvas.State.TextureBaseSize.X,
pointBoundingRect.H / canvas.State.TextureBaseSize.Y);
}
canvas.State.TransformAngle = angle;
canvas.State.TransformScale = new Vector2(scale, scale);
canvas.FillPolygon(shape.Vertices, pos.X, pos.Y, pos.Z);
}
示例7: Draw
public override void Draw(Canvas target, Vector3 basePos, float baseRotation, float baseScale)
{
float originRadius = 5.0f;
float vectorThickness = 4.0f;
float borderRadius = DefaultOutlineWidth;
float vectorLengthFactor = 1.0f;
// Scale anti-proportional to perspective scale in order to keep a constant size
// in screen space even when actually drawing in world space.
{
float scale = 1.0f;
Vector3 posTemp = this.origin + basePos;
target.DrawDevice.PreprocessCoords(ref posTemp, ref scale);
originRadius /= scale;
borderRadius /= scale;
vectorThickness /= scale;
if (this.invariantScale) vectorLengthFactor /= scale;
}
// Determine base and target positions
Vector3 originPos = this.origin;
Vector3 targetPos = this.origin + new Vector3(this.vec * vectorLengthFactor);
MathF.TransformCoord(ref originPos.X, ref originPos.Y, baseRotation, baseScale);
MathF.TransformCoord(ref targetPos.X, ref targetPos.Y, baseRotation, baseScale);
originPos += basePos;
targetPos += basePos;
// Downscale vector arrow, if too small for display otherwise
float vectorLen = (targetPos.Xy - originPos.Xy).Length;
float vectorLenScale = MathF.Clamp(vectorLen / (vectorThickness * 7.0f), 0.0f, 1.0f);
vectorThickness *= vectorLenScale;
// Create arrow polygon
Vector2 dirForward = (targetPos.Xy - originPos.Xy).Normalized;
Vector2 dirLeft = dirForward.PerpendicularLeft;
Vector2 dirRight = -dirLeft;
Vector2[] arrow = new Vector2[7];
arrow[0] = dirLeft * vectorThickness * 0.5f;
arrow[1] = dirLeft * vectorThickness * 0.5f + dirForward * (vectorLen - vectorThickness * 2);
arrow[2] = dirLeft * vectorThickness * 1.25f + dirForward * (vectorLen - vectorThickness * 2);
arrow[3] = dirForward * vectorLen;
arrow[4] = dirRight * vectorThickness * 1.25f + dirForward * (vectorLen - vectorThickness * 2);
arrow[5] = dirRight * vectorThickness * 0.5f + dirForward * (vectorLen - vectorThickness * 2);
arrow[6] = dirRight * vectorThickness * 0.5f;
Vector2[] arrowHead = new Vector2[3];
arrowHead[0] = arrow[2];
arrowHead[1] = arrow[3];
arrowHead[2] = arrow[4];
Vector2[] arrowLine = new Vector2[4];
arrowLine[0] = arrow[0];
arrowLine[1] = arrow[1];
arrowLine[2] = arrow[5];
arrowLine[3] = arrow[6];
// Draw vector and outline
ColorRgba areaColor = target.State.ColorTint * this.Color;
ColorRgba outlineColor = areaColor * ColorRgba.Black;
target.State.ColorTint = areaColor;
target.FillPolygon(
arrowLine,
originPos.X,
originPos.Y,
originPos.Z);
target.FillPolygon(
arrowHead,
originPos.X,
originPos.Y,
originPos.Z);
if (target.DrawDevice.DepthWrite) target.State.ZOffset -= 0.1f;
target.State.ColorTint = outlineColor;
target.FillPolygonOutline(
arrow,
borderRadius,
originPos.X,
originPos.Y,
originPos.Z);
// Draw origin and outline
if (target.DrawDevice.DepthWrite) target.State.ZOffset -= 0.1f;
target.State.ColorTint = areaColor;
target.FillCircle(
originPos.X,
originPos.Y,
originPos.Z,
originRadius - borderRadius * 0.5f);
if (target.DrawDevice.DepthWrite) target.State.ZOffset -= 0.1f;
target.State.ColorTint = outlineColor;
target.FillCircleSegment(
originPos.X,
originPos.Y,
originPos.Z,
originRadius,
0.0f,
MathF.RadAngle360,
borderRadius);
}