From f2dbc88f3d64b468b891704d63c85fa10d37967e Mon Sep 17 00:00:00 2001 From: Brandon Dyck Date: Mon, 15 Apr 2024 20:56:58 -0600 Subject: [PATCH] Press Esc to exit --- main.lua | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/main.lua b/main.lua index c36327c..7745ed7 100644 --- a/main.lua +++ b/main.lua @@ -4,6 +4,7 @@ local loveframes = require"loveframes" local Clock = require"clock" local clock +local exitNote local inputSource @@ -23,6 +24,9 @@ function love.mousereleased(x, y, button, istouch, presses) end function love.keypressed(key, scancode, isrepeat) + if scancode == "escape" then + love.event.quit() + end loveframes.keypressed(key, isrepeat) end @@ -37,10 +41,15 @@ end function love.load() 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 margin = love.graphics.getHeight() / 20 + + 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 controls = loveframes.Create("panel"):SetPos(10,10) + local column2X = diameter + 2*margin + local controls = loveframes.Create("panel"):SetPos(column2X, margin) local toggleTime = loveframes.Create("checkbox"):SetParent(controls):SetPos(0,0) toggleTime:SetText("Show time") 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) 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() local t = Time:new(hourBox:GetValue(), minuteBox:GetValue()) clock:setTime(t) @@ -71,14 +87,16 @@ function love.load() clock.onSetHands = updateInputs 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 function love.update(dt) loveframes.update(dt) end -function love.draw() - loveframes.draw() - local shift = (love.graphics.getWidth() - love.graphics.getHeight()) / 2 - clock:draw() -end