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


C# Canvas.PushState方法代码示例

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


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

示例1: Canvas

        void ICmpRenderer.Draw(IDrawDevice device)
        {
            if (device.VisibilityMask.HasFlag(VisibilityFlag.ScreenOverlay))
            {
                Canvas target = new Canvas(device, this.vertexBufferScreen);
                target.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White));
                foreach (VisualLog log in VisualLog.All)
                {
                    if (!log.Visible) continue;
                    if (log.BaseColor.A == 0) continue;
                    if ((log.VisibilityGroup & device.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None) continue;

                    target.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, log.BaseColor));
                    foreach (VisualLogEntry logEntry in log.Entries)
                    {
                        if (logEntry.Anchor != VisualLogAnchor.Screen) continue;
                        target.PushState();
                        if (logEntry.LifetimeAsAlpha)
                            target.State.ColorTint = new ColorRgba(1.0f, logEntry.LifetimeRatio);
                        else
                            target.State.ColorTint = ColorRgba.White;
                        logEntry.Draw(target);
                        target.PopState();
                    }
                }
            }
            else
            {
                Canvas target = new Canvas(device, this.vertexBufferWorld);
                target.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White));
                target.State.ZOffset = -1;
                foreach (VisualLog log in VisualLog.All)
                {
                    if (!log.Visible) continue;
                    if (log.BaseColor.A == 0) continue;
                    if ((log.VisibilityGroup & device.VisibilityMask & VisibilityFlag.AllGroups) == VisibilityFlag.None) continue;

                    target.State.SetMaterial(new BatchInfo(DrawTechnique.Alpha, log.BaseColor));
                    foreach (VisualLogEntry logEntry in log.Entries)
                    {
                        if (logEntry.Anchor == VisualLogAnchor.Screen) continue;
                        target.PushState();
                        target.State.ZOffset += logEntry.DepthOffset;
                        target.State.ColorTint = new ColorRgba(1.0f, logEntry.LifetimeRatio);
                        if (logEntry.Anchor == VisualLogAnchor.Object && logEntry.AnchorObj != null && logEntry.AnchorObj.Transform != null)
                        {
                            Transform anchorTransform = logEntry.AnchorObj.Transform;
                            logEntry.Draw(target, anchorTransform.Pos, anchorTransform.Angle, anchorTransform.Scale);
                        }
                        else
                        {
                            logEntry.Draw(target);
                        }
                        target.PopState();
                    }
                }
            }
        }
开发者ID:SirePi,项目名称:duality,代码行数:58,代码来源:VisualLogRenderer.cs

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

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

示例4: CollectLayerBackgroundDrawcalls

		protected void CollectLayerBackgroundDrawcalls(Canvas canvas)
		{
			var layers = this.View.ActiveLayers.ToArray();
			layers.StableSort((a, b) => a.Priority - b.Priority);
			foreach (var layer in layers)
			{
				canvas.PushState();
				layer.OnCollectBackgroundDrawcalls(canvas);
				canvas.PopState();
			}
		}
开发者ID:Scottyaim,项目名称:duality,代码行数:11,代码来源:CamViewState.cs

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

示例6: Canvas

		void ICmpRenderer.Draw(IDrawDevice device)
		{
			// Create a buffer to cache and re-use vertices. Not required, but will boost performance.
			if (this.buffer == null) this.buffer = new CanvasBuffer();

			// Create a Canvas to auto-generate vertices from high-level drawing commands.
			Canvas canvas = new Canvas(device, this.buffer);
			canvas.State.TextFont = this.font;

			// If the game is over or won, display "game over" screen
			if (this.gameOver || this.gameWin)
			{
				// Various animation timing variables.
				float animOffset = this.gameWin ? 0.0f : 2500.0f;
				float animTime = this.gameWin ? 10000.0f : 4500.0f;
				float blendDurationRatio = this.gameWin ? 0.6f : 0.5f;
				float textOffsetRatio = this.gameWin ? 0.2f : 0.0f;

				float timeSinceGameOver = (float)Time.MainTimer.TotalMilliseconds - this.lastTimeAnyAlive;
				float gameOverAnimProgress = MathF.Clamp((timeSinceGameOver - animOffset) / animTime, 0.0f, 1.0f);
				float controlInfoAnimProgress = MathF.Clamp(((timeSinceGameOver - animOffset) - animTime - 2000.0f) / 2000.0f, 0.0f, 1.0f);
				float blendAnimProgress = MathF.Clamp(gameOverAnimProgress / blendDurationRatio, 0.0f, 1.0f);
				float textAnimProgress = MathF.Clamp((gameOverAnimProgress - blendDurationRatio - textOffsetRatio) / (1.0f - blendDurationRatio - textOffsetRatio), 0.0f, 1.0f);

				if (this.blendMaterial != null && blendAnimProgress > 0.0f)
				{
					canvas.PushState();

					if (this.gameOver)
					{
						// Set up our special blending Material and specify the threshold to blend to
						this.blendMaterial.SetUniform("threshold", 1.0f - blendAnimProgress);
						canvas.State.SetMaterial(this.blendMaterial);
						canvas.State.ColorTint = ColorRgba.Black;

						// Specify a texture coordinate rect so it spans the entire screen repeating itself, instead of being stretched
						if (this.blendMaterial.MainTexture != null)
						{
							Random rnd = new Random((int)this.lastTimeAnyAlive);
							Vector2 randomTranslate = rnd.NextVector2(0.0f, 0.0f, canvas.State.TextureBaseSize.X, canvas.State.TextureBaseSize.Y);
							canvas.State.TextureCoordinateRect = new Rect(
								randomTranslate.X, 
								randomTranslate.Y, 
								device.TargetSize.X / canvas.State.TextureBaseSize.X, 
								device.TargetSize.Y / canvas.State.TextureBaseSize.Y);
						}
					}
					else
					{
						// If we won, simply fade to white
						canvas.State.SetMaterial(new BatchInfo(DrawTechnique.Add, ColorRgba.White));
						canvas.State.ColorTint = ColorRgba.White.WithAlpha(blendAnimProgress);
					}

					// Fill the screen with a rect of our Material
					canvas.FillRect(0, 0, device.TargetSize.X, device.TargetSize.Y);

					canvas.PopState();
				}

				if (this.font != null && textAnimProgress > 0.0f)
				{
					canvas.PushState();

					// Determine which text to draw to screen and where to draw it
					string gameOverText = this.gameWin ? "is it over..?" : "darkness...";
					Vector2 fullTextSize = canvas.MeasureText(gameOverText);
					Vector2 textPos = device.TargetSize * 0.5f - fullTextSize * 0.5f;
					gameOverText = gameOverText.Substring(0, MathF.RoundToInt(gameOverText.Length * textAnimProgress));

					// Make sure not to draw inbetween pixels, so the text is perfectly sharp.
					textPos.X = MathF.Round(textPos.X);
					textPos.Y = MathF.Round(textPos.Y);

					// Draw the text to screen
					canvas.State.ColorTint = this.gameWin ? ColorRgba.Black : ColorRgba.White;
					canvas.DrawText(gameOverText, textPos.X, textPos.Y);

					canvas.PopState();
				}

				if (controlInfoAnimProgress > 0.0f)
				{
					Vector2 infoBasePos = device.TargetSize * 0.5f + new Vector2(0.0f, device.TargetSize.Y * 0.25f);
					if (this.controlInfoMouseKeyboard != null)
					{
						canvas.PushState();

						Vector2 texSize = this.controlInfoMouseKeyboard.Res.MainTexture.Res.Size * 0.5f;

						canvas.State.SetMaterial(this.controlInfoMouseKeyboard);
						canvas.State.ColorTint = ColorRgba.White.WithAlpha(controlInfoAnimProgress);
						canvas.FillRect(
							infoBasePos.X - texSize.X * 0.5f,
							infoBasePos.Y - texSize.Y - 10,
							texSize.X,
							texSize.Y);

						canvas.PopState();
					}
//.........这里部分代码省略.........
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:101,代码来源:GameOverScreen.cs

示例7: DrawTileHighlights

        private static void DrawTileHighlights(Canvas canvas, ICmpTilemapRenderer renderer, Point2 origin, IReadOnlyGrid<bool> highlight, ColorRgba fillTint, ColorRgba outlineTint, TileHighlightMode mode, List<Vector2[]> outlineCache = null)
        {
            if (highlight.Width == 0 || highlight.Height == 0) return;

            // Generate strippled line texture if not available yet
            if (strippledLineTex == null)
            {
                PixelData pixels = new PixelData(8, 1);
                for (int i = 0; i < pixels.Width / 2; i++)
                    pixels[i, 0] = ColorRgba.White;
                for (int i = pixels.Width / 2; i < pixels.Width; i++)
                    pixels[i, 0] = ColorRgba.TransparentWhite;

                using (Pixmap pixmap = new Pixmap(pixels))
                {
                    strippledLineTex = new Texture(pixmap,
                        TextureSizeMode.Default,
                        TextureMagFilter.Nearest,
                        TextureMinFilter.Nearest,
                        TextureWrapMode.Repeat,
                        TextureWrapMode.Repeat,
                        TexturePixelFormat.Rgba);
                }
            }

            BatchInfo defaultMaterial = new BatchInfo(DrawTechnique.Alpha, canvas.State.Material.MainColor);
            BatchInfo strippleMaterial = new BatchInfo(DrawTechnique.Alpha, canvas.State.Material.MainColor, strippledLineTex);
            bool uncertain = (mode & TileHighlightMode.Uncertain) != 0;
            bool selection = (mode & TileHighlightMode.Selection) != 0;

            Component component = renderer as Component;
            Transform transform = component.GameObj.Transform;
            Tilemap tilemap = renderer.ActiveTilemap;
            Tileset tileset = tilemap != null ? tilemap.Tileset.Res : null;
            Vector2 tileSize = tileset != null ? tileset.TileSize : Tileset.DefaultTileSize;
            Rect localRect = renderer.LocalTilemapRect;

            // Determine the object's local coordinate system (rotated, scaled) in world space
            Vector2 worldAxisX = Vector2.UnitX;
            Vector2 worldAxisY = Vector2.UnitY;
            MathF.TransformCoord(ref worldAxisX.X, ref worldAxisX.Y, transform.Angle, transform.Scale);
            MathF.TransformCoord(ref worldAxisY.X, ref worldAxisY.Y, transform.Angle, transform.Scale);

            Vector2 localOriginPos = tileSize * origin;
            Vector2 worldOriginPos = localOriginPos.X * worldAxisX + localOriginPos.Y * worldAxisY;

            canvas.PushState();
            {
                // Configure the canvas so our shapes are properly rotated and scaled
                canvas.State.TransformHandle = -localRect.TopLeft;
                canvas.State.TransformAngle = transform.Angle;
                canvas.State.TransformScale = new Vector2(transform.Scale);

                // Fill all highlighted tiles that are currently visible
                {
                    canvas.State.SetMaterial(defaultMaterial);
                    canvas.State.ColorTint = fillTint * ColorRgba.White.WithAlpha(selection ? 0.2f : 0.375f);

                    // Determine tile visibility
                    Vector2 worldTilemapOriginPos = localRect.TopLeft;
                    MathF.TransformCoord(ref worldTilemapOriginPos.X, ref worldTilemapOriginPos.Y, transform.Angle, transform.Scale);
                    TilemapCulling.TileInput cullingIn = new TilemapCulling.TileInput
                    {
                        // Remember: All these transform values are in world space
                        TilemapPos = transform.Pos + new Vector3(worldTilemapOriginPos) + new Vector3(worldOriginPos),
                        TilemapScale = transform.Scale,
                        TilemapAngle = transform.Angle,
                        TileCount = new Point2(highlight.Width, highlight.Height),
                        TileSize = tileSize
                    };
                    TilemapCulling.TileOutput cullingOut = TilemapCulling.GetVisibleTileRect(canvas.DrawDevice, cullingIn);
                    int renderedTileCount = cullingOut.VisibleTileCount.X * cullingOut.VisibleTileCount.Y;

                    // Draw all visible highlighted tiles
                    {
                        Point2 tileGridPos = cullingOut.VisibleTileStart;
                        Vector2 renderStartPos = worldOriginPos + tileGridPos.X * tileSize.X * worldAxisX + tileGridPos.Y * tileSize.Y * worldAxisY;;
                        Vector2 renderPos = renderStartPos;
                        Vector2 tileXStep = worldAxisX * tileSize.X;
                        Vector2 tileYStep = worldAxisY * tileSize.Y;
                        int lineMergeCount = 0;
                        int totalRects = 0;
                        for (int tileIndex = 0; tileIndex < renderedTileCount; tileIndex++)
                        {
                            bool current = highlight[tileGridPos.X, tileGridPos.Y];
                            if (current)
                            {
                                // Try to merge consecutive rects in the same line to reduce drawcalls / CPU load
                                bool hasNext = (tileGridPos.X + 1 < highlight.Width) && ((tileGridPos.X + 1 - cullingOut.VisibleTileStart.X) < cullingOut.VisibleTileCount.X);
                                bool next = hasNext ? highlight[tileGridPos.X + 1, tileGridPos.Y] : false;
                                if (next)
                                {
                                    lineMergeCount++;
                                }
                                else
                                {
                                    totalRects++;
                                    canvas.FillRect(
                                        transform.Pos.X + renderPos.X - lineMergeCount * tileXStep.X,
                                        transform.Pos.Y + renderPos.Y - lineMergeCount * tileXStep.Y,
//.........这里部分代码省略.........
开发者ID:SirePi,项目名称:duality,代码行数:101,代码来源:TilemapEditorCamViewState.cs

示例8: DrawShapeOutline

 private void DrawShapeOutline(Canvas canvas, Transform transform, ShapeInfo shape)
 {
     canvas.PushState();
     if		(shape is CircleShapeInfo)	this.DrawShapeOutline(canvas, transform, shape as CircleShapeInfo);
     else if (shape is PolyShapeInfo)	this.DrawShapeOutline(canvas, transform, shape as PolyShapeInfo);
     else if (shape is LoopShapeInfo)	this.DrawShapeOutline(canvas, transform, shape as LoopShapeInfo);
     canvas.PopState();
 }
开发者ID:ninja2003,项目名称:duality,代码行数:8,代码来源:RigidBodyRenderer.cs

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

示例10: DrawShapeArea

 private void DrawShapeArea(Canvas canvas, Transform transform, ShapeInfo shape)
 {
     canvas.PushState();
     if      (shape is CircleShapeInfo)                         this.DrawShapeArea(canvas, transform, shape as CircleShapeInfo);
     else if (shape is PolyShapeInfo)                           this.DrawShapeArea(canvas, transform, (shape as PolyShapeInfo).Vertices);
     else if (shape is LoopShapeInfo && this.fillHollowShapes)  this.DrawShapeArea(canvas, transform, (shape as LoopShapeInfo).Vertices);
     else if (shape is ChainShapeInfo && this.fillHollowShapes) this.DrawShapeArea(canvas, transform, (shape as ChainShapeInfo).Vertices);
     canvas.PopState();
 }
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:9,代码来源:RigidBodyRenderer.cs

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

示例12: OnCollectStateOverlayDrawcalls

        protected override void OnCollectStateOverlayDrawcalls(Canvas canvas)
        {
            base.OnCollectStateOverlayDrawcalls(canvas);

            Point cursorPos = this.PointToClient(Cursor.Position);
            canvas.PushState();
            {
                // Draw rect selection
                if (this.action == ObjectEditorAction.RectSelect)
                    canvas.DrawRect(this.actionBeginLoc.X, this.actionBeginLoc.Y, cursorPos.X - this.actionBeginLoc.X, cursorPos.Y - this.actionBeginLoc.Y);
            }
            canvas.PopState();
        }
开发者ID:SirePi,项目名称:duality,代码行数:13,代码来源:ObjectEditorCamViewState.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: 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


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