SDXFrameWork  0.07
SDXFrameWork
 全て クラス ネームスペース 関数 変数 列挙型 列挙型の値 ページ
Font.h
1 #pragma once//☀SDL
2 #include <Multimedia/SDX.h>
3 #include <Multimedia/Screen.h>
4 #include <Multimedia/IFont.h>
5 #include <Multimedia/SystemFont.h>
6 #include <Multimedia/Image.h>
7 #include <Multimedia/Window.h>
8 
9 namespace SDX
10 {
12 enum class FontType
13 {
14  Normal,
15  Edge,
16  AntiAliase,
17  AntiAliaseEdge
18 };
19 
20 
23 class Font : public IFont
24 {
25 private:
26  FontHandle handle = NULL_HANDLE;
27  int size = 0;
28  int thick = 0;
29  int enterHeight = 0;
30 public:
31  Font(){}
32 
33  Font(const char *フォント名,int 大きさ ,int 太さ = 1 , int 改行高さ = 0 , FontType フォントタイプ = FontType::Normal)
34  {
35  Font::Load( フォント名 , 大きさ , 太さ , 改行高さ , フォントタイプ);
36  }
37 
43  bool Load(const char *フォント名,int 大きさ ,int 太さ = 1 , int 改行高さ = 0, FontType フォントタイプ = FontType::Normal)
44  {
45  Release();
46  this->size = 大きさ;
47  this->enterHeight = 改行高さ + 大きさ;
48  this->thick = 太さ;
49 
50  handle = TTF_OpenFont(フォント名,大きさ);
51  return (handle != nullptr);
52  }
53 
55  bool Release() const
56  {
57  if(handle != nullptr) return false;
58 
59  TTF_CloseFont(handle);
60  return true;
61  }
62 
64  FontHandle GetHandle() const
65  {
66  return handle;
67  }
68 
70  Image MakeImage(Color 文字色, bool 反転フラグ, VariadicStream 描画する文字列) const
71  {
72  Image image;
73  int 幅 = GetDrawStringWidth(描画する文字列);
74  int 高さ = ((int)描画する文字列.StringS.size()-1) * enterHeight + size;
75  int Y座標 = 0;
76 
77  std::vector<SDL_Surface*> surfaces;
78 
79  for (auto it : 描画する文字列.StringS)
80  {
81  SDL_Surface* surface = TTF_RenderUTF8_Blended(handle, it.c_str(), 文字色);
82  幅 = std::max(幅, surface->w);
83  surfaces.push_back( surface );
84  }
85 
86  SDL_Surface* toRend = SDL_CreateRGBSurface(0, 幅, 高さ, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
87  SDL_Renderer* render = SDL_CreateSoftwareRenderer( toRend );
88 
89  for (auto it : surfaces)
90  {
91  SDL_Texture* texture = SDL_CreateTextureFromSurface( render , it);
92 
93  SDL_Rect temp = { 0, Y座標, it->w, it->h };
94  SDL_RenderCopy( render , texture , 0, &temp);
95 
96  Y座標 += this->enterHeight;
97 
98  SDL_FreeSurface(it);
99  SDL_DestroyTexture( texture );
100  }
101  //描画先を戻す
102  image.handle = SDL_CreateTextureFromSurface( Screen::GetHandle() , toRend);
103  image.part.x = 0;
104  image.part.y = 0;
105  image.part.w = 幅;
106  image.part.h = 高さ;
107 
108  SDL_FreeSurface(toRend);
109  SDL_DestroyRenderer(render);
110 
111  return image;
112  }
113 
115  int GetSize() const
116  {
117  return this->size;
118  }
119 
121  int Getthick() const
122  {
123  return this->thick;
124  }
125 
127  int GetDrawStringWidth( VariadicStream 幅を計算する文字列 ) const
128  {
129  int 幅 = 0;
130 
131  return 幅;
132  }
133 
135  bool Draw(int X座標, int Y座標, Color 色, VariadicStream 描画する文字列) const
136  {
137  if( !handle ) return false;
138 
139  SDL_Surface* image;
140  SDL_Texture* moji;
141  SDL_Rect temp;
142 
143  for( auto it : 描画する文字列.StringS)
144  {
145  if(it.size() > 0)
146  {
147  image = TTF_RenderUTF8_Blended(handle, it.c_str() , 色);
148 
149  moji = SDL_CreateTextureFromSurface(Screen::GetHandle(), image);
150  temp = { X座標, Y座標, image->w, image->h };
151  SDL_RenderCopy(Screen::GetHandle(), moji, 0, &temp);
152 
153  SDL_FreeSurface(image);
154  SDL_DestroyTexture(moji);
155  }
156  Y座標 += this->enterHeight;
157  }
158 
159  return true;
160  }
162  bool ZMask(int X座標, int Y座標, ZMaskType Zマスクタイプ, VariadicStream 描画する文字列 ) const
163  {
164  return false;
165  }
166 
169  bool DrawRotate(int X座標, int Y座標, double 拡大率, double 角度, Color 描画色 , bool 反転フラグ, VariadicStream 描画する文字列) const
170  {
171  Image 文字イメージ = MakeImage(描画色, 反転フラグ, 描画する文字列);
172  文字イメージ.DrawRotate(X座標,Y座標,拡大率,角度,反転フラグ);
173  文字イメージ.Release();
174  return true;
175  }
176 
178  bool ZMaskRotate(int X座標, int Y座標, double 拡大率, double 角度, ZMaskType Zマスクタイプ, bool 反転フラグ, VariadicStream 描画する文字列) const
179  {
180  Image 文字イメージ = MakeImage(Color::White, 反転フラグ, 描画する文字列);
181  文字イメージ.ZMaskRotate(X座標, Y座標, 拡大率, 角度, Zマスクタイプ, 反転フラグ);
182  文字イメージ.Release();
183  return true;
184  }
185 
187  bool DrawExtend(int X座標, int Y座標, double X拡大率, double Y拡大率, Color 描画色, VariadicStream 描画する文字列) const
188  {
189  if( !handle ) return false;
190 
191  SDL_Surface* image;
192  SDL_Texture* moji;
193  SDL_Rect temp;
194  for (auto it:描画する文字列.StringS)
195  {
196  if(it.size() > 0 )
197  {
198  image = TTF_RenderUTF8_Blended(handle, it.c_str() , 描画色);
199 
200  moji = SDL_CreateTextureFromSurface(Screen::GetHandle(), image);
201  temp = { X座標, Y座標, int(image->w * X拡大率), int(image->h * Y拡大率) };
202 
203  SDL_RenderCopy(Screen::GetHandle(), moji, 0, &temp);
204  SDL_FreeSurface(image);
205  SDL_DestroyTexture(moji);
206  }
207 
208  Y座標 += int(this->enterHeight * Y拡大率);
209  }
210 
211  return true;
212  }
214  bool ZMaskExtend(int X座標, int Y座標, double X拡大率, double Y拡大率, ZMaskType Zマスクタイプ, VariadicStream 描画する文字列) const
215  {
216  return false;
217  }
218 };
219 }
ZMaskType
Zマスクの種類.
Definition: Image.h:8
次のコマに進む
Font,BmpFont等のインターフェース.
Definition: IFont.h:9
bool ZMaskRotate(int X座標, int Y座標, double 拡大率, double 角度, ZMaskType Zマスクタイプ, bool 反転フラグ=false) const
角度、拡大率を指定してマスク[DXLIB].
Definition: Image.h:205
bool DrawRotate(int X座標, int Y座標, double 拡大率, double 角度, Color 描画色, bool 反転フラグ, VariadicStream 描画する文字列) const
文字を回転して描画.
Definition: Font.h:169
FontHandle GetHandle() const
フォントのハンドルを取得.
Definition: Font.h:64
フォントデータを表すクラス.
Definition: Font.h:23
int GetDrawStringWidth(VariadicStream 幅を計算する文字列) const
描画時の幅を取得[DXLIB].
Definition: Font.h:127
int GetSize() const
大きさを取得.
Definition: Font.h:115
bool ZMask(int X座標, int Y座標, ZMaskType Zマスクタイプ, VariadicStream 描画する文字列) const
文字をマスク[DXLIB].
Definition: Font.h:162
画像データを表すクラス.
Definition: Image.h:37
色を表すクラス.
Definition: Color.h:7
int Getthick() const
太さを取得.
Definition: Font.h:121
bool Release() const
フォントをメモリから開放する.
Definition: Font.h:55
bool DrawExtend(int X座標, int Y座標, double X拡大率, double Y拡大率, Color 描画色, VariadicStream 描画する文字列) const
拡大率を指定して文字を描画.
Definition: Font.h:187
bool Release()
イメージをメモリから開放.
Definition: Image.h:112
可変数引数な文字列を処理するクラス.
Definition: VariadicStream.h:8
Image MakeImage(Color 文字色, bool 反転フラグ, VariadicStream 描画する文字列) const
フォントから画像を生成
Definition: Font.h:70
bool ZMaskRotate(int X座標, int Y座標, double 拡大率, double 角度, ZMaskType Zマスクタイプ, bool 反転フラグ, VariadicStream 描画する文字列) const
文字を回転してマスク[DXLIB].
Definition: Font.h:178
FontType
フォントの種類.
Definition: Font.h:12
bool Draw(int X座標, int Y座標, Color 色, VariadicStream 描画する文字列) const
文字を描画.
Definition: Font.h:135
bool Load(const char *フォント名, int 大きさ, int 太さ=1, int 改行高さ=0, FontType フォントタイプ=FontType::Normal)
メモリ上にフォントを作成する.
Definition: Font.h:43
bool ZMaskExtend(int X座標, int Y座標, double X拡大率, double Y拡大率, ZMaskType Zマスクタイプ, VariadicStream 描画する文字列) const
拡大率を指定して文字をマスク[DXLIB].
Definition: Font.h:214
static ScreenHandle GetHandle()
スクリーンハンドルを取得.
Definition: Screen.h:49
bool DrawRotate(int X座標, int Y座標, double 拡大率, double 角度, bool 反転フラグ=false) const
角度、拡大率を指定して描画.
Definition: Image.h:195