QUEMVUYEJDMX2YR3FKTSEZ2IUSTSW6H7GV7XQ3A3BDIITALYH7KAC J62CVGNGJZSN7TMTE2SG53O47YG4SJGJFTUFKVOZY4TM4KAC566QC T7T66GEUFLP3YHZN5UNOVBYK33KISJWJQKCPZU6MQH45KSU7CZZQC R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC YUQ4YINAT5YTK3CAY4VK3HSYQ4D63FXLLPMC4R3DUFHIZIUQO7WQC LFAROW2YSPM7534MX4G4BM6GSIHEQWQJH4QTGP4EGYQKRX5FP27AC FS2ITYYHBLFT66YUC3ENPFYI2HOYHOVEPQIN7NQR6KF5MEK4NKZAC UJ2RZ43LIVRIBWIXHXMLIQIQTL32VVEN4CVU7PEBTITQFPO4EXXQC 2GOAQOS3LSYMBT2H6SFEN23EV6F47BDQQY2G2IENB5CGE6SF7PKAC MFBZCXOUHS7ELP3SRTA7VDO32CUSRDIX44LXSMBPIAE5JXKFWXOQC update_editor_box = function(node, preserve_screen_top_of_cursor_node)if node.editor == nil then return endif node.y > Viewport.y thenif not preserve_screen_top_of_cursor_node or node ~= Cursor_node thennode.editor.screen_top1.line = 1node.editor.screen_top1.pos = 1endnode.editor.top = vy(node.y)elsenode.editor.screen_top1, node.editor.top = schema1_of_y(node.editor, Viewport.y - node.y)endnode.editor.left = math.floor(vx(node.x))node.editor.right = math.ceil(vx(node.x+node.w))edit.update_font_settings(node.editor, scale(20))Text.redraw_all(node.editor)end
Page2 = {x=500, y=300,-- pagetype='text',data={"Call me Ishmael. Some years ago--never mind how long precisely--having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world. It is a way I have of driving off the spleen and regulating the circulation. Whenever I find myself growing grim about the mouth; whenever it is a damp, drizzly November in my soul; whenever I find myself involuntarily pausing before coffin warehouses, and bringing up the rear of every funeral I meet; and especially whenever my hypos get such an upper hand of me, that it requires a strong moral principle to prevent me from deliberately stepping into the street, and methodically knocking people's hats off--then, I account it high time to get to sea as soon as I can. This is my substitute for pistol and ball. With a philosophical flourish Cato throws himself upon his sword; I quietly take to the ship. There is nothing surprising in this. If they but knew it, almost all men in their degree, some time or other, cherish very nearly the same feelings towards the ocean with me."},width=400, bg={r=0,g=0.8,b=0}}
A = function(preserve_screen_top_of_cursor_node)-- translate Page to Surfacewhile #Surface > 3 do table.remove(Surface) end -- HACKlocal red = falsefor x=-1000,2000,300 dofor y=-10000,10000,200 doadd_thick_line({type='line', data={x,y, x+200,y+200, x,y+400}, r=red and 1 or 0,g=red and 0 or 0.5,b=0}, 10)red = not redendendcompute_layout(Page, Page.x,Page.y, Surface, preserve_screen_top_of_cursor_node)compute_layout(Page2, Page2.x,Page2.y, Surface, preserve_screen_top_of_cursor_node)-- continue the pipelineB(preserve_screen_top_of_cursor_node)-- TODO: ugly that we're manipulating editor objects twiceend
add_thick_line = function(s, thickness)-- increase the thickness of a horizontal-ish linetable.insert(Surface, s)for i=1,thickness-1 dos = copy_shape(s)for j=2,#s.data, 2 dos.data[j] = s.data[j]+1endtable.insert(Surface, s)endend
on.keychord_press = function(chord, key)if chord == 'C-=' then-- zoom inViewport.zoom = Viewport.zoom+0.1B()elseif chord == 'C--' then-- zoom outViewport.zoom = Viewport.zoom-0.1B()elseif chord == 'C-0' then-- reset zoomViewport.zoom = 1.0B()elseif Cursor_node thenlocal old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos}edit.keychord_press(Cursor_node.editor, chord, key)if not eq(Cursor_node.editor.screen_top1, old_top) thenViewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)endA(--[[preserve screen_top of cursor node]] true)elseif chord == 'up' thenViewport.y = Viewport.y - scale(20)B()elseif chord == 'down' thenViewport.y = Viewport.y + scale(20)B()elseif chord == 'left' thenViewport.x = Viewport.x - scale(50)B()elseif chord == 'right' thenViewport.x = Viewport.x + scale(50)B()elseif chord == 'pageup' thenViewport.y = Viewport.y - App.screen.height/Viewport.zoomB()elseif chord == 'S-up' thenViewport.y = Viewport.y - App.screen.height/Viewport.zoomB()elseif chord == 'pagedown' thenViewport.y = Viewport.y + App.screen.height/Viewport.zoomB()elseif chord == 'S-down' thenViewport.y = Viewport.y + App.screen.height/Viewport.zoomB()elseif chord == 'S-left' thenViewport.x = Viewport.x - App.screen.width/Viewport.zoomB()elseif chord == 'S-right' thenViewport.x = Viewport.x + App.screen.width/Viewport.zoomB()endendend
on.text_input = function(t)if Cursor_node thenlocal old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos}edit.text_input(Cursor_node.editor, t)if not eq(Cursor_node.editor.screen_top1, old_top) thenViewport.y = Cursor_node.y + y_of_schema1(Cursor_node.editor, Cursor_node.editor.screen_top1)endA(--[[preserve screen_top of cursor node]] true)endend
data={"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.",'1','2','3','mno','Acb','g','hij','klm','nop',},width=400, bg={r=1,g=1,b=0}},-- a table on the right{ type='rows', name='searches', margin=50, data={{ type='text', data={''},},{ type='cols', data={{ type='text', data={'search:'},},{ type='text', name='search', bg={r=0.8,g=0.8,b=0.8}, data={''}, width=90,},}},{ type='text', data={'table:'},},{ type='cols', bg={r=0.8,g=0.8,b=0.8}, data={{ type='rows', width=90, data={{type='text', data={'abc'},},{type='text', data={'abc'},},}},{ type='rows', width=90, data={{type='text', data={'def'},},{type='text', data={'def'},},}},}},}},},}
B = function(preserve_screen_top_of_cursor_node)-- recompute various aspects based on the current viewport settingslove.graphics.setFont(love.graphics.newFont(scale(20))) -- editor objects implicitly depend on current font so update itfor _,obj in ipairs(Surface) doif obj.type == 'line' thenobj.zdata = {}for i=1,#obj.data,2 dotable.insert(obj.zdata, vx(obj.data[i]))table.insert(obj.zdata, vy(obj.data[i+1]))endelseif obj.type == 'bezier' thenzdata = {}for i=1,#obj.data,2 dotable.insert(zdata, vx(obj.data[i]))table.insert(zdata, vy(obj.data[i+1]))endobj.zdata = love.math.newBezierCurve(zdata):render()elseif obj.type == 'text' thenif obj.w thenupdate_editor_box(obj, preserve_screen_top_of_cursor_node)elseobj.text = love.graphics.newText(love.graphics.getFont(), obj.data)endendendend
schema1_of_y = function(editor, y)-- return line/pos of screen line starting near a given y offset,-- and the (negative) offset remaining after the calculation-- invariants:-- - 0 >= y_offset >= -Line_height-- - let loc, y_offset = schema1_of_y(pane, y)-- y + y_offset == y_of_schema1(pane, loc)assert(y >= 0)local y_offset = yfor i=1,#editor.lines doText.populate_screen_line_starting_pos(editor, i)local height = line_height(editor, i)if y_offset < height thenlocal line = editor.lines[i]local nlines = math.floor(y_offset/editor.line_height)assert(nlines >= 0 and nlines < #editor.line_cache[i].screen_line_starting_pos)local pos = editor.line_cache[i].screen_line_starting_pos[nlines+1] -- switch to 1-indexingy_offset = y_offset - nlines*editor.line_heightreturn {line=i, pos=pos}, -y_offsetendy_offset = y_offset - heightend-- y is below the panereturn {line=#editor.lines+1, pos=1}, y_offset -- positive valueend
y_of_schema1 = function(editor, loc)local result = 0if loc.line == 1 and loc.pos == 1 thenreturn resultendfor i=1,loc.line-1 doText.populate_screen_line_starting_pos(editor, i)result = result + line_height(editor, i)endText.populate_screen_line_starting_pos(editor, loc.line)for i,screen_line_starting_pos in ipairs(editor.line_cache[loc.line].screen_line_starting_pos) doif screen_line_starting_pos >= loc.pos thenbreakendresult = result + editor.line_heightendreturn resultend
to_text = function(x,y)for _,node in ipairs(Surface) doif node.type == 'text' thenif x >= vx(node.x) and node.w and x < vx(node.x + node.w) thenif y >= vy(node.y) and node.h and y < vy(node.y + node.h) thenreturn nodeendendendendend
on.mouse_press = function(x,y, mouse_button)if Cursor_node thenCursor_node.show_cursor = nilCursor_node = nilendlocal node = to_text(x,y)if node thenCursor_node = nodeedit.mouse_press(node.editor, x,y, mouse_button)elsePan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom}endend