當前位置: 首頁>>代碼示例>>C#>>正文


C# Canvas.DrawCross方法代碼示例

本文整理匯總了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);
				}
			}
		}
開發者ID:KETMGaming,項目名稱:duality,代碼行數:101,代碼來源:RigidBodyShapeCamViewLayer.cs

示例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);
                }
            }
        }
開發者ID:Andrea,項目名稱:dualityTechDemos,代碼行數:42,代碼來源:Testbed.cs


注:本文中的Canvas.DrawCross方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。