text2.love/main.lua

100 lines
2.6 KiB
Lua
Raw Permalink Normal View History

local edit = require 'edit'
local Margin_top = 15
local Margin_left = 25
local Margin_right = 25
local Editor -- most data will be here
2022-09-05 19:28:03 +01:00
function love.load(arg)
if not edit.is_this_love_version_supported() then
local major_version, minor_version = love.getVersion()
error(
("This app hasn't been tested with LÖVE version %d.%d. Please add %d.%d to `is_this_love_version_supported` in edit.lua to try it out, and switch to version %s if you run into issues."):format(major_version, minor_version, major_version, minor_version, edit.preferred_love_version()))
2022-06-07 21:35:56 +01:00
end
2022-07-01 06:46:45 +01:00
2023-01-16 17:48:06 +00:00
love.keyboard.setKeyRepeat(true)
love.graphics.setBackgroundColor(1,1,1)
edit.load()
2024-06-23 00:21:03 +01:00
-- editor remembers settings across restarts
local settings = edit.load_settings()
if settings == nil then
local screen_width, screen_height = love.window.getMode()
Editor = edit.new_from_defaults(Margin_top, Margin_left, screen_width-Margin_right, screen_height-Margin_top)
if #arg > 0 then
edit.load_file(Editor, arg[1])
end
2024-07-21 20:06:21 +01:00
else
Editor = edit.new_from_settings(settings, Margin_top, Margin_left, settings.width-Margin_right, settings.height-Margin_top)
if #arg > 0 and Editor.filename ~= edit.absolutize(arg[1]) then
edit.load_file(Editor, arg[1])
end
2024-07-21 20:06:21 +01:00
end
if #arg > 1 then
print('ignoring commandline args after '..arg[1])
end
2024-09-09 05:39:00 +01:00
love.window.setTitle('text2.love - '..Editor.filename)
end
function love.filedropped(file)
-- first make sure to autosave edits on any existing file
edit.final_save(Editor)
2024-06-23 00:21:03 +01:00
-- clear the slate for the new file
edit.load_file(Editor, file:getFilename())
2024-06-23 00:21:03 +01:00
2024-09-20 06:05:57 +01:00
love.window.setTitle('text2.love - '..Editor.filename)
2024-06-23 00:21:03 +01:00
end
function love.resize(w,h)
2024-09-01 08:14:53 +01:00
edit.resize(Editor, w, h, w-Margin_right, h-Margin_top)
end
function love.draw()
love.graphics.setFont(Editor.font)
2024-07-20 08:24:12 +01:00
edit.draw(Editor)
2022-05-02 05:55:57 +01:00
end
function love.mousepressed(x,y, mouse_button)
love.keyboard.setTextInput(true) -- bring up keyboard on touch screen
edit.on_mouse_pressed(Editor, x,y, mouse_button)
end
function love.mousereleased(x,y, mouse_button)
edit.on_mouse_released(Editor, x,y, mouse_button)
end
function love.wheelmoved(dx,dy)
edit.on_mouse_wheel_moved(Editor, dx,dy)
2022-05-12 06:29:21 +01:00
end
function love.keypressed(key, scancode, isrepeat)
edit.on_key_pressed(Editor, key, scancode, isrepeat)
end
function love.textinput(t)
edit.on_text_input(Editor, t)
end
function love.keyreleased(key, scancode)
edit.on_key_released(Editor, key, scancode)
2024-05-20 06:40:27 +01:00
end
function love.update(dt)
edit.maybe_autosave(Editor, dt)
2023-03-24 04:00:09 +00:00
end
function love.quit()
edit.save_settings(Editor)
edit.final_save(Editor)
2024-05-20 06:41:52 +01:00
end
function love.focus(in_focus)
edit.on_focus(in_focus)
end