diff --git a/fcore/app-update.sml b/fcore/app-update.sml index dac196c..ea9acee 100644 --- a/fcore/app-update.sml +++ b/fcore/app-update.sml @@ -12,7 +12,7 @@ struct val newBuffer = LineGap.goToLine (startLine, buffer) val drawMsg = TextBuilder.build - (startLine, cursorIdx, newBuffer, newWidth, newHeight) + (startLine, 2, newBuffer, newWidth, newHeight) val newApp = AppWith.bufferAndSize (app, newBuffer, newWidth, newHeight) in diff --git a/fcore/text-builder.sml b/fcore/text-builder.sml index 0ad6591..6e0473f 100644 --- a/fcore/text-builder.sml +++ b/fcore/text-builder.sml @@ -26,12 +26,14 @@ struct [DRAW textMsg, DRAW cursorMsg] end - fun buildCursor (posX, posY, fWindowWidth, fWindowHeight) = + fun buildCursor (posX, posY, fWindowWidth, fWindowHeight, r, g, b) = let - val top = Real32.fromInt posX - val left = Real32.fromInt posY - val right = left + fontSize - val bottom = top + fontSize + 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 @@ -42,13 +44,13 @@ struct val right = (right - halfWidth) / halfWidth val vec = - #[ left, top, 1.0, 1.0, 1.0 - , right, top, 1.0, 1.0, 1.0 - , left, bottom, 1.0, 1.0, 1.0 + #[ left, top, r, g, b + , right, top, r, g, b + , left, bottom, r, g, b - , left, bottom, 1.0, 1.0, 1.0 - , right, bottom, 1.0, 1.0, 1.0 - , right, top, 1.0, 1.0, 1.0 + , left, bottom, r, g, b + , right, bottom, r, g, b + , right, top, r, g, b ] in [vec] @@ -191,7 +193,7 @@ struct fun buildTextStringBeforeCursor ( pos, str, acc, posX, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx, cursorPos + , r, g, b, tl, absIdx, cursorPos, hr, hg, hb ) = if pos < String.size str then case String.sub (str, pos) of @@ -199,20 +201,20 @@ struct buildTextStringBeforeCursor ( pos + 1, str, acc, posX + xSpace, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos + , r, g, b, tl, absIdx + 1, cursorPos, hr, hg, hb ) | #"\t" => buildTextStringBeforeCursor ( pos + 1, str, acc, posX + xSpace3, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos + , r, g, b, tl, absIdx + 1, cursorPos, hr, hg, hb ) | #"\n" => if posY + ySpace < windowHeight then buildTextStringBeforeCursor ( pos + 1, str, acc, startX, posY + ySpace, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos + , r, g, b, tl, absIdx + 1, cursorPos, hr, hg, hb ) else accToDrawMsg (acc, []) @@ -225,13 +227,13 @@ struct buildTextStringBeforeCursor ( pos + 2, str, acc, startX, posY + ySpace, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos + , r, g, b, tl, absIdx + 1, cursorPos, hr, hg, hb ) else buildTextStringBeforeCursor ( pos + 1, str, acc, startX, posY + ySpace, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos + , r, g, b, tl, absIdx + 1, cursorPos, hr, hg, hb ) else accToDrawMsg (acc, []) @@ -248,7 +250,7 @@ struct buildTextStringBeforeCursor ( pos + 1, str, acc, posX + xSpace, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos + , r, g, b, tl, absIdx + 1, cursorPos, hr, hg, hb ) end else if posY + ySpace < windowHeight then @@ -263,7 +265,7 @@ struct buildTextStringBeforeCursor ( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos + , r, g, b, tl, absIdx + 1, cursorPos, hr, hg, hb ) end else @@ -273,13 +275,13 @@ struct continueBuildTextLineGapBeforeCursor ( tl, acc, posX, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, absIdx, cursorPos + , r, g, b, absIdx, cursorPos, hr, hg, hb ) and buildTextStringWithinCursor ( pos, str, acc, posX, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx, cursorPos, cursorAcc + , r, g, b, tl, absIdx, cursorPos, cursorAcc, hr, hg, hb ) = if pos < String.size str then case String.sub (str, pos) of @@ -287,20 +289,20 @@ struct buildTextStringWithinCursor ( pos + 1, str, acc, posX + xSpace, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc + , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb ) | #"\t" => buildTextStringWithinCursor ( pos + 1, str, acc, posX + xSpace3, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc + , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb ) | #"\n" => if posY + ySpace < windowHeight then buildTextStringWithinCursor ( pos + 1, str, acc, startX, posY + ySpace, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc + , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb ) else accToDrawMsg (acc, cursorAcc) @@ -313,55 +315,95 @@ struct buildTextStringWithinCursor ( pos + 2, str, acc, startX, posY + ySpace, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc + , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb ) else buildTextStringWithinCursor ( pos + 1, str, acc, startX, posY + ySpace, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc + , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb ) else accToDrawMsg (acc, cursorAcc) | chr => let val chrFun = Vector.sub (CozetteAscii.asciiTable, Char.ord chr) - val cursorAcc = - if absIdx <> cursorPos then - cursorAcc - else - buildCursor (posX, posY, fWindowWidth, fWindowHeight) in - if posX + xSpace < windowWidth then - let - val chrVec = chrFun - (posX, posY, fontSize, fontSize, fWindowWidth, fWindowHeight, r, g, b) - val acc = chrVec :: acc - in - buildTextStringWithinCursor - ( pos + 1, str, acc, posX + xSpace, posY, startX - , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc - ) - end - else if posY + ySpace < windowHeight then - let - val chrVec = chrFun - ( startX, posY + ySpace, fontSize, fontSize - , fWindowWidth, fWindowHeight - , r, g, b - ) - val acc = chrVec :: acc - in - buildTextStringWithinCursor - ( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX - , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc - ) - end + if absIdx <> cursorPos then + (* not equal to cursor *) + if posX + xSpace < windowWidth then + let + val chrVec = chrFun + (posX, posY, fontSize, fontSize, fWindowWidth, fWindowHeight, r, g, b) + val acc = chrVec :: acc + in + buildTextStringWithinCursor + ( pos + 1, str, acc, posX + xSpace, posY, startX + , windowWidth, windowHeight, fWindowWidth, fWindowHeight + , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb + ) + end + else if posY + ySpace < windowHeight then + let + val chrVec = chrFun + ( startX, posY + ySpace, fontSize, fontSize + , fWindowWidth, fWindowHeight + , r, g, b + ) + val acc = chrVec :: acc + in + buildTextStringWithinCursor + ( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX + , windowWidth, windowHeight, fWindowWidth, fWindowHeight + , r, g, b, tl, absIdx + 1, cursorPos, cursorAcc, hr, hg, hb + ) + end + else + accToDrawMsg (acc, cursorAcc) else - accToDrawMsg (acc, cursorAcc) + (* equal to cursor *) + let + val cursorAcc = buildCursor (posX, posY, fWindowWidth, fWindowHeight, r, g ,b) + in + if posX + xSpace < windowWidth then + let + val chrVec = chrFun + ( posX, posY, fontSize, fontSize + , fWindowWidth, fWindowHeight + , hr, hg, hb + ) + val acc = chrVec :: acc + in + (* can start building after cursor now, + * since cursor was built *) + buildTextStringAfterCursor + ( pos + 1, str, acc, posX + xSpace, posY, startX + , windowWidth, windowHeight, fWindowWidth, fWindowHeight + , r, g, b, tl, cursorAcc + ) + end + else if posY + ySpace < windowHeight then + let + val chrVec = chrFun + ( startX, posY + ySpace, fontSize, fontSize + , fWindowWidth, fWindowHeight + , hr, hg, hb + ) + val acc = chrVec :: acc + in + (* can start building after cursor now, + * since cursor was built *) + buildTextStringAfterCursor + ( pos + 1, str, acc, startX + xSpace, posY + ySpace, startX + , windowWidth, windowHeight, fWindowWidth, fWindowHeight + , r, g, b, tl, cursorAcc + ) + end + else + accToDrawMsg (acc, cursorAcc) + end end + else (* we have built cursor now, so can call after-cursor function * to build rest of text *) @@ -374,7 +416,7 @@ struct and continueBuildTextLineGapBeforeCursor ( strList, acc, posX, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, absIdx, cursorPos + , r, g, b, absIdx, cursorPos, hr, hg, hb ) = case strList of hd :: tl => @@ -383,14 +425,14 @@ struct buildTextStringBeforeCursor ( 0, hd, acc, posX, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx, cursorPos + , r, g, b, tl, absIdx, cursorPos, hr, hg, hb ) else (* if within cursor *) buildTextStringWithinCursor ( 0, hd, acc, posX, posY, startX , windowWidth, windowHeight, fWindowWidth, fWindowHeight - , r, g, b, tl, absIdx, cursorPos, [] + , r, g, b, tl, absIdx, cursorPos, [], hr, hg, hb ) | [] => accToDrawMsg (acc, []) @@ -434,6 +476,7 @@ struct , Real32.fromInt windowWidth, Real32.fromInt windowHeight , 0.67, 0.51, 0.83 , rStrTl, absIdx, cursorPos, [] + , 0.211, 0.219, 0.25 ) else (* if cursor is after string *) @@ -444,6 +487,7 @@ struct , Real32.fromInt windowWidth, Real32.fromInt windowHeight , 0.67, 0.51, 0.83 , rStrTl, absIdx, cursorPos + , 0.211, 0.219, 0.25 ) end | (_, _) => diff --git a/shf b/shf index 0860c09..d5ffeee 100755 Binary files a/shf and b/shf differ