Created
September 24, 2013 14:58
-
-
Save hirosof/6686030 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#module | |
#uselib "gdi32.dll" | |
#func GetTextExtentPoint32 "GetTextExtentPoint32A" int , str , int , sptr | |
//一行の文字列から描画時のサイズを求める | |
#deffunc GetStringDrawSize str string, var sx , var sy | |
if(strlen(string)){ | |
dim size,2 | |
GetTextExtentPoint32 hdc , string , strlen(string) , varptr(size) | |
sx = size(0) : sy = size(1) | |
return 1 | |
}else{ | |
return 0 | |
} | |
//複数行の文字列から描画時のサイズを求める | |
#deffunc GetStringDrawSizeEx str string, var sx , var sy | |
if(strlen(string)){ | |
sdim b_str | |
b_str = string | |
notesel b_str | |
repeat notemax | |
noteget b_str_one , cnt | |
GetStringDrawSize b_str_one , b_sx, b_sy | |
if(stat == 1){ | |
if( cnt == 0) { | |
sx = size(0) : sy = size(1) | |
}else{ | |
if(sx < size(0)) : sx = size(0) | |
sy+=size(1) | |
} | |
} | |
loop | |
noteunsel | |
return 1 | |
}else{ | |
return 0 | |
} | |
#global | |
//以下サンプル | |
//描画対象文字列 | |
Text = "描画文字列\nDraw Text" | |
//フォント変更 | |
// ※GetStringDrawSize又は | |
// GetStringDrawSizeExを呼ぶ前に | |
// 行うこと | |
font "メイリオ",72 | |
//文字列の描画時のサイズを求める | |
GetStringDrawSizeEx Text, sx ,sy | |
//文字列の描画領域を塗りつぶす | |
color 0,128,0 | |
boxf (ginfo(12) - sx) / 2 , (ginfo(13) - sy)/2 , (ginfo(12) + sx) / 2 , (ginfo(13) + sy)/2 | |
//文字列表示 | |
color 255,255,0 | |
pos (ginfo(12) - sx) / 2 , (ginfo(13) - sy)/2 | |
print Text | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment