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


C# Canvas.MeasureText方法代码示例

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


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

示例1: Draw

 public override void Draw(Canvas canvas)
 {
     this.W = (int)canvas.MeasureText(character.ToString()).X;
     this.H = (int)canvas.MeasureText(character.ToString()).Y;
     if (character != '\t' && character != '\n' && character != '\0')
     {
         canvas.State.ColorTint = Theme.ForegroundColour;
         canvas.DrawText(character.ToString(), X, Y);
     }
 }
开发者ID:generatives,项目名称:Magic-Game,代码行数:10,代码来源:ComplexCharacter.cs

示例2: RenderForeground

        protected override void RenderForeground(Canvas canvas)
        {
            var text = "Enter address:";
            var style = new Font(30, new Color(0.5f, 0.5f, 0.5f));
            canvas.Print(
                style,
                0.5f * (canvas.Width - canvas.MeasureText(style, text)),
                canvas.Height * 0.5f - 15 - 40,
                text);

            text = _address + "_";
            style = new Font(30, new Color(1, 1, 1));
            canvas.Print(
                style,
                0.5f * (canvas.Width - canvas.MeasureText(style, text)),
                canvas.Height * 0.5f - 15 + 40,
                text);
        }
开发者ID:AndiAngerer,项目名称:cubehack,代码行数:18,代码来源:ConnectScreen.cs

示例3: RenderForeground

 protected override void RenderForeground(Canvas canvas)
 {
     if (_connectionManager.IsConnecting)
     {
         var status = "Connecting...";
         var style = new Font(30, new Color(1, 1, 1)) { Animation = FontAnimation.Wave };
         canvas.Print(
             style,
             0.5f * (canvas.Width - canvas.MeasureText(style, status)),
             canvas.Height * 0.5f - 15,
             status);
     }
 }
开发者ID:AndiAngerer,项目名称:cubehack,代码行数:13,代码来源:OutOfGameMenu.cs

示例4: LayoutText

        private void LayoutText(Canvas canvas)
        {
            textNeedsLayout = false;
            int yOffset = 0;
            int longestXOffset = 0;
            for(int line = 0; line < characters.Length; line++)
            {
                int xOffset = 0;
                for(int offset = 0; offset < characters[line].Length; offset++)
                {
                    ComplexCharacter cChar = characters[line][offset];
                    cChar.OffsetX = xOffset;
                    cChar.OffsetY = yOffset;

                    if (cChar.Character == '\t')
                    {
                        xOffset += (int)(canvas.MeasureText("    ").X);
                    }
                    else
                    {
                        xOffset += (int)(canvas.MeasureText(cChar.Character.ToString()).X);
                    }

                    if (xOffset > longestXOffset)
                    {
                        longestXOffset = xOffset;
                    }
                }
                if (xOffset > longestXOffset)
                {
                    longestXOffset = xOffset;
                }
                yOffset += (int)(canvas.MeasureText("W").Y);
            }
            this.H = yOffset;
            this.W = longestXOffset;
        }
开发者ID:generatives,项目名称:Magic-Game,代码行数:37,代码来源:Text.cs

示例5: Draw

 public override void Draw(Canvas canvas)
 {
     text.Draw(canvas);
     Vector2 realCaretPosition = text.getPositionFromCaret(caretPosition);
     Vector2 characterSize = canvas.MeasureText("A");
     canvas.State.ColorTint = Theme.ForegroundColour;
     canvas.DrawRect(X, Y, W, H);
     canvas.FillRect(realCaretPosition.X, realCaretPosition.Y, characterSize.X, characterSize.Y);
 }
开发者ID:generatives,项目名称:Magic-Game,代码行数:9,代码来源:TextBox.cs

示例6: DrawLocalText

        private void DrawLocalText(Canvas canvas, RigidBody body, string text, Vector2 pos, Vector2 handle, float baseAngle)
        {
            Vector3 bodyPos = body.GameObj.Transform.Pos;
            Vector2 textSize = canvas.MeasureText(text);
            bool flipText = MathF.TurnDir(baseAngle - canvas.DrawDevice.RefAngle, MathF.RadAngle90) < 0;
            baseAngle = MathF.NormalizeAngle(flipText ? baseAngle + MathF.RadAngle180 : baseAngle);

            handle *= textSize;
            if (flipText) handle = textSize - handle;

            canvas.State.TransformHandle = handle;
            canvas.State.TransformAngle = baseAngle;
            canvas.DrawText(text,
                bodyPos.X + pos.X,
                bodyPos.Y + pos.Y,
                bodyPos.Z);
            canvas.State.TransformAngle = 0.0f;
            canvas.State.TransformHandle = Vector2.Zero;
        }
开发者ID:CKoewing,项目名称:duality,代码行数:19,代码来源:RigidBodyJointCamViewLayer.cs

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

示例8: 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.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White));
			canvas.State.TextFont = this.font;

			// Retrieve players
			if (this.playerOne == null)
				this.playerOne = Scene.Current.FindComponents<Player>().Where(p => p.Id == PlayerId.PlayerOne).FirstOrDefault();
			if (this.playerTwo == null)
				this.playerTwo = Scene.Current.FindComponents<Player>().Where(p => p.Id == PlayerId.PlayerTwo).FirstOrDefault();

			// Is someone playing using mouse / keyboard? Display a mouse cursor then
			if (Player.AlivePlayers.Any(p => p.InputMethod == InputMethod.MouseAndKeyboard))
			{
				canvas.FillCircle(DualityApp.Mouse.X, DualityApp.Mouse.Y, 2.0f);
			}

			// Is any player alive? Keep that value in mind, won't change here anyway.
			bool isAnyPlayerAlive = Player.IsAnyPlayerAlive;

			// Draw health and info of player one
			if (this.IsPlayerActive(this.playerOne))
			{
				Ship playerShip = this.playerOne.ControlObject;

				if (playerShip.Active)
				{
					// Draw a health bar when alive
					float health = playerShip.Hitpoints;

					canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
					canvas.FillRect(12 - 1, device.TargetSize.Y - 10 - 198 - 1, 16 + 2, 196 + 2);

					canvas.State.ColorTint = this.playerOne.Color;
					canvas.DrawRect(10, device.TargetSize.Y - 10 - 200, 20, 200);
					canvas.FillRect(12, device.TargetSize.Y - 10 - health * 198.0f, 16, health * 196.0f);
				}
				else if (isAnyPlayerAlive && !this.playerOne.HasReachedGoal)
				{
					// Draw a respawn timer when dead
					float respawnPercentage = this.playerOne.RespawnTime / Player.RespawnDelay;
					string respawnText = string.Format("Respawn in {0:F1}", (Player.RespawnDelay - this.playerOne.RespawnTime) / 1000.0f);
					Vector2 textSize = canvas.MeasureText(string.Format("Respawn in {0:F1}", 0.0f));

					canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
					canvas.FillRect(10 - 1, device.TargetSize.Y - 10 - textSize.Y - 2, textSize.X + 5, textSize.Y + 8);

					canvas.State.ColorTint = this.playerOne.Color;
					canvas.DrawText(respawnText, 10, device.TargetSize.Y - 10, 0.0f, Alignment.BottomLeft);
					canvas.FillRect(10, device.TargetSize.Y - 10 - textSize.Y, textSize.X * respawnPercentage, 3);
					canvas.FillRect(10, device.TargetSize.Y - 10, textSize.X * respawnPercentage, 3);
				}
			}

			// Draw health and info of player two
			if (this.IsPlayerActive(this.playerTwo))
			{
				Ship playerShip = this.playerTwo.ControlObject;

				if (playerShip.Active)
				{
					// Draw a health bar when alive
					float health = playerShip.Hitpoints;

					canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
					canvas.FillRect(device.TargetSize.X - 12 - 16 - 1, device.TargetSize.Y - 10 - 198 - 1, 16 + 2, 196 + 2);

					canvas.State.ColorTint = this.playerTwo.Color;
					canvas.DrawRect(device.TargetSize.X - 10 - 20, device.TargetSize.Y - 10 - 200, 20, 200);
					canvas.FillRect(device.TargetSize.X - 12 - 16, device.TargetSize.Y - 10 - health * 198.0f, 16, health * 196.0f);
				}
				else if (isAnyPlayerAlive && !this.playerTwo.HasReachedGoal)
				{
					// Draw a respawn timer when dead
					float respawnPercentage = this.playerTwo.RespawnTime / Player.RespawnDelay;
					string respawnText = string.Format("{0:F1} to Respawn", (Player.RespawnDelay - this.playerTwo.RespawnTime) / 1000.0f);
					Vector2 textSize = canvas.MeasureText(string.Format("{0:F1} to Respawn", 0.0f));

					canvas.State.ColorTint = ColorRgba.Black.WithAlpha(0.5f);
					canvas.FillRect(device.TargetSize.X - 10 - textSize.X - 3, device.TargetSize.Y - 10 - textSize.Y - 2, textSize.X + 2, textSize.Y + 10);

					canvas.State.ColorTint = this.playerTwo.Color;
					canvas.DrawText(respawnText, device.TargetSize.X - 10, device.TargetSize.Y - 10, 0.0f, Alignment.BottomRight);
					canvas.FillRect(device.TargetSize.X - 10 - textSize.X * respawnPercentage, device.TargetSize.Y - 10 - textSize.Y, textSize.X * respawnPercentage, 3);
					canvas.FillRect(device.TargetSize.X - 10 - textSize.X * respawnPercentage, device.TargetSize.Y - 10, textSize.X * respawnPercentage, 3);
				}
			}
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:93,代码来源:HeadUpDisplay.cs

示例9: RenderForeground

        protected override void RenderForeground(Canvas canvas)
        {
            var left = Left?.Value ?? 0;
            var top = Top?.Value ?? 0;
            var text = Text?.Value;

            var style = new Font(_fonstSize);

            style.Color = new Color(0, 0, 0, 0.5f);
            canvas.Print(style, left + _shadowOffset + 0.5f * (Width - canvas.MeasureText(style, text)), top + _marginTop + _shadowOffset, text);

            style.Color = new Color(1, 1, 1);
            canvas.Print(style, left + 0.5f * (Width - canvas.MeasureText(style, text)), top + _marginTop, text);
        }
开发者ID:AndiAngerer,项目名称:cubehack,代码行数:14,代码来源:Button.cs


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