-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from Renzo904/c-my-font
Add `CMyFont`
- Loading branch information
Showing
9 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// font.cpp - フォント描画部分 | ||
// | ||
// Copyright (c) 2001 if (if@edokko.com) | ||
// All Rights Reserved. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include "CMyFont.hpp" | ||
#include "GameWindow.hpp" | ||
#include "i18n.hpp" | ||
#include <d3d8.h> | ||
|
||
namespace th06 | ||
{ | ||
|
||
void CMyFont::Init(LPDIRECT3DDEVICE8 lpD3DDEV, int w, int h) | ||
{ | ||
HDC hTextDC = NULL; | ||
HFONT hFont = NULL, hOldFont = NULL; | ||
|
||
hTextDC = CreateCompatibleDC(NULL); | ||
hFont = CreateFont(h, w, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS, | ||
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, TH_FONT_NAME); | ||
if (!hFont) | ||
return; | ||
hOldFont = (HFONT)SelectObject(hTextDC, hFont); | ||
|
||
if (FAILED(D3DXCreateFont(lpD3DDEV, hFont, &m_lpFont))) | ||
{ | ||
MessageBox(0, "D3DXCreateFontIndirect FALSE", "ok", MB_OK); | ||
return; | ||
} | ||
SelectObject(hTextDC, hOldFont); | ||
DeleteObject(hFont); | ||
} | ||
// ---------------------------------------------------------------------------- | ||
void CMyFont::Print(char *str, int x, int y, D3DCOLOR color) | ||
{ | ||
RECT rect; | ||
rect.left = x; | ||
rect.right = GAME_WINDOW_WIDTH; | ||
rect.top = y; | ||
rect.bottom = GAME_WINDOW_HEIGHT; | ||
|
||
m_lpFont->DrawText(str, -1, &rect, DT_LEFT | DT_EXPANDTABS, color); | ||
} | ||
// ---------------------------------------------------------------------------- | ||
void CMyFont::Clean() | ||
{ | ||
RELEASE(m_lpFont); | ||
} | ||
} // namespace th06 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// ---------------------------------------------------------------------------- | ||
// | ||
// font.h - 文字表示 | ||
// | ||
// Copyright (c) 2001 if (if@edokko.com) | ||
// All Rights Reserved. | ||
// | ||
// ---------------------------------------------------------------------------- | ||
#pragma once | ||
|
||
#include <d3d8.h> | ||
#include <d3dx8.h> | ||
|
||
namespace th06 | ||
{ | ||
|
||
#define RELEASE(o) \ | ||
if (o) \ | ||
{ \ | ||
o->Release(); \ | ||
o = NULL; \ | ||
} | ||
|
||
class CMyFont | ||
{ | ||
private: | ||
LPD3DXFONT m_lpFont; | ||
|
||
public: | ||
CMyFont() | ||
{ | ||
m_lpFont = NULL; | ||
}; | ||
virtual void Init(LPDIRECT3DDEVICE8 lpD3DDEV, int w, int h); | ||
virtual void Print(char *str, int x, int y, D3DCOLOR color = 0xffffffff); | ||
virtual void Clean(); | ||
}; | ||
|
||
} // namespace th06 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters