当前位置: 首页>>代码示例>>C#>>正文


C# Canvas.DrawLine方法代码示例

本文整理汇总了C#中Canvas.DrawLine方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawLine方法的具体用法?C# Canvas.DrawLine怎么用?C# Canvas.DrawLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Canvas的用法示例。


在下文中一共展示了Canvas.DrawLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawWorldAxisMotor

        private void DrawWorldAxisMotor(Canvas canvas, RigidBody body, Vector2 worldAxis, Vector2 localAnchor, Vector2 worldAnchor, float speed, float maxForce, float offset)
        {
            Vector3 bodyPos = body.GameObj.Transform.Pos;

            ColorRgba clr = this.MotorColor;

            Vector2 anchorToWorld = body.GameObj.Transform.GetWorldVector(localAnchor);
            float axisAngle = worldAxis.Angle;
            float maxForceTemp = MathF.Sign(speed) * maxForce * 0.1f;
            Vector2 arrowBegin = bodyPos.Xy + worldAxis.PerpendicularRight * offset;
            Vector2 arrowBase = arrowBegin + worldAxis * speed * 10.0f;
            Vector2 arrowA = Vector2.FromAngleLength(axisAngle + MathF.RadAngle45 + MathF.RadAngle180, MathF.Sign(speed) * MathF.Max(offset * 0.05f, 5.0f));
            Vector2 arrowB = Vector2.FromAngleLength(axisAngle - MathF.RadAngle45 + MathF.RadAngle180, MathF.Sign(speed) * MathF.Max(offset * 0.05f, 5.0f));

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                arrowBegin.X + worldAxis.PerpendicularLeft.X * 2.0f,
                arrowBegin.Y + worldAxis.PerpendicularLeft.Y * 2.0f,
                bodyPos.Z,
                arrowBegin.X + worldAxis.PerpendicularLeft.X * 2.0f + worldAxis.X * maxForceTemp,
                arrowBegin.Y + worldAxis.PerpendicularLeft.Y * 2.0f + worldAxis.Y * maxForceTemp,
                bodyPos.Z);
            canvas.DrawLine(
                arrowBegin.X + worldAxis.PerpendicularRight.X * 2.0f,
                arrowBegin.Y + worldAxis.PerpendicularRight.Y * 2.0f,
                bodyPos.Z,
                arrowBegin.X + worldAxis.PerpendicularRight.X * 2.0f + worldAxis.X * maxForceTemp,
                arrowBegin.Y + worldAxis.PerpendicularRight.Y * 2.0f + worldAxis.Y * maxForceTemp,
                bodyPos.Z);
            canvas.DrawLine(
                arrowBegin.X,
                arrowBegin.Y,
                bodyPos.Z,
                arrowBase.X,
                arrowBase.Y,
                bodyPos.Z);
            canvas.DrawLine(
                arrowBase.X,
                arrowBase.Y,
                bodyPos.Z,
                arrowBase.X + arrowA.X,
                arrowBase.Y + arrowA.Y,
                bodyPos.Z);
            canvas.DrawLine(
                arrowBase.X,
                arrowBase.Y,
                bodyPos.Z,
                arrowBase.X + arrowB.X,
                arrowBase.Y + arrowB.Y,
                bodyPos.Z);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:51,代码来源:RigidBodyJointCamViewLayer.cs

示例2: DrawWorldDistConstraint

        private void DrawWorldDistConstraint(Canvas canvas, RigidBody body, Vector2 localAnchor, Vector2 worldAnchor, float minDist, float maxDist)
        {
            Vector3 colliderPosA = body.GameObj.Transform.Pos;

            ColorRgba clr = this.JointColor;
            ColorRgba clrErr = this.JointErrorColor;

            float markerCircleRad = body.BoundRadius * 0.02f;
            Vector2 anchorA = body.GameObj.Transform.GetWorldVector(localAnchor);
            Vector2 errorVec = worldAnchor - (colliderPosA.Xy + anchorA);
            Vector2 lineNormal = errorVec.PerpendicularRight.Normalized;
            float dist = errorVec.Length;
            Vector2 distVec = errorVec.Normalized * MathF.Clamp(dist, minDist, maxDist);
            bool hasError = (errorVec - distVec).Length >= 1.0f;

            if (hasError)
            {
                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clrErr));
                canvas.DrawLine(
                    colliderPosA.X + anchorA.X + distVec.X,
                    colliderPosA.Y + anchorA.Y + distVec.Y,
                    colliderPosA.Z,
                    colliderPosA.X + anchorA.X + errorVec.X,
                    colliderPosA.Y + anchorA.Y + errorVec.Y,
                    colliderPosA.Z);
                this.DrawLocalText(canvas, body,
                    string.Format("{0:F1}", dist),
                    anchorA + errorVec,
                    Vector2.UnitY,
                    errorVec.Angle);
            }
            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                colliderPosA.X + anchorA.X,
                colliderPosA.Y + anchorA.Y,
                colliderPosA.Z,
                colliderPosA.X + anchorA.X + distVec.X,
                colliderPosA.Y + anchorA.Y + distVec.Y,
                colliderPosA.Z);
            if (hasError)
            {
                canvas.DrawLine(
                    colliderPosA.X + anchorA.X + distVec.X - lineNormal.X * 5.0f,
                    colliderPosA.Y + anchorA.Y + distVec.Y - lineNormal.Y * 5.0f,
                    colliderPosA.Z,
                    colliderPosA.X + anchorA.X + distVec.X + lineNormal.X * 5.0f,
                    colliderPosA.Y + anchorA.Y + distVec.Y + lineNormal.Y * 5.0f,
                    colliderPosA.Z);
            }
            this.DrawLocalText(canvas, body,
                string.Format("{0:F1}", MathF.Clamp(dist, minDist, maxDist)),
                anchorA + distVec,
                Vector2.Zero,
                errorVec.Angle);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:55,代码来源:RigidBodyJointCamViewLayer.cs

示例3: DrawLocalPosConstraint

        private void DrawLocalPosConstraint(Canvas canvas, RigidBody bodyA, RigidBody bodyB, Vector2 anchorA, Vector2 anchorB)
        {
            Vector3 colliderPosA = bodyA.GameObj.Transform.Pos;
            Vector3 colliderPosB = bodyB.GameObj.Transform.Pos;

            ColorRgba clr = this.JointColor;
            ColorRgba clrErr = this.JointErrorColor;

            Vector2 anchorAToWorld = bodyA.GameObj.Transform.GetWorldVector(anchorA);
            Vector2 anchorBToWorld = bodyB.GameObj.Transform.GetWorldVector(anchorB);
            Vector2 errorVec = (colliderPosB.Xy + anchorBToWorld) - (colliderPosA.Xy + anchorAToWorld);

            bool hasError = errorVec.Length >= 1.0f;
            if (hasError)
            {
                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clrErr));
                canvas.DrawLine(
                    colliderPosA.X + anchorAToWorld.X,
                    colliderPosA.Y + anchorAToWorld.Y,
                    colliderPosA.Z,
                    colliderPosB.X + anchorBToWorld.X,
                    colliderPosB.Y + anchorBToWorld.Y,
                    colliderPosB.Z);
                this.DrawLocalText(canvas, bodyA,
                    string.Format("{0:F1}", errorVec.Length),
                    anchorAToWorld + errorVec * 0.5f,
                    new Vector2(0.5f, 0.0f),
                    errorVec.PerpendicularLeft.Angle);
            }

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                colliderPosA.X,
                colliderPosA.Y,
                colliderPosA.Z,
                colliderPosA.X + anchorAToWorld.X,
                colliderPosA.Y + anchorAToWorld.Y,
                colliderPosA.Z);
            canvas.DrawLine(
                colliderPosB.X,
                colliderPosB.Y,
                colliderPosB.Z,
                colliderPosB.X + anchorBToWorld.X,
                colliderPosB.Y + anchorBToWorld.Y,
                colliderPosB.Z);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:46,代码来源:RigidBodyJointCamViewLayer.cs

示例4: DrawWorldAxisConstraint

        private void DrawWorldAxisConstraint(Canvas canvas, RigidBody body, Vector2 worldAxis, Vector2 localAnchor, Vector2 worldAnchor, float min = 1, float max = -1)
        {
            Vector3 bodyPos = body.GameObj.Transform.Pos;
            worldAxis = worldAxis.Normalized;
            bool infinite = false;
            if (min > max)
            {
                min = -10000000.0f;
                max = 10000000.0f;
                infinite = true;
            }
            Vector2 anchorToWorld = body.GameObj.Transform.GetWorldVector(localAnchor);
            float axisVal = Vector2.Dot(bodyPos.Xy + anchorToWorld - worldAnchor, worldAxis);
            Vector2 basePos = MathF.PointLineNearestPoint(
                bodyPos.X + anchorToWorld.X,
                bodyPos.Y + anchorToWorld.Y,
                worldAnchor.X + worldAxis.X * min,
                worldAnchor.Y + worldAxis.Y * min,
                worldAnchor.X + worldAxis.X * max,
                worldAnchor.Y + worldAxis.Y * max,
                infinite);
            float errorVal = (bodyPos.Xy + anchorToWorld - basePos).Length;
            Vector2 errorVec = basePos - bodyPos.Xy;
            bool hasError = errorVal >= 1.0f;

            ColorRgba clr = this.JointColor;
            ColorRgba clrErr = this.JointErrorColor;

            if (hasError)
            {
                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clrErr));
                canvas.DrawLine(
                    bodyPos.X + anchorToWorld.X,
                    bodyPos.Y + anchorToWorld.Y,
                    bodyPos.Z,
                    basePos.X,
                    basePos.Y,
                    bodyPos.Z);
                this.DrawLocalText(canvas, body,
                    string.Format("{0:F1}", errorVal),
                    errorVec * 0.5f,
                    new Vector2(0.5f, 0.0f),
                    errorVec.PerpendicularLeft.Angle);
            }

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                worldAnchor.X + worldAxis.X * min,
                worldAnchor.Y + worldAxis.Y * min,
                bodyPos.Z,
                worldAnchor.X + worldAxis.X * max,
                worldAnchor.Y + worldAxis.Y * max,
                bodyPos.Z);
            if (!infinite)
            {
                canvas.DrawLine(
                    worldAnchor.X + worldAxis.X * min + worldAxis.PerpendicularLeft.X * 5.0f,
                    worldAnchor.Y + worldAxis.Y * min + worldAxis.PerpendicularLeft.Y * 5.0f,
                    bodyPos.Z,
                    worldAnchor.X + worldAxis.X * min + worldAxis.PerpendicularRight.X * 5.0f,
                    worldAnchor.Y + worldAxis.Y * min + worldAxis.PerpendicularRight.Y * 5.0f,
                    bodyPos.Z);
                canvas.DrawLine(
                    worldAnchor.X + worldAxis.X * max + worldAxis.PerpendicularLeft.X * 5.0f,
                    worldAnchor.Y + worldAxis.Y * max + worldAxis.PerpendicularLeft.Y * 5.0f,
                    bodyPos.Z,
                    worldAnchor.X + worldAxis.X * max + worldAxis.PerpendicularRight.X * 5.0f,
                    worldAnchor.Y + worldAxis.Y * max + worldAxis.PerpendicularRight.Y * 5.0f,
                    bodyPos.Z);
            }
        }
开发者ID:CKoewing,项目名称:duality,代码行数:71,代码来源:RigidBodyJointCamViewLayer.cs

示例5: DrawLockedAxes

        protected void DrawLockedAxes(Canvas canvas, float x, float y, float z, float r)
        {
            Vector3 refPos = canvas.DrawDevice.RefCoord;
            float nearZ = canvas.DrawDevice.NearZ;

            canvas.PushState();
            if (this.actionLockedAxis == ObjectEditorAxisLock.X)
            {
                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Solid, ColorRgba.Lerp(this.FgColor, ColorRgba.Red, 0.5f)));
                canvas.DrawLine(x - r, y, z, x + r, y, z);
            }
            if (this.actionLockedAxis == ObjectEditorAxisLock.Y)
            {
                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Solid, ColorRgba.Lerp(this.FgColor, ColorRgba.Green, 0.5f)));
                canvas.DrawLine(x, y - r, z, x, y + r, z);
            }
            if (this.actionLockedAxis == ObjectEditorAxisLock.Z)
            {
                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Solid, ColorRgba.Lerp(this.FgColor, ColorRgba.Blue, 0.5f)));
                canvas.DrawLine(x, y, MathF.Max(z - r, refPos.Z + nearZ + 10), x, y, z);
                canvas.DrawLine(x, y, z, x, y, z + r);
            }
            canvas.PopState();
        }
开发者ID:SirePi,项目名称:duality,代码行数:24,代码来源:ObjectEditorCamViewState.cs

示例6: DrawLocalAngleMotor

        private void DrawLocalAngleMotor(Canvas canvas, RigidBody body, Vector2 anchor, float speed, float maxTorque, float radius)
        {
            Vector3 bodyPos = body.GameObj.Transform.Pos;

            ColorRgba clr = this.MotorColor;

            float baseAngle = body.GameObj.Transform.Angle;
            float speedAngle = baseAngle + speed;
            float maxTorqueAngle = baseAngle + MathF.Sign(speed) * maxTorque * 0.01f;
            Vector2 anchorToWorld = body.GameObj.Transform.GetWorldVector(anchor);
            Vector2 arrowBase = anchorToWorld + Vector2.FromAngleLength(speedAngle, radius);
            Vector2 arrorA = Vector2.FromAngleLength(speedAngle - MathF.RadAngle45, MathF.Sign(speed) * radius * 0.05f);
            Vector2 arrorB = Vector2.FromAngleLength(speedAngle - MathF.RadAngle45 + MathF.RadAngle270, MathF.Sign(speed) * radius * 0.05f);

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawCircleSegment(
                bodyPos.X + anchorToWorld.X,
                bodyPos.Y + anchorToWorld.Y,
                bodyPos.Z,
                radius - 2,
                MathF.Sign(speed) >= 0 ? baseAngle : maxTorqueAngle,
                MathF.Sign(speed) >= 0 ? maxTorqueAngle : baseAngle);
            canvas.DrawCircleSegment(
                bodyPos.X + anchorToWorld.X,
                bodyPos.Y + anchorToWorld.Y,
                bodyPos.Z,
                radius + 2,
                MathF.Sign(speed) >= 0 ? baseAngle : maxTorqueAngle,
                MathF.Sign(speed) >= 0 ? maxTorqueAngle : baseAngle);
            canvas.DrawCircleSegment(
                bodyPos.X + anchorToWorld.X,
                bodyPos.Y + anchorToWorld.Y,
                bodyPos.Z,
                radius,
                MathF.Sign(speed) >= 0 ? baseAngle : speedAngle,
                MathF.Sign(speed) >= 0 ? speedAngle : baseAngle);
            canvas.DrawLine(
                bodyPos.X + arrowBase.X,
                bodyPos.Y + arrowBase.Y,
                bodyPos.Z,
                bodyPos.X + arrowBase.X + arrorA.X,
                bodyPos.Y + arrowBase.Y + arrorA.Y,
                bodyPos.Z);
            canvas.DrawLine(
                bodyPos.X + arrowBase.X,
                bodyPos.Y + arrowBase.Y,
                bodyPos.Z,
                bodyPos.X + arrowBase.X + arrorB.X,
                bodyPos.Y + arrowBase.Y + arrorB.Y,
                bodyPos.Z);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:51,代码来源:RigidBodyJointCamViewLayer.cs

示例7: OnCollectStateOverlayDrawcalls

		protected virtual void OnCollectStateOverlayDrawcalls(Canvas canvas)
		{
			// Gather general data
			Point cursorPos = this.PointToClient(Cursor.Position);

			// Update action text from hovered / selection / action object
			Vector2 actionTextPos = new Vector2(cursorPos.X + 30, cursorPos.Y + 10);
			this.actionText.SourceText = this.UpdateActionText(ref actionTextPos);

			// Collect the views overlay layer drawcalls
			this.CollectLayerOverlayDrawcalls(canvas);

			// Collect the states overlay drawcalls
			canvas.PushState();
			{
				// Draw camera movement indicators
				if (this.camAction != CameraAction.None)
				{
					canvas.PushState();
					canvas.State.ColorTint = ColorRgba.White.WithAlpha(0.5f);
					if (this.camAction == CameraAction.DragScene)
					{
						// Don't draw anything.
					}
					else if (this.camAction == CameraAction.RotateScene)
					{
						canvas.FillCircle(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, 3);
						canvas.DrawLine(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, cursorPos.X, this.camActionBeginLoc.Y);
					}
					else if (this.camAction == CameraAction.Move)
					{
						canvas.FillCircle(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, 3);
						canvas.DrawLine(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, cursorPos.X, cursorPos.Y);
					}
					else if (this.camAction == CameraAction.Rotate)
					{
						canvas.FillCircle(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, 3);
						canvas.DrawLine(this.camActionBeginLoc.X, this.camActionBeginLoc.Y, cursorPos.X, this.camActionBeginLoc.Y);
					}
					canvas.PopState();
				}
				
				// Normalize action text position
				if (this.actionText.Fonts != null && this.actionText.Fonts.Any(r => r.IsAvailable && r.Res.IsPixelGridAligned))
				{
					actionTextPos.X = MathF.Round(actionTextPos.X);
					actionTextPos.Y = MathF.Round(actionTextPos.Y);
				}

				// Draw current action text
				if (!this.actionText.IsEmpty)
				{
					canvas.DrawText(this.actionText, actionTextPos.X, actionTextPos.Y, drawBackground: true);
				}

				// Update / Draw current status text
				{
					this.statusText.SourceText = this.UpdateStatusText();
					if (!this.statusText.IsEmpty)
					{
						Vector2 statusTextSize = this.statusText.Size;
						canvas.DrawText(this.statusText, 10, this.ClientSize.Height - statusTextSize.Y - 10, drawBackground: true);
					}
				}
			}
			canvas.PopState();

			// Draw a focus indicator at the view border
			canvas.PushState();
			{
				ColorRgba focusColor = ColorRgba.Lerp(this.FgColor, this.BgColor, 0.25f).WithAlpha(255);
				ColorRgba noFocusColor = ColorRgba.Lerp(this.FgColor, this.BgColor, 0.75f).WithAlpha(255);
				canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Mask, this.Focused ? focusColor : noFocusColor));
				canvas.DrawRect(0, 0, this.ClientSize.Width, this.ClientSize.Height);
			}
			canvas.PopState();
		}
开发者ID:Scottyaim,项目名称:duality,代码行数:77,代码来源:CamViewState.cs

示例8: Canvas


//.........这里部分代码省略.........
				if (this.textReport == null || (Time.MainTimer - this.textReportLast).TotalMilliseconds > this.updateInterval)
				{
					string report = Profile.GetTextReport(counters, this.textReportOptions | ReportOptions.FormattedText);

					if (this.textReport == null)
					{
						this.textReport = new FormattedText();
						this.textReport.Fonts = new[] { Font.GenericMonospace8 };
					}
					this.textReport.MaxWidth = (int)textReportRect.W;
					this.textReport.SourceText = report;
					this.textReportLast = Time.MainTimer;
				}

				// Draw Report
				canvas.DrawTextBackground(textReport, textReportRect.X, textReportRect.Y);
				canvas.DrawText(textReport, ref textReportTextVert, ref textReportIconVert, textReportRect.X, textReportRect.Y);
			}

			// Counter Graphs
			if (anyGraph)
			{
				// Mark graph cache as unused
				foreach (GraphCacheEntry entry in this.graphCache.Values)
				{
					entry.WasUsed = false;
				}

				int space = 5;
				int graphY = (int)graphRect.Y;
				int graphH = MathF.Min((int)(graphRect.H / this.counterGraphs.Count) - space, (int)graphRect.W / 2);
				foreach (string counterName in this.counterGraphs)
				{
					ProfileCounter counter = Profile.GetCounter<ProfileCounter>(counterName);
					if (counter == null) return;

					// Create or retrieve graph cache entry
					GraphCacheEntry cache = null;
					if (!this.graphCache.TryGetValue(counterName, out cache))
					{
						cache = new GraphCacheEntry();
						cache.GraphValues = new float[ProfileCounter.ValueHistoryLen];
						cache.GraphColors = new ColorRgba[ProfileCounter.ValueHistoryLen];
						this.graphCache[counterName] = cache;
					}
					cache.WasUsed = true;

					float cursorRatio = 0.0f;
					if (counter is TimeCounter)
					{
						TimeCounter timeCounter = counter as TimeCounter;
						for (int i = 0; i < ProfileCounter.ValueHistoryLen; i++)
						{
							float factor = timeCounter.ValueGraph[i] / Time.MsPFMult;
							cache.GraphValues[i] = factor * 0.75f;
							cache.GraphColors[i] = ColorRgba.Lerp(ColorRgba.White, ColorRgba.Red, factor);
						}
						canvas.CurrentState.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
						canvas.FillRect(graphRect.X, graphY, graphRect.W, graphH);
						canvas.CurrentState.ColorTint = ColorRgba.White;
						canvas.DrawHorizontalGraph(cache.GraphValues, cache.GraphColors, ref cache.VertGraph, graphRect.X, graphY, graphRect.W, graphH);
						cursorRatio = (float)timeCounter.ValueGraphCursor / (float)ProfileCounter.ValueHistoryLen;
					}
					else if (counter is StatCounter)
					{
						StatCounter statCounter = counter as StatCounter;
						for (int i = 0; i < ProfileCounter.ValueHistoryLen; i++)
						{
							cache.GraphValues[i] = (float)(statCounter.ValueGraph[i] - statCounter.MinValue) / statCounter.MaxValue;
							cache.GraphColors[i] = ColorRgba.White;
						}
						canvas.CurrentState.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
						canvas.FillRect(graphRect.X, graphY, graphRect.W, graphH);
						canvas.CurrentState.ColorTint = ColorRgba.White;
						canvas.DrawHorizontalGraph(cache.GraphValues, cache.GraphColors, ref cache.VertGraph, graphRect.X, graphY, graphRect.W, graphH);
						cursorRatio = (float)statCounter.ValueGraphCursor / (float)ProfileCounter.ValueHistoryLen;
					}
					
					canvas.DrawText(new string[] { counter.FullName }, ref cache.VertText, graphRect.X, graphY);
					canvas.DrawLine(graphRect.X + graphRect.W * cursorRatio, graphY, graphRect.X + graphRect.W * cursorRatio, graphY + graphH);

					graphY += graphH + space;
				}

				// Remove unused graph cache entries
				foreach (var pair in this.graphCache.ToArray())
				{
					if (!pair.Value.WasUsed)
					{
						pair.Value.GraphColors = null;
						pair.Value.GraphValues = null;
						pair.Value.VertGraph = null;
						pair.Value.VertText = null;
						this.graphCache.Remove(pair.Key);
					}
				}
			}

			Profile.EndMeasure(@"ProfileRenderer");
		}
开发者ID:KETMGaming,项目名称:duality,代码行数:101,代码来源:ProfileRenderer.cs

示例9: OnRender

        public override void OnRender(Canvas c)
        {
            _box.X = _client_area.X;
            _box.Y = _client_area.Y;
            _box.Width = _client_area.Width / 4;
            _box.Height = _client_area.Height;

            c.DrawRect(_box, Color.Yellow);
            c.DrawLine(Color.Yellow, 1, _box.X, _box.Y, _box.Right, _box.Bottom);
            c.DrawLine(Color.Yellow, 1, _box.Right, _box.Top, _box.Left, _box.Bottom);       
        }
开发者ID:wshanshan,项目名称:DDD,代码行数:11,代码来源:PanelCheckbox.cs

示例10: OnCollectWorldOverlayDrawcalls


//.........这里部分代码省略.........
                        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
                        if (fillShape)
                        {
                            VertexC1P3T2[] fillVertices = drawVertices.Clone() as VertexC1P3T2[];
                            for (int i = 0; i < fillVertices.Length; i++)
                                fillVertices[i].Color = vertexFillColor;
                            canvas.DrawVertices(fillVertices, VertexMode.TriangleFan);
                        }

                        // Draw the outline
                        canvas.DrawVertices(drawVertices, shape is ChainShapeInfo ? VertexMode.LineStrip : VertexMode.LineLoop);
                    }

                    // Draw shape index
                    if (body == selectedBody)
                    {
                        string indexText = index.ToString();
                        Vector2 textSize = textFont.MeasureText(indexText);
                        canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, fontClr.WithAlpha((shapeAlpha + 1.0f) * 0.5f)));
                        canvas.DrawText(indexText,
                            objPos.X + center.X,
                            objPos.Y + center.Y,
                            objPos.Z);
                    }

                    index++;
                }

                // Draw center of mass
                if (body.BodyType == BodyType.Dynamic)
                {
                    Vector2 localMassCenter = body.LocalMassCenter;
                    MathF.TransformCoord(ref localMassCenter.X, ref localMassCenter.Y, objAngle, objScale);
                    canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, this.MassCenterColor.WithAlpha(colliderAlpha)));
                    canvas.DrawLine(
                        objPos.X + localMassCenter.X - 5.0f,
                        objPos.Y + localMassCenter.Y,
                        objPos.Z,
                        objPos.X + localMassCenter.X + 5.0f,
                        objPos.Y + localMassCenter.Y,
                        objPos.Z);
                    canvas.DrawLine(
                        objPos.X + localMassCenter.X,
                        objPos.Y + localMassCenter.Y - 5.0f,
                        objPos.Z,
                        objPos.X + localMassCenter.X,
                        objPos.Y + localMassCenter.Y + 5.0f,
                        objPos.Z);
                }
            }
        }
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:101,代码来源:RigidBodyShapeCamViewLayer.cs

示例11: 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

示例12: DrawEditBox

        private void DrawEditBox(Canvas c)
        {
            _editbox_viewport.X = _client_area.X;
            //_editbox_viewport.Y = _caption_area.Bottom + 1;
            _editbox_viewport.Y = _editbox_rect.Y;

            _editbox_viewport.Width = _text_area.Width;
            _editbox_viewport.Height = _input_buffer_rect.Height;

            Viewport v = c.Viewport;
            c.Viewport = _editbox_viewport;
            DrawInputBuffer(_editbox_rect);
            c.DrawLine(BorderColor, 1, _editbox_rect.X,  _editbox_rect.Bottom-1, _editbox_rect.Right, _editbox_rect.Bottom-1);
            c.Viewport = v;

        }
开发者ID:wshanshan,项目名称:DDD,代码行数:16,代码来源:PanelTextRegion.cs

示例13: 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();
        }
开发者ID:SirePi,项目名称:duality,代码行数:57,代码来源:ObjectEditorCamViewState.cs

示例14: DrawWorldPosConstraint

        private void DrawWorldPosConstraint(Canvas canvas, RigidBody body, Vector2 localAnchor, Vector2 worldAnchor)
        {
            Vector3 bodyPos = body.GameObj.Transform.Pos;

            ColorRgba clr = this.JointColor;
            ColorRgba clrErr = this.JointErrorColor;

            float angularCircleRadA = body.BoundRadius * 0.25f;
            float markerCircleRad = body.BoundRadius * 0.02f;
            Vector2 anchorAToWorld = body.GameObj.Transform.GetWorldVector(localAnchor);
            Vector2 errorVec = worldAnchor - (bodyPos.Xy + anchorAToWorld);

            bool hasError = errorVec.Length >= 1.0f;
            if (hasError)
            {
                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clrErr));
                canvas.DrawLine(
                    bodyPos.X + anchorAToWorld.X,
                    bodyPos.Y + anchorAToWorld.Y,
                    bodyPos.Z,
                    worldAnchor.X,
                    worldAnchor.Y,
                    bodyPos.Z);
                this.DrawLocalText(canvas, body,
                    string.Format("{0:F1}", errorVec.Length),
                    anchorAToWorld + errorVec * 0.5f,
                    new Vector2(0.5f, 0.0f),
                    errorVec.PerpendicularLeft.Angle);
            }

            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                bodyPos.X,
                bodyPos.Y,
                bodyPos.Z,
                bodyPos.X + anchorAToWorld.X,
                bodyPos.Y + anchorAToWorld.Y,
                bodyPos.Z);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:39,代码来源:RigidBodyJointCamViewLayer.cs

示例15: DrawLocalAngleConstraint

        private void DrawLocalAngleConstraint(Canvas canvas, RigidBody body, Vector2 anchor, float targetAngle, float currentAngle, float radius)
        {
            Vector3 bodyPos = body.GameObj.Transform.Pos;

            ColorRgba clr = this.JointColor;
            ColorRgba clrErr = this.JointErrorColor;

            Vector2 anchorToWorld = body.GameObj.Transform.GetWorldVector(anchor);
            Vector2 angleVec = Vector2.FromAngleLength(targetAngle, radius);
            Vector2 errorVec = Vector2.FromAngleLength(currentAngle, radius);
            bool hasError = MathF.CircularDist(targetAngle, currentAngle) >= MathF.RadAngle1;

            if (hasError)
            {
                float circleBegin = currentAngle;
                float circleEnd = targetAngle;
                if (MathF.TurnDir(circleBegin, circleEnd) < 0)
                {
                    MathF.Swap(ref circleBegin, ref circleEnd);
                    circleEnd = circleBegin + MathF.CircularDist(circleBegin, circleEnd);
                }

                canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clrErr));
                canvas.DrawLine(
                    bodyPos.X + anchorToWorld.X,
                    bodyPos.Y + anchorToWorld.Y,
                    bodyPos.Z,
                    bodyPos.X + anchorToWorld.X + errorVec.X,
                    bodyPos.Y + anchorToWorld.Y + errorVec.Y,
                    bodyPos.Z);
                canvas.DrawCircleSegment(
                    bodyPos.X + anchorToWorld.X,
                    bodyPos.Y + anchorToWorld.Y,
                    bodyPos.Z,
                    radius,
                    circleBegin,
                    circleEnd);
                this.DrawLocalText(canvas, body,
                    string.Format("{0:F0}°", MathF.RadToDeg(MathF.NormalizeAngle(currentAngle))),
                    anchorToWorld + errorVec,
                    Vector2.UnitY,
                    errorVec.Angle);
            }
            canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, clr));
            canvas.DrawLine(
                bodyPos.X + anchorToWorld.X,
                bodyPos.Y + anchorToWorld.Y,
                bodyPos.Z,
                bodyPos.X + anchorToWorld.X + angleVec.X,
                bodyPos.Y + anchorToWorld.Y + angleVec.Y,
                bodyPos.Z);
            this.DrawLocalText(canvas, body,
                string.Format("{0:F0}°", MathF.RadToDeg(MathF.NormalizeAngle(targetAngle))),
                anchorToWorld + angleVec,
                angleVec.Angle);
        }
开发者ID:CKoewing,项目名称:duality,代码行数:56,代码来源:RigidBodyJointCamViewLayer.cs


注:本文中的Canvas.DrawLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。