Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not texter_font then dofile('texter_basic.txt') end
- function setFont(name)
- dofile(name .. '.txt')
- texter_font = _G[name]
- end
- local newmatrix = function(...)
- local data = {...}
- local get = function(x, y)
- return data[y][x]
- end
- local set = function(n, x, y)
- data[y][x] = n
- return n
- end
- return {data = data, get = get, set = set} or 'ERROR: UNABLE TO CREATE 2-D MATRIX'
- end
- function drawLetter(l, x, y)
- for cx = 0, texter_font['width'] - 1 + texter_font[l]['kerning'] do
- for cy = texter_font[l]['descender'], texter_font['height'] - 1 do
- if texter_font[l]['pixels'][cy + 1 - texter_font[l]['descender']][cx + 1] == 1 then
- tpt.create(x + cx, y + cy - texter_font[l]['descender'], 'dmnd')
- end
- end
- end
- end
- function drawText(t, x, y)
- local cl
- local ox = x
- for p = 1, #t do
- cl = string.sub(t, p, p)
- if cl == '\n' then
- x = ox
- y = y + texter_font['height'] + 4
- elseif texter_font[cl] then
- drawLetter(cl, x, y)
- x = x + texter_font['width'] + 1 + texter_font[cl]['kerning']
- else
- drawLetter('NULL', x, y)
- x = x + texter_font['width'] + 1 + texter_font['NULL']['kerning']
- end
- end
- end
- function texter_key_test(a)
- if a == 't' then
- local cmx, cmy = tpt.mousex, tpt.mousey
- local texterWindow = Window:new(-1, -1, 525, 75)
- local currentY = 10
- local texterstr, texterstr2 = '', ''
- local testTextbox = Textbox:new(10, currentY, (select(1, texterWindow:size()))-20, 16, "", "[place text here]")
- testTextbox:onTextChanged(
- function(sender)
- texterstr = testTextbox:text()
- end
- )
- currentY = currentY + 20
- local testTextbox2 = Textbox:new(10, currentY, (select(1, texterWindow:size()))-20, 16, "", "[and here, if you need more space]")
- testTextbox2:onTextChanged(
- function(sender)
- texterstr2 = testTextbox2:text();
- end
- )
- local closeButton = Button:new(10, select(2, texterWindow:size())-26, 100, 16, "Draw text")
- closeButton:action(function() drawText(string.gsub(texterstr, '\\n', '\n') .. '\n' .. string.gsub(texterstr2, '\\n', '\n'), cmx, cmy); interface.closeWindow(texterWindow) end)
- texterWindow:onTryExit(function() interface.closeWindow(texterWindow) end) -- Allow the default exit events
- texterWindow:addComponent(testTextbox)
- texterWindow:addComponent(testTextbox2)
- texterWindow:addComponent(closeButton)
- interface.showWindow(texterWindow)
- end
- end
- tpt.register_keypress(texter_key_test)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement