Press Esc to exit
This commit is contained in:
parent
f17eca0e52
commit
f2dbc88f3d
34
main.lua
34
main.lua
@ -4,6 +4,7 @@ local loveframes = require"loveframes"
|
|||||||
local Clock = require"clock"
|
local Clock = require"clock"
|
||||||
|
|
||||||
local clock
|
local clock
|
||||||
|
local exitNote
|
||||||
|
|
||||||
local inputSource
|
local inputSource
|
||||||
|
|
||||||
@ -23,6 +24,9 @@ function love.mousereleased(x, y, button, istouch, presses)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function love.keypressed(key, scancode, isrepeat)
|
function love.keypressed(key, scancode, isrepeat)
|
||||||
|
if scancode == "escape" then
|
||||||
|
love.event.quit()
|
||||||
|
end
|
||||||
loveframes.keypressed(key, isrepeat)
|
loveframes.keypressed(key, isrepeat)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -37,10 +41,15 @@ end
|
|||||||
function love.load()
|
function love.load()
|
||||||
if arg[#arg] == "-debug" then require("mobdebug").start() end
|
if arg[#arg] == "-debug" then require("mobdebug").start() end
|
||||||
|
|
||||||
local clockTransform = love.math.newTransform(love.graphics.getWidth()/2, love.graphics.getHeight()/2)
|
local margin = love.graphics.getHeight() / 20
|
||||||
clock = Clock:new(nil, love.graphics.getHeight(), clockTransform)
|
|
||||||
|
|
||||||
local controls = loveframes.Create("panel"):SetPos(10,10)
|
local diameter = love.graphics.getHeight() - 2 * margin
|
||||||
|
local offset = diameter/2 + margin
|
||||||
|
local clockTransform = love.math.newTransform(offset, offset)
|
||||||
|
clock = Clock:new(nil, diameter, clockTransform)
|
||||||
|
|
||||||
|
local column2X = diameter + 2*margin
|
||||||
|
local controls = loveframes.Create("panel"):SetPos(column2X, margin)
|
||||||
local toggleTime = loveframes.Create("checkbox"):SetParent(controls):SetPos(0,0)
|
local toggleTime = loveframes.Create("checkbox"):SetParent(controls):SetPos(0,0)
|
||||||
toggleTime:SetText("Show time")
|
toggleTime:SetText("Show time")
|
||||||
local hourBox = loveframes.Create("numberbox"):SetMinMax(1, 12):SetValue(12)
|
local hourBox = loveframes.Create("numberbox"):SetMinMax(1, 12):SetValue(12)
|
||||||
@ -49,6 +58,13 @@ function love.load()
|
|||||||
loveframes.Create("text"):SetText(":"):SetParent(controls):SetPos(80,30)
|
loveframes.Create("text"):SetText(":"):SetParent(controls):SetPos(80,30)
|
||||||
minuteBox:SetParent(controls):SetPos(100,30)
|
minuteBox:SetParent(controls):SetPos(100,30)
|
||||||
|
|
||||||
|
|
||||||
|
local exitNote = "Press \"Esc\" to exit."
|
||||||
|
local exitNoteWidth = love.graphics.getWidth() - column2X - margin
|
||||||
|
local exitNoteFont = love.graphics.newFont(love.graphics.getHeight()/20)
|
||||||
|
local _, wraps = exitNoteFont:getWrap(exitNote, exitNoteWidth)
|
||||||
|
local exitNoteY = love.graphics.getHeight() - table.maxn(wraps) * exitNoteFont:getHeight() - margin
|
||||||
|
|
||||||
function setClock()
|
function setClock()
|
||||||
local t = Time:new(hourBox:GetValue(), minuteBox:GetValue())
|
local t = Time:new(hourBox:GetValue(), minuteBox:GetValue())
|
||||||
clock:setTime(t)
|
clock:setTime(t)
|
||||||
@ -71,14 +87,16 @@ function love.load()
|
|||||||
clock.onSetHands = updateInputs
|
clock.onSetHands = updateInputs
|
||||||
|
|
||||||
love.graphics.setBackgroundColor(0.02,0.53,0.77)
|
love.graphics.setBackgroundColor(0.02,0.53,0.77)
|
||||||
|
|
||||||
|
function draw()
|
||||||
|
loveframes.draw()
|
||||||
|
clock:draw()
|
||||||
|
love.graphics.printf(exitNote, exitNoteFont, column2X, exitNoteY, exitNoteWidth)
|
||||||
|
end
|
||||||
|
love.draw = draw
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
loveframes.update(dt)
|
loveframes.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
|
||||||
loveframes.draw()
|
|
||||||
local shift = (love.graphics.getWidth() - love.graphics.getHeight()) / 2
|
|
||||||
clock:draw()
|
|
||||||
end
|
|
||||||
|
Loading…
Reference in New Issue
Block a user