MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_font.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_FONT_H_1622099992
12#define INCGUARD_MGL_FONT_H_1622099992
13
17
18namespace MGL::Render
19{
21class Font
22{
23public:
24 /* ------------------------------------------------------------------------- */
29 /* ------------------------------------------------------------------------- */
30 Font(FontKey key) noexcept
31 : _resource(FontStorage::GetInstance().Get(key))
32 , _work()
33 , _key(key)
34 , _isOnceLimit(false)
35 {
36 }
37
38 /* ------------------------------------------------------------------------- */
42 /* ------------------------------------------------------------------------- */
43 constexpr Font() noexcept
44 : _resource(nullptr)
45 , _work()
46 , _key()
47 , _isOnceLimit(false)
48 {
49 }
50
51 static Font AddStorage(FontKey key, const SharedFontResource &resource) noexcept;
52
53 /* ------------------------------------------------------------------------- */
61 /* ------------------------------------------------------------------------- */
62 template <class FontResourceClass, class... Args>
63 static Font Create(FontKey key, Args... args) noexcept
64 {
65 return AddStorage(key, STL::make_shared<FontResourceClass>(args...));
66 }
67
68 /* ------------------------------------------------------------------------- */
72 /* ------------------------------------------------------------------------- */
73 static void Remove(FontKey key) noexcept
74 {
75 FontStorage::GetInstance().Remove(key);
76 }
77
78 bool Load(FontKey key) noexcept;
79
80 /* ------------------------------------------------------------------------- */
85 /* ------------------------------------------------------------------------- */
86 [[nodiscard]] constexpr FontKey GetFontKey() const noexcept
87 {
88 return _key;
89 }
90
91 /* ------------------------------------------------------------------------- */
96 /* ------------------------------------------------------------------------- */
97 constexpr void SetPosition(const Vector2 &position) noexcept
98 {
99 _work.position = _option.firstPosition = position;
100 }
101
102 /* ------------------------------------------------------------------------- */
108 /* ------------------------------------------------------------------------- */
109 constexpr void SetPosition(float x, float y) noexcept
110 {
111 _work.position.x = x;
112 _work.position.y = y;
113 _option.firstPosition = _work.position;
114 }
115
116 /* ------------------------------------------------------------------------- */
121 /* ------------------------------------------------------------------------- */
122 [[nodiscard]] constexpr const Vector2 &GetPosition() const noexcept
123 {
124 return _work.position;
125 }
126
127 /* ------------------------------------------------------------------------- */
132 /* ------------------------------------------------------------------------- */
133 constexpr void SetScale(const Vector2 &scale) noexcept
134 {
135 _option.scale = scale;
136 }
137
138 /* ------------------------------------------------------------------------- */
144 /* ------------------------------------------------------------------------- */
145 constexpr void SetScale(float scaleX, float scaleY) noexcept
146 {
147 _option.scale.x = scaleX;
148 _option.scale.y = scaleY;
149 }
150
151 /* ------------------------------------------------------------------------- */
156 /* ------------------------------------------------------------------------- */
157 constexpr void SetScale(float scale) noexcept
158 {
159 _option.scale.x = _option.scale.y = scale;
160 }
161
162 /* ------------------------------------------------------------------------- */
167 /* ------------------------------------------------------------------------- */
168 [[nodiscard]] constexpr const Vector2 &GetScale() const noexcept
169 {
170 return _option.scale;
171 }
172
173 /* ------------------------------------------------------------------------- */
178 /* ------------------------------------------------------------------------- */
179 constexpr void SetHorizontalAlignment(Alignment::Horizontal alignment) noexcept
180 {
181 _option.horizontalAlignment = alignment;
182 }
183
184 /* ------------------------------------------------------------------------- */
189 /* ------------------------------------------------------------------------- */
190 [[nodiscard]] constexpr Alignment::Horizontal GetHorizontalAlignment() const noexcept
191 {
192 return _option.horizontalAlignment;
193 }
194
195 /* ------------------------------------------------------------------------- */
200 /* ------------------------------------------------------------------------- */
201 constexpr void SetMaskColor(const Color &color) noexcept
202 {
203 _option.maskColor = color;
204 }
205
206 /* ------------------------------------------------------------------------- */
211 /* ------------------------------------------------------------------------- */
212 [[nodiscard]] constexpr const Color &GetMaskColor() const noexcept
213 {
214 return _option.maskColor;
215 }
216
217 /* ------------------------------------------------------------------------- */
222 /* ------------------------------------------------------------------------- */
223 constexpr void SetSamplerType(SamplerType samplerType) noexcept
224 {
225 _option.samplerType = samplerType;
226 }
227
228 /* ------------------------------------------------------------------------- */
233 /* ------------------------------------------------------------------------- */
234 [[nodiscard]] constexpr SamplerType GetSamplerType() const noexcept
235 {
236 return _option.samplerType;
237 }
238
239 /* ------------------------------------------------------------------------- */
245 /* ------------------------------------------------------------------------- */
246 constexpr void SetTransparency(float transparency) noexcept
247 {
248 _option.maskColor.alpha = transparency;
249 }
250
251 /* ------------------------------------------------------------------------- */
257 /* ------------------------------------------------------------------------- */
258 [[nodiscard]] constexpr float GetTransparency() const noexcept
259 {
260 return _option.maskColor.alpha;
261 }
262
263 /* ------------------------------------------------------------------------- */
268 /* ------------------------------------------------------------------------- */
269 constexpr void SetMargin(const Vector2 &margin) noexcept
270 {
271 _option.margin = margin;
272 }
273
274 /* ------------------------------------------------------------------------- */
279 /* ------------------------------------------------------------------------- */
280 [[nodiscard]] constexpr const Vector2 &GetMargin() const noexcept
281 {
282 return _option.margin;
283 }
284
285 /* ------------------------------------------------------------------------- */
291 /* ------------------------------------------------------------------------- */
292 [[nodiscard]] bool IsValid() const noexcept
293 {
294 return _resource->IsValid();
295 }
296
297 /* ------------------------------------------------------------------------- */
303 /* ------------------------------------------------------------------------- */
304 explicit operator bool() const noexcept
305 {
306 return IsValid();
307 }
308
309 /* ------------------------------------------------------------------------- */
315 /* ------------------------------------------------------------------------- */
316 bool operator!() const noexcept
317 {
318 return !static_cast<bool>(*this);
319 }
320
321 bool Print(const char *text, const Text::FormatArgs &args = Text::FormatArgs()) noexcept;
322 bool Print(const Text::IndexedCharacter *indexedString, const Text::FormatArgs &args = Text::FormatArgs()) noexcept;
323
324 /* ------------------------------------------------------------------------- */
330 /* ------------------------------------------------------------------------- */
331 template <class... Args>
332 constexpr bool Print(const char *text, const Args &...args) noexcept
333 {
334 return Print(text, {args...});
335 }
336
337 /* ------------------------------------------------------------------------- */
343 /* ------------------------------------------------------------------------- */
344 template <class... Args>
345 constexpr bool Print(const Text::IndexedCharacter *indexedString, const Args &...args) noexcept
346 {
347 return Print(indexedString, {args...});
348 }
349
350 /* ------------------------------------------------------------------------- */
357 /* ------------------------------------------------------------------------- */
358 [[nodiscard]] constexpr bool IsEnabled(FontFeature feature) const noexcept
359 {
360 return (_resource != nullptr) ? _resource->IsEnabled(feature) : false;
361 }
362
363 /* ------------------------------------------------------------------------- */
370 /* ------------------------------------------------------------------------- */
371 [[nodiscard]] constexpr bool HasFontFace(FontFaceType faceType) const noexcept
372 {
373 return (_resource != nullptr) ? _resource->HasFontFace(faceType) : false;
374 }
375
376 /* ------------------------------------------------------------------------- */
384 /* ------------------------------------------------------------------------- */
385 STL::unique_ptr<Text::IndexedCharacter[]> ToIndexedString(const char *text, bool enableFormat, bool enableTag) const noexcept
386 {
387 return (_resource != nullptr) ? _resource->GetIndexConverter().ToIndexedString(text, enableFormat, enableTag) : nullptr;
388 }
389
390 /* ------------------------------------------------------------------------- */
397 /* ------------------------------------------------------------------------- */
398 [[nodiscard]] Text::IndexedCharacter ToIndexedCharacter(char32_t character, FontFaceType faceType = FontFaceType::Default) const noexcept
399 {
400 return (_resource != nullptr) ? _resource->ToIndexedCharacter(character, faceType) : Text::kIndexedCharacterInvalid;
401 }
402
403 /* ------------------------------------------------------------------------- */
408 /* ------------------------------------------------------------------------- */
409 [[nodiscard]] constexpr FontOrigin GetOriginType() const noexcept
410 {
411 return (_resource != nullptr) ? _resource->GetOriginType() : FontOrigin::TopLeft;
412 }
413
414 /* ------------------------------------------------------------------------- */
421 /* ------------------------------------------------------------------------- */
422 [[nodiscard]] constexpr const FontGlyph *GetGlyph(char32_t character, FontFaceType faceType = FontFaceType::Default) const noexcept
423 {
424 return (_resource != nullptr) ? _resource->GetGlyph(character, faceType, _option) : nullptr;
425 }
426
427 /* ------------------------------------------------------------------------- */
434 /* ------------------------------------------------------------------------- */
435 [[nodiscard]] constexpr const FontGlyph *GetGlyph(Text::IndexedCharacter character, FontFaceType faceType = FontFaceType::Default) const noexcept
436 {
437 return (_resource != nullptr) ? _resource->GetGlyph(character, faceType, _option) : nullptr;
438 }
439
440 /* ------------------------------------------------------------------------- */
446 /* ------------------------------------------------------------------------- */
447 constexpr void SetLimits(int32_t limitCount, bool isOnce) noexcept
448 {
449 _work.limitCount = limitCount;
450 _isOnceLimit = isOnce;
451 }
452
453 /* ------------------------------------------------------------------------- */
457 /* ------------------------------------------------------------------------- */
458 constexpr void ClearLimits() noexcept
459 {
460 _work.limitCount = -1;
461 }
462
463 /* ------------------------------------------------------------------------- */
468 /* ------------------------------------------------------------------------- */
469 [[nodiscard]] constexpr int32_t GetLimits() const noexcept
470 {
471 return _work.limitCount;
472 }
473
474 /* ------------------------------------------------------------------------- */
481 /* ------------------------------------------------------------------------- */
483 {
484 return (_resource != nullptr) ? Text::Format(text, _resource->GetIndexConverter(), args) : STL::vector<Text::IndexedCharacter>();
485 }
486
487 /* ------------------------------------------------------------------------- */
494 /* ------------------------------------------------------------------------- */
495 template <class... Args>
496 STL::vector<Text::IndexedCharacter> Format(const Text::IndexedCharacter *text, const Args &...args) noexcept
497 {
498 return Format(text, {args...});
499 }
500
501private:
502 SharedFontResource _resource;
503 FontWorkdata _work;
504 FontOption _option;
505 FontKey _key;
506 bool _isOnceLimit;
507};
508} // namespace MGL::Render
509
510#endif // INCGUARD_MGL_FONT_H_1622099992
511
512// vim: et ts=4 sw=4 sts=4
MGL フォントクラス
Definition mgl_font.h:22
static Font AddStorage(FontKey key, const SharedFontResource &resource) noexcept
フォントをフォントストレージに追加
Definition mgl_font.cc:23
constexpr void SetMargin(const Vector2 &margin) noexcept
字間と行間の設定
Definition mgl_font.h:269
bool Print(const char *text, const Text::FormatArgs &args=Text::FormatArgs()) noexcept
文字の表示
Definition mgl_font.cc:64
bool Load(FontKey key) noexcept
フォントストレージからフォントを読み込み
Definition mgl_font.cc:46
constexpr void SetPosition(const Vector2 &position) noexcept
表示位置の設定
Definition mgl_font.h:97
constexpr void SetScale(float scaleX, float scaleY) noexcept
スケール値の設定
Definition mgl_font.h:145
constexpr void SetScale(const Vector2 &scale) noexcept
スケール値の設定
Definition mgl_font.h:133
static Font Create(FontKey key, Args... args) noexcept
フォント生成用テンプレート
Definition mgl_font.h:63
constexpr const Color & GetMaskColor() const noexcept
マスクカラーの取得
Definition mgl_font.h:212
constexpr const Vector2 & GetMargin() const noexcept
字間と行間の取得
Definition mgl_font.h:280
constexpr void SetMaskColor(const Color &color) noexcept
マスクカラーの設定
Definition mgl_font.h:201
constexpr bool IsEnabled(FontFeature feature) const noexcept
このフォントが扱える機能を取得
Definition mgl_font.h:358
constexpr FontOrigin GetOriginType() const noexcept
フォントの原点タイプを取得
Definition mgl_font.h:409
STL::vector< Text::IndexedCharacter > Format(const Text::IndexedCharacter *text, const Text::FormatArgs &args) const noexcept
インデックス文字列の整形
Definition mgl_font.h:482
static void Remove(FontKey key) noexcept
フォントの削除
Definition mgl_font.h:73
Font(FontKey key) noexcept
コンストラクタ
Definition mgl_font.h:30
constexpr const Vector2 & GetScale() const noexcept
スケール値の取得
Definition mgl_font.h:168
constexpr SamplerType GetSamplerType() const noexcept
サンプラータイプの取得
Definition mgl_font.h:234
constexpr bool Print(const Text::IndexedCharacter *indexedString, const Args &...args) noexcept
インデックス化した文字の表示
Definition mgl_font.h:345
bool operator!() const noexcept
有効状態を否定演算子で取得
Definition mgl_font.h:316
constexpr void SetLimits(int32_t limitCount, bool isOnce) noexcept
表示上限数の設定
Definition mgl_font.h:447
constexpr const Vector2 & GetPosition() const noexcept
表示位置の取得
Definition mgl_font.h:122
constexpr Font() noexcept
コンストラクタ
Definition mgl_font.h:43
bool IsValid() const noexcept
フォントの有効状態を取得
Definition mgl_font.h:292
constexpr float GetTransparency() const noexcept
透過値の取得
Definition mgl_font.h:258
Text::IndexedCharacter ToIndexedCharacter(char32_t character, FontFaceType faceType=FontFaceType::Default) const noexcept
UTF-32文字をこのフォント用のインデックス文字に変換
Definition mgl_font.h:398
STL::unique_ptr< Text::IndexedCharacter[]> ToIndexedString(const char *text, bool enableFormat, bool enableTag) const noexcept
文字列をこのフォント用のインデックス文字列に変換
Definition mgl_font.h:385
constexpr void SetSamplerType(SamplerType samplerType) noexcept
サンプラータイプの設定
Definition mgl_font.h:223
STL::vector< Text::IndexedCharacter > Format(const Text::IndexedCharacter *text, const Args &...args) noexcept
インデックス文字列の整形
Definition mgl_font.h:496
constexpr Alignment::Horizontal GetHorizontalAlignment() const noexcept
水平方向の配置情報の取得
Definition mgl_font.h:190
constexpr int32_t GetLimits() const noexcept
表示上限数の取得
Definition mgl_font.h:469
constexpr const FontGlyph * GetGlyph(char32_t character, FontFaceType faceType=FontFaceType::Default) const noexcept
グリフ情報の取得
Definition mgl_font.h:422
constexpr void SetTransparency(float transparency) noexcept
透過値の設定
Definition mgl_font.h:246
constexpr const FontGlyph * GetGlyph(Text::IndexedCharacter character, FontFaceType faceType=FontFaceType::Default) const noexcept
グリフ情報の取得
Definition mgl_font.h:435
constexpr void SetPosition(float x, float y) noexcept
表示位置の設定
Definition mgl_font.h:109
constexpr bool HasFontFace(FontFaceType faceType) const noexcept
指定したフェイスを保持しているかを取得
Definition mgl_font.h:371
constexpr FontKey GetFontKey() const noexcept
このフォントのキーを取得
Definition mgl_font.h:86
constexpr void SetHorizontalAlignment(Alignment::Horizontal alignment) noexcept
水平方向の配置情報の設定
Definition mgl_font.h:179
constexpr void ClearLimits() noexcept
表示上限数をクリア
Definition mgl_font.h:458
constexpr void SetScale(float scale) noexcept
スケール値の設定
Definition mgl_font.h:157
static FontStorage & GetInstance() noexcept
Definition mgl_singleton.h:74
FontOrigin
フォントの原点
Definition mgl_font_defs.h:52
FontFeature
フォントの機能
Definition mgl_font_defs.h:41
FontFaceType
フォントのフェイスタイプ
Definition mgl_font_defs.h:21
std::shared_ptr< FontResource > SharedFontResource
フォントリソースの共有ポインタ
Definition mgl_font_resource.h:287
MGL フォントストレージ
FontKey
フォントリソースにアクセスするキーの型
Definition mgl_font_storage.h:24
SamplerType
サンプラー
Definition mgl_render_types.h:59
MGL レンダラセット
std::vector< T, Allocator< T > > vector
std::vectorの代替
Definition mgl_stl_containers.h:51
std::unique_ptr< T, Deleter > unique_ptr
MGLのアロケータを利用するユニークポインタ
Definition mgl_stl_memory.h:247
uint16_t IndexedCharacter
インデックス化文字
Definition mgl_text_defs.h:30
MGL テキストフォーマット
STL::vector< FormatArgument > FormatArgs
テキストフォーマットの引数の配列
Definition mgl_text_format_argument.h:282
Horizontal
水平方向の配置
Definition mgl_alignment.h:24
色情報
Definition mgl_color.h:22
float alpha
アルファ値
Definition mgl_color.h:26
グリフ情報
Definition mgl_font_glyph.h:20
フォント描画オプション
Definition mgl_font_option.h:22
Vector2 firstPosition
初期基準位置
Definition mgl_font_option.h:23
Vector2 margin
字間と行間
Definition mgl_font_option.h:28
Alignment::Horizontal horizontalAlignment
水平方向の配置情報
Definition mgl_font_option.h:24
SamplerType samplerType
サンプラータイプ
Definition mgl_font_option.h:27
Color maskColor
マスクカラー
Definition mgl_font_option.h:26
Vector2 scale
スケール値
Definition mgl_font_option.h:25
フォント描画のワークデータ
Definition mgl_font_defs.h:59
int32_t limitCount
表示上限数
Definition mgl_font_defs.h:61
Vector2 position
表示位置
Definition mgl_font_defs.h:60
2Dベクトル
Definition mgl_vector2.h:23
float y
Y成分
Definition mgl_vector2.h:25
float x
X成分
Definition mgl_vector2.h:24