2025-02-19 04:07:27 +00:00
|
|
|
structure TitleVec =
|
|
|
|
|
struct
|
2025-02-19 20:06:12 +00:00
|
|
|
open TitleType
|
|
|
|
|
|
2025-02-19 05:37:04 +00:00
|
|
|
fun helpGetTextVec
|
2025-02-20 05:46:00 +00:00
|
|
|
( x
|
|
|
|
|
, y
|
|
|
|
|
, fontSize
|
|
|
|
|
, fontSpace
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, pos
|
|
|
|
|
, str
|
|
|
|
|
, acc
|
|
|
|
|
, r
|
|
|
|
|
, g
|
|
|
|
|
, b
|
|
|
|
|
) =
|
2025-02-19 04:07:27 +00:00
|
|
|
if pos = String.size str then
|
2025-02-20 06:00:49 +00:00
|
|
|
acc
|
2025-02-19 04:07:27 +00:00
|
|
|
else
|
|
|
|
|
let
|
|
|
|
|
val chr = String.sub (str, pos)
|
|
|
|
|
val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr)
|
2025-02-19 05:37:04 +00:00
|
|
|
|
2025-02-19 04:07:27 +00:00
|
|
|
val hd = chrFun
|
2025-02-19 20:06:12 +00:00
|
|
|
(x, y, fontSize, fontSize, windowWidth, windowHeight, r, g, b)
|
2025-02-19 04:07:27 +00:00
|
|
|
val acc = hd :: acc
|
|
|
|
|
in
|
2025-02-19 05:37:04 +00:00
|
|
|
helpGetTextVec
|
|
|
|
|
( x + fontSpace
|
|
|
|
|
, y
|
|
|
|
|
, fontSize
|
|
|
|
|
, fontSpace
|
|
|
|
|
, windowWidth
|
|
|
|
|
, windowHeight
|
|
|
|
|
, pos + 1
|
|
|
|
|
, str
|
|
|
|
|
, acc
|
2025-02-19 20:06:12 +00:00
|
|
|
, r
|
|
|
|
|
, g
|
|
|
|
|
, b
|
2025-02-19 05:37:04 +00:00
|
|
|
)
|
2025-02-19 04:07:27 +00:00
|
|
|
end
|
|
|
|
|
|
2025-02-20 05:46:00 +00:00
|
|
|
fun getTextWidth text = String.size text * Constants.fontSpace
|
2025-02-19 19:59:05 +00:00
|
|
|
|
|
|
|
|
(* x coordinate that will let us place this text on centre of screen *)
|
|
|
|
|
fun getTextCentreX text =
|
2025-02-20 05:46:00 +00:00
|
|
|
let val textWidth = getTextWidth text
|
|
|
|
|
in (Constants.worldWidth - textWidth) div 2
|
2025-02-19 19:59:05 +00:00
|
|
|
end
|
|
|
|
|
|
2025-02-20 06:00:49 +00:00
|
|
|
fun getTextVec (x, y, width, height, str, r, g, b, acc) =
|
2025-02-19 05:37:04 +00:00
|
|
|
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
|
2025-02-20 05:46:00 +00:00
|
|
|
helpGetTextVec
|
2025-02-20 06:00:49 +00:00
|
|
|
(x, y, fontSize, fontSpace, width, height, 0, str, acc, r, g, b)
|
2025-02-19 05:37:04 +00:00
|
|
|
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
|
2025-02-20 05:46:00 +00:00
|
|
|
helpGetTextVec
|
2025-02-20 06:00:49 +00:00
|
|
|
(x, y, fontSize, fontSpace, width, height, 0, str, acc, r, g, b)
|
2025-02-19 05:37:04 +00:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2025-02-19 04:07:27 +00:00
|
|
|
fun getDrawVec (title: TitleType.title_type, width, height) =
|
2025-02-19 20:06:12 +00:00
|
|
|
case #focus title of
|
|
|
|
|
START_BUTTON =>
|
2025-02-20 06:00:49 +00:00
|
|
|
let
|
|
|
|
|
val playX = getTextCentreX "Play game"
|
|
|
|
|
val acc =
|
|
|
|
|
getTextVec (playX, 500, width, height, "Play game", 0.3, 0.3, 0.7, [])
|
|
|
|
|
|
|
|
|
|
val optionsX = getTextCentreX "Options"
|
|
|
|
|
val acc =
|
|
|
|
|
getTextVec (optionsX, 600, width, height, "Options", 0.0, 0.0, 0.0, acc)
|
|
|
|
|
in
|
|
|
|
|
Vector.concat acc
|
|
|
|
|
end
|
|
|
|
|
| OPTIONS_BUTTON =>
|
|
|
|
|
let
|
|
|
|
|
val playX = getTextCentreX "Play game"
|
|
|
|
|
val acc =
|
|
|
|
|
getTextVec (playX, 500, width, height, "Play game", 0.0, 0.0, 0.0, [])
|
|
|
|
|
|
|
|
|
|
val optionsX = getTextCentreX "Options"
|
|
|
|
|
val acc =
|
|
|
|
|
getTextVec (optionsX, 600, width, height, "Options", 0.3, 0.3, 0.7, acc)
|
|
|
|
|
in
|
|
|
|
|
Vector.concat acc
|
2025-02-19 20:06:12 +00:00
|
|
|
end
|
2025-02-19 04:07:27 +00:00
|
|
|
end
|