make sure that drawn text is scaled + centered to middle of screen, if window size doesn't match expected ratio of 16:9
This commit is contained in:
@@ -1,23 +1,80 @@
|
|||||||
structure TitleVec =
|
structure TitleVec =
|
||||||
struct
|
struct
|
||||||
val fontSpace = Constants.fontSpace
|
fun helpGetTextVec
|
||||||
val fontSize = Constants.fontSize
|
(x, y, fontSize, fontSpace, windowWidth, windowHeight, pos, str, acc) =
|
||||||
|
|
||||||
fun getTextVec (x, y, windowWidth, windowHeight, pos, str, acc) =
|
|
||||||
if pos = String.size str then
|
if pos = String.size str then
|
||||||
Vector.concat acc
|
Vector.concat acc
|
||||||
else
|
else
|
||||||
let
|
let
|
||||||
val chr = String.sub (str, pos)
|
val chr = String.sub (str, pos)
|
||||||
val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr)
|
val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr)
|
||||||
|
|
||||||
val hd = chrFun
|
val hd = chrFun
|
||||||
(x, y, fontSize, fontSize, windowWidth, windowHeight, 0.0, 0.0, 0.0)
|
(x, y, fontSize, fontSize, windowWidth, windowHeight, 0.0, 0.0, 0.0)
|
||||||
val acc = hd :: acc
|
val acc = hd :: acc
|
||||||
in
|
in
|
||||||
getTextVec
|
helpGetTextVec
|
||||||
(x + fontSpace, y, windowWidth, windowHeight, pos + 1, str, acc)
|
( x + fontSpace
|
||||||
|
, y
|
||||||
|
, fontSize
|
||||||
|
, fontSpace
|
||||||
|
, windowWidth
|
||||||
|
, windowHeight
|
||||||
|
, pos + 1
|
||||||
|
, str
|
||||||
|
, acc
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fun getTextVec (x, y, width, height, str) =
|
||||||
|
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, [])
|
||||||
|
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, [])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
fun getDrawVec (title: TitleType.title_type, width, height) =
|
fun getDrawVec (title: TitleType.title_type, width, height) =
|
||||||
getTextVec (555, 55, width, height, 0, "hello world", [])
|
getTextVec (0, 0, width, height, "hello world")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user