function TextEditor:draw()
fontSize(self.fontSize)
nW = textSize(lines)
for n, t in pairs(editor) do
local tW, tH = textSize(t)
local h = self.t_m + tH * n
fill(50, 205)
pushStyle()
textMode(CENTER)
text(n, self.l_m+nW/2+1.25, HEIGHT-h+tH/2-1.25)
fill(255, 180)
text(n, self.l_m+nW/2, HEIGHT-h+tH/2)
popStyle()
if n ~= lines+inline then
rect(self.l_m+nW+5, HEIGHT-h-0.505, tW+10, tH+1.05)
fill(25, 130)
text(t, self.l_m+nW+10+1.25, HEIGHT-h-1.25)
fill(255)
text(t, self.l_m+nW+10, HEIGHT-h)
end
end
local currentLine = editor[lines+inline]
local blink = math.sin(ElapsedTime/0.125)*0.5+1.0
local cursor = "" --string.rep("\\u{25ae}", math.floor(blink))..string.rep("\\u{25af}", 1-math.floor(blink))
if self.monkey then cursor = string.rep(" ", math.floor(blink))..string.rep(" ", 1-math.floor(blink)) end
head = string.sub(currentLine, 1, cursorPos)
tail = string.sub(currentLine, cursorPos+1, #currentLine)
local editorW, editorH = textSize(currentLine)
local h = self.t_m + editorH * (lines+inline)
fill(50 , 140+60*blink)
rect(-5, HEIGHT-h, self.l_m+2.5, editorH)
rect(self.l_m+nW+5, HEIGHT-h, WIDTH+10, editorH)
fill(0)
text(head..cursor..tail, self.l_m+nW+10+1.25, HEIGHT-h-1.25)
fill(255)
text(head..cursor..tail, self.l_m+nW+10, HEIGHT-h)
local sW, sH = textSize(" ")
local cP = vec2(self.l_m+nW+10+sW*cursorPos, HEIGHT-self.t_m-sH*(lines+inline))
pushStyle()
stroke(255)
strokeWidth(3.75*blink)
lineCapMode(PROJECT)
if self.monkey == false then line(cP.x, cP.y+2.5, cP.x, cP.y+self.fontSize-2.5) end
popStyle()
end
function TextEditor:input(s)
lines = 0
local t = {}
for l in string.gmatch(s, "([^".."\
“…”]+)") do
table.insert(t, l)
lines = lines + 1
end
editor = t
cursorPos = #editor[lines]
tempCursorPos = 0
self:updateinfo()
end
function TextEditor:output()
return table.concat(editor, "\
")
end