replace text-builder.sml's 'buildCursor' function with a new 'Rect.lerp' function (which is in fcore/rect.sml)
This commit is contained in:
27
fcore/rect.sml
Normal file
27
fcore/rect.sml
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
structure Rect =
|
||||||
|
struct
|
||||||
|
fun lerp (startX, startY, drawWidth, drawHeight, windowWidth, windowHeight, r, g, b) : Real32.real vector =
|
||||||
|
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
|
||||||
|
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
|
||||||
|
end
|
||||||
@@ -24,34 +24,6 @@ struct
|
|||||||
[DRAW bgMsg, DRAW textMsg, DRAW cursorMsg]
|
[DRAW bgMsg, DRAW textMsg, DRAW cursorMsg]
|
||||||
end
|
end
|
||||||
|
|
||||||
fun buildCursor (posX, posY, fWindowWidth, fWindowHeight, r, g, b) =
|
|
||||||
let
|
|
||||||
val left = posX + 9
|
|
||||||
val left = Real32.fromInt left
|
|
||||||
val right = left + 12.0
|
|
||||||
|
|
||||||
val top = Real32.fromInt posY
|
|
||||||
val bottom = top + fontSize + 2.0
|
|
||||||
|
|
||||||
val halfHeight = fWindowHeight / 2.0
|
|
||||||
val top = (~(top - halfHeight)) / halfHeight
|
|
||||||
val bottom = (~(bottom - halfHeight)) / halfHeight
|
|
||||||
|
|
||||||
val halfWidth = fWindowWidth / 2.0
|
|
||||||
val left = (left - halfWidth) / halfWidth
|
|
||||||
val right = (right - halfWidth) / halfWidth
|
|
||||||
|
|
||||||
in
|
|
||||||
#[ left, top, r, g, b
|
|
||||||
, right, top, r, g, b
|
|
||||||
, left, bottom, r, g, b
|
|
||||||
|
|
||||||
, left, bottom, r, g, b
|
|
||||||
, right, bottom, r, g, b
|
|
||||||
, right, top, r, g, b
|
|
||||||
]
|
|
||||||
end
|
|
||||||
|
|
||||||
(* builds text from a string with char-wrap.
|
(* builds text from a string with char-wrap.
|
||||||
* char-wrap is a similar concept to word-wrap,
|
* char-wrap is a similar concept to word-wrap,
|
||||||
* but it breaks on character in the middle of a word.
|
* but it breaks on character in the middle of a word.
|
||||||
@@ -105,7 +77,8 @@ struct
|
|||||||
val {fw, fh, ...} = windowData
|
val {fw, fh, ...} = windowData
|
||||||
val {r, g, b, ...} = colourData
|
val {r, g, b, ...} = colourData
|
||||||
|
|
||||||
val cursorAcc = buildCursor (posX, posY, fw, fh, r, g ,b)
|
val cursorAcc =
|
||||||
|
Rect.lerp (posX, posY, fontSize, fontSize, fw, fh, r, g ,b)
|
||||||
in
|
in
|
||||||
buildTextString
|
buildTextString
|
||||||
( pos + 1, str, acc, posX + xSpace, posY, startX
|
( pos + 1, str, acc, posX + xSpace, posY, startX
|
||||||
@@ -128,7 +101,8 @@ struct
|
|||||||
val {fw, fh, ...} = windowData
|
val {fw, fh, ...} = windowData
|
||||||
val {r, g, b, ...} = colourData
|
val {r, g, b, ...} = colourData
|
||||||
|
|
||||||
val cursorAcc = buildCursor (posX, posY, fw, fh, r, g ,b)
|
val cursorAcc =
|
||||||
|
Rect.lerp (posX, posY, fontSize, fontSize, fw, fh, r, g ,b)
|
||||||
in
|
in
|
||||||
buildTextString
|
buildTextString
|
||||||
( pos + 1, str, acc, startX, posY + ySpace, startX
|
( pos + 1, str, acc, startX, posY + ySpace, startX
|
||||||
@@ -183,7 +157,8 @@ struct
|
|||||||
let
|
let
|
||||||
val {fw, fh, ...} = windowData
|
val {fw, fh, ...} = windowData
|
||||||
val {r, g, b, hr, hg, hb} = colourData
|
val {r, g, b, hr, hg, hb} = colourData
|
||||||
val cursorAcc = buildCursor (posX, posY, fw, fh, r, g ,b)
|
val cursorAcc =
|
||||||
|
Rect.lerp (posX, posY, fontSize, fontSize, fw, fh, r, g ,b)
|
||||||
in
|
in
|
||||||
if posX + xSpace < #w windowData then
|
if posX + xSpace < #w windowData then
|
||||||
let
|
let
|
||||||
@@ -286,7 +261,8 @@ struct
|
|||||||
val b: Real32.real = 0.1
|
val b: Real32.real = 0.1
|
||||||
val {fw, fh, ...} = windowData
|
val {fw, fh, ...} = windowData
|
||||||
|
|
||||||
val space = buildCursor (posX, posY, fw, fh, r, g, b)
|
val space =
|
||||||
|
Rect.lerp (posX, posY, fontSize, fontSize, fw, fh, r, g, b)
|
||||||
val bgAcc = space :: bgAcc
|
val bgAcc = space :: bgAcc
|
||||||
in
|
in
|
||||||
buildTextStringSearch
|
buildTextStringSearch
|
||||||
@@ -309,7 +285,8 @@ struct
|
|||||||
val {fw, fh, ...} = windowData
|
val {fw, fh, ...} = windowData
|
||||||
val {r, g, b, ...} = colourData
|
val {r, g, b, ...} = colourData
|
||||||
|
|
||||||
val cursorAcc = buildCursor (posX, posY, fw, fh, r, g ,b)
|
val cursorAcc =
|
||||||
|
Rect.lerp (posX, posY, fontSize, fontSize, fw, fh, r, g ,b)
|
||||||
in
|
in
|
||||||
buildTextStringSearch
|
buildTextStringSearch
|
||||||
( pos + 1, str, acc, posX + xSpace, posY, startX
|
( pos + 1, str, acc, posX + xSpace, posY, startX
|
||||||
@@ -334,7 +311,8 @@ struct
|
|||||||
val {fw, fh, ...} = windowData
|
val {fw, fh, ...} = windowData
|
||||||
val {r, g, b, ...} = colourData
|
val {r, g, b, ...} = colourData
|
||||||
|
|
||||||
val cursorAcc = buildCursor (posX, posY, fw, fh, r, g ,b)
|
val cursorAcc =
|
||||||
|
Rect.lerp (posX, posY, fontSize, fontSize, fw, fh, r, g ,b)
|
||||||
in
|
in
|
||||||
buildTextStringSearch
|
buildTextStringSearch
|
||||||
( pos + 1, str, acc, startX, posY + ySpace, startX
|
( pos + 1, str, acc, startX, posY + ySpace, startX
|
||||||
@@ -371,7 +349,8 @@ struct
|
|||||||
val g: Real32.real = 0.1
|
val g: Real32.real = 0.1
|
||||||
val b: Real32.real = 0.1
|
val b: Real32.real = 0.1
|
||||||
|
|
||||||
val space = buildCursor (posX, posY, fw, fh, r, g, b)
|
val space =
|
||||||
|
Rect.lerp (posX, posY, fontSize, fontSize, fw, fh, r, g, b)
|
||||||
val bgAcc = space :: bgAcc
|
val bgAcc = space :: bgAcc
|
||||||
in
|
in
|
||||||
buildTextStringSearch
|
buildTextStringSearch
|
||||||
@@ -426,7 +405,8 @@ struct
|
|||||||
let
|
let
|
||||||
val {fw, fh, ...} = windowData
|
val {fw, fh, ...} = windowData
|
||||||
val {r, g, b, hr, hg, hb} = colourData
|
val {r, g, b, hr, hg, hb} = colourData
|
||||||
val cursorAcc = buildCursor (posX, posY, fw, fh, r, g ,b)
|
val cursorAcc =
|
||||||
|
Rect.lerp (posX, posY, fontSize, fontSize, fw, fh, r, g ,b)
|
||||||
in
|
in
|
||||||
if posX + xSpace < #w windowData then
|
if posX + xSpace < #w windowData then
|
||||||
let
|
let
|
||||||
|
|||||||
Reference in New Issue
Block a user