Add 'game-sml/' from commit '113c3e67abe635f714f972a1e2ab0e4b24ff10f4'
git-subtree-dir: game-sml git-subtree-mainline:aa5357714dgit-subtree-split:113c3e67ab
This commit is contained in:
102
game-sml/fcore/make-text-vec.sml
Normal file
102
game-sml/fcore/make-text-vec.sml
Normal file
@@ -0,0 +1,102 @@
|
||||
structure MakeTextVec =
|
||||
struct
|
||||
fun helpGetTextVec
|
||||
( x
|
||||
, y
|
||||
, fontSize
|
||||
, fontSpace
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, pos
|
||||
, str
|
||||
, acc
|
||||
, r
|
||||
, g
|
||||
, b
|
||||
) =
|
||||
if pos = String.size str then
|
||||
acc
|
||||
else
|
||||
let
|
||||
val chr = String.sub (str, pos)
|
||||
val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr)
|
||||
|
||||
val hd = chrFun
|
||||
(x, y, fontSize, fontSize, windowWidth, windowHeight, r, g, b)
|
||||
val acc = hd :: acc
|
||||
in
|
||||
helpGetTextVec
|
||||
( x + fontSpace
|
||||
, y
|
||||
, fontSize
|
||||
, fontSpace
|
||||
, windowWidth
|
||||
, windowHeight
|
||||
, pos + 1
|
||||
, str
|
||||
, acc
|
||||
, r
|
||||
, g
|
||||
, b
|
||||
)
|
||||
end
|
||||
|
||||
fun getTextWidth text = String.size text * Constants.fontSpace
|
||||
|
||||
(* x coordinate that will let us place this text on centre of screen *)
|
||||
fun getTextCentreX text =
|
||||
let val textWidth = getTextWidth text
|
||||
in (Constants.worldWidth - textWidth) div 2
|
||||
end
|
||||
|
||||
fun make (x, y, width, height, str, r, g, b, acc) =
|
||||
let
|
||||
val wratio = width / Constants.worldWidthReal
|
||||
val hratio = height / Constants.worldHeightReal
|
||||
in
|
||||
if wratio < hratio then
|
||||
let
|
||||
val scale = Constants.worldHeightReal * wratio
|
||||
val yOffset =
|
||||
if height > scale then (height - scale) / 2.0
|
||||
else if height < scale then (scale - height) / 2.0
|
||||
else 0.0
|
||||
|
||||
val x = Real32.fromInt x * wratio
|
||||
val y = Real32.fromInt y * wratio + yOffset
|
||||
|
||||
val x = Real32.toInt IEEEReal.TO_NEAREST x
|
||||
val y = Real32.toInt IEEEReal.TO_NEAREST y
|
||||
|
||||
val fontSize = Constants.fontSize * wratio
|
||||
|
||||
val fontSpace = Real32.fromInt Constants.fontSpace * wratio
|
||||
val fontSpace = Real32.toInt IEEEReal.TO_NEAREST fontSpace
|
||||
in
|
||||
helpGetTextVec
|
||||
(x, y, fontSize, fontSpace, width, height, 0, str, acc, r, g, b)
|
||||
end
|
||||
else
|
||||
let
|
||||
val scale = Constants.worldWidthReal * hratio
|
||||
val xOffset =
|
||||
if width > scale then (width - scale) / 2.0
|
||||
else if width < scale then (scale - width) / 2.0
|
||||
else 0.0
|
||||
|
||||
val x = Real32.fromInt x * hratio + xOffset
|
||||
val y = Real32.fromInt y * hratio
|
||||
|
||||
val x = Real32.toInt IEEEReal.TO_NEAREST x
|
||||
val y = Real32.toInt IEEEReal.TO_NEAREST y
|
||||
|
||||
val fontSize = Constants.fontSize * hratio
|
||||
|
||||
val fontSpace = Real32.fromInt Constants.fontSpace * hratio
|
||||
val fontSpace = Real32.toInt IEEEReal.TO_NEAREST fontSpace
|
||||
in
|
||||
helpGetTextVec
|
||||
(x, y, fontSize, fontSpace, width, height, 0, str, acc, r, g, b)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user