clocktoy/main.lua

56 lines
1.6 KiB
Lua
Raw Normal View History

local Time = require"time"
2024-03-27 03:57:50 +00:00
local Clock = require"clock"
2024-03-24 22:26:07 +00:00
function love.load()
if arg[#arg] == "-debug" then require("mobdebug").start() end
2024-04-21 21:04:16 +00:00
2024-04-19 04:13:07 +00:00
local fontsize = love.graphics.getHeight() / 20
2024-04-16 02:56:58 +00:00
local margin = love.graphics.getHeight() / 20
local diameter = love.graphics.getHeight() - 2 * margin
local offset = diameter/2 + margin
local clockTransform = love.math.newTransform(offset, offset)
2024-04-19 18:44:32 +00:00
local clock = Clock:new(nil, diameter, clockTransform)
2024-04-16 02:56:58 +00:00
local column2X = diameter + 2*margin
2024-04-19 18:44:32 +00:00
clock.onSetHands = function(time)
local h, m = time:get()
end
2024-04-16 03:27:34 +00:00
local exitNote = "Press \"Esc\" to exit."
local exitNoteWidth = love.graphics.getWidth() - column2X - margin
2024-04-19 04:13:07 +00:00
local exitNoteFont = love.graphics.newFont(fontsize)
2024-04-16 03:27:34 +00:00
local _, wraps = exitNoteFont:getWrap(exitNote, exitNoteWidth)
local exitNoteY = love.graphics.getHeight() - table.maxn(wraps) * exitNoteFont:getHeight() - margin
love.graphics.setBackgroundColor(0.02,0.53,0.77)
2024-04-16 02:56:58 +00:00
2024-04-19 18:44:32 +00:00
function love.mousemoved(x, y, dx, dy, istouch)
clock:movemouse(x, y)
end
-- todo mousepressed & mousereleased
function love.mousepressed(x, y, button, istouch, presses)
clock:pressmouse(x, y, button)
end
function love.mousereleased(x, y, button, istouch, presses)
clock:releasemouse(button)
end
function love.draw()
2024-04-16 02:56:58 +00:00
clock:draw()
love.graphics.printf(exitNote, exitNoteFont, column2X, exitNoteY, exitNoteWidth)
end
2024-04-19 18:44:32 +00:00
end
function love.keypressed(key, scancode, isrepeat)
if scancode == "escape" then
love.event.quit()
end
2024-03-24 22:26:07 +00:00
end