本文整理汇总了C#中SharpDX.Direct3D9.Font.MeasureText方法的典型用法代码示例。如果您正苦于以下问题:C# Font.MeasureText方法的具体用法?C# Font.MeasureText怎么用?C# Font.MeasureText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpDX.Direct3D9.Font
的用法示例。
在下文中一共展示了Font.MeasureText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawText
public static void DrawText(Font font, string text, int posX, int posY, Color color)
{
Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);
font.DrawText(null, text, posX + 1 + rec.X, posY + 1, Color.Black);
font.DrawText(null, text, posX + rec.X, posY + 1, Color.Black);
font.DrawText(null, text, posX - 1 + rec.X, posY - 1, Color.Black);
font.DrawText(null, text, posX + rec.X, posY - 1, Color.Black);
font.DrawText(null, text, posX + rec.X, posY, color);
}
示例2: GetMeasured
private static Rectangle GetMeasured(Font font, string text) {
Rectangle rec;
var key = font.Description.FaceName + font.Description.Width + font.Description.Height +
font.Description.Weight + text;
if (!Measured.TryGetValue(key, out rec))
{
rec = font.MeasureText(null, text, FontDrawFlags.Center);
Measured.Add(key, rec);
}
return rec;
}
示例3: GetCenteredText
/// <summary>
/// Calculates the center position for the given text on within a rectangle boundaries.
/// </summary>
/// <param name="rectangle">Rectangle boundaries</param>
/// <param name="sprite">Sprite which is being drawn on</param>
/// <param name="font">Text Font</param>
/// <param name="text">The Text</param>
/// <param name="flags">Centered Flags</param>
/// <returns>Returns the center position of the text on the rectangle.</returns>
public static Vector2 GetCenteredText(
this Rectangle rectangle,
Sprite sprite,
Font font,
string text,
CenteredFlags flags)
{
return font == null
? rectangle.GetCenteredText(sprite, text, flags)
: rectangle.GetCenter(sprite, font.MeasureText(sprite, text, 0), flags);
}
示例4: Main
static void Main()
{
var form = new RenderForm("SharpDX - Direct3D9 Font Sample");
int width = form.ClientSize.Width;
int height = form.ClientSize.Height;
var device = new Device(new Direct3D(), 0, DeviceType.Hardware, form.Handle, CreateFlags.HardwareVertexProcessing, new PresentParameters(width, height) { PresentationInterval = PresentInterval.One });
// Initialize the Font
FontDescription fontDescription = new FontDescription()
{
Height = 72,
Italic = false,
CharacterSet = FontCharacterSet.Ansi,
FaceName = "Arial",
MipLevels = 0,
OutputPrecision = FontPrecision.TrueType,
PitchAndFamily = FontPitchAndFamily.Default,
Quality = FontQuality.ClearType,
Weight = FontWeight.Bold
};
var font = new Font(device, fontDescription);
var displayText = "Direct3D9 Text!";
// Measure the text to display
var fontDimension = font.MeasureText(null, displayText, new Rectangle(0, 0, width, height), FontDrawFlags.Center | FontDrawFlags.VerticalCenter);
int xDir = 1;
int yDir = 1;
RenderLoop.Run(form, () =>
{
device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
device.BeginScene();
// Make the text boucing on the screen limits
if ((fontDimension.Right + xDir) > width)
xDir = -1;
else if ((fontDimension.Left + xDir) <= 0)
xDir = 1;
if ((fontDimension.Bottom + yDir) > height)
yDir = -1;
else if ((fontDimension.Top + yDir) <= 0)
yDir = 1;
fontDimension.Left += (int)xDir;
fontDimension.Top += (int)yDir;
fontDimension.Bottom += (int)yDir;
fontDimension.Right += (int)xDir;
// Draw the text
font.DrawText(null, displayText, fontDimension, FontDrawFlags.Center | FontDrawFlags.VerticalCenter, Color.White);
device.EndScene();
device.Present();
});
}
示例5: DrawText
public static void DrawText(Font font, String text, int posX, int posY, Color color)
{
if (font == null || font.IsDisposed)
{
throw new SharpDXException("");
return;
}
Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);
font.DrawText(null, text, posX + 1 + rec.X, posY, Color.Black);
font.DrawText(null, text, posX + 1 + rec.X, posY + 1, Color.Black);
font.DrawText(null, text, posX + rec.X, posY + 1, Color.Black);
font.DrawText(null, text, posX - 1 + rec.X, posY, Color.Black);
font.DrawText(null, text, posX - 1 + rec.X, posY - 1, Color.Black);
font.DrawText(null, text, posX + rec.X, posY - 1, Color.Black);
font.DrawText(null, text, posX + rec.X, posY, color);
}
示例6: DrawText
public static void DrawText(Font font, String text, int posX, int posY, Color color)
{
Rectangle rec = font.MeasureText(null, text, FontDrawFlags.Center);
font.DrawText(null, text, posX + 1 + rec.X, posY + 1, SharpColor.White);
}
示例7: UpvoteItem
public UpvoteItem(string name)
{
_text = string.Format("Please consider to upvote {0} in the Assembly Database.", name);
_font = new Font(
Drawing.Direct3DDevice,
new FontDescription
{
FaceName = "Calibri",
Height = 20,
OutputPrecision = FontPrecision.Default,
Quality = FontQuality.Default
});
_measured = _font.MeasureText(null, _text, FontDrawFlags.Center);
_line = new Line(Drawing.Direct3DDevice) { Width = _measured.Height + (Padding * 2) };
}