DXフレームワーク　リファレンス・マニュアル 0.01 DXフレームワークのリファレンスです。詳細は公式wiki

- メインページ
- 関連ページ
- クラス
- ファイル

- ファイル一覧

BmpFont.h
1 #pragma once
2 #include "Image.h"
3 #include "Anime.h"
4 #include "Font.h"
5 #include "Screen.h"
6
7 namespace DXFW
8 {
23 class BmpFont : public IFont
24 {
25 private:
26 ImagePack *divImageNumber;
27 ImagePack *divImageAlphabetCapital;
28 ImagePack *divImageAlphabetLow;
29
30 bool isNumber;
31 bool isAlphabetCapital;
32 bool isAlphabetLow;
33 int numberHeight;
34 int numberWidth;
35
36 int alphabetCapitalHeight;
37 int alphabetCapitalWidth;
38
39 int alphabetLowHeight;
40 int alphabetLowWidth;
41
42 int maxHeight;
43
44 int enterSpace;
45
46 int spaceWidth;
47 public:
48 BmpFont():
49 isNumber(false),
50 isAlphabetCapital(false),
51 isAlphabetLow(false),
52 enterSpace(0)
53 {}
54
55 ~BmpFont(){};
56
59 int GetEnterHeight() const
60 {
61 return this->enterSpace;
62 }
63
67 void SetEnterHeight(int height)
68 {
69 this->enterSpace;
70 }
71
75 bool SetNumber( ImagePack &数字用イメージ )
76 {
77 if( 数字用イメージ.GetSize() < 10 ) return false;
78
79 this->divImageNumber = &数字用イメージ;
80
81 this->numberWidth = 数字用イメージ.GetWidth();
82 this->numberHeight = 数字用イメージ.GetHeight();
83 this->spaceWidth = 数字用イメージ.GetWidth();
84
85 this->maxHeight = max( this->maxHeight , 数字用イメージ.GetHeight() );
86
87 this->isNumber = true;
88
89 return true;
90 }
91
95 bool SetAlphabetCapital(ImagePack &大文字用イメージ )
96 {
97 if( 大文字用イメージ.GetSize() < 26 ) return false;
98
99 this->divImageAlphabetCapital = &大文字用イメージ;
100
101 this->alphabetCapitalWidth = 大文字用イメージ.GetWidth();
102 this->alphabetCapitalHeight = 大文字用イメージ.GetHeight();
103 this->spaceWidth = 大文字用イメージ.GetWidth();
104
105 this->maxHeight = max( this->maxHeight , 大文字用イメージ.GetHeight() );
106
107 this->isAlphabetCapital = true;
108
109 return true;
110 }
111
115 bool SetAlphabetLow(ImagePack &小文字用イメージ )
116 {
117 if( 小文字用イメージ.GetSize() < 26 ) return false;
118
119 this->divImageAlphabetLow = &小文字用イメージ;
120
121 this->alphabetLowWidth = 小文字用イメージ.GetWidth();
122 this->alphabetLowHeight = 小文字用イメージ.GetHeight();
123 this->spaceWidth = 小文字用イメージ.GetWidth();
124
125 this->maxHeight = max( this->maxHeight , 小文字用イメージ.GetHeight() );
126
127 this->isAlphabetLow = true;
128 return true;
129 }
130
133 bool Draw(int x , int y , int rgb , const char *str , ...) const
134 {
135 char bufstr[1024];
136 va_list args;
137 va_start(args,str);
138 vsprintf_s( bufstr , 1024 ,str, args );
139 va_end(args);
140
141 int i = 0;
142 int addX = 0;
143 int addY = this->maxHeight;
144
145 while( bufstr[i] != NULL)
146 {
147 if( bufstr[i] >= '0' && bufstr[i] <= '9' && this->isNumber)
148 {
149 this->divImageNumber[0][ bufstr[i] - '0' ]->DrawExtend(
150 x + addX,
151 y + addY - this->numberHeight ,
152 x + addX + this->numberWidth ,
153 y + addY );
154
155 addX += this->numberWidth;
156 }
157 else if (bufstr[i] >= 'A' && bufstr[i] <= 'Z' && this->isAlphabetCapital)
158 {
159
160 this->divImageAlphabetCapital[0][ bufstr[i] - 'A' ]->DrawExtend
161 (
162 x + addX ,
163 y + addY - this->alphabetCapitalHeight ,
164 x + addX + this->alphabetCapitalWidth ,
165 y + addY
166 );
167
168 addX += this->alphabetCapitalWidth;
169
170 }
171 else if (bufstr[i] >= 'a' && bufstr[i] <= 'z' && this->isAlphabetLow)
172 {
173
174 this->divImageAlphabetLow[0][ bufstr[i] - 'a']->DrawExtend
175 (
176 x + addX,
177 y + addY - this->numberHeight ,
178 x + addX + this->numberWidth ,
179 y + addY
180 );
181
182 addX += this->alphabetLowWidth;
183
184 }
185 else if (bufstr[i] == ' ')
186 {
187 addX += this->spaceWidth;
188 }
189 else if (bufstr[i] == '\\' && bufstr[i+1] == 'n' )
190 {
191 addY += this->maxHeight + this->enterSpace;
192 }
193 i++;
194 if(i == strlen(bufstr) ) break;
195 }
196 return true;
197 }
198 bool ZMask(int x , int y , ZMaskType Zマスクタイプ , const char *str , ...) const
199 {
200 char bufstr[1024];
201 va_list args;
202 va_start(args,str);
203 vsprintf_s( bufstr , 1024 ,str, args );
204 va_end(args);
205
206 int i = 0;
207 int addX = 0;
208 int addY = this->maxHeight;
209
210 while( bufstr[i] != NULL)
211 {
212 if( bufstr[i] >= '0' && bufstr[i] <= '9' && this->isNumber)
213 {
214 this->divImageNumber[0][ bufstr[i] - '0' ]->ZMaskExtend
215 (
216 x + addX,
217 y + addY - this->numberHeight ,
218 x + addX + this->numberWidth ,
219 y + addY ,
220 Zマスクタイプ
221 );
222 addX += this->numberWidth;
223 }
224 else if (bufstr[i] >= 'A' && bufstr[i] <= 'Z' && this->isAlphabetCapital)
225 {
226
227 this->divImageAlphabetCapital[0][ bufstr[i] - 'A' ]->ZMaskExtend
228 (
229 x + addX ,
230 y + addY - this->alphabetCapitalHeight ,
231 x + addX + this->alphabetCapitalWidth ,
232 y + addY ,
233 Zマスクタイプ
234 );
235
236 addX += this->alphabetCapitalWidth;
237
238 }
239 else if (bufstr[i] >= 'a' && bufstr[i] <= 'z' && this->isAlphabetLow)
240 {
241
242 this->divImageAlphabetLow[0][ bufstr[i] - 'a']->ZMaskExtend
243 (
244 x + addX,
245 y + addY - this->numberHeight ,
246 x + addX + this->numberWidth ,
247 y + addY,
248 Zマスクタイプ
249 );
250
251 addX += this->alphabetLowWidth;
252
253 }
254 else if (bufstr[i] == ' ')
255 {
256 addX += this->spaceWidth;
257 }
258 else if (bufstr[i] == '\\' && bufstr[i+1] == 'n' )
259 {
260 addY += this->maxHeight + this->enterSpace;
261 }
262 i++;
263 if(i == strlen(bufstr) ) break;
264 }
265 return true;
266 }
267
270 bool DrawExtend( int x , int y , double extRateX , double extRateY , int rgb , const char *str , ...) const
271 {
272 char bufstr[1024];
273 va_list args;
274 va_start(args,str);
275 vsprintf_s( bufstr , 1024 ,str, args );
276 va_end(args);
277
278 int i = 0;
279 double addX = 0;
280 double addY = this->maxHeight;
281
282 while( bufstr[i] != NULL)
283 {
284 if( bufstr[i] >= '0' && bufstr[i] <= '9' && this->isNumber)
285 {
286
287 this->divImageNumber[0][bufstr[i] - '0' ]->DrawExtend
288 (
289 x + int(addX * extRateX ) ,
290 y + int((addY - this->numberHeight) * extRateY) ,
291 x + int((addX + this->numberWidth ) * extRateX ),
292 y + int(addY * extRateY )
293 );
294
295 addX += this->numberWidth;
296
297 }
298 else if (bufstr[i] >= 'A' && bufstr[i] <= 'Z' && this->isAlphabetCapital)
299 {
300
301 this->divImageAlphabetCapital[0][ bufstr[i] - 'A' ]->DrawExtend
302 (
303 x + int(addX * extRateX ) ,
304 y + int((addY - this->alphabetCapitalHeight) * extRateY) ,
305 x + int((addX + this->alphabetCapitalWidth) * extRateX ),
306 y + int(addY * extRateY )
307 );
308
309 addX += this->alphabetCapitalWidth;
310
311 }
312 else if (bufstr[i] >= 'a' && bufstr[i] <= 'z' && this->isAlphabetLow)
313 {
314 this->divImageAlphabetLow[0][ bufstr[i] - 'a']->DrawExtend
315 (
316 x + int(addX * extRateX ) ,
317 y + int((addY - this->alphabetLowHeight) * extRateY ) ,
318 x + int((addX + this->alphabetLowWidth) * extRateX ),
319 y + int(addY * extRateY )
320 );
321
322 addX += this->alphabetLowWidth;
323 }
324 else if (bufstr[i] == ' ')
325 {
326 addX += this->spaceWidth;
327 }
328 else if (bufstr[i] == '\\' && bufstr[i+1] == 'n' )
329 {
330 addY += this->maxHeight + this->enterSpace;
331 }
332 i++;
333 if(i == strlen(bufstr) ) break;
334 }
335 return true;
336 }
337 bool ZMaskExtend( int x , int y , double extRateX , double extRateY , ZMaskType Zマスクタイプ, const char *str , ...) const
338 {
339 char bufstr[1024];
340 va_list args;
341 va_start(args,str);
342 vsprintf_s( bufstr , 1024 ,str, args );
343 va_end(args);
344
345 int i = 0;
346 double addX = 0;
347 double addY = this->maxHeight;
348
349 while( bufstr[i] != NULL)
350 {
351 if( bufstr[i] >= '0' && bufstr[i] <= '9' && this->isNumber)
352 {
353
354 this->divImageNumber[0][bufstr[i] - '0' ]->ZMaskExtend
355 (
356 x + int(addX * extRateX ) ,
357 y + int((addY - this->numberHeight) * extRateY) ,
358 x + int((addX + this->numberWidth ) * extRateX ),
359 y + int(addY * extRateY ),
360 Zマスクタイプ
361 );
362
363 addX += this->numberWidth;
364
365 }
366 else if (bufstr[i] >= 'A' && bufstr[i] <= 'Z' && this->isAlphabetCapital)
367 {
368
369 this->divImageAlphabetCapital[0][ bufstr[i] - 'A' ]->ZMaskExtend
370 (
371 x + int(addX * extRateX ) ,
372 y + int((addY - this->alphabetCapitalHeight) * extRateY) ,
373 x + int((addX + this->alphabetCapitalWidth) * extRateX ),
374 y + int(addY * extRateY ),
375 Zマスクタイプ
376 );
377
378 addX += this->alphabetCapitalWidth;
379
380 }
381 else if (bufstr[i] >= 'a' && bufstr[i] <= 'z' && this->isAlphabetLow)
382 {
383 this->divImageAlphabetLow[0][ bufstr[i] - 'a']->ZMaskExtend
384 (
385 x + int(addX * extRateX ) ,
386 y + int((addY - this->alphabetLowHeight) * extRateY ) ,
387 x + int((addX + this->alphabetLowWidth) * extRateX ),
388 y + int(addY * extRateY ),
389 Zマスクタイプ
390 );
391
392 addX += this->alphabetLowWidth;
393 }
394 else if (bufstr[i] == ' ')
395 {
396 addX += this->spaceWidth;
397 }
398 else if (bufstr[i] == '\\' && bufstr[i+1] == 'n' )
399 {
400 addY += this->maxHeight + this->enterSpace;
401 }
402 i++;
403 if(i == strlen(bufstr) ) break;
404 }
405 return true;
406 }
407
408 };
409 }
DXFW::ImagePack::GetWidth
int GetWidth() const
最大幅を取得
Definition: Image.h:410
DXFW::ImagePack
複数のImageをまとめるクラス
Definition: Image.h:306
DXFW::BmpFont
ビットマップフォントを扱うクラス
Definition: BmpFont.h:23
DXFW::ImagePack::GetHeight
int GetHeight() const
最大高さを取得
Definition: Image.h:416
DXFW::BmpFont::SetNumber
bool SetNumber(ImagePack &数字用イメージ)
Definition: BmpFont.h:75
DXFW::ZMaskType
ZMaskType
Zマスクの種類
Definition: Image.h:12
DXFW::ImagePack::GetSize
int GetSize() const
要素数を取得
Definition: Image.h:404
DXFW::BmpFont::GetEnterHeight
int GetEnterHeight() const
Definition: BmpFont.h:59
DXFW::BmpFont::SetAlphabetCapital
bool SetAlphabetCapital(ImagePack &大文字用イメージ)
Definition: BmpFont.h:95
DXFW::BmpFont::ZMask
bool ZMask(int x, int y, ZMaskType Zマスクタイプ, const char *str,...) const
Definition: BmpFont.h:198
DXFW::IFont
説明
Definition: IFont.h:18
DXFW::BmpFont::SetEnterHeight
void SetEnterHeight(int height)
Definition: BmpFont.h:67
DXFW::BmpFont::Draw
bool Draw(int x, int y, int rgb, const char *str,...) const
書式付きで文字を描画
Definition: BmpFont.h:133
DXFW::BmpFont::SetAlphabetLow
bool SetAlphabetLow(ImagePack &小文字用イメージ)
Definition: BmpFont.h:115