ddfpspainter.cs

来自「这是网上下载的很好的串口发短信的程序! 是用VC++来做的」· CS 代码 · 共 61 行

CS
61
字号
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 + =
减小字号Ctrl + -
显示快捷键?