Avionics
Dropship Simulator
Font.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 class Font
6 {
7 public:
8  ID3DX10Font* pFont = nullptr;
9 
11  int width;
12  int height;
13  std::string name;
14  std::string pathAndFilename;
15 
16  void OnD3D10CreateDevice(Logger* pLogger, ID3D10Device* pDevice)
17  {
18  char err[256];
19  sprintf_s(err, 256, "Font::OnD3D10CreateDevice AddFontResourceExA: %s", pathAndFilename.c_str());
20  pLogger->Log(err);
21 
22  int fontsAdded = AddFontResourceExA(pathAndFilename.c_str(), FR_PRIVATE, nullptr);
23  if (fontsAdded == 0)
24  {
25  sprintf_s(err, 256, "Font::OnD3D10CreateDevice AddFontResourceExA: %s", pathAndFilename.c_str());
26  pLogger->Log(err, Logger::Warn);
27  }
28 
29  HRESULT hr;
30  if (FAILED(hr = D3DX10CreateFontA(pDevice, height, width, FW_LIGHT, 1, false, DEFAULT_CHARSET,
31  OUT_TT_ONLY_PRECIS, DEFAULT_QUALITY, FIXED_PITCH | FF_DONTCARE,
32  name.c_str(), &pFont)))
33  {
34  sprintf_s(err, 256, "Font::OnD3D10CreateDevice D3DX10CreateFont failed: %s", name.c_str());
35  pLogger->Log(err, Logger::Error, hr);
36  }
37  }
38 
40  {
41  SAFE_RELEASE(pFont);
42  RemoveFontResourceA(pathAndFilename.c_str());
43  }
44 };
ID3DX10Font * pFont
Definition: Font.h:8
Definition: Font.h:5
int width
config items
Definition: Font.h:11
Definition: Logger.h:5
void OnD3D10CreateDevice(Logger *pLogger, ID3D10Device *pDevice)
Definition: Font.h:16
void Log(const char *msg, Level level=Info, int errorCode=0)
These have to be in this order.
Definition: Logger.cpp:16
std::string pathAndFilename
Definition: Font.h:14
void DeviceCleanup()
Definition: Font.h:39
std::string name
Definition: Font.h:13
int height
Definition: Font.h:12