2022-09-03 21:13:22 +00:00
|
|
|
run = {}
|
|
|
|
|
|
|
|
Editor_state = {}
|
|
|
|
|
|
|
|
-- called both in tests and real run
|
|
|
|
function run.initialize_globals()
|
|
|
|
-- tests currently mostly clear their own state
|
|
|
|
|
|
|
|
-- a few text objects we can avoid recomputing unless the font changes
|
|
|
|
Text_cache = {}
|
|
|
|
|
|
|
|
-- blinking cursor
|
|
|
|
Cursor_time = 0
|
|
|
|
end
|
|
|
|
|
|
|
|
-- called only for real run
|
|
|
|
function run.initialize(arg)
|
2022-09-18 03:37:40 +00:00
|
|
|
log_new('run')
|
2022-09-03 21:13:22 +00:00
|
|
|
if Settings then
|
|
|
|
run.load_settings()
|
|
|
|
else
|
|
|
|
run.initialize_default_settings()
|
|
|
|
end
|
|
|
|
|
2023-01-31 05:02:35 +00:00
|
|
|
-- '/' should work even on Windows
|
2022-09-03 22:27:15 +00:00
|
|
|
Editor_state.file_path = os.date('%Y/%m/%d/%H-%M-%S')
|
2023-01-31 05:02:35 +00:00
|
|
|
local base_dir = dirname(love.filesystem.getSaveDirectory())
|
|
|
|
if #arg == 0 then
|
|
|
|
Editor_state.directory = 'pensieve/data/'
|
|
|
|
else
|
|
|
|
Editor_state.directory = 'pensieve/data.'..arg[1]..'/'
|
|
|
|
end
|
|
|
|
Editor_state.filename = base_dir..Editor_state.directory..Editor_state.file_path
|
2022-09-03 22:27:15 +00:00
|
|
|
Text.redraw_all(Editor_state)
|
|
|
|
os.execute('mkdir -p '..dirname(Editor_state.filename))
|
|
|
|
assert(not file_exists(Editor_state.filename))
|
2022-09-03 21:13:22 +00:00
|
|
|
|
2022-09-03 22:27:15 +00:00
|
|
|
love.window.setTitle('capture.love - '..Editor_state.filename)
|
2022-09-03 21:13:22 +00:00
|
|
|
|
|
|
|
if rawget(_G, 'jit') then
|
|
|
|
jit.off()
|
|
|
|
jit.flush()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function run.load_settings()
|
|
|
|
love.graphics.setFont(love.graphics.newFont(Settings.font_height))
|
2023-01-01 17:14:08 +00:00
|
|
|
-- determine default dimensions and flags
|
2022-09-03 21:13:22 +00:00
|
|
|
App.screen.width, App.screen.height, App.screen.flags = love.window.getMode()
|
|
|
|
-- set up desired window dimensions
|
|
|
|
App.screen.flags.resizable = true
|
|
|
|
App.screen.flags.minwidth = math.min(App.screen.width, 200)
|
2023-01-02 01:59:10 +00:00
|
|
|
App.screen.flags.minheight = math.min(App.screen.height, 200)
|
2022-09-03 21:13:22 +00:00
|
|
|
App.screen.width, App.screen.height = Settings.width, Settings.height
|
|
|
|
love.window.setMode(App.screen.width, App.screen.height, App.screen.flags)
|
2022-09-04 00:00:58 +00:00
|
|
|
love.window.setPosition(Settings.x, Settings.y, Settings.displayindex)
|
2022-09-03 21:13:22 +00:00
|
|
|
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right, Settings.font_height, math.floor(Settings.font_height*1.3))
|
|
|
|
end
|
|
|
|
|
|
|
|
function run.initialize_default_settings()
|
|
|
|
local font_height = 20
|
|
|
|
love.graphics.setFont(love.graphics.newFont(font_height))
|
|
|
|
local em = App.newText(love.graphics.getFont(), 'm')
|
|
|
|
run.initialize_window_geometry(App.width(em))
|
|
|
|
Editor_state = edit.initialize_state(Margin_top, Margin_left, App.screen.width-Margin_right)
|
|
|
|
Editor_state.font_height = font_height
|
|
|
|
Editor_state.line_height = math.floor(font_height*1.3)
|
|
|
|
Editor_state.em = em
|
|
|
|
Settings = run.settings()
|
|
|
|
end
|
|
|
|
|
|
|
|
function run.initialize_window_geometry(em_width)
|
|
|
|
-- maximize window
|
|
|
|
love.window.setMode(0, 0) -- maximize
|
|
|
|
App.screen.width, App.screen.height, App.screen.flags = love.window.getMode()
|
|
|
|
-- shrink height slightly to account for window decoration
|
|
|
|
App.screen.height = App.screen.height-100
|
|
|
|
App.screen.width = 40*em_width
|
|
|
|
App.screen.flags.resizable = true
|
|
|
|
App.screen.flags.minwidth = math.min(App.screen.width, 200)
|
2023-01-02 01:59:10 +00:00
|
|
|
App.screen.flags.minheight = math.min(App.screen.height, 200)
|
2022-09-03 21:13:22 +00:00
|
|
|
love.window.setMode(App.screen.width, App.screen.height, App.screen.flags)
|
|
|
|
end
|
|
|
|
|
|
|
|
function run.resize(w, h)
|
|
|
|
--? print(("Window resized to width: %d and height: %d."):format(w, h))
|
|
|
|
App.screen.width, App.screen.height = w, h
|
|
|
|
Text.redraw_all(Editor_state)
|
|
|
|
Editor_state.selection1 = {} -- no support for shift drag while we're resizing
|
|
|
|
Editor_state.right = App.screen.width-Margin_right
|
|
|
|
Editor_state.width = Editor_state.right-Editor_state.left
|
|
|
|
Text.tweak_screen_top_and_cursor(Editor_state, Editor_state.left, Editor_state.right)
|
|
|
|
end
|
|
|
|
|
|
|
|
function run.draw()
|
|
|
|
edit.draw(Editor_state)
|
|
|
|
end
|
|
|
|
|
|
|
|
function run.update(dt)
|
|
|
|
Cursor_time = Cursor_time + dt
|
|
|
|
edit.update(Editor_state, dt)
|
|
|
|
end
|
|
|
|
|
|
|
|
function run.quit()
|
|
|
|
edit.quit(Editor_state)
|
|
|
|
end
|
|
|
|
|
|
|
|
function run.settings()
|
2022-09-04 04:08:30 +00:00
|
|
|
if Settings == nil then
|
|
|
|
Settings = {}
|
|
|
|
end
|
2022-09-04 00:00:58 +00:00
|
|
|
if Current_app == 'run' then
|
|
|
|
Settings.x, Settings.y, Settings.displayindex = love.window.getPosition()
|
|
|
|
end
|
2022-09-03 21:13:22 +00:00
|
|
|
return {
|
2022-09-04 00:00:58 +00:00
|
|
|
x=Settings.x, y=Settings.y, displayindex=Settings.displayindex,
|
2022-09-03 21:13:22 +00:00
|
|
|
width=App.screen.width, height=App.screen.height,
|
|
|
|
font_height=Editor_state.font_height,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-01-07 01:38:40 +00:00
|
|
|
function run.mouse_press(x,y, mouse_button)
|
2022-09-03 21:13:22 +00:00
|
|
|
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
|
2023-01-07 01:38:40 +00:00
|
|
|
return edit.mouse_press(Editor_state, x,y, mouse_button)
|
2022-09-03 21:13:22 +00:00
|
|
|
end
|
|
|
|
|
2022-12-24 01:16:19 +00:00
|
|
|
function run.mouse_release(x,y, mouse_button)
|
2022-09-03 21:13:22 +00:00
|
|
|
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
|
2022-12-24 01:16:19 +00:00
|
|
|
return edit.mouse_release(Editor_state, x,y, mouse_button)
|
2022-09-03 21:13:22 +00:00
|
|
|
end
|
|
|
|
|
2022-12-24 01:16:19 +00:00
|
|
|
function run.text_input(t)
|
2022-09-03 21:13:22 +00:00
|
|
|
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
|
2022-12-24 01:16:19 +00:00
|
|
|
return edit.text_input(Editor_state, t)
|
2022-09-03 21:13:22 +00:00
|
|
|
end
|
|
|
|
|
2022-12-24 01:16:19 +00:00
|
|
|
function run.keychord_press(chord, key)
|
2022-09-03 21:13:22 +00:00
|
|
|
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
|
2022-12-24 01:16:19 +00:00
|
|
|
return edit.keychord_press(Editor_state, chord, key)
|
2022-09-03 21:13:22 +00:00
|
|
|
end
|
|
|
|
|
2022-12-24 01:16:19 +00:00
|
|
|
function run.key_release(key, scancode)
|
2022-09-03 21:13:22 +00:00
|
|
|
Cursor_time = 0 -- ensure cursor is visible immediately after it moves
|
2022-12-24 01:16:19 +00:00
|
|
|
return edit.key_release(Editor_state, key, scancode)
|
2022-09-03 21:13:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- use this sparingly
|
|
|
|
function to_text(s)
|
|
|
|
if Text_cache[s] == nil then
|
|
|
|
Text_cache[s] = App.newText(love.graphics.getFont(), s)
|
|
|
|
end
|
|
|
|
return Text_cache[s]
|
|
|
|
end
|