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>
19 FontHandle handle = NULL_HANDLE;
23 std::map<std::string, Image*> hash;
29 HashFont(
const char *フォント名,
int 大きさ,
int 太さ = 1,
int 改行高さ = 0,
FontType フォントタイプ = FontType::Normal)
31 Load( フォント名 , 大きさ , 太さ , 改行高さ , フォントタイプ);
39 bool Load(
const char *フォント名,
int 大きさ ,
int 太さ = 1 ,
int 改行高さ = 0,
FontType フォントタイプ = FontType::Normal)
43 this->enterHeight = 改行高さ + 大きさ;
45 handle = TTF_OpenFont(フォント名,大きさ);
52 if(handle != NULL_HANDLE)
return false;
53 TTF_CloseFont(handle);
69 std::vector<SDL_Surface*> surfaces;
72 for (
auto it : 描画する文字列.StringS)
74 surface = TTF_RenderUTF8_Blended(handle, it.c_str(), 文字色);
75 幅 = std::max(幅, surface->w);
76 surfaces.push_back( surface );
79 SDL_Surface* toRend = SDL_CreateRGBSurface(0, 幅, 高さ, 32, 0, 0, 0, 0);
80 SDL_Renderer* render = SDL_CreateSoftwareRenderer( toRend );
82 for (
auto it : surfaces)
84 SDL_Texture* texture = SDL_CreateTextureFromSurface(render, it);
86 SDL_Rect temp = { 0, Y座標, it->w, it->h };
87 SDL_RenderCopy( render , texture , 0, &temp);
89 Y座標 += this->enterHeight;
92 SDL_DestroyTexture( texture );
99 SDL_FreeSurface(toRend);
100 SDL_DestroyRenderer(render);
105 Image* GetHash(
const char* 文字)
const
107 auto it = hash.find(文字);
109 if (it == hash.end())
111 SDL_Surface* surface = TTF_RenderUTF8_Blended(handle, 文字, { 255, 255, 255 });
113 Image* image =
new Image(moji, surface->w, surface->h);
114 std::map<std::string, Image*> *map =
const_cast<std::map<std::string, Image*>*
>( &hash);
115 map->operator[](文字) = image;
116 SDL_FreeSurface(surface);
137 for (
auto it : 幅を計算する文字列.StringS)
139 幅 = std::max( 幅 , DxLib::GetDrawStringWidthToHandle(it.c_str(), strlen(it.c_str()), this->handle) );
144 void DrawUTFString(
int X座標 ,
int Y座標 ,
const std::string &文字列)
const
148 for (
auto it = 文字列.begin(); it != 文字列.end(); it += charSize)
151 if(lead < 0x80) charSize = 1;
152 else if (lead < 0xE0) charSize = 2;
153 else if (lead < 0xF0) charSize = 3;
156 Image* str = GetHash( 文字列.substr(std::distance(文字列.begin() , it) , charSize).c_str() );
165 if( !handle )
return false;
166 for (
auto it : 描画する文字列.StringS)
168 DrawUTFString(X座標, Y座標, it);
169 Y座標 += this->enterHeight;
199 for (
auto it:描画する文字列.StringS)
201 image = TTF_RenderUTF8_Blended(handle, it.c_str() , 描画色);
204 temp = { X座標, Y座標, int(image->w * X拡大率), int(image->h * Y拡大率) };
208 Y座標 += int(this->enterHeight * Y拡大率);
209 SDL_FreeSurface(image);
210 SDL_DestroyTexture(moji);
ZMaskType
Zマスクの種類.
Definition: Image.h:8
Font,BmpFont等のインターフェース.
Definition: IFont.h:9
bool Release() const
フォントをメモリから開放する.
Definition: HashFont.h:50
bool ZMaskRotate(int X座標, int Y座標, double 拡大率, double 角度, ZMaskType Zマスクタイプ, bool 反転フラグ, VariadicStream 描画する文字列) const
文字を回転してマスク[DXLIB].
Definition: HashFont.h:188
bool Load(const char *フォント名, int 大きさ, int 太さ=1, int 改行高さ=0, FontType フォントタイプ=FontType::Normal)
メモリ上にフォントを作成する.
Definition: HashFont.h:39
bool Draw(int X座標, int Y座標, bool 反転フラグ=false) const
指定座標に描画.
Definition: Image.h:163
bool ZMask(int X座標, int Y座標, ZMaskType Zマスクタイプ, VariadicStream 描画する文字列) const
文字をマスク[DXLIB].
Definition: HashFont.h:175
int GetDrawStringWidth(VariadicStream 幅を計算する文字列) const
描画時の幅を取得[DXLIB].
Definition: HashFont.h:135
bool ZMaskExtend(int X座標, int Y座標, double X拡大率, double Y拡大率, ZMaskType Zマスクタイプ, VariadicStream 描画する文字列) const
拡大率を指定して文字をマスク[DXLIB].
Definition: HashFont.h:214
画像データを表すクラス.
Definition: Image.h:37
int Getthick() const
太さを取得.
Definition: HashFont.h:129
色を表すクラス.
Definition: Color.h:7
bool Draw(int X座標, int Y座標, Color 色, VariadicStream 描画する文字列) const
文字を描画.
Definition: HashFont.h:163
int GetWidth() const
幅を取得.
Definition: Image.h:277
可変数引数な文字列を処理するクラス.
Definition: VariadicStream.h:8
bool DrawRotate(int X座標, int Y座標, double 拡大率, double 角度, Color 描画色, bool 反転フラグ, VariadicStream 描画する文字列) const
文字を回転して描画.
Definition: HashFont.h:182
フォントデータを表すクラス[SDL専用].
Definition: HashFont.h:16
FontType
フォントの種類.
Definition: Font.h:12
FontHandle GetHandle() const
フォントのハンドルを取得.
Definition: HashFont.h:62
static ScreenHandle GetHandle()
スクリーンハンドルを取得.
Definition: Screen.h:49
bool DrawExtend(int X座標, int Y座標, double X拡大率, double Y拡大率, Color 描画色, VariadicStream 描画する文字列) const
拡大率を指定して文字を描画.
Definition: HashFont.h:194
int GetSize() const
大きさを取得.
Definition: HashFont.h:123