100 lines
2.6 KiB
Lua
100 lines
2.6 KiB
Lua
local edit = require 'edit'
|
|
|
|
local Margin_top = 15
|
|
local Margin_left = 25
|
|
local Margin_right = 25
|
|
|
|
local Editor -- most data will be here
|
|
|
|
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()))
|
|
end
|
|
|
|
love.keyboard.setKeyRepeat(true)
|
|
|
|
love.graphics.setBackgroundColor(1,1,1)
|
|
|
|
edit.load()
|
|
|
|
-- 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
|
|
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
|
|
end
|
|
|
|
if #arg > 1 then
|
|
print('ignoring commandline args after '..arg[1])
|
|
end
|
|
|
|
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)
|
|
|
|
-- clear the slate for the new file
|
|
edit.load_file(Editor, file:getFilename())
|
|
|
|
love.window.setTitle('lines2.love - '..Editor.filename)
|
|
end
|
|
|
|
function love.resize(w,h)
|
|
edit.resize(Editor, w, h, w-Margin_right, h-Margin_top)
|
|
end
|
|
|
|
function love.draw()
|
|
love.graphics.setFont(Editor.font)
|
|
edit.draw(Editor)
|
|
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)
|
|
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)
|
|
end
|
|
|
|
function love.update(dt)
|
|
edit.maybe_autosave(Editor, dt)
|
|
end
|
|
|
|
function love.quit()
|
|
edit.save_settings(Editor)
|
|
edit.final_save(Editor)
|
|
end
|
|
|
|
function love.focus(in_focus)
|
|
edit.on_focus(in_focus)
|
|
end
|