mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-12-22 13:19:02 -06:00
Bound printscreen to saving screenshots
This commit is contained in:
parent
e19da98ea1
commit
68760105cc
27
main.lua
27
main.lua
@ -15,6 +15,9 @@ function love.load()
|
||||
config["fullscreen"] = false
|
||||
|
||||
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
|
||||
@ -108,7 +111,10 @@ function love.update(dt)
|
||||
end
|
||||
|
||||
function love.draw()
|
||||
love.graphics.push()
|
||||
love.graphics.setCanvas(GLOBAL_CANVAS)
|
||||
love.graphics.clear()
|
||||
|
||||
love.graphics.push()
|
||||
|
||||
-- get offset matrix
|
||||
love.graphics.setDefaultFilter("linear", "nearest")
|
||||
@ -120,9 +126,13 @@ function love.draw()
|
||||
(height - scale_factor * 480) / 2
|
||||
)
|
||||
love.graphics.scale(scale_factor)
|
||||
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user