Tidy up main.lua
This commit is contained in:
parent
6cd03c6481
commit
293b31d39a
87
main.lua
87
main.lua
@ -3,41 +3,6 @@ local Time = require"time"
|
|||||||
local loveframes = require"loveframes"
|
local loveframes = require"loveframes"
|
||||||
local Clock = require"clock"
|
local Clock = require"clock"
|
||||||
|
|
||||||
local clock
|
|
||||||
local exitNote
|
|
||||||
|
|
||||||
local inputSource
|
|
||||||
|
|
||||||
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)
|
|
||||||
loveframes.mousepressed(x, y, button)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.mousereleased(x, y, button, istouch, presses)
|
|
||||||
clock:releasemouse(button)
|
|
||||||
loveframes.mousereleased(x, y, button)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.keypressed(key, scancode, isrepeat)
|
|
||||||
if scancode == "escape" then
|
|
||||||
love.event.quit()
|
|
||||||
end
|
|
||||||
loveframes.keypressed(key, isrepeat)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.keyreleased(key)
|
|
||||||
loveframes.keyreleased(key)
|
|
||||||
end
|
|
||||||
|
|
||||||
function love.textinput(text)
|
|
||||||
loveframes.textinput(text)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- TODO delete this when the skin is done
|
-- TODO delete this when the skin is done
|
||||||
function setupSkin(fontsize)
|
function setupSkin(fontsize)
|
||||||
local font = love.graphics.newFont(fontsize)
|
local font = love.graphics.newFont(fontsize)
|
||||||
@ -75,7 +40,7 @@ function love.load()
|
|||||||
local diameter = love.graphics.getHeight() - 2 * margin
|
local diameter = love.graphics.getHeight() - 2 * margin
|
||||||
local offset = diameter/2 + margin
|
local offset = diameter/2 + margin
|
||||||
local clockTransform = love.math.newTransform(offset, offset)
|
local clockTransform = love.math.newTransform(offset, offset)
|
||||||
clock = Clock:new(nil, diameter, clockTransform)
|
local clock = Clock:new(nil, diameter, clockTransform)
|
||||||
|
|
||||||
local column2X = diameter + 2*margin
|
local column2X = diameter + 2*margin
|
||||||
local timeInputs = loveframes.Create("panel")
|
local timeInputs = loveframes.Create("panel")
|
||||||
@ -98,21 +63,20 @@ function love.load()
|
|||||||
:SetPos(column2X, margin)
|
:SetPos(column2X, margin)
|
||||||
:SetObject(timeInputs)
|
:SetObject(timeInputs)
|
||||||
|
|
||||||
function controls:OnOpenedClosed()
|
controls.OnOpenedClosed = function()
|
||||||
if self:GetOpen() then
|
if controls:GetOpen() then
|
||||||
self:SetText("Hide time")
|
controls:SetText("Hide time")
|
||||||
else
|
else
|
||||||
self:SetText("Show time")
|
controls:SetText("Show time")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
controls:OnOpenedClosed()
|
controls:OnOpenedClosed()
|
||||||
|
|
||||||
local function setClock()
|
hourBox.OnValueChanged = function()
|
||||||
local t = Time:new(hourBox:GetValue(), minuteBox:GetValue())
|
local t = Time:new(hourBox:GetValue(), minuteBox:GetValue())
|
||||||
clock:setTime(t)
|
clock:setTime(t)
|
||||||
end
|
end
|
||||||
hourBox.OnValueChanged = setClock
|
minuteBox.OnValueChanged = hourBox.OnValueChanged
|
||||||
minuteBox.OnValueChanged = setClock
|
|
||||||
|
|
||||||
local function updateInputNoCallback(input, value)
|
local function updateInputNoCallback(input, value)
|
||||||
local callback = input.OnValueChanged
|
local callback = input.OnValueChanged
|
||||||
@ -121,12 +85,11 @@ function love.load()
|
|||||||
input.OnValueChanged = callback
|
input.OnValueChanged = callback
|
||||||
end
|
end
|
||||||
|
|
||||||
local function updateInputs(time)
|
clock.onSetHands = function(time)
|
||||||
local h, m = time:get()
|
local h, m = time:get()
|
||||||
updateInputNoCallback(hourBox, h)
|
updateInputNoCallback(hourBox, h)
|
||||||
updateInputNoCallback(minuteBox, math.floor(m))
|
updateInputNoCallback(minuteBox, math.floor(m))
|
||||||
end
|
end
|
||||||
clock.onSetHands = updateInputs
|
|
||||||
|
|
||||||
local exitNote = "Press \"Esc\" to exit."
|
local exitNote = "Press \"Esc\" to exit."
|
||||||
local exitNoteWidth = love.graphics.getWidth() - column2X - margin
|
local exitNoteWidth = love.graphics.getWidth() - column2X - margin
|
||||||
@ -136,12 +99,42 @@ function love.load()
|
|||||||
|
|
||||||
love.graphics.setBackgroundColor(0.02,0.53,0.77)
|
love.graphics.setBackgroundColor(0.02,0.53,0.77)
|
||||||
|
|
||||||
local function draw()
|
|
||||||
|
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)
|
||||||
|
loveframes.mousepressed(x, y, button)
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.mousereleased(x, y, button, istouch, presses)
|
||||||
|
clock:releasemouse(button)
|
||||||
|
loveframes.mousereleased(x, y, button)
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.draw()
|
||||||
loveframes.draw()
|
loveframes.draw()
|
||||||
clock:draw()
|
clock:draw()
|
||||||
love.graphics.printf(exitNote, exitNoteFont, column2X, exitNoteY, exitNoteWidth)
|
love.graphics.printf(exitNote, exitNoteFont, column2X, exitNoteY, exitNoteWidth)
|
||||||
end
|
end
|
||||||
love.draw = draw
|
end
|
||||||
|
|
||||||
|
function love.keypressed(key, scancode, isrepeat)
|
||||||
|
if scancode == "escape" then
|
||||||
|
love.event.quit()
|
||||||
|
end
|
||||||
|
loveframes.keypressed(key, isrepeat)
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.keyreleased(key)
|
||||||
|
loveframes.keyreleased(key)
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.textinput(text)
|
||||||
|
loveframes.textinput(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
|
Loading…
Reference in New Issue
Block a user