implement function to initialise env for text builder
This commit is contained in:
@@ -59,341 +59,6 @@ struct
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun buildTextStringSearch
|
|
||||||
( pos
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, posX
|
|
||||||
, posY
|
|
||||||
, tl
|
|
||||||
, absIdx
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env: Utils.env_data
|
|
||||||
, searchPos
|
|
||||||
) =
|
|
||||||
if searchPos = Vector.length (#searchList env) then
|
|
||||||
(* exhausted search list so call normal build function *)
|
|
||||||
buildTextString
|
|
||||||
( pos
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, posX
|
|
||||||
, posY
|
|
||||||
, tl
|
|
||||||
, absIdx
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
)
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val searchPos =
|
|
||||||
advanceSearchPos (absIdx, searchPos, #searchList env, #searchLen env)
|
|
||||||
in
|
|
||||||
if searchPos = Vector.length (#searchList env) then
|
|
||||||
(* exhausted search list so call normal build function *)
|
|
||||||
buildTextString
|
|
||||||
( pos
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, posX
|
|
||||||
, posY
|
|
||||||
, tl
|
|
||||||
, absIdx
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
)
|
|
||||||
else if pos < String.size str then
|
|
||||||
case String.sub (str, pos) of
|
|
||||||
#" " =>
|
|
||||||
(* if inside cursor, then create cursorAcc;
|
|
||||||
* else, just skip as usual *)
|
|
||||||
if absIdx <> cursorPos then
|
|
||||||
(* not in cursur *)
|
|
||||||
if
|
|
||||||
isInSearchRange
|
|
||||||
(absIdx, searchPos, #searchList env, #searchLen env)
|
|
||||||
then
|
|
||||||
(* draw *)
|
|
||||||
let
|
|
||||||
(* todo: temp colours *)
|
|
||||||
val r: Real32.real = 0.3
|
|
||||||
val g: Real32.real = 0.1
|
|
||||||
val b: Real32.real = 0.1
|
|
||||||
val {fw, fh, ...} = env
|
|
||||||
|
|
||||||
val space = makeRect (posX, posY, fw, fh, r, g, b)
|
|
||||||
val bgAcc = space :: bgAcc
|
|
||||||
in
|
|
||||||
buildTextStringSearch
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, posX + xSpace
|
|
||||||
, posY
|
|
||||||
, tl
|
|
||||||
, absIdx + 1
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
buildTextStringSearch
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, posX + xSpace
|
|
||||||
, posY
|
|
||||||
, tl
|
|
||||||
, absIdx + 1
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
else
|
|
||||||
(* in cursor *)
|
|
||||||
let
|
|
||||||
val {fw, fh, r, g, b, ...} = env
|
|
||||||
|
|
||||||
val cursorAcc = makeRect (posX, posY, fw, fh, r, g, b)
|
|
||||||
in
|
|
||||||
buildTextStringSearch
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, posX + xSpace
|
|
||||||
, posY
|
|
||||||
, tl
|
|
||||||
, absIdx + 1
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
end
|
|
||||||
| #"\n" =>
|
|
||||||
if posY + ySpace < #h env then
|
|
||||||
if absIdx <> cursorPos then
|
|
||||||
(* not in cursor position, so iterate like normal *)
|
|
||||||
buildTextStringSearch
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, #startX env
|
|
||||||
, posY + ySpace
|
|
||||||
, tl
|
|
||||||
, absIdx + 1
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
else
|
|
||||||
(* in cursor position, so build cursorAcc *)
|
|
||||||
let
|
|
||||||
val {fw, fh, r, g, b, ...} = env
|
|
||||||
|
|
||||||
val cursorAcc = makeRect (posX, posY, fw, fh, r, g, b)
|
|
||||||
in
|
|
||||||
buildTextStringSearch
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, #startX env
|
|
||||||
, posY + ySpace
|
|
||||||
, tl
|
|
||||||
, absIdx + 1
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
accToDrawMsg (acc, cursorAcc, bgAcc, env)
|
|
||||||
| chr =>
|
|
||||||
let
|
|
||||||
val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr)
|
|
||||||
in
|
|
||||||
if absIdx <> cursorPos then
|
|
||||||
(* not equal to cursor *)
|
|
||||||
if posX + xSpace < #w env then
|
|
||||||
if
|
|
||||||
isInSearchRange
|
|
||||||
(absIdx, searchPos, #searchList env, #searchLen env)
|
|
||||||
then
|
|
||||||
let
|
|
||||||
val {fw, fh, ...} = env
|
|
||||||
|
|
||||||
(* todo: temp colours *)
|
|
||||||
val r: Real32.real = 0.7
|
|
||||||
val g: Real32.real = 0.7
|
|
||||||
val b: Real32.real = 0.7
|
|
||||||
|
|
||||||
(* build char vec *)
|
|
||||||
val chrVec = makeChr (chr, posX, posY, fw, fh, r, g, b)
|
|
||||||
val acc = chrVec :: acc
|
|
||||||
|
|
||||||
(* build cursor (behind text) vec *)
|
|
||||||
val r: Real32.real = 0.3
|
|
||||||
val g: Real32.real = 0.1
|
|
||||||
val b: Real32.real = 0.1
|
|
||||||
|
|
||||||
val space = makeRect (posX, posY, fw, fh, r, g, b)
|
|
||||||
val bgAcc = space :: bgAcc
|
|
||||||
in
|
|
||||||
buildTextStringSearch
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, posX + xSpace
|
|
||||||
, posY
|
|
||||||
, tl
|
|
||||||
, absIdx + 1
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
let
|
|
||||||
val {fw, fh, r, g, b, ...} = env
|
|
||||||
|
|
||||||
val chrVec = makeChr (chr, posX, posY, fw, fh, r, g, b)
|
|
||||||
val acc = chrVec :: acc
|
|
||||||
in
|
|
||||||
buildTextStringSearch
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, posX + xSpace
|
|
||||||
, posY
|
|
||||||
, tl
|
|
||||||
, absIdx + 1
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else if posY + ySpace < #h env then
|
|
||||||
let
|
|
||||||
val {fw, fh, r, g, b, ...} = env
|
|
||||||
|
|
||||||
val chrVec = makeChr
|
|
||||||
(chr, #startX env, posY + ySpace, fw, fh, r, g, b)
|
|
||||||
val acc = chrVec :: acc
|
|
||||||
in
|
|
||||||
buildTextStringSearch
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, #startX env + xSpace
|
|
||||||
, posY + ySpace
|
|
||||||
, tl
|
|
||||||
, absIdx + 1
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
accToDrawMsg (acc, cursorAcc, bgAcc, env)
|
|
||||||
else
|
|
||||||
(* equal to cursor *)
|
|
||||||
let
|
|
||||||
val {fw, fh, r, g, b, hr, hg, hb, ...} = env
|
|
||||||
val cursorAcc = makeRect (posX, posY, fw, fh, r, g, b)
|
|
||||||
in
|
|
||||||
if posX + xSpace < #w env then
|
|
||||||
let
|
|
||||||
val chrVec = makeChr
|
|
||||||
(chr, posX, posY, fw, fh, hr, hg, hb)
|
|
||||||
val acc = chrVec :: acc
|
|
||||||
in
|
|
||||||
(* can start building after cursor now,
|
|
||||||
* since cursor was built *)
|
|
||||||
buildTextStringSearch
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, posX + xSpace
|
|
||||||
, posY
|
|
||||||
, tl
|
|
||||||
, absIdx + 1
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else if posY + ySpace < #h env then
|
|
||||||
let
|
|
||||||
val chrVec = makeChr
|
|
||||||
(chr, #startX env, posY + ySpace, fw, fh, hr, hg, hb)
|
|
||||||
val acc = chrVec :: acc
|
|
||||||
in
|
|
||||||
(* can start building after cursor now,
|
|
||||||
* since cursor was built *)
|
|
||||||
buildTextStringSearch
|
|
||||||
( pos + 1
|
|
||||||
, str
|
|
||||||
, acc
|
|
||||||
, #startX env + xSpace
|
|
||||||
, posY + ySpace
|
|
||||||
, tl
|
|
||||||
, absIdx + 1
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
accToDrawMsg (acc, cursorAcc, bgAcc, env)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
(* change to searching in string's tl *)
|
|
||||||
case tl of
|
|
||||||
hd :: tl =>
|
|
||||||
buildTextStringSearch
|
|
||||||
( 0
|
|
||||||
, hd
|
|
||||||
, acc
|
|
||||||
, posX
|
|
||||||
, posY
|
|
||||||
, tl
|
|
||||||
, absIdx
|
|
||||||
, cursorPos
|
|
||||||
, cursorAcc
|
|
||||||
, bgAcc
|
|
||||||
, env
|
|
||||||
, searchPos
|
|
||||||
)
|
|
||||||
| [] => accToDrawMsg (acc, cursorAcc, bgAcc, env)
|
|
||||||
end
|
|
||||||
|
|
||||||
(* gets line start idx, relative to right hd *)
|
(* gets line start idx, relative to right hd *)
|
||||||
fun helpGetLineStartIdx (startLine, curLine, rLnHd) =
|
fun helpGetLineStartIdx (startLine, curLine, rLnHd) =
|
||||||
if startLine > curLine then
|
if startLine > curLine then
|
||||||
@@ -431,7 +96,6 @@ struct
|
|||||||
, windowHeight
|
, windowHeight
|
||||||
, floatWindowWidth
|
, floatWindowWidth
|
||||||
, floatWindowHeight
|
, floatWindowHeight
|
||||||
, msgs
|
|
||||||
, searchList
|
, searchList
|
||||||
, searchLen
|
, searchLen
|
||||||
) =
|
) =
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ struct
|
|||||||
, charG: Real32.real
|
, charG: Real32.real
|
||||||
, charB: Real32.real
|
, charB: Real32.real
|
||||||
|
|
||||||
(* different colours for char when cursor is on char *)
|
|
||||||
, cursorOnCharR: Real32.real
|
|
||||||
, cursorOnCharG: Real32.real
|
|
||||||
, cursorOnCharB: Real32.real
|
|
||||||
|
|
||||||
, cursorR: Real32.real
|
, cursorR: Real32.real
|
||||||
, cursorG: Real32.real
|
, cursorG: Real32.real
|
||||||
, cursorB: Real32.real
|
, cursorB: Real32.real
|
||||||
@@ -20,6 +15,15 @@ struct
|
|||||||
, highlightG: Real32.real
|
, highlightG: Real32.real
|
||||||
, highlightB: Real32.real
|
, highlightB: Real32.real
|
||||||
|
|
||||||
|
(* different colours for char when cursor is on char *)
|
||||||
|
, cursorOnCharR: Real32.real
|
||||||
|
, cursorOnCharG: Real32.real
|
||||||
|
, cursorOnCharB: Real32.real
|
||||||
|
|
||||||
|
, highlightOnCharR: Real32.real
|
||||||
|
, highlightOnCharG: Real32.real
|
||||||
|
, highlightOnCharB: Real32.real
|
||||||
|
|
||||||
, charZ: Real32.real
|
, charZ: Real32.real
|
||||||
, cursorZ: Real32.real
|
, cursorZ: Real32.real
|
||||||
, highlightZ: Real32.real
|
, highlightZ: Real32.real
|
||||||
@@ -39,6 +43,114 @@ struct
|
|||||||
, searchLen: int
|
, searchLen: int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun initEnv
|
||||||
|
( endX
|
||||||
|
, endY
|
||||||
|
, floatWindowWidth
|
||||||
|
, floatWindowHeight
|
||||||
|
, searchList
|
||||||
|
, searchLen
|
||||||
|
, visualScrollColumn
|
||||||
|
, startLine
|
||||||
|
) : env_data =
|
||||||
|
if TC.textLineWidth > endX then
|
||||||
|
{ charR = 0.67
|
||||||
|
, charG = 0.51
|
||||||
|
, charB = 0.83
|
||||||
|
|
||||||
|
, highlightR = 0.211
|
||||||
|
, highlightG = 0.219
|
||||||
|
, highlightB = 0.25
|
||||||
|
|
||||||
|
, cursorR = 1.0
|
||||||
|
, cursorG = 1.0
|
||||||
|
, cursorB = 1.0
|
||||||
|
|
||||||
|
, highlightOnCharR = 0.0
|
||||||
|
, highlightOnCharG = 0.0
|
||||||
|
, highlightOnCharB = 0.0
|
||||||
|
|
||||||
|
, cursorOnCharR = 0.67
|
||||||
|
, cursorOnCharG = 0.51
|
||||||
|
, cursorOnCharB = 0.83
|
||||||
|
|
||||||
|
, charZ = 0.01
|
||||||
|
, cursorZ = 0.05
|
||||||
|
, highlightZ = 0.03
|
||||||
|
|
||||||
|
, startX = 5
|
||||||
|
, startY = 5
|
||||||
|
|
||||||
|
, scrollColumnStart = visualScrollColumn
|
||||||
|
, scrollColumnEnd = let val width = endX - 5
|
||||||
|
in width div TC.xSpace + visualScrollColumn
|
||||||
|
end
|
||||||
|
|
||||||
|
, lastLineNumber =
|
||||||
|
let
|
||||||
|
val height = endY - 5
|
||||||
|
val howManyLines = height div TC.ySpace
|
||||||
|
in
|
||||||
|
startLine + howManyLines
|
||||||
|
end
|
||||||
|
|
||||||
|
, fw = floatWindowWidth
|
||||||
|
, fh = floatWindowHeight
|
||||||
|
|
||||||
|
, searchList = searchList
|
||||||
|
, searchLen = searchLen
|
||||||
|
}
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val startX = (endX - TC.textLineWidth) div 2
|
||||||
|
val finishWidth = startX + TC.textLineWidth
|
||||||
|
in
|
||||||
|
{ charR = 0.67
|
||||||
|
, charG = 0.51
|
||||||
|
, charB = 0.83
|
||||||
|
|
||||||
|
, highlightR = 0.211
|
||||||
|
, highlightG = 0.219
|
||||||
|
, highlightB = 0.25
|
||||||
|
|
||||||
|
, cursorR = 1.0
|
||||||
|
, cursorG = 1.0
|
||||||
|
, cursorB = 1.0
|
||||||
|
|
||||||
|
, highlightOnCharR = 0.0
|
||||||
|
, highlightOnCharG = 0.0
|
||||||
|
, highlightOnCharB = 0.0
|
||||||
|
|
||||||
|
, cursorOnCharR = 0.67
|
||||||
|
, cursorOnCharG = 0.51
|
||||||
|
, cursorOnCharB = 0.83
|
||||||
|
|
||||||
|
, charZ = 0.01
|
||||||
|
, cursorZ = 0.05
|
||||||
|
, highlightZ = 0.03
|
||||||
|
|
||||||
|
, startX = startX
|
||||||
|
, startY = 5
|
||||||
|
|
||||||
|
, scrollColumnStart = visualScrollColumn
|
||||||
|
, scrollColumnEnd = TC.textLineCount
|
||||||
|
|
||||||
|
, lastLineNumber =
|
||||||
|
let
|
||||||
|
val height = endY - 5
|
||||||
|
val howManyLines = height div TC.ySpace
|
||||||
|
in
|
||||||
|
startLine + howManyLines
|
||||||
|
end
|
||||||
|
|
||||||
|
, fw = floatWindowWidth
|
||||||
|
, fh = floatWindowHeight
|
||||||
|
|
||||||
|
, searchList = searchList
|
||||||
|
, searchLen = searchLen
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
(* different functions to make vectors of different things we want to draw. *)
|
(* different functions to make vectors of different things we want to draw. *)
|
||||||
fun makeCursor (posX, posY, env: env_data) =
|
fun makeCursor (posX, posY, env: env_data) =
|
||||||
Rect.lerp
|
Rect.lerp
|
||||||
@@ -94,6 +206,20 @@ struct
|
|||||||
, #cursorOnCharB env
|
, #cursorOnCharB env
|
||||||
)
|
)
|
||||||
|
|
||||||
|
fun makeHighlightChr (chr, posX, posY, env: env_data) =
|
||||||
|
CozetteAscii.make
|
||||||
|
( chr
|
||||||
|
, Real32.fromInt posX
|
||||||
|
, Real32.fromInt posY
|
||||||
|
, #charZ env
|
||||||
|
, TC.scale
|
||||||
|
, #fw env
|
||||||
|
, #fh env
|
||||||
|
, #highlightOnCharR env
|
||||||
|
, #highlightOnCharG env
|
||||||
|
, #highlightOnCharB env
|
||||||
|
)
|
||||||
|
|
||||||
fun isInSearchRange
|
fun isInSearchRange
|
||||||
(absIdx, searchPos, {searchList, searchLen, ...}: env_data) =
|
(absIdx, searchPos, {searchList, searchLen, ...}: env_data) =
|
||||||
let val searchIdx = Vector.sub (searchList, searchPos)
|
let val searchIdx = Vector.sub (searchList, searchPos)
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ struct
|
|||||||
Utils.makeCursor (posX, posY, env)
|
Utils.makeCursor (posX, posY, env)
|
||||||
:: Utils.makeCursorOnChr (chr, posX, posY, env) :: acc
|
:: Utils.makeCursorOnChr (chr, posX, posY, env) :: acc
|
||||||
else if Utils.isInSearchRange (absIdx, searchPos, env) then
|
else if Utils.isInSearchRange (absIdx, searchPos, env) then
|
||||||
Utils.makeCursorOnChr (chr, posX, posY, env)
|
Utils.makeHighlightChr (chr, posX, posY, env)
|
||||||
:: Utils.makeHighlight (posX, posY, env) :: acc
|
:: Utils.makeHighlight (posX, posY, env) :: acc
|
||||||
else
|
else
|
||||||
acc
|
acc
|
||||||
|
|||||||
Reference in New Issue
Block a user