本文整理汇总了C#中Canvas.DrawCross方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawCross方法的具体用法?C# Canvas.DrawCross怎么用?C# Canvas.DrawCross使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.DrawCross方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCollectDrawcalls
//.........这里部分代码省略.........
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.CurrentState.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.CurrentState.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);
polyVert[i] += colliderPos.Xy;
}
center /= polyVert.Length;
Vector2.Multiply(ref center, colliderScale, out center);
MathF.TransformCoord(ref center.X, ref center.Y, c.GameObj.Transform.Angle);
canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr.WithAlpha((0.25f + densityRelative * 0.25f) * shapeAlpha)));
canvas.FillConvexPolygon(polyVert, colliderPos.Z);
canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr.WithAlpha(shapeAlpha)));
canvas.DrawPolygon(polyVert, 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);
loopVert[i] += colliderPos.Xy;
}
center /= loopVert.Length;
Vector2.Multiply(ref center, colliderScale, out center);
MathF.TransformCoord(ref center.X, ref center.Y, c.GameObj.Transform.Angle);
canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr.WithAlpha(shapeAlpha)));
canvas.DrawPolygon(loopVert, colliderPos.Z);
}
// Draw shape index
if (c == selectedBody)
{
Vector2 textSize = textFont.MeasureText(index.ToString(CultureInfo.InvariantCulture));
canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Alpha, fontClr.WithAlpha((shapeAlpha + 1.0f) * 0.5f)));
canvas.CurrentState.TransformHandle = textSize * 0.5f;
canvas.DrawText(index.ToString(CultureInfo.InvariantCulture),
colliderPos.X + center.X,
colliderPos.Y + center.Y,
colliderPos.Z);
canvas.CurrentState.TransformHandle = Vector2.Zero;
}
index++;
}
// Draw center of mass
if (c.BodyType == BodyType.Dynamic)
{
Vector2 localMassCenter = c.LocalMassCenter;
MathF.TransformCoord(ref localMassCenter.X, ref localMassCenter.Y, c.GameObj.Transform.Angle);
canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Alpha, this.MassCenterColor.WithAlpha(colliderAlpha)));
canvas.DrawCross(
colliderPos.X + localMassCenter.X,
colliderPos.Y + localMassCenter.Y,
colliderPos.Z,
5.0f);
}
}
}
示例2: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
Canvas canvas = new Canvas(device);
if (device.IsScreenOverlay)
{
// Testbed text
Vector2 nameSize = this.name.Measure().Size;
Vector2 descSize = this.desc.Measure().Size;
Vector2 ctrlSize = this.controls.Measure().Size;
Vector2 statsSize = this.stats.Measure().Size;
canvas.PushState();
// Text background
canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White));
canvas.CurrentState.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
canvas.FillRect(10, 10, MathF.Max(nameSize.X, descSize.X, ctrlSize.X) + 20, nameSize.Y + descSize.Y + 10 + ctrlSize.Y + 10);
canvas.FillRect(10, DualityApp.TargetResolution.Y - 20 - statsSize.Y, statsSize.X + 20, statsSize.Y + 10);
// Caption / Name
canvas.CurrentState.ColorTint = ColorRgba.White.WithAlpha(0.85f);
canvas.DrawText(this.name, 20, 15);
// Description, Controls, Stats
canvas.CurrentState.ColorTint = ColorRgba.White.WithAlpha(0.65f);
canvas.DrawText(this.desc, 20, 15 + nameSize.Y);
canvas.DrawText(this.controls, 20, 15 + nameSize.Y + descSize.Y + 10);
canvas.DrawText(this.stats, 20, DualityApp.TargetResolution.Y - 15 - statsSize.Y);
canvas.PopState();
// Mouse cursor
canvas.DrawCross(DualityApp.Mouse.X, DualityApp.Mouse.Y, 5.0f);
}
else
{
// Mouse joint, if existing
if (this.mouseJoint != null)
{
Vector3 jointBegin = this.mouseJoint.BodyA.GameObj.Transform.GetWorldPoint(new Vector3(this.mouseJoint.LocalAnchor, -0.01f));
Vector3 jointEnd = new Vector3(this.mouseJoint.WorldAnchor, -0.01f);
canvas.CurrentState.ColorTint = ColorRgba.Red.WithAlpha(0.5f);
canvas.DrawLine(jointBegin.X, jointBegin.Y, jointBegin.Z, jointEnd.X, jointEnd.Y, jointEnd.Z);
}
}
}