Bound printscreen to saving screenshots

This commit is contained in:
Oshisaure 2021-01-29 04:13:17 +00:00
parent e19da98ea1
commit 68760105cc

View File

@ -16,6 +16,9 @@ function love.load()
love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {resizable = true});
-- used for screenshots
GLOBAL_CANVAS = love.graphics.newCanvas()
-- init config
if not config.das then config.das = 10 end
if not config.arr then config.arr = 2 end
@ -108,6 +111,9 @@ function love.update(dt)
end
function love.draw()
love.graphics.setCanvas(GLOBAL_CANVAS)
love.graphics.clear()
love.graphics.push()
-- get offset matrix
@ -123,6 +129,10 @@ function love.draw()
scene:render()
love.graphics.pop()
love.graphics.setCanvas()
love.graphics.setColor(1,1,1,1)
love.graphics.draw(GLOBAL_CANVAS)
end
function love.keypressed(key, scancode)
@ -146,6 +156,14 @@ function love.keypressed(key, scancode)
-- escape is reserved for menu_back
elseif scancode == "escape" then
scene:onInputPress({input="menu_back", type="key", key=key, scancode=scancode})
-- printscreen is reserved for printing the screen i know impressive keybind
elseif scancode == "printscreen" then
local ss_name = os.date("ss/%Y-%m-%d_%H-%M-%S.png")
if not love.filesystem.getInfo("ss") then
love.filesystem.createDirectory("ss")
end
print("Saving screenshot as "..ss_name)
GLOBAL_CANVAS:newImageData():encode("png", ss_name)
-- pass any other key to the scene, with its configured mapping
else
local input_pressed = nil
@ -261,3 +279,8 @@ function love.focus(f)
pauseBGM()
end
end
function love.resize(w, h)
GLOBAL_CANVAS:release()
GLOBAL_CANVAS = love.graphics.newCanvas(w, h)
end