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/'..id
end
metadata_file = function(filename)
return filename:gsub('%.md$', '')..'.json'
end
full_path = function(id)
return love.filesystem.getSaveDirectory()..'/data/'..id
end
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 = filename
result.filename = full_path(filename)
result.editable = false
result.replies = {}
load_from_disk(result)
Text.redraw_all(result)
return result
end
load_metadata = function(filename)
local mfile = metadata_file(filename)
local mpath = save_dir_path(mfile)
if not love.filesystem.getInfo(mpath) then
return {replies={}}
end
return 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).replies
for i,reply_id in ipairs(replies) do
local reply = load_subtree(reply_id, left+2*em_width, em_width)
table.insert(state.replies, reply)
end
return state
end
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.root
love.window.setTitle('pothi.love - '..Global_state.root.id)
end
mouse_press_on_surface = function(x,y, mouse_button)
if Cursor_node then
Cursor_node.show_cursor = nil
Cursor_node = nil
end
if mouse_press_consumed_by_any_button_handler(HUD, x,y, mouse_button) then
return
end
local node = on_text(x,y)
if node then
-- position cursor in node
Cursor_node = node
edit.mouse_press(node.editor, x,y, mouse_button)
return
end
-- pan surface
Pan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom}
end
update_font_size = function(n)
Font_height = n
love.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 + 5
if Global_state.root then
edit.update_font_settings(Global_state, n)
end
end
draw_file_picker = function()
local font = love.graphics.getFont()
local y, x = Margin_top, Margin_left
for _,f in ipairs(Files) do
local w = font:getWidth(f)
if x + w > App.screen.width then
y = y + font:getHeight()*font:getLineHeight() + 10
x = Margin_left
end
button(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) + 15
end
end
draw_surface = function()
for _,obj in ipairs(Surface) do
love.graphics.setColor(obj.r or 0, obj.g or 0, obj.b or 0)
if obj.type == 'rectangle' then
love.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' then
love.graphics.line(unpack(obj.zdata))
elseif obj.type == 'circle' then
love.graphics.circle(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radius))
elseif obj.type == 'arc' then
love.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' then
love.graphics.ellipse(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radiusx), scale(obj.radiusy))
elseif obj.type == 'bezier' then
love.graphics.line(unpack(obj.zdata))
elseif obj.type == 'text' then
if obj.w == nil then
love.graphics.draw(obj.text, vx(obj.x), vy(obj.y))
else
edit.draw(obj.editor, obj.fg, not obj.show_cursor)
end
end
end
draw_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) do
love.graphics.setColor(obj.r or 0, obj.g or 0, obj.b or 0)
if obj.type == 'rectangle' then
love.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' then
love.graphics.line(unpack(obj.zdata))
elseif obj.type == 'circle' then
love.graphics.circle(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radius))
elseif obj.type == 'arc' then
love.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' then
love.graphics.ellipse(obj.drawmode or 'fill', vx(obj.x), vy(obj.y), scale(obj.radiusx), scale(obj.radiusy))
elseif obj.type == 'bezier' then
love.graphics.line(unpack(obj.zdata))
elseif obj.type == 'text' then
if obj.w == nil then
love.graphics.draw(obj.text, vx(obj.x), vy(obj.y))
else
edit.draw(obj.editor, obj.fg, not obj.show_cursor)
end
end
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 well
draw_file_picker()
else
draw_surface()
if Cursor_node then
Cursor_node.show_cursor = nil
Cursor_node = nil
end
if 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 node
Cursor_node = node
edit.mouse_press(node.editor, x,y, mouse_button)
return
if Global_state.root then
mouse_press_on_surface(x,y, mouse_button)