2024-04-16 01:51:42 +00:00
|
|
|
|
2024-04-12 03:42:11 +00:00
|
|
|
local Time = require"time"
|
|
|
|
local loveframes = require"loveframes"
|
2024-03-27 03:57:50 +00:00
|
|
|
local Clock = require"clock"
|
2024-04-12 03:42:11 +00:00
|
|
|
|
2024-04-16 01:51:42 +00:00
|
|
|
local clock
|
2024-03-27 03:57:50 +00:00
|
|
|
|
|
|
|
function love.mousemoved(x, y, dx, dy, istouch)
|
|
|
|
clock:movemouse(x, y)
|
2024-03-24 22:26:07 +00:00
|
|
|
end
|
|
|
|
|
2024-03-27 03:57:50 +00:00
|
|
|
-- todo mousepressed & mousereleased
|
|
|
|
function love.mousepressed(x, y, button, istouch, presses)
|
|
|
|
clock:pressmouse(x, y, button)
|
2024-04-12 03:42:11 +00:00
|
|
|
loveframes.mousepressed(x, y, button)
|
2024-03-24 22:26:07 +00:00
|
|
|
end
|
|
|
|
|
2024-03-27 03:57:50 +00:00
|
|
|
function love.mousereleased(x, y, button, istouch, presses)
|
|
|
|
clock:releasemouse(button)
|
2024-04-12 03:42:11 +00:00
|
|
|
loveframes.mousereleased(x, y, button)
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.keypressed(key, scancode, isrepeat)
|
|
|
|
loveframes.keypressed(key, isrepeat)
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.keyreleased(key)
|
|
|
|
loveframes.keyreleased(key)
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.textinput(text)
|
|
|
|
loveframes.textinput(text)
|
2024-03-27 03:57:50 +00:00
|
|
|
end
|
2024-03-24 22:26:07 +00:00
|
|
|
|
|
|
|
function love.load()
|
2024-04-16 01:51:42 +00:00
|
|
|
if arg[#arg] == "-debug" then require("mobdebug").start() end
|
|
|
|
|
|
|
|
local clockTransform = love.math.newTransform(love.graphics.getWidth()/2, love.graphics.getHeight()/2)
|
|
|
|
clock = Clock:new(nil, love.graphics.getHeight(), clockTransform)
|
|
|
|
|
|
|
|
local controls = loveframes.Create("panel"):SetPos(10,10)
|
|
|
|
local toggleTime = loveframes.Create("checkbox"):SetParent(controls):SetPos(0,0)
|
|
|
|
toggleTime:SetText("Show time")
|
|
|
|
local hourBox = loveframes.Create("numberbox"):SetMinMax(1, 12):SetValue(12)
|
|
|
|
hourBox:SetParent(controls):SetPos(0,30)
|
|
|
|
local minuteBox = loveframes.Create("numberbox"):SetMinMax(0, 59):SetValue(0)
|
|
|
|
loveframes.Create("text"):SetText(":"):SetParent(controls):SetPos(80,30)
|
|
|
|
minuteBox:SetParent(controls):SetPos(100,30)
|
|
|
|
|
|
|
|
function setClock()
|
|
|
|
local t = Time:new(hourBox:GetValue(), minuteBox:GetValue())
|
|
|
|
clock:setTime(t)
|
|
|
|
end
|
|
|
|
hourBox.OnValueChanged = setClock
|
|
|
|
minuteBox.OnValueChanged = setClock
|
|
|
|
|
|
|
|
function updateInputNoCallback(input, value)
|
|
|
|
callback = input.onValueChanged
|
|
|
|
input.onValueChanged = nil
|
|
|
|
input:SetValue(value)
|
|
|
|
input.onValueChanged = callback
|
|
|
|
end
|
|
|
|
|
|
|
|
function updateInputs(time)
|
|
|
|
local h, m = time:get()
|
|
|
|
updateInputNoCallback(hourBox, h)
|
|
|
|
updateInputNoCallback(minuteBox, math.floor(m))
|
|
|
|
end
|
|
|
|
clock.onSetHands = updateInputs
|
|
|
|
|
2024-04-12 03:42:11 +00:00
|
|
|
love.graphics.setBackgroundColor(0.02,0.53,0.77)
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.update(dt)
|
|
|
|
loveframes.update(dt)
|
2024-03-24 22:26:07 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function love.draw()
|
2024-04-12 03:42:11 +00:00
|
|
|
loveframes.draw()
|
|
|
|
local shift = (love.graphics.getWidth() - love.graphics.getHeight()) / 2
|
2024-03-27 03:57:50 +00:00
|
|
|
clock:draw()
|
2024-03-24 22:26:07 +00:00
|
|
|
end
|