2024-04-16 01:51:42 +00:00
|
|
|
|
2024-04-12 03:42:11 +00:00
|
|
|
local Time = require"time"
|
2024-03-27 03:57:50 +00:00
|
|
|
local Clock = require"clock"
|
2024-04-21 22:42:22 +00:00
|
|
|
local Checkbox = require"checkbox"
|
2024-04-12 03:42:11 +00:00
|
|
|
|
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
|
2024-04-19 04:13:07 +00:00
|
|
|
|
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 01:51:42 +00:00
|
|
|
|
2024-04-16 02:56:58 +00:00
|
|
|
local column2X = diameter + 2*margin
|
2024-04-16 01:51:42 +00:00
|
|
|
|
2024-04-19 18:44:32 +00:00
|
|
|
clock.onSetHands = function(time)
|
2024-04-16 01:51:42 +00:00
|
|
|
local h, m = time:get()
|
|
|
|
end
|
|
|
|
|
2024-04-16 03:27:34 +00:00
|
|
|
local exitNote = "Press \"Esc\" to exit."
|
2024-04-21 22:42:22 +00:00
|
|
|
local column2Width = love.graphics.getWidth() - column2X - margin
|
2024-04-21 22:44:14 +00:00
|
|
|
local textFont = love.graphics.newFont(love.graphics.getHeight() / 20)
|
|
|
|
local timeFont = love.graphics.newFont(love.graphics.getHeight() / 10)
|
2024-04-16 03:27:34 +00:00
|
|
|
|
2024-04-21 22:44:14 +00:00
|
|
|
local _, exitNoteWraps = textFont:getWrap(exitNote, column2Width)
|
|
|
|
local exitNoteY = love.graphics.getHeight() - table.maxn(exitNoteWraps) * textFont:getHeight() - margin
|
2024-04-21 22:42:22 +00:00
|
|
|
|
2024-04-21 22:44:14 +00:00
|
|
|
local checkboxSize = textFont:getBaseline()
|
2024-04-21 22:42:22 +00:00
|
|
|
local checkboxLine = love.graphics.getHeight()/180
|
|
|
|
local checkbox = Checkbox:new(checkboxSize, checkboxLine, love.math.newTransform(column2X, margin), false)
|
|
|
|
local showTime = checkbox.checked
|
|
|
|
checkbox.onChanged = function(checked)
|
|
|
|
showTime = checked
|
|
|
|
end
|
|
|
|
|
|
|
|
local textCanvas = love.graphics.newCanvas(love.graphics.getWidth(), love.graphics.getHeight())
|
|
|
|
love.graphics.setCanvas(textCanvas)
|
|
|
|
love.graphics.setColor(1,1,1)
|
2024-04-21 22:44:14 +00:00
|
|
|
love.graphics.printf(" Show time", textFont, column2X + checkboxSize + checkboxLine, margin, column2Width)
|
|
|
|
love.graphics.printf("Press \"Esc\" to exit.", textFont, column2X, exitNoteY, column2Width)
|
2024-04-21 22:42:22 +00:00
|
|
|
love.graphics.setCanvas()
|
2024-04-16 02:56:58 +00:00
|
|
|
|
2024-04-21 22:42:22 +00:00
|
|
|
local timeString
|
|
|
|
local timeIndent
|
2024-04-21 22:44:14 +00:00
|
|
|
local figureWidth = timeFont:getWidth("0")
|
2024-04-21 22:42:22 +00:00
|
|
|
clock.onSetHands = function(t)
|
|
|
|
timeString = tostring(clock:getTime())
|
|
|
|
if #timeString < 5 then
|
|
|
|
timeIndent = figureWidth
|
|
|
|
else
|
|
|
|
timeIndent = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
clock.onSetHands(clock:getTime())
|
|
|
|
|
|
|
|
love.graphics.setBackgroundColor(0.02,0.53,0.77)
|
2024-04-19 18:44:32 +00:00
|
|
|
|
|
|
|
function love.mousemoved(x, y, dx, dy, istouch)
|
|
|
|
clock:movemouse(x, y)
|
|
|
|
end
|
|
|
|
|
|
|
|
function love.mousepressed(x, y, button, istouch, presses)
|
|
|
|
clock:pressmouse(x, y, button)
|
2024-04-21 22:42:22 +00:00
|
|
|
checkbox:pressmouse(x, y, button)
|
2024-04-19 18:44:32 +00:00
|
|
|
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()
|
2024-04-21 22:42:22 +00:00
|
|
|
checkbox:draw()
|
|
|
|
love.graphics.draw(textCanvas, 0, 0)
|
|
|
|
if showTime then
|
2024-04-21 22:44:14 +00:00
|
|
|
love.graphics.printf(timeString, timeFont, column2X+timeIndent, margin+textFont:getHeight(), column2Width)
|
2024-04-21 22:42:22 +00:00
|
|
|
end
|
2024-04-16 02:56:58 +00:00
|
|
|
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
|