Nothing displayed yet. I need to convert threads to Surface nodes.
ZXQ2MMPAOIA4TN3TWMFPXZUL7NUE3EWXLV2JHBQXEINE7WCKFSIQC 6C3UZDESM2HPFIHAW5YIPUV6VXO4YV5DIEY574HUGP2DGOQNUVOAC R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC 7TQAF4BYIK75EEYCCK7VEUSZHNCWMWIA3HZGQKIILYESUZ5ZZRVQC K6ZDYZKXSLTLCCHWYK6K6WOCNXBZOXEDKDVNNJVCZUFOLLSUO5UAC JIBCE66ZTWM5WEHEHNKKTRWBJQSQWBDDWPMOJIJR5Q676OSHYCNAC SUPHTPXYKS4JBDPASHAYA5OBVJ45QT7ZV2HYNTF7OJYOKKS6DW5QC UGWH4VEHN5G6REWZU6BCXZ57AFU7PGK4MULMMHMJCMEMVVEDH2KAC BF7TW3EKRIDYC6J2Q2J4YOBAVQF55Y3H6KGZIHNXMH4N72MR6GXQC X7HYGAL2QVKG7M5EMZ2VSH37UYWGE3EPUXYQBJOVL6IGJFZ2I5AAC FBDRJ53NJ5BWDQGU2GWZ6NEYHKCCRD7RODMIG7QQZBRFUB4HR7OAC OLCKKDVSDTIBX5U3IRCLRL6KQMG2RDWKGDN4OTPI3WMN4FSX6ROQC ZANGJNNX6EITFBOF6NWCF2EM5BDQDEIOD4UPWMF5I6SKAURRTIHAC DXFOMHQIWZ6EAUIDZQLY3ZRRDWJRB2VQHJXHBBNXQYCYCABIMJ5QC save_dir_path = function(id)return 'data/'..idend
metadata_file = function(filename)return filename:gsub('%.md$', '')..'.json'end
full_path = function(id)return love.filesystem.getSaveDirectory()..'/data/'..idend
initialize_item = function(top, left, right, filename)local font = love.graphics.getFont()local result = edit.initialize_state(top, left, right, font:getHeight(), font:getHeight()*font:getLineHeight())result.id = filenameresult.filename = full_path(filename)result.editable = falseresult.replies = {}load_from_disk(result)Text.redraw_all(result)return resultend
load_metadata = function(filename)local mfile = metadata_file(filename)local mpath = save_dir_path(mfile)if not love.filesystem.getInfo(mpath) thenreturn {replies={}}endreturn json.decode(love.filesystem.read(mpath))end
load_subtree = function(filename, left, em_width)-- load a file and recursively all replies to it-- print('load_subtree', filename)local state = initialize_item(0, left, left+40*em_width, filename)local replies = load_metadata(filename).repliesfor i,reply_id in ipairs(replies) dolocal reply = load_subtree(reply_id, left+2*em_width, em_width)table.insert(state.replies, reply)endreturn stateend
open_thread = function(filename)local font = love.graphics.getFont()local em_width = font:getWidth('m')Global_state.root = load_subtree(filename, Margin_left, em_width)Global_state.root.top = Menu_bar_height + Margin_top-- HERE: Cursor_node needs to be set at the Surface level of abstraction--Cursor_node = Global_state.rootlove.window.setTitle('pothi.love - '..Global_state.root.id)end
mouse_press_on_surface = function(x,y, mouse_button)if Cursor_node thenCursor_node.show_cursor = nilCursor_node = nilendif mouse_press_consumed_by_any_button_handler(HUD, x,y, mouse_button) thenreturnendlocal node = on_text(x,y)if node then-- position cursor in nodeCursor_node = nodeedit.mouse_press(node.editor, x,y, mouse_button)returnend-- pan surfacePan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom}end
update_font_size = function(n)Font_height = nlove.graphics.setFont(love.graphics.newFont(Font_height))local font = love.graphics.getFont()font:setLineHeight(1.3)Line_height = math.floor(Font_height*1.3)Menu_bar_height = 5 + Line_height + 5if Global_state.root thenedit.update_font_settings(Global_state, n)endend
draw_file_picker = function()local font = love.graphics.getFont()local y, x = Margin_top, Margin_leftfor _,f in ipairs(Files) dolocal w = font:getWidth(f)if x + w > App.screen.width theny = y + font:getHeight()*font:getLineHeight() + 10x = Margin_leftendbutton(Global_state, f, {x=x-5, y=y-2, w=w+10, h=font:getHeight()*font:getLineHeight()+4,color={0.7,0.7,1.0},icon=function(p)App.color{r=0.4,g=0.4,b=0.7}love.graphics.rectangle('line', p.x,p.y, p.w,p.h, 5,5)App.color{r=0,g=0,b=0}love.graphics.print(f, x,y)end,onpress1 = function()open_thread(f)end,})x = x + App.width(f) + 15endend
draw_surface = function()for _,obj in ipairs(Surface) dolove.graphics.setColor(obj.r or 0, obj.g or 0, obj.b or 0)if obj.type == 'rectangle' thenlove.graphics.rectangle(obj.drawmode or 'fill', vx(obj.x),vy(obj.y), scale(obj.w),scale(obj.h), scale(obj.rx or 5), scale(obj.ry or 5))elseif obj.type == 'line' thenlove.graphics.line(unpack(obj.zdata))elseif obj.type == 'circle' thenlove.graphics.circle(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radius))elseif obj.type == 'arc' thenlove.graphics.arc(obj.drawmode or 'line', obj.arctype or 'open', vx(obj.x), vy(obj.y), scale(obj.radius), obj.angle1, obj.angle2, obj.segments)elseif obj.type == 'ellipse' thenlove.graphics.ellipse(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radiusx), scale(obj.radiusy))elseif obj.type == 'bezier' thenlove.graphics.line(unpack(obj.zdata))elseif obj.type == 'text' thenif obj.w == nil thenlove.graphics.draw(obj.text, vx(obj.x), vy(obj.y))elseedit.draw(obj.editor, obj.fg, not obj.show_cursor)endendenddraw_menu_bar()end
Global_state = {}-- button_handlers: for the file picker-- root: when reading a single thread
Files = nil -- array of filenames
for _,obj in ipairs(Surface) dolove.graphics.setColor(obj.r or 0, obj.g or 0, obj.b or 0)if obj.type == 'rectangle' thenlove.graphics.rectangle(obj.drawmode or 'fill', vx(obj.x),vy(obj.y), scale(obj.w),scale(obj.h), scale(obj.rx or 5), scale(obj.ry or 5))elseif obj.type == 'line' thenlove.graphics.line(unpack(obj.zdata))elseif obj.type == 'circle' thenlove.graphics.circle(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radius))elseif obj.type == 'arc' thenlove.graphics.arc(obj.drawmode or 'line', obj.arctype or 'open', vx(obj.x), vy(obj.y), scale(obj.radius), obj.angle1, obj.angle2, obj.segments)elseif obj.type == 'ellipse' thenlove.graphics.ellipse(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radiusx), scale(obj.radiusy))elseif obj.type == 'bezier' thenlove.graphics.line(unpack(obj.zdata))elseif obj.type == 'text' thenif obj.w == nil thenlove.graphics.draw(obj.text, vx(obj.x), vy(obj.y))elseedit.draw(obj.editor, obj.fg, not obj.show_cursor)endend
Global_state.button_handlers = {}local font = love.graphics.getFont()font:setLineHeight(1.3)if Global_state.root == nil then-- TODO: use surface for file picker as welldraw_file_picker()elsedraw_surface()
if Cursor_node thenCursor_node.show_cursor = nilCursor_node = nilendif mouse_press_consumed_by_any_button_handler(HUD, x,y, mouse_button) then
if mouse_press_consumed_by_any_button_handler(Global_state, x,y, mouse_button) then
local node = on_text(x,y)if node then-- position cursor in nodeCursor_node = nodeedit.mouse_press(node.editor, x,y, mouse_button)return
if Global_state.root thenmouse_press_on_surface(x,y, mouse_button)