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