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

@ -15,6 +15,9 @@ function love.load()
config["fullscreen"] = false config["fullscreen"] = false
love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {resizable = true}); love.window.setMode(love.graphics.getWidth(), love.graphics.getHeight(), {resizable = true});
-- used for screenshots
GLOBAL_CANVAS = love.graphics.newCanvas()
-- init config -- init config
if not config.das then config.das = 10 end if not config.das then config.das = 10 end
@ -108,7 +111,10 @@ function love.update(dt)
end end
function love.draw() function love.draw()
love.graphics.push() love.graphics.setCanvas(GLOBAL_CANVAS)
love.graphics.clear()
love.graphics.push()
-- get offset matrix -- get offset matrix
love.graphics.setDefaultFilter("linear", "nearest") love.graphics.setDefaultFilter("linear", "nearest")
@ -120,9 +126,13 @@ function love.draw()
(height - scale_factor * 480) / 2 (height - scale_factor * 480) / 2
) )
love.graphics.scale(scale_factor) love.graphics.scale(scale_factor)
scene:render() scene:render()
love.graphics.pop() love.graphics.pop()
love.graphics.setCanvas()
love.graphics.setColor(1,1,1,1)
love.graphics.draw(GLOBAL_CANVAS)
end end
function love.keypressed(key, scancode) function love.keypressed(key, scancode)
@ -146,6 +156,14 @@ function love.keypressed(key, scancode)
-- escape is reserved for menu_back -- escape is reserved for menu_back
elseif scancode == "escape" then elseif scancode == "escape" then
scene:onInputPress({input="menu_back", type="key", key=key, scancode=scancode}) 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 -- pass any other key to the scene, with its configured mapping
else else
local input_pressed = nil local input_pressed = nil
@ -261,3 +279,8 @@ function love.focus(f)
pauseBGM() pauseBGM()
end end
end end
function love.resize(w, h)
GLOBAL_CANVAS:release()
GLOBAL_CANVAS = love.graphics.newCanvas(w, h)
end