本文整理汇总了C#中Canvas.DrawText方法的典型用法代码示例。如果您正苦于以下问题:C# Canvas.DrawText方法的具体用法?C# Canvas.DrawText怎么用?C# Canvas.DrawText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Canvas
的用法示例。
在下文中一共展示了Canvas.DrawText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
Canvas canvas = new Canvas(device);
// Update input stats texts for drawing
this.WriteInputStats(ref this.mouseStatsText, DualityApp.Mouse);
this.WriteInputStats(ref this.keyboardStatsText, DualityApp.Keyboard);
this.WriteInputStats(ref this.joystickStatsText, DualityApp.Joysticks);
this.WriteInputStats(ref this.gamepadStatsText, DualityApp.Gamepads);
// Draw input stats texts
{
int y = 10;
canvas.DrawText(this.mouseStatsText, 10, y, 0, null, Alignment.TopLeft, true);
y += 20 + (int)this.mouseStatsText.TextMetrics.Size.Y;
canvas.DrawText(this.keyboardStatsText, 10, y, 0, null, Alignment.TopLeft, true);
y += 20 + (int)this.keyboardStatsText.TextMetrics.Size.Y;
canvas.DrawText(this.joystickStatsText, 10, y, 0, null, Alignment.TopLeft, true);
y += 20 + (int)this.joystickStatsText.TextMetrics.Size.Y;
canvas.DrawText(this.gamepadStatsText, 10, y, 0, null, Alignment.TopLeft, true);
y += 20 + (int)this.gamepadStatsText.TextMetrics.Size.Y;
}
// Draw the mouse cursor's movement trail
if (DualityApp.Mouse.IsAvailable)
{
canvas.State.ColorTint = new ColorRgba(128, 192, 255, 128);
canvas.FillThickLine(
DualityApp.Mouse.X - DualityApp.Mouse.XSpeed,
DualityApp.Mouse.Y - DualityApp.Mouse.YSpeed,
DualityApp.Mouse.X,
DualityApp.Mouse.Y,
2);
// Draw the mouse cursor at its local window coordiates
canvas.State.ColorTint = ColorRgba.White;
canvas.FillCircle(
DualityApp.Mouse.X,
DualityApp.Mouse.Y,
2);
}
}
示例2: 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);
}
}
示例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();
}
示例4: OnCollectOverlayDrawcalls
protected internal override void OnCollectOverlayDrawcalls(Canvas canvas)
{
base.OnCollectOverlayDrawcalls(canvas);
bool noActionText = string.IsNullOrEmpty(this.View.ActiveState.ActionText);
bool mouseover = this.View.ActiveState.Mouseover;
Point cursorPos = this.PointToClient(Cursor.Position);
if (noActionText && mouseover &&
cursorPos.X > 0 && cursorPos.X < this.ClientSize.Width &&
cursorPos.Y > 0 && cursorPos.Y < this.ClientSize.Height)
{
GridLayerData displayedData = default(GridLayerData);
this.View.ActiveState.GetDisplayedGridData(cursorPos, ref displayedData);
cursorPos.X += 30;
cursorPos.Y += 10;
string[] text = new string[]
{
string.Format("X:{0,7:0}", displayedData.DisplayedGridPos.X),
string.Format("Y:{0,7:0}", displayedData.DisplayedGridPos.Y)
};
canvas.DrawText(text, cursorPos.X, cursorPos.Y, drawBackground: true);
}
}
示例5: 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;
}
示例6: 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();
}
示例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();
}
//.........这里部分代码省略.........
示例8: OnCollectOverlayDrawcalls
protected internal override void OnCollectOverlayDrawcalls(Canvas canvas)
{
base.OnCollectOverlayDrawcalls(canvas);
bool noActionText = string.IsNullOrEmpty(this.View.ActiveState.ActionText);
bool mouseover = this.View.ActiveState.Mouseover;
Point cursorPos = this.PointToClient(Cursor.Position);
if (noActionText && mouseover &&
cursorPos.X > 0 && cursorPos.X < this.ClientSize.Width &&
cursorPos.Y > 0 && cursorPos.Y < this.ClientSize.Height)
{
var cursorSpacePos = this.GetSpaceCoord(new Vector2(cursorPos.X, cursorPos.Y));
cursorPos.X += 30;
cursorPos.Y += 10;
string[] text = new string[]
{
string.Format("X:{0,7:0}", cursorSpacePos.X),
string.Format("Y:{0,7:0}", cursorSpacePos.Y)
};
canvas.DrawText(text, cursorPos.X, cursorPos.Y, drawBackground: true);
}
}
示例9: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
Canvas canvas = new Canvas(device);
Vector2 screenSize = device.TargetSize;
ICameraController activeController = this.mainCameraObj.GetComponent<ICameraController>();
Transform camTransform = this.mainCameraObj.Transform;
Transform targetTransform = this.targetObj.Transform;
float camDist = (camTransform.Pos.Xy - targetTransform.Pos.Xy).Length;
string activeControllerName = activeController != null ? activeController.GetType().Name : "None";
activeControllerName = activeControllerName.Replace("CameraController", "");
// Draw the screen center, so we know what exactly our camera controller is pointing at
canvas.State.ColorTint = ColorRgba.Green.WithAlpha(0.5f);
canvas.FillCircle(screenSize.X * 0.5f, screenSize.Y * 0.5f, 8.0f);
// Draw the camera distance around the screen center
canvas.State.ColorTint = ColorRgba.Green.WithAlpha(0.25f);
canvas.DrawCircle(screenSize.X * 0.5f, screenSize.Y * 0.5f, camDist);
// Draw the camera velocity (movement per second) around the screen center
canvas.State.ColorTint = ColorRgba.Green.WithAlpha(0.5f);
canvas.DrawLine(
screenSize.X * 0.5f,
screenSize.Y * 0.5f,
screenSize.X * 0.5f + camTransform.Vel.X / Time.SPFMult,
screenSize.Y * 0.5f + camTransform.Vel.Y / Time.SPFMult);
// Draw some info text
if (this.infoText == null)
{
this.infoText = new FormattedText();
this.infoText.MaxWidth = 350;
}
this.infoText.SourceText = string.Format(
"Camera Controller Sample/n/n" +
"Use /c44AAFFFFarrow keys/cFFFFFFFF // /c44AAFFFFleft thumbstick/cFFFFFFFF to move./n" +
"Use /c44AAFFFFnumber keys 1, 2/cFFFFFFFF // /c44AAFFFFbuttons A, B/cFFFFFFFF to select a Camera Controller./n" +
"Use the /c44AAFFFFM key/cFFFFFFFF // /c44AAFFFFbutton X/cFFFFFFFF to toggle movement history./n/n" +
"Active Camera Controller:/n/cFF8800FF{0}/cFFFFFFFF",
activeControllerName);
canvas.State.ColorTint = ColorRgba.White;
canvas.DrawText(this.infoText, 10, 10, 0.0f, null, Alignment.TopLeft, true);
// Draw state information on the current camera controller
if (this.stateText == null) this.stateText = new FormattedText();
this.stateText.SourceText = string.Format(
"Camera Distance: {0:F}/n" +
"Camera Velocity: {1:F}, {2:F}",
camDist,
camTransform.Vel.X,
camTransform.Vel.Y);
canvas.State.ColorTint = ColorRgba.White;
canvas.DrawText(this.stateText, 10, screenSize.Y - 10, 0.0f, null, Alignment.BottomLeft, true);
}
示例10: 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);
}
}
}
示例11: Canvas
void ICmpScreenOverlayRenderer.DrawOverlay(IDrawDevice device)
{
if (!GameRes.Data.Fonts.HUD_Font.IsAvailable) return;
if (GameSceneController.Instance == null) return;
Font hudFont = GameRes.Data.Fonts.HUD_Font.Res;
Font highscoreFont = GameRes.Data.Fonts.Highscore_Font.Res;
Font debugFont = Font.GenericMonospace10.Res;
Canvas canvas = new Canvas(device);
string txt;
Vector2 size;
canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Add, ColorRgba.Green + ColorRgba.LightGrey));
canvas.CurrentState.TextFont = hudFont;
// Draw player score
txt = string.Format("{0} pts", Player.Score);
size = hudFont.MeasureText(txt);
canvas.DrawText(txt, DualityApp.TargetResolution.X - size.X - 10, 10);
// Draw level
txt = string.Format("Level {0}", GameSceneController.Instance.CurrentLevel);
canvas.DrawText(txt, 10, 10);
// Draw asteroid timer
txt = string.Format("New asteroid in {0} s", (int)GameSceneController.Instance.AsteroidCountdown / 1000);
size = hudFont.MeasureText(txt);
canvas.DrawText(txt, 10, DualityApp.TargetResolution.Y - size.Y - 10);
canvas.CurrentState.TextFont = debugFont;
// Draw performance info
txt = string.Format("Update: {0} ms", MathF.RoundToInt(Performance.UpdateTime).ToString().PadLeft(4));
size = debugFont.MeasureText(txt);
canvas.DrawText(txt,
DualityApp.TargetResolution.X - size.X - 10,
DualityApp.TargetResolution.Y - size.Y - 10 - size.Y * 2);
txt = string.Format("Render: {0} ms", MathF.RoundToInt(Performance.RenderTime).ToString().PadLeft(4));
size = debugFont.MeasureText(txt);
canvas.DrawText(txt,
DualityApp.TargetResolution.X - size.X - 10,
DualityApp.TargetResolution.Y - size.Y - 10 - size.Y * 1);
txt = string.Format("Frame: {0} ms", MathF.RoundToInt(Time.LastDelta).ToString().PadLeft(4));
size = debugFont.MeasureText(txt);
canvas.DrawText(txt,
DualityApp.TargetResolution.X - size.X - 10,
DualityApp.TargetResolution.Y - size.Y - 10);
if (Player.Instance == null)
{
canvas.CurrentState.TextFont = hudFont;
// Game over text
txt = "GAME OVER";
size = hudFont.MeasureText(txt);
canvas.DrawText(txt,
DualityApp.TargetResolution.X / 2 - size.X / 2,
DualityApp.TargetResolution.Y / 2 - size.Y / 2 - size.Y);
if (this.highscore.Count() < 10 || Player.Score > this.highscore.Min(entry => entry.Score))
{
// Enter name
txt = "Enter your name:";
size = hudFont.MeasureText(txt);
canvas.DrawText(txt,
DualityApp.TargetResolution.X / 2 - size.X / 2,
DualityApp.TargetResolution.Y / 2 - size.Y / 2);
txt = this.gameOverEnterName ?? "";
txt = txt + new string('_', 10 - txt.Length);
size = highscoreFont.MeasureText(txt);
canvas.DrawText(txt,
DualityApp.TargetResolution.X / 2 - size.X / 2,
DualityApp.TargetResolution.Y / 2 - size.Y / 2 + size.Y);
}
}
}
示例12: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
Canvas canvas = new Canvas(device);
Vector2 screenSize = device.TargetSize;
// Draw some info text
if (this.infoText == null)
{
this.infoText = new FormattedText();
this.infoText.MaxWidth = 350;
}
this.infoText.SourceText = string.Format(
"Manual Audio Handling Sample/n/n" +
"Use /c44AAFFFFnumber key 1/cFFFFFFFF // Gamepad /c44AAFFFFbutton A/cFFFFFFFF to go inside and close the door./n" +
"Use /c44AAFFFFnumber key 2/cFFFFFFFF // Gamepad /c44AAFFFFbutton B/cFFFFFFFF to open the door and go back outside.");
canvas.State.ColorTint = ColorRgba.White;
canvas.DrawText(this.infoText, 10, 10, 0.0f, null, Alignment.TopLeft, true);
// Draw state information on the current camera controller
if (this.stateText == null) this.stateText = new FormattedText();
this.stateText.SourceText = string.Format(
"Where am I? /cFF8800FF{0}/cFFFFFFFF",
this.inside > 0.5f ? "In my cozy room" : "Out in the cold");
canvas.State.ColorTint = ColorRgba.White;
canvas.DrawText(this.stateText, 10, screenSize.Y - 10, 0.0f, null, Alignment.BottomLeft, true);
canvas.DrawText(string.Format("{0:F}", this.inside), 250, screenSize.Y - 10, 0.0f, Alignment.BottomLeft, true);
}
示例13: Draw
public override void Draw(Canvas target, Vector3 basePos, float baseRotation, float baseScale)
{
float borderRadius = DefaultOutlineWidth;
float textScale = 1.0f;
bool worldSpace;
// Scale anti-proportional to perspective scale in order to keep a constant size
// in screen space even when actually drawing in world space.
{
float scale = 1.0f;
Vector3 posTemp = this.pos + basePos;
target.DrawDevice.PreprocessCoords(ref posTemp, ref scale);
worldSpace = (posTemp != this.pos + basePos);
borderRadius /= scale;
textScale /= scale;
}
// Determine base position
Vector3 originPos = this.pos;
MathF.TransformCoord(ref originPos.X, ref originPos.Y, baseRotation, baseScale);
originPos += basePos;
// Draw text and background
BatchInfo matBoostAlpha = target.State.Material;
matBoostAlpha.MainColor = matBoostAlpha.MainColor.WithAlpha(matBoostAlpha.MainColor.A * 2.0f / 255.0f);
target.State.SetMaterial(matBoostAlpha);
target.State.ColorTint *= this.Color;
if (worldSpace) target.State.TransformAngle = target.DrawDevice.RefAngle;
target.State.TransformScale = new Vector2(textScale, textScale);
target.DrawText(
this.lines,
originPos.X,
originPos.Y,
originPos.Z,
this.blockAlign,
true);
}
示例14: 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);
}
}
}
示例15: Canvas
void ICmpRenderer.Draw(IDrawDevice device)
{
Profile.BeginMeasure(@"ProfileRenderer");
Canvas canvas = new Canvas(device);
canvas.CurrentState.SetMaterial(new BatchInfo(DrawTechnique.Alpha, ColorRgba.White, null));
bool anyTextReport = this.textReportPerf || this.textReportStat;
bool anyGraph = this.drawGraphs && this.counterGraphs.Count > 0;
// Determine geometry
int areaWidth = (int)device.TargetSize.X - 20;
if (anyGraph && anyTextReport)
areaWidth = (areaWidth - 10) / 2;
Rect textReportRect = new Rect(
10,
10,
anyTextReport ? areaWidth : 0,
(int)device.TargetSize.Y - 20);
Rect graphRect = new Rect(
anyTextReport ? (textReportRect.MaximumX + 10) : 10,
10,
anyGraph ? areaWidth : 0,
(int)device.TargetSize.Y - 20);
// Text Reports
if (anyTextReport)
{
// Update Report
IEnumerable<ProfileCounter> counters = Profile.GetUsedCounters();
if (!this.textReportPerf) counters = counters.Where(c => !(c is TimeCounter));
if (!this.textReportStat) counters = counters.Where(c => !(c is StatCounter));
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;
//.........这里部分代码省略.........