📄 ddfpspainter.cs
字号:
using System;
using System.Drawing;
using Microsoft.DirectX.DirectDraw;
namespace DDGameHelper
{
public class DDFPSPainter
{
/// <summary>
/// 显示字符信息用的 surface
/// </summary>
protected Surface _textSurface;
/// <summary>
/// 输出用 surface
/// </summary>
protected Surface _renderSurface;
/// <summary>
/// 初始化 surface
/// </summary>
public DDFPSPainter(Device dddevice, Surface renderSurface)
{
_renderSurface=renderSurface;
SurfaceDescription description=new SurfaceDescription();
description.SurfaceCaps.OffScreenPlain = true;
description.Width = 400; description.Height = 20;
ColorKey tempKey = new ColorKey();
tempKey.ColorSpaceHighValue = 0;
tempKey.ColorSpaceLowValue = 0;
_textSurface = new Surface(description, dddevice);
_textSurface.ForeColor = Color.White;
_textSurface.SetColorKey(ColorKeyFlags.SourceDraw, tempKey);
}
/// <summary>
/// 显示 fps 及附加字符串到屏幕上
/// </summary>
public void PaintFPS(DXTimer dXTimer, string append)
{
double fps=dXTimer.CalculateFPS();
string s="FPS:"+((int)fps).ToString()+append;
_textSurface.ColorFill(0);
_textSurface.DrawText(0, 0, s , false);
_renderSurface.DrawFast(10, 10, _textSurface, DrawFastFlags.SourceColorKey | DrawFastFlags.DoNotWait);
}
/// <summary>
/// 显示 fps 数据到屏幕上
/// </summary>
public void PaintFPS(DXTimer dXTimer)
{
double fps=dXTimer.CalculateFPS();
string s="FPS:"+((int)fps).ToString();
_textSurface.ColorFill(0);
_textSurface.DrawText(0, 0, s , false);
_renderSurface.DrawFast(10, 10, _textSurface, DrawFastFlags.SourceColorKey | DrawFastFlags.DoNotWait);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -