Last active
June 18, 2022 12:00
-
-
Save Islington036/f55bd26af77e21a76a1282b2e619ae1f to your computer and use it in GitHub Desktop.
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
#pragma once | |
//============================================================================= | |
// フォントリスト | |
//============================================================================= | |
enum class Font | |
{ | |
Meiryo, | |
Arial, | |
MeiryoUI | |
}; | |
//============================================================================= | |
// フォント名 | |
//============================================================================= | |
namespace | |
{ | |
const WCHAR* FontList[] | |
{ | |
L"メイリオ", | |
L"Arial", | |
L"Meiryo UI" | |
}; | |
} | |
//============================================================================= | |
// フォント設定 | |
//============================================================================= | |
struct FontData | |
{ | |
Font font; // フォント名 | |
IDWriteFontCollection* fontCollection; // フォントコレクション | |
DWRITE_FONT_WEIGHT fontWeight; // フォントの太さ | |
DWRITE_FONT_STYLE fontStyle; // フォントスタイル | |
DWRITE_FONT_STRETCH fontStretch; // フォントの幅 | |
FLOAT fontSize; // フォントサイズ | |
WCHAR const* localeName; // ロケール名 | |
DWRITE_TEXT_ALIGNMENT textAlignment; // テキストの配置 | |
D2D1_COLOR_F Color; // フォントの色 | |
// デフォルト設定 | |
FontData() | |
{ | |
font = Font::Meiryo; | |
fontCollection = nullptr; | |
fontWeight = DWRITE_FONT_WEIGHT::DWRITE_FONT_WEIGHT_NORMAL; | |
fontStyle = DWRITE_FONT_STYLE::DWRITE_FONT_STYLE_NORMAL; | |
fontStretch = DWRITE_FONT_STRETCH::DWRITE_FONT_STRETCH_NORMAL; | |
fontSize = 20; | |
localeName = L"ja-jp"; | |
textAlignment = DWRITE_TEXT_ALIGNMENT::DWRITE_TEXT_ALIGNMENT_LEADING; | |
Color = D2D1::ColorF(D2D1::ColorF::White); | |
} | |
}; | |
//============================================================================= | |
// DirectWrite設定 | |
//============================================================================= | |
class DirectWrite | |
{ | |
private: | |
ID2D1Factory* pD2DFactory = NULL; | |
IDWriteFactory* pDWriteFactory = NULL; | |
IDWriteTextFormat* pTextFormat = NULL; | |
IDWriteTextLayout* pTextLayout = NULL; | |
ID2D1RenderTarget* pRT = NULL; | |
ID2D1SolidColorBrush* pSolidBrush = NULL; | |
IDXGISurface* pBackBuffer = NULL; | |
// フォントデータ | |
FontData* Setting = new FontData(); | |
// stringをwstringへ変換する | |
std::wstring StringToWString(std::string oString); | |
public: | |
// デフォルトコンストラクタを制限 | |
DirectWrite() = delete; | |
// コンストラクタ | |
// 第1引数:フォント設定 | |
DirectWrite(FontData* set) :Setting(set) {}; | |
// コンストラクタ | |
// 第1引数:フォント名(L"メイリオ", L"Arial", L"Meiryo UI"等) | |
// 第2引数:フォントコレクション(nullptr) | |
// 第3引数:フォントの太さ(DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_WEIGHT_BOLD等) | |
// 第4引数:フォントスタイル(DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STYLE_OBLIQUE, DWRITE_FONT_STYLE_ITALIC) | |
// 第5引数:フォントの幅(DWRITE_FONT_STRETCH_NORMAL,DWRITE_FONT_STRETCH_EXTRA_EXPANDED等) | |
// 第6引数:フォントサイズ(20, 30等) | |
// 第7引数:ロケール名(L"ja-jp"等) | |
// 第8引数:テキストの配置(DWRITE_TEXT_ALIGNMENT_LEADING:前, 等) | |
// 第9引数:フォントの色(D2D1::ColorF(D2D1::ColorF::Black):黒, D2D1::ColorF(D2D1::ColorF(0.0f, 0.2f, 0.9f, 1.0f)):RGBA指定等) | |
DirectWrite(Font font, // フォント名 | |
IDWriteFontCollection* fontCollection, // フォントコレクション | |
DWRITE_FONT_WEIGHT fontWeight, // フォントの太さ | |
DWRITE_FONT_STYLE fontStyle, // フォントスタイル | |
DWRITE_FONT_STRETCH fontStretch, // フォントの幅 | |
FLOAT fontSize, // フォントサイズ | |
WCHAR const* localeName, // ロケール名 | |
DWRITE_TEXT_ALIGNMENT textAlignment, // テキストの配置 | |
D2D1_COLOR_F Color // フォントの色 | |
); | |
// フォント設定 | |
// 第1引数:フォントデータ構造体 | |
void SetFont(FontData* set); | |
// フォント設定 | |
// 第1引数:フォント名(L"メイリオ", L"Arial", L"Meiryo UI"等) | |
// 第2引数:フォントコレクション(nullptr) | |
// 第3引数:フォントの太さ(DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_WEIGHT_BOLD等) | |
// 第4引数:フォントスタイル(DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STYLE_OBLIQUE, DWRITE_FONT_STYLE_ITALIC) | |
// 第5引数:フォントの幅(DWRITE_FONT_STRETCH_NORMAL,DWRITE_FONT_STRETCH_EXTRA_EXPANDED等) | |
// 第6引数:フォントサイズ(20, 30等) | |
// 第7引数:ロケール名(L"ja-jp"等) | |
// 第8引数:テキストの配置(DWRITE_TEXT_ALIGNMENT_LEADING:前, 等) | |
// 第9引数:フォントの色(D2D1::ColorF(D2D1::ColorF::Black):黒, D2D1::ColorF(D2D1::ColorF(0.0f, 0.2f, 0.9f, 1.0f)):RGBA指定等) | |
void SetFont(Font font, // フォント名 | |
IDWriteFontCollection* fontCollection, // フォントコレクション | |
DWRITE_FONT_WEIGHT fontWeight, // フォントの太さ | |
DWRITE_FONT_STYLE fontStyle, // フォントスタイル | |
DWRITE_FONT_STRETCH fontStretch, // フォントの幅 | |
FLOAT fontSize, // フォントサイズ | |
WCHAR const* localeName, // ロケール名 | |
DWRITE_TEXT_ALIGNMENT textAlignment, // テキストの配置 | |
D2D1_COLOR_F Color); // フォントの色 | |
// 文字描画 | |
// string:文字列 | |
// pos:描画ポジション | |
// options:テキストの整形 | |
void DrawString(std::string str, D3DXVECTOR2 pos, D2D1_DRAW_TEXT_OPTIONS options); | |
// 文字描画 | |
// string:文字列 | |
// rect:領域指定 | |
// options:テキストの整形 | |
void DrawString(std::string str, D2D1_RECT_F rect, D2D1_DRAW_TEXT_OPTIONS options); | |
// 初期化 | |
void Init(); | |
// 終了処理 | |
void Release(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment