⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 font.h

📁 一个自己写的游戏引擎,用DirectX 写成
💻 H
字号:
//--------------------------------------------------
//  Desc: Texture Font
//  Date: 2006.11.03 /update
//  Author: artsylee
//
//  Copyright (C) 2006 artsylee
//
//	扩展: 增加简单字体(2006_11_16)
//		  简单字体的纹理大小可变(2006_11_21)
//		  GFont字体的纹理可变,数量可变(2006_11_22)
//		  GFont::Update函数,删除无用字体纹理(2006_11_22)
//        条件编译纹理大小是否为2的N次方,以支持某些低端显卡(GeforceMX440)(2007_3_7)
//
//--------------------------------------------------

#ifndef _FONT_
#define _FONT_

#include <map>
#include <Windows.h>
class CFontTexture;
class CTextureManager;

typedef std::map<DWORD, CFontTexture*>	FontTextureMap;
typedef FontTextureMap::iterator				FontTextureItor;
typedef FontTextureMap::value_type				FontTextureValue;

#define FONTUPDATETIME	3000
#define FONTMAXEXIST	2000

class ASE_DLL GFont
{
public:
	GFont();
	virtual ~GFont();

	void		Release();
	bool		CreateFont(const char *szFontName, DWORD height, DWORD width = 0, DWORD weight = FW_NORMAL);
	void		SetLineCount(DWORD dwCount);
	void		SetLineHeight(DWORD dwLineHeight)	{ m_LineHeight = dwLineHeight; }
	RECT		GetStringRect(const char *pString);
	RECT		GetStringRectMultiLine(const char *pString);
	// one line
	void		DrawSingleLine(int x, int y, DWORD color, bool bCenter, const char *pString, ...);
	// multi lines & fomat
	int			DrawText(int x, int y, DWORD color, const char *pString, ...);
	void		Update();
protected:
	DWORD		GetIdleTexture();
	void		TextOut(int x, int y, DWORD color, const char *pString);
protected:
	HFONT		m_hFont;
	FontTextureMap		m_FontTextureMap;
	DWORD		m_UpdateTime;

	char		m_FontFamily[32];
	DWORD		m_FontWidth;
	DWORD		m_FontHeight;
	DWORD		m_FontWeight;
	DWORD		m_LineCount;  //一行的文字数 中文=m_LineCount/2
	DWORD		m_LineHeight; //行间距
};

class ASE_DLL CSimFont
{
public:
	CSimFont();
	virtual ~CSimFont();

	bool		CreateFont(int nHeight, int nWidth, int nEscapement, int nOrientation, 
		int fnWeight, DWORD fdwItalic, DWORD fdwUnderline, DWORD fdwStrikeOut,
		DWORD fdwOutputPrecision, DWORD fdwClipPrecision, DWORD fdwQuality,
		DWORD fdwPitchAndFamily, LPCTSTR lpszFace);
	bool		CreateFont(char * szFontName, DWORD height, DWORD width = 0, DWORD weight = FW_NORMAL);
	void		DrawText(int x, int y, DWORD color, bool bCenter, char * pString, ...);
	RECT		GetStringRect(char * pString);
protected:
	void		TextOut(int x, int y, DWORD color, char * pString);

protected:
	HFONT			m_hFont;
	CFontTexture*	m_pfTexture;
	DWORD			m_texHandle;
};



#endif // _FONT_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -