SDXFrameWork  0.09
SDXFrameWork
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
BmpFont.h
1 #pragma once//©SDXFramework http://sourceforge.jp/projects/dxframework/
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 {
11 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 
53  void SetEnterHeight(int 改行の高さ)
54  {
55  this->enterSpace = 改行の高さ;
56  }
57 
61  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 
80  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 
100  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(const Point &座標 , Color 描画色 , VariadicStream 描画する文字列 ) const override
118  {
119  Screen::SetBright(描画色);
120 
121 
122  for (auto it : 描画する文字列.StringS)
123  {
124  int a = 0;
125  int addX = 0;
126  int addY = this->maxHeight;
127  const char* bufstr = it.c_str();
128 
129  while ( bufstr[a] != 0)//終端なら終了
130  {
131  if (bufstr[a] >= '0' && bufstr[a] <= '9' && this->isNumber)
132  {
133  divImageNumber[0][bufstr[a] - '0']->DrawExtend(
134  { 座標.x + addX,
135  座標.y + addY - this->numberHeight },
136  { 座標.x + addX + this->numberWidth,
137  座標.y + addY });
138 
139  addX += this->numberWidth;
140  }
141  else if (bufstr[a] >= 'A' && bufstr[a] <= 'Z' && this->isAlphabetCapital)
142  {
143 
144  divImageAlphabetCapital[0][bufstr[a] - 'A']->DrawExtend
145  (
146  { 座標.x + addX,
147  座標.y + addY - this->alphabetCapitalHeight },
148  { 座標.x + addX + this->alphabetCapitalWidth,
149  座標.y + addY }
150  );
151 
152  addX += this->alphabetCapitalWidth;
153 
154  }
155  else if (bufstr[a] >= 'a' && bufstr[a] <= 'z' && this->isAlphabetLow)
156  {
157 
158  divImageAlphabetLow[0][bufstr[a] - 'a']->DrawExtend
159  (
160  { 座標.x + addX,
161  座標.y + addY - this->numberHeight },
162  { 座標.x + addX + this->numberWidth,
163  座標.y + addY }
164  );
165 
166  addX += this->alphabetLowWidth;
167 
168  }
169  else if ( bufstr[a] == ' ')
170  {
171  addX += spaceWidth;
172  }
173  ++a;
174  if (a == strlen( bufstr )) break;
175  }
176  addY += maxHeight + enterSpace;
177  }
178 
179  Screen::SetBright(Color::White);
180  return true;
181  }
182 
184  bool DrawRotate(const Point &座標, double 拡大率, double 角度, Color 描画色, bool 反転フラグ, VariadicStream 描画する文字列) const override
185  {
186  return false;
187  }
188 
190  bool DrawExtend(const Point &座標, double X拡大率, double Y拡大率, Color 描画色, VariadicStream 描画する文字列) const override
191  {
192  for (auto it : 描画する文字列.StringS)
193  {
194  int a = 0;
195  int addX = 0;
196  int addY = this->maxHeight;
197  const char* bufstr = it.c_str();
198 
199  Screen::SetBright(描画色);
200 
201  while (bufstr[a] != 0)
202  {
203  if (bufstr[a] >= '0' && bufstr[a] <= '9' && this->isNumber)
204  {
205 
206  this->divImageNumber[0][bufstr[a] - '0']->DrawExtend
207  (
208  { 座標.x + int(addX * X拡大率),
209  座標.y + int((addY - this->numberHeight) * Y拡大率) },
210  { 座標.x + int((addX + this->numberWidth) * X拡大率),
211  座標.y + int(addY * Y拡大率) }
212  );
213 
214  addX += this->numberWidth;
215 
216  }
217  else if (bufstr[a] >= 'A' && bufstr[a] <= 'Z' && this->isAlphabetCapital)
218  {
219 
220  this->divImageAlphabetCapital[0][bufstr[a] - 'A']->DrawExtend
221  (
222  { 座標.x + int(addX * X拡大率),
223  座標.y + int((addY - this->alphabetCapitalHeight) * Y拡大率) },
224  { 座標.x + int((addX + this->alphabetCapitalWidth) * X拡大率),
225  座標.y + int(addY * Y拡大率) }
226  );
227 
228  addX += this->alphabetCapitalWidth;
229 
230  }
231  else if (bufstr[a] >= 'a' && bufstr[a] <= 'z' && this->isAlphabetLow)
232  {
233  this->divImageAlphabetLow[0][bufstr[a] - 'a']->DrawExtend
234  (
235  { 座標.x + int(addX * X拡大率),
236  座標.y + int((addY - this->alphabetLowHeight) * Y拡大率) },
237  { 座標.x + int((addX + this->alphabetLowWidth) * X拡大率),
238  座標.y + int(addY * Y拡大率) }
239  );
240 
241  addX += this->alphabetLowWidth;
242  }
243  else if (bufstr[a] == ' ')
244  {
245  addX += this->spaceWidth;
246  }
247  ++a;
248  if (a == strlen(bufstr)) break;
249  }
250  addY += this->maxHeight + this->enterSpace;
251  }
252 
253  Screen::SetBright(Color::White);
254 
255  return true;
256  }
257 
258 };
259 }
bool DrawRotate(const Point &座標, double 拡大率, double 角度, Color 描画色, bool 反転フラグ, VariadicStream 描画する文字列) const override
文字を回転して描画[未実装].
Definition: BmpFont.h:184
bool DrawExtend(const Point &座標, double X拡大率, double Y拡大率, Color 描画色, VariadicStream 描画する文字列) const override
拡大率を指定して文字を描画.
Definition: BmpFont.h:190
Font,BmpFont等のインターフェース.
Definition: IFont.h:9
int GetWidth() const
最大幅を取得.
Definition: ImagePack.h:107
static bool SetBright(Color 輝度)
描画輝度を設定.
Definition: Screen.h:149
点を表す図形クラス.
Definition: Shape.h:129
ビットマップフォントを表すクラス.
Definition: BmpFont.h:11
bool SetNumber(ImagePack *数字用イメージ)
数字フォントを設定.
Definition: BmpFont.h:61
bool SetAlphabetCapital(ImagePack *大文字用イメージ)
英大文字フォントをセット.
Definition: BmpFont.h:80
bool Draw(const Point &座標, Color 描画色, VariadicStream 描画する文字列) const override
書式付きで文字を描画.
Definition: BmpFont.h:117
色を表すクラス.
Definition: Color.h:7
int GetSize() const
要素数を取得.
Definition: ImagePack.h:101
可変数引数な文字列を処理するクラス.
Definition: VariadicStream.h:8
int GetHeight() const
最大高さを取得.
Definition: ImagePack.h:113
bool SetAlphabetLow(ImagePack *小文字用イメージ)
英小文字フォントをセット.
Definition: BmpFont.h:100
複数のImageをまとめるクラス.
Definition: ImagePack.h:9
int GetEnterHeight() const
改行の高さを取得.
Definition: BmpFont.h:46
void SetEnterHeight(int 改行の高さ)
改行の高さを設定.
Definition: BmpFont.h:53