Align clock face and mouse inputs to center of screen
This commit is contained in:
parent
4e9be28c42
commit
2283224516
@ -89,9 +89,9 @@ end
|
||||
local Clock = {}
|
||||
Clock.__index = Clock
|
||||
|
||||
function Clock:new(time, diameter)
|
||||
function Clock:new(time, diameter, transform)
|
||||
local radius = diameter and diameter/2 or 300
|
||||
local transform = love.math.newTransform(radius, radius)
|
||||
transform = transform or love.math.newTransform()
|
||||
local lineWidth = radius/200
|
||||
local c = {
|
||||
time = (time or Time:new()),
|
||||
@ -118,8 +118,8 @@ function Clock:draw()
|
||||
local _, m = self.time:get()
|
||||
local h = self.time:getHoursSinceTwelve()
|
||||
love.graphics.push("all")
|
||||
love.graphics.draw(self.faceCanvas)
|
||||
love.graphics.applyTransform(self.transform)
|
||||
love.graphics.draw(self.faceCanvas, -self.radius, -self.radius)
|
||||
self.minuteHand:draw(m / 60)
|
||||
self.hourHand:draw(h / 12)
|
||||
love.graphics.pop()
|
||||
|
66
main.lua
66
main.lua
@ -1,8 +1,42 @@
|
||||
|
||||
local Time = require"time"
|
||||
local loveframes = require"loveframes"
|
||||
|
||||
local Clock = require"clock"
|
||||
local clock = Clock:new(nil, love.graphics.getHeight())
|
||||
|
||||
local clock
|
||||
|
||||
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)
|
||||
loveframes.keypressed(key, isrepeat)
|
||||
end
|
||||
|
||||
function love.keyreleased(key)
|
||||
loveframes.keyreleased(key)
|
||||
end
|
||||
|
||||
function love.textinput(text)
|
||||
loveframes.textinput(text)
|
||||
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 controls = loveframes.Create("panel"):SetPos(10,10)
|
||||
local toggleTime = loveframes.Create("checkbox"):SetParent(controls):SetPos(0,0)
|
||||
@ -34,34 +68,6 @@ function updateInputs(time)
|
||||
end
|
||||
clock.onSetHands = updateInputs
|
||||
|
||||
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)
|
||||
loveframes.keypressed(key, isrepeat)
|
||||
end
|
||||
|
||||
function love.keyreleased(key)
|
||||
loveframes.keyreleased(key)
|
||||
end
|
||||
|
||||
function love.textinput(text)
|
||||
loveframes.textinput(text)
|
||||
end
|
||||
|
||||
function love.load()
|
||||
love.graphics.setBackgroundColor(0.02,0.53,0.77)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user