diff --git a/0006-on.mouse_press b/0006-on.mouse_press index 7a086b1..2a241f8 100644 --- a/0006-on.mouse_press +++ b/0006-on.mouse_press @@ -1,18 +1,8 @@ on.mouse_press = 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 + if mouse_press_consumed_by_any_button_handler(Global_state, 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 + if Global_state.root then + mouse_press_on_surface(x,y, mouse_button) end - -- pan surface - Pan = {x=Viewport.x+x/Viewport.zoom,y=Viewport.y+y/Viewport.zoom} end \ No newline at end of file diff --git a/0012-on.initialize b/0012-on.initialize index c548742..c40a24a 100644 --- a/0012-on.initialize +++ b/0012-on.initialize @@ -1,4 +1,11 @@ on.initialize = function() + Files = love.filesystem.getDirectoryItems('data') + for i=#Files,1,-1 do + if (not Files[i]:match('%.md$')) or Files[i]:match('%-%d+.md$') then + table.remove(Files, i) + end + end + table.sort(Files) new_definition() A() end \ No newline at end of file diff --git a/0023-on.keychord_press b/0023-on.keychord_press index 043d404..ab19d95 100644 --- a/0023-on.keychord_press +++ b/0023-on.keychord_press @@ -14,8 +14,6 @@ on.keychord_press = function(chord, key) -- reset zoom Viewport.zoom = 1.0 B() - elseif chord == 'C-q' then - live.send_to_app('QUIT') elseif Cursor_node then local old_top = {line=Cursor_node.editor.screen_top1.line, pos=Cursor_node.editor.screen_top1.pos} edit.keychord_press(Cursor_node.editor, chord, key) diff --git a/0026-on.draw b/0026-on.draw index ddc390d..4590425 100644 --- a/0026-on.draw +++ b/0026-on.draw @@ -1,25 +1,11 @@ on.draw = 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 + 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() end - draw_menu_bar() end \ No newline at end of file diff --git a/0081-draw_menu_bar b/0081-draw_menu_bar index 43d5225..e7d0720 100644 --- a/0081-draw_menu_bar +++ b/0081-draw_menu_bar @@ -6,6 +6,7 @@ draw_menu_bar = function() love.graphics.rectangle('line', 0,0, App.screen.width, Menu_bar_height) App.color(Menu_command_color) Menu_cursor = 5 + add_hotkey_to_menu('ctrl+o: switch file') add_hotkey_to_menu('ctrl+f: find') add_hotkey_to_menu('ctrl+left ctrl+right: prev/next word') add_hotkey_to_menu('ctrl+z ctrl+y: undo/redo') diff --git a/0111-Files b/0111-Files new file mode 100644 index 0000000..08f64a5 --- /dev/null +++ b/0111-Files @@ -0,0 +1 @@ +Files = nil -- array of filenames \ No newline at end of file diff --git a/0112-Global_state b/0112-Global_state new file mode 100644 index 0000000..4517df5 --- /dev/null +++ b/0112-Global_state @@ -0,0 +1,3 @@ +Global_state = {} + -- button_handlers: for the file picker + -- root: when reading a single thread \ No newline at end of file diff --git a/0113-draw_surface b/0113-draw_surface new file mode 100644 index 0000000..cc003d3 --- /dev/null +++ b/0113-draw_surface @@ -0,0 +1,25 @@ +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 \ No newline at end of file diff --git a/0114-draw_file_picker b/0114-draw_file_picker new file mode 100644 index 0000000..5637aa6 --- /dev/null +++ b/0114-draw_file_picker @@ -0,0 +1,25 @@ +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 \ No newline at end of file diff --git a/0115-update_font_size b/0115-update_font_size new file mode 100644 index 0000000..6bed895 --- /dev/null +++ b/0115-update_font_size @@ -0,0 +1,11 @@ +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 diff --git a/0116-mouse_press_on_surface b/0116-mouse_press_on_surface new file mode 100644 index 0000000..1b1690d --- /dev/null +++ b/0116-mouse_press_on_surface @@ -0,0 +1,18 @@ +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 \ No newline at end of file diff --git a/0117-open_thread b/0117-open_thread new file mode 100644 index 0000000..9ac8a0e --- /dev/null +++ b/0117-open_thread @@ -0,0 +1,9 @@ +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 \ No newline at end of file diff --git a/0118-load_subtree b/0118-load_subtree new file mode 100644 index 0000000..116916a --- /dev/null +++ b/0118-load_subtree @@ -0,0 +1,11 @@ +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 \ No newline at end of file diff --git a/0119-load_metadata b/0119-load_metadata new file mode 100644 index 0000000..f3de79c --- /dev/null +++ b/0119-load_metadata @@ -0,0 +1,8 @@ +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 \ No newline at end of file diff --git a/0120-initialize_item b/0120-initialize_item new file mode 100644 index 0000000..d3b391e --- /dev/null +++ b/0120-initialize_item @@ -0,0 +1,11 @@ +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 \ No newline at end of file diff --git a/0121-full_path b/0121-full_path new file mode 100644 index 0000000..67b0f56 --- /dev/null +++ b/0121-full_path @@ -0,0 +1,3 @@ +full_path = function(id) + return love.filesystem.getSaveDirectory()..'/data/'..id +end \ No newline at end of file diff --git a/0122-metadata_file b/0122-metadata_file new file mode 100644 index 0000000..f146acd --- /dev/null +++ b/0122-metadata_file @@ -0,0 +1,3 @@ +metadata_file = function(filename) + return filename:gsub('%.md$', '')..'.json' +end \ No newline at end of file diff --git a/0123-save_dir_path b/0123-save_dir_path new file mode 100644 index 0000000..b958190 --- /dev/null +++ b/0123-save_dir_path @@ -0,0 +1,3 @@ +save_dir_path = function(id) + return 'data/'..id +end \ No newline at end of file