src/core: add mouse support to scenes

This commit is contained in:
Kazhnuz 2019-01-28 09:44:07 +01:00
parent ecf32133e8
commit 706565eb5d
6 changed files with 48 additions and 2 deletions

View file

@ -41,6 +41,17 @@ function CoreSystem:new()
self.scenemanager = SceneManager(self)
end
function CoreSystem:mousemoved(x, y, dx, dy)
local x, y = self.screen:project(x, y)
local dx, dy = self.screen:project(dx, dy)
self.scenemanager:mousemoved(x, y, dx, dy)
end
function CoreSystem:mousepressed( x, y, button, istouch )
local x, y = self.screen:project(x, y)
self.scenemanager:mousepressed( x, y, button, istouch )
end
function CoreSystem:update(dt)
self.debug:update(dt)
self.input:update(dt)

View file

@ -25,7 +25,8 @@
local Scene = Object:extend()
function Scene:new()
self.mouse = {}
self.mouse.x, self.mouse.y = core.screen:getMousePosition()
end
function Scene:register()
@ -36,6 +37,14 @@ function Scene:update(dt)
-- Empty function, is just here to avoid crash
end
function Scene:mousemoved(x, y, dx, dy)
-- Empty function, is just here to avoid crash
end
function Scene:mousepressed( x, y, button, istouch )
-- Empty function, is just here to avoid crash
end
function Scene:draw()
end

View file

@ -36,6 +36,16 @@ function SceneManager:update(dt)
end
end
function SceneManager:mousemoved(x, y, dx, dy)
self.currentScene.mouse.x,
self.currentScene.mouse.y = x, y
self.currentScene:mousemoved(x, y, dx, dy)
end
function SceneManager:mousepressed( x, y, button, istouch )
self.currentScene:mousepressed( x, y, button, istouch )
end
function SceneManager:clearScene()
self.currentScene = nil
end

View file

@ -53,6 +53,14 @@ function ScreenManager:applySettings()
CScreen.update(width, height)
end
function ScreenManager:project(x, y)
return CScreen.project(x, y)
end
function ScreenManager:getMousePosition()
return CScreen.project(love.mouse.getX(), love.mouse.getY())
end
function ScreenManager:apply()
CScreen.apply()
end

View file

@ -43,3 +43,11 @@ end
function love.draw()
core:draw()
end
function love.mousemoved(x, y, dx, dy)
core:mousemoved(x, y, dx, dy)
end
function love.mousepressed( x, y, button, istouch )
core:mousemoved(x, y, button, istouch)
end

View file

@ -41,7 +41,7 @@ function TestScene:draw()
love.graphics.rectangle("fill", 0, 0, 424, 240)
love.graphics.setColor(0, 0, 0, 1)
love.graphics.print(self.i, 16, 16)
love.graphics.print(self.i .. " ; " .. self.mouse.x .. ":" .. self.mouse.y, 16, 16)
end
return TestScene