本文整理汇总了C#中Canvas.DrawCircle方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawCircle方法的具体用法?C# Canvas.DrawCircle怎么用?C# Canvas.DrawCircle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.DrawCircle方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCollectStateOverlayDrawcalls
protected override void OnCollectStateOverlayDrawcalls(Canvas canvas)
{
base.OnCollectStateOverlayDrawcalls(canvas);
if (this.SelObjAction == ObjectAction.None && this.DragMustWait && !this.dragLastLoc.IsEmpty)
{
canvas.PushState();
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White));
canvas.State.ColorTint = ColorRgba.White.WithAlpha(this.DragMustWaitProgress);
canvas.FillCircle(
this.dragLastLoc.X,
this.dragLastLoc.Y,
15.0f);
canvas.State.ColorTint = ColorRgba.White;
canvas.DrawCircle(
this.dragLastLoc.X,
this.dragLastLoc.Y,
15.0f);
canvas.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: DrawLocalFrictionMarker
private void DrawLocalFrictionMarker(Canvas canvas, RigidBody body, Vector2 anchor)
{
Vector3 colliderPos = body.GameObj.Transform.Pos;
ColorRgba clr = this.JointColor;
float markerCircleRad = body.BoundRadius * 0.02f;
Vector2 anchorToWorld = body.GameObj.Transform.GetWorldVector(anchor);
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
canvas.FillCircle(
colliderPos.X + anchorToWorld.X,
colliderPos.Y + anchorToWorld.Y,
colliderPos.Z,
markerCircleRad * 0.5f);
canvas.DrawCircle(
colliderPos.X + anchorToWorld.X,
colliderPos.Y + anchorToWorld.Y,
colliderPos.Z,
markerCircleRad);
canvas.DrawCircle(
colliderPos.X + anchorToWorld.X,
colliderPos.Y + anchorToWorld.Y,
colliderPos.Z,
markerCircleRad * 1.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: OnCollectWorldOverlayDrawcalls
protected internal override void OnCollectWorldOverlayDrawcalls(Canvas canvas)
{
base.OnCollectWorldOverlayDrawcalls(canvas);
List<RigidBody> visibleColliders = this.QueryVisibleColliders().ToList();
RigidBody selectedBody = this.QuerySelectedCollider();
canvas.State.TextFont = Font.GenericMonospace10;
canvas.State.TextInvariantScale = true;
canvas.State.ZOffset = -0.5f;
Font textFont = canvas.State.TextFont.Res;
// Draw Shape layer
foreach (RigidBody body in visibleColliders)
{
if (!body.Shapes.Any()) continue;
float colliderAlpha = body == selectedBody ? 1.0f : (selectedBody != null ? 0.25f : 0.5f);
float maxDensity = body.Shapes.Max(s => s.Density);
float minDensity = body.Shapes.Min(s => s.Density);
float avgDensity = (maxDensity + minDensity) * 0.5f;
Vector3 objPos = body.GameObj.Transform.Pos;
float objAngle = body.GameObj.Transform.Angle;
float objScale = body.GameObj.Transform.Scale;
int index = 0;
foreach (ShapeInfo shape in body.Shapes)
{
CircleShapeInfo circle = shape as CircleShapeInfo;
PolyShapeInfo poly = shape as PolyShapeInfo;
ChainShapeInfo chain = shape as ChainShapeInfo;
LoopShapeInfo loop = shape as LoopShapeInfo;
ObjectEditorCamViewState editorState = this.View.ActiveState as ObjectEditorCamViewState;
float shapeAlpha = colliderAlpha * (selectedBody == null || editorState == null || editorState.SelectedObjects.Any(sel => sel.ActualObject == shape) ? 1.0f : 0.5f);
float densityRelative = MathF.Abs(maxDensity - minDensity) < 0.01f ? 1.0f : shape.Density / avgDensity;
ColorRgba clr = shape.IsSensor ? this.ShapeSensorColor : this.ShapeColor;
ColorRgba fontClr = this.FgColor;
Vector2 center = Vector2.Zero;
if (!body.IsAwake) clr = clr.ToHsva().WithSaturation(0.0f).ToRgba();
if (!shape.IsValid) clr = this.ShapeErrorColor;
bool fillShape = (poly != null || circle != null);
Vector2[] shapeVertices = null;
if (poly != null) shapeVertices = poly .Vertices;
else if (loop != null) shapeVertices = loop .Vertices;
else if (chain != null) shapeVertices = chain.Vertices;
if (circle != null)
{
Vector2 circlePos = circle.Position * objScale;
MathF.TransformCoord(ref circlePos.X, ref circlePos.Y, objAngle);
if (fillShape)
{
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr.WithAlpha((0.25f + densityRelative * 0.25f) * shapeAlpha)));
canvas.FillCircle(
objPos.X + circlePos.X,
objPos.Y + circlePos.Y,
objPos.Z,
circle.Radius * objScale);
}
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr.WithAlpha(shapeAlpha)));
canvas.DrawCircle(
objPos.X + circlePos.X,
objPos.Y + circlePos.Y,
objPos.Z,
circle.Radius * objScale);
center = circlePos;
}
else if (shapeVertices != null)
{
ColorRgba vertexFillColor = canvas.State.ColorTint * clr.WithAlpha((0.25f + densityRelative * 0.25f) * shapeAlpha);
ColorRgba vertexOutlineColor = canvas.State.ColorTint * clr;
// Prepare vertices to submit. We can't use higher-level canvas functionality
// here, because we want direct control over the vertex mode.
float viewSpaceScale = objScale;
Vector3 viewSpacePos = objPos;
canvas.DrawDevice.PreprocessCoords(ref viewSpacePos, ref viewSpaceScale);
VertexC1P3T2[] drawVertices = new VertexC1P3T2[shapeVertices.Length];
for (int i = 0; i < drawVertices.Length; i++)
{
drawVertices[i].Pos.X = shapeVertices[i].X * viewSpaceScale + viewSpacePos.X;
drawVertices[i].Pos.Y = shapeVertices[i].Y * viewSpaceScale + viewSpacePos.Y;
drawVertices[i].Pos.Z = viewSpacePos.Z;
drawVertices[i].Color = vertexOutlineColor;
MathF.TransformCoord(ref drawVertices[i].Pos.X, ref drawVertices[i].Pos.Y, objAngle);
}
// Calculate the center coordinate
for (int i = 0; i < drawVertices.Length; i++)
center += shapeVertices[i];
center /= shapeVertices.Length;
MathF.TransformCoord(ref center.X, ref center.Y, objAngle, objScale);
// Make sure to render using an alpha material
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White));
// Fill the shape
//.........这里部分代码省略.........
示例6: OnCollectStateOverlayDrawcalls
protected override void OnCollectStateOverlayDrawcalls(Canvas canvas)
{
base.OnCollectStateOverlayDrawcalls(canvas);
if (this.SelObjAction == ObjectAction.None && this.DragMustWait && !this.dragLastLoc.IsEmpty)
{
canvas.CurrentState.ColorTint = ColorRgba.White.WithAlpha(this.DragMustWaitProgress);
canvas.FillCircle(
this.dragLastLoc.X,
this.dragLastLoc.Y,
15.0f);
canvas.CurrentState.ColorTint = ColorRgba.White;
canvas.DrawCircle(
this.dragLastLoc.X,
this.dragLastLoc.Y,
15.0f);
}
}
示例7: OnCollectStateWorldOverlayDrawcalls
protected override void OnCollectStateWorldOverlayDrawcalls(Canvas canvas)
{
base.OnCollectStateWorldOverlayDrawcalls(canvas);
// Assure we know how to display the current selection
this.ValidateSelectionStats();
List<ObjectEditorSelObj> transformObjSel = this.allObjSel.Where(s => s.HasTransform).ToList();
Point cursorPos = this.PointToClient(Cursor.Position);
canvas.PushState();
canvas.State.ZOffset = -1.0f;
// Draw indirectly selected object overlay
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Solid, ColorRgba.Lerp(this.FgColor, this.BgColor, 0.75f)));
this.DrawSelectionMarkers(canvas, this.indirectObjSel);
if (this.mouseoverObject != null && (this.mouseoverAction == ObjectEditorAction.RectSelect || this.mouseoverSelect) && !transformObjSel.Contains(this.mouseoverObject))
this.DrawSelectionMarkers(canvas, new [] { this.mouseoverObject });
// Draw selected object overlay
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Solid, this.FgColor));
this.DrawSelectionMarkers(canvas, transformObjSel);
// Draw overall selection boundary
if (transformObjSel.Count > 1)
{
float midZ = transformObjSel.Average(t => t.Pos.Z);
float maxZDiff = transformObjSel.Max(t => MathF.Abs(t.Pos.Z - midZ));
if (maxZDiff > 0.001f)
{
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Solid, ColorRgba.Lerp(this.FgColor, this.BgColor, 0.5f)));
canvas.DrawSphere(
this.selectionCenter.X,
this.selectionCenter.Y,
this.selectionCenter.Z,
this.selectionRadius);
}
else
{
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Solid, ColorRgba.Lerp(this.FgColor, this.BgColor, 0.5f)));
canvas.DrawCircle(
this.selectionCenter.X,
this.selectionCenter.Y,
this.selectionCenter.Z,
this.selectionRadius);
}
}
// Draw scale action dots
bool canMove = this.actionObjSel.Any(s => s.IsActionAvailable(ObjectEditorAction.Move));
bool canScale = (canMove && this.actionObjSel.Count > 1) || this.actionObjSel.Any(s => s.IsActionAvailable(ObjectEditorAction.Scale));
if (canScale)
{
float dotR = 3.0f / this.GetScaleAtZ(this.selectionCenter.Z);
canvas.State.ZOffset -= 0.1f;
canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Solid, this.FgColor));
canvas.FillCircle(
this.selectionCenter.X + this.selectionRadius,
this.selectionCenter.Y,
this.selectionCenter.Z,
dotR);
canvas.FillCircle(
this.selectionCenter.X - this.selectionRadius,
this.selectionCenter.Y,
this.selectionCenter.Z,
dotR);
canvas.FillCircle(
this.selectionCenter.X,
this.selectionCenter.Y + this.selectionRadius,
this.selectionCenter.Z,
dotR);
canvas.FillCircle(
this.selectionCenter.X,
this.selectionCenter.Y - this.selectionRadius,
this.selectionCenter.Z,
dotR);
canvas.State.ZOffset += 0.1f;
}
if (this.action != ObjectEditorAction.None)
{
// Draw action lock axes
this.DrawLockedAxes(canvas, this.selectionCenter.X, this.selectionCenter.Y, this.selectionCenter.Z, this.selectionRadius * 4);
}
canvas.PopState();
}
示例8: DrawSelectionMarkers
protected void DrawSelectionMarkers(Canvas canvas, IEnumerable<ObjectEditorSelObj> obj)
{
// Determine turned Camera axes for angle-independent drawing
Vector2 catDotX, catDotY;
float camAngle = this.CameraObj.Transform.Angle;
MathF.GetTransformDotVec(camAngle, out catDotX, out catDotY);
Vector3 right = new Vector3(1.0f, 0.0f, 0.0f);
Vector3 down = new Vector3(0.0f, 1.0f, 0.0f);
MathF.TransformDotVec(ref right, ref catDotX, ref catDotY);
MathF.TransformDotVec(ref down, ref catDotX, ref catDotY);
canvas.PushState();
canvas.State.ZOffset = -1.0f;
foreach (ObjectEditorSelObj selObj in obj)
{
if (!selObj.HasTransform) continue;
Vector3 posTemp = selObj.Pos;
float scaleTemp = 1.0f;
float radTemp = selObj.BoundRadius;
if (!canvas.DrawDevice.IsCoordInView(posTemp, radTemp)) continue;
// Draw selection marker
if (selObj.ShowPos)
{
canvas.DrawDevice.PreprocessCoords(ref posTemp, ref scaleTemp);
posTemp.Z = 0.0f;
{
ColorRgba color = canvas.State.ColorTint * canvas.State.Material.MainColor;
VertexC1P3[] vertices = new VertexC1P3[4];
vertices[0].Pos = posTemp - right * 5.0f;
vertices[1].Pos = posTemp + right * 5.0f;
vertices[2].Pos = posTemp - down * 5.0f;
vertices[3].Pos = posTemp + down * 5.0f;
vertices[0].Color = color;
vertices[1].Color = color;
vertices[2].Color = color;
vertices[3].Color = color;
canvas.DrawDevice.AddVertices(canvas.State.Material, VertexMode.Lines, vertices);
}
}
// Draw angle marker
if (selObj.ShowAngle)
{
posTemp = selObj.Pos +
radTemp * right * MathF.Sin(selObj.Angle - camAngle) -
radTemp * down * MathF.Cos(selObj.Angle - camAngle);
canvas.DrawLine(selObj.Pos.X, selObj.Pos.Y, selObj.Pos.Z, posTemp.X, posTemp.Y, posTemp.Z);
}
// Draw boundary
if (selObj.ShowBoundRadius && radTemp > 0.0f)
canvas.DrawCircle(selObj.Pos.X, selObj.Pos.Y, selObj.Pos.Z, radTemp);
}
canvas.PopState();
}
示例9: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
Canvas canvas = new Canvas(device);
Vector2 screenSize = device.TargetSize;
ICameraController activeController = this.mainCameraObj.GetComponent<ICameraController>();
Transform camTransform = this.mainCameraObj.Transform;
Transform targetTransform = this.targetObj.Transform;
float camDist = (camTransform.Pos.Xy - targetTransform.Pos.Xy).Length;
string activeControllerName = activeController != null ? activeController.GetType().Name : "None";
activeControllerName = activeControllerName.Replace("CameraController", "");
// Draw the screen center, so we know what exactly our camera controller is pointing at
canvas.State.ColorTint = ColorRgba.Green.WithAlpha(0.5f);
canvas.FillCircle(screenSize.X * 0.5f, screenSize.Y * 0.5f, 8.0f);
// Draw the camera distance around the screen center
canvas.State.ColorTint = ColorRgba.Green.WithAlpha(0.25f);
canvas.DrawCircle(screenSize.X * 0.5f, screenSize.Y * 0.5f, camDist);
// Draw the camera velocity (movement per second) around the screen center
canvas.State.ColorTint = ColorRgba.Green.WithAlpha(0.5f);
canvas.DrawLine(
screenSize.X * 0.5f,
screenSize.Y * 0.5f,
screenSize.X * 0.5f + camTransform.Vel.X / Time.SPFMult,
screenSize.Y * 0.5f + camTransform.Vel.Y / Time.SPFMult);
// Draw some info text
if (this.infoText == null)
{
this.infoText = new FormattedText();
this.infoText.MaxWidth = 350;
}
this.infoText.SourceText = string.Format(
"Camera Controller Sample/n/n" +
"Use /c44AAFFFFarrow keys/cFFFFFFFF // /c44AAFFFFleft thumbstick/cFFFFFFFF to move./n" +
"Use /c44AAFFFFnumber keys 1, 2/cFFFFFFFF // /c44AAFFFFbuttons A, B/cFFFFFFFF to select a Camera Controller./n" +
"Use the /c44AAFFFFM key/cFFFFFFFF // /c44AAFFFFbutton X/cFFFFFFFF to toggle movement history./n/n" +
"Active Camera Controller:/n/cFF8800FF{0}/cFFFFFFFF",
activeControllerName);
canvas.State.ColorTint = ColorRgba.White;
canvas.DrawText(this.infoText, 10, 10, 0.0f, null, Alignment.TopLeft, true);
// Draw state information on the current camera controller
if (this.stateText == null) this.stateText = new FormattedText();
this.stateText.SourceText = string.Format(
"Camera Distance: {0:F}/n" +
"Camera Velocity: {1:F}, {2:F}",
camDist,
camTransform.Vel.X,
camTransform.Vel.Y);
canvas.State.ColorTint = ColorRgba.White;
canvas.DrawText(this.stateText, 10, screenSize.Y - 10, 0.0f, null, Alignment.BottomLeft, true);
}