create new rect which is adapted to new text, and use it in text-builder.sml
This commit is contained in:
@@ -1,27 +1,35 @@
|
||||
structure Rect =
|
||||
structure Rect =
|
||||
struct
|
||||
fun lerp (startX, startY, drawWidth, drawHeight, windowWidth, windowHeight, r, g, b) : Real32.real vector =
|
||||
fun xToNdc (xOffset, xpos, scale, halfWidth) =
|
||||
((xpos * scale + xOffset) - halfWidth) / halfWidth
|
||||
|
||||
fun yToNdc (yOffset, ypos, scale, halfHeight) =
|
||||
~(((ypos * scale + yOffset) - halfHeight) / halfHeight)
|
||||
|
||||
fun lerp (xOffset: Real32.real, yOffset, scale, windowWidth, windowHeight, r, g, b) =
|
||||
let
|
||||
val startX = Real32.fromInt startX
|
||||
val startY = Real32.fromInt startY
|
||||
val endY = windowHeight - startY
|
||||
val startY = windowHeight - (startY + drawHeight)
|
||||
val endX = startX + drawWidth
|
||||
val windowHeight = windowHeight / 2.0
|
||||
val windowWidth = windowWidth / 2.0
|
||||
val halfWidth = windowWidth / 2.0
|
||||
val halfHeight = windowHeight / 2.0
|
||||
in
|
||||
#[ (((startX * (1.0 - 0.733333349228)) + (endX * 0.733333349228)) / windowWidth) - 1.0,
|
||||
(((startY * (1.0 - 1.0)) + (endY * 1.0)) / windowHeight) - 1.0, r, g, b,
|
||||
(((startX * (1.0 - 0.733333349228)) + (endX * 0.733333349228)) / windowWidth) - 1.0,
|
||||
(((startY * (1.0 - 0.0)) + (endY * 0.0)) / windowHeight) - 1.0, r, g, b,
|
||||
(((startX * (1.0 - 0.266666650772)) + (endX * 0.266666650772)) / windowWidth) - 1.0,
|
||||
(((startY * (1.0 - 0.0)) + (endY * 0.0)) / windowHeight) - 1.0, r, g, b,
|
||||
(((startX * (1.0 - 0.266666650772)) + (endX * 0.266666650772)) / windowWidth) - 1.0,
|
||||
(((startY * (1.0 - 0.0)) + (endY * 0.0)) / windowHeight) - 1.0, r, g, b,
|
||||
(((startX * (1.0 - 0.266666650772)) + (endX * 0.266666650772)) / windowWidth) - 1.0,
|
||||
(((startY * (1.0 - 1.0)) + (endY * 1.0)) / windowHeight) - 1.0, r, g, b,
|
||||
(((startX * (1.0 - 0.733333349228)) + (endX * 0.733333349228)) / windowWidth) - 1.0,
|
||||
(((startY * (1.0 - 1.0)) + (endY * 1.0)) / windowHeight) - 1.0, r, g, b
|
||||
]
|
||||
end
|
||||
#[
|
||||
xToNdc (xOffset, 0.000000000000000, scale, halfWidth),
|
||||
yToNdc (yOffset, 13.000000000000000, scale, halfHeight),
|
||||
r, g, b,
|
||||
xToNdc (xOffset, 6.000000000000000, scale, halfWidth),
|
||||
yToNdc (yOffset, 13.000000000000000, scale, halfHeight),
|
||||
r, g, b,
|
||||
xToNdc (xOffset, 0.000000000000000, scale, halfWidth),
|
||||
yToNdc (yOffset, 0.000000000000000, scale, halfHeight),
|
||||
r, g, b,
|
||||
xToNdc (xOffset, 0.000000000000000, scale, halfWidth),
|
||||
yToNdc (yOffset, 0.000000000000000, scale, halfHeight),
|
||||
r, g, b,
|
||||
xToNdc (xOffset, 6.000000000000000, scale, halfWidth),
|
||||
yToNdc (yOffset, 13.000000000000000, scale, halfHeight),
|
||||
r, g, b,
|
||||
xToNdc (xOffset, 6.000000000000000, scale, halfWidth),
|
||||
yToNdc (yOffset, 0.000000000000000, scale, halfHeight),
|
||||
r, g, b
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -71,6 +71,10 @@ struct
|
||||
(* same as buildTextStringAfterCursor, except this keeps track of absolute
|
||||
* index and cursor pos too *)
|
||||
|
||||
fun makeRect (posX, posY, fw, fh, r, g, b) =
|
||||
Rect.lerp
|
||||
(Real32.fromInt (posX - 1), Real32.fromInt posY, scale, fw, fh, r, g, b)
|
||||
|
||||
fun makeChr (chr, posX, posY, windowWidth, windowHeight, r, g, b) =
|
||||
CozetteAscii.make
|
||||
( chr
|
||||
@@ -124,8 +128,7 @@ struct
|
||||
let
|
||||
val {r, g, b, fw, fh, ...} = env
|
||||
|
||||
val cursorAcc = Rect.lerp
|
||||
(posX, posY, fontSize, fontSize, fw, fh, r, g, b)
|
||||
val cursorAcc = makeRect (posX, posY, fw, fh, r, g, b)
|
||||
in
|
||||
buildTextString
|
||||
( pos + 1
|
||||
@@ -165,8 +168,7 @@ struct
|
||||
let
|
||||
val {r, g, b, fw, fh, ...} = env
|
||||
|
||||
val cursorAcc = Rect.lerp
|
||||
(posX, posY, fontSize, fontSize, fw, fh, r, g, b)
|
||||
val cursorAcc = makeRect (posX, posY, fw, fh, r, g, b)
|
||||
in
|
||||
buildTextString
|
||||
( pos + 1
|
||||
@@ -241,8 +243,7 @@ struct
|
||||
let
|
||||
val {fw, fh, r, g, b, hr, hg, hb, ...} = env
|
||||
|
||||
val cursorAcc = Rect.lerp
|
||||
(posX, posY, fontSize, fontSize, fw, fh, r, g, b)
|
||||
val cursorAcc = makeRect (posX, posY, fw, fh, r, g, b)
|
||||
in
|
||||
if posX + xSpace < #w env then
|
||||
let
|
||||
@@ -372,8 +373,7 @@ struct
|
||||
val b: Real32.real = 0.1
|
||||
val {fw, fh, ...} = env
|
||||
|
||||
val space = Rect.lerp
|
||||
(posX, posY, fontSize, fontSize, fw, fh, r, g, b)
|
||||
val space = makeRect (posX, posY, fw, fh, r, g, b)
|
||||
val bgAcc = space :: bgAcc
|
||||
in
|
||||
buildTextStringSearch
|
||||
@@ -417,8 +417,7 @@ struct
|
||||
let
|
||||
val {fw, fh, r, g, b, ...} = env
|
||||
|
||||
val cursorAcc = Rect.lerp
|
||||
(posX, posY, fontSize, fontSize, fw, fh, r, g, b)
|
||||
val cursorAcc = makeRect (posX, posY, fw, fh, r, g, b)
|
||||
in
|
||||
buildTextStringSearch
|
||||
( pos + 1
|
||||
@@ -464,8 +463,7 @@ struct
|
||||
let
|
||||
val {fw, fh, r, g, b, ...} = env
|
||||
|
||||
val cursorAcc = Rect.lerp
|
||||
(posX, posY, fontSize, fontSize, fw, fh, r, g, b)
|
||||
val cursorAcc = makeRect (posX, posY, fw, fh, r, g, b)
|
||||
in
|
||||
buildTextStringSearch
|
||||
( pos + 1
|
||||
@@ -512,8 +510,7 @@ struct
|
||||
val g: Real32.real = 0.1
|
||||
val b: Real32.real = 0.1
|
||||
|
||||
val space = Rect.lerp
|
||||
(posX, posY, fontSize, fontSize, fw, fh, r, g, b)
|
||||
val space = makeRect (posX, posY, fw, fh, r, g, b)
|
||||
val bgAcc = space :: bgAcc
|
||||
in
|
||||
buildTextStringSearch
|
||||
@@ -597,8 +594,7 @@ struct
|
||||
(* equal to cursor *)
|
||||
let
|
||||
val {fw, fh, r, g, b, hr, hg, hb, ...} = env
|
||||
val cursorAcc = Rect.lerp
|
||||
(posX, posY, fontSize, fontSize, fw, fh, r, g, b)
|
||||
val cursorAcc = makeRect (posX, posY, fw, fh, r, g, b)
|
||||
in
|
||||
if posX + xSpace < #w env then
|
||||
let
|
||||
|
||||
Reference in New Issue
Block a user