screenshot
This commit is contained in:
parent
78dbca6c05
commit
6164974241
3 changed files with 72 additions and 17 deletions
31
main.lua
31
main.lua
|
@ -38,6 +38,10 @@ dropdownWidth = 186
|
||||||
lineWidth = 2
|
lineWidth = 2
|
||||||
fontHeight = love.graphics.getFont():getHeight()
|
fontHeight = love.graphics.getFont():getHeight()
|
||||||
|
|
||||||
|
screenshot = false
|
||||||
|
screenshotCanvas = nil
|
||||||
|
screenshotsize = 512
|
||||||
|
|
||||||
-- global for convinience's sake
|
-- global for convinience's sake
|
||||||
|
|
||||||
mode = nil
|
mode = nil
|
||||||
|
@ -60,6 +64,33 @@ function love.draw()
|
||||||
local sw, sh = love.graphics.getDimensions()
|
local sw, sh = love.graphics.getDimensions()
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = love.mouse.getPosition()
|
||||||
|
|
||||||
|
if screenshot then
|
||||||
|
love.graphics.setCanvas(screenshotCanvas)
|
||||||
|
sw, sh = screenshotsize, screenshotsize
|
||||||
|
love.graphics.setColor(0.09, 0.09, 0.12, 1)
|
||||||
|
love.graphics.rectangle('fill', 0, 0, sw, sh)
|
||||||
|
love.graphics.setColor(0.08, 0.08, 0.1, 1)
|
||||||
|
love.graphics.rectangle('line', 0, 0, sw, sh)
|
||||||
|
graph.render()
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
|
||||||
|
--[[
|
||||||
|
-- for seeing what gets drawn to it
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
love.graphics.draw(screenshotCanvas)
|
||||||
|
|
||||||
|
return
|
||||||
|
]]
|
||||||
|
|
||||||
|
local ss = screenshotCanvas:newImageData(0, 1, 0, 0, screenshotsize, screenshotsize)
|
||||||
|
ss:encode('png', 'screenshot ' .. os.date('%Y-%m-%d %H-%m') .. '.png')
|
||||||
|
love.system.openURL('file://' .. love.filesystem.getSaveDirectory())
|
||||||
|
|
||||||
|
screenshot = false
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
|
||||||
-- this is fine to do since all textures are already loaded with nearest
|
-- this is fine to do since all textures are already loaded with nearest
|
||||||
love.graphics.setDefaultFilter('linear', 'linear')
|
love.graphics.setDefaultFilter('linear', 'linear')
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,18 @@ function self.createButtons()
|
||||||
love.system.setClipboardText(s)
|
love.system.setClipboardText(s)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
insertButton(s, {
|
||||||
|
x = outerpadding + padding + 32,
|
||||||
|
y = love.graphics.getHeight() - outerpadding - fontHeight * 4 - padding * 2 - 32,
|
||||||
|
size = 32,
|
||||||
|
name = 'screenshot',
|
||||||
|
displayname = 'Screenshot',
|
||||||
|
tooltip = 'Take a screenshot',
|
||||||
|
func = function()
|
||||||
|
screenshot = true
|
||||||
|
screenshotCanvas = love.graphics.newCanvas()
|
||||||
|
end
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
buttons = s
|
buttons = s
|
||||||
|
|
|
@ -55,7 +55,15 @@ function self.render()
|
||||||
local csize = 10 -- preview point size
|
local csize = 10 -- preview point size
|
||||||
local size = math.min((sw - outerpadding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + dropdownWidth + padding), sh - outerpadding * 2 - padding * 3 - csize)
|
local size = math.min((sw - outerpadding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + dropdownWidth + padding), sh - outerpadding * 2 - padding * 3 - csize)
|
||||||
|
|
||||||
|
if screenshot then
|
||||||
|
size = screenshotsize - outerpadding * 2
|
||||||
|
end
|
||||||
|
|
||||||
local x, y, w, h = sw - outerpadding - size, outerpadding, size, size
|
local x, y, w, h = sw - outerpadding - size, outerpadding, size, size
|
||||||
|
if screenshot then
|
||||||
|
x, y = outerpadding, outerpadding
|
||||||
|
end
|
||||||
|
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
love.graphics.rectangle('line', x, y, w, h)
|
love.graphics.rectangle('line', x, y, w, h)
|
||||||
|
|
||||||
|
@ -77,8 +85,10 @@ function self.render()
|
||||||
|
|
||||||
-- preview point
|
-- preview point
|
||||||
local t = timer % 1
|
local t = timer % 1
|
||||||
love.graphics.setColor(0.4, 0.4, 1, 0.4)
|
if not screenshot then
|
||||||
love.graphics.line(x + t * w, y, x + margin + t * (w - margin * 2), y + h)
|
love.graphics.setColor(0.4, 0.4, 1, 0.4)
|
||||||
|
love.graphics.line(x + t * w, y, x + margin + t * (w - margin * 2), y + h)
|
||||||
|
end
|
||||||
|
|
||||||
-- y = 0 point
|
-- y = 0 point
|
||||||
-- todo: this will break with eases that dont have the first point at y0
|
-- todo: this will break with eases that dont have the first point at y0
|
||||||
|
@ -116,23 +126,25 @@ function self.render()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- preview
|
-- preview
|
||||||
love.graphics.setColor(0.16, 0.16, 0.17, 1)
|
if not screenshot then
|
||||||
love.graphics.line(x + margin, y + h + padding * 2 + csize/2, x + w - margin, y + h + padding * 2 + csize/2)
|
love.graphics.setColor(0.16, 0.16, 0.17, 1)
|
||||||
love.graphics.setColor(0.3, 0.3, 0.31, 1)
|
love.graphics.line(x + margin, y + h + padding * 2 + csize/2, x + w - margin, y + h + padding * 2 + csize/2)
|
||||||
love.graphics.line(x + margin + (w - margin * 2) * (1 - zoome) * 0.5, y + h + padding * 2 + csize/2, x + w - margin - (w - margin * 2) * (1 - zoome) * 0.5, y + h + padding * 2 + csize/2)
|
love.graphics.setColor(0.3, 0.3, 0.31, 1)
|
||||||
|
love.graphics.line(x + margin + (w - margin * 2) * (1 - zoome) * 0.5, y + h + padding * 2 + csize/2, x + w - margin - (w - margin * 2) * (1 - zoome) * 0.5, y + h + padding * 2 + csize/2)
|
||||||
|
|
||||||
love.graphics.setColor(0.4, 0.4, 1, 1)
|
love.graphics.setColor(0.4, 0.4, 1, 1)
|
||||||
local a1 = ease.ease(t)
|
local a1 = ease.ease(t)
|
||||||
local a2 = ease.ease(math.max(math.min(t - 0.1, 1), 0))
|
local a2 = ease.ease(math.max(math.min(t - 0.1, 1), 0))
|
||||||
local da = ((a1 - 0.5) * zoome) + 0.5
|
local da = ((a1 - 0.5) * zoome) + 0.5
|
||||||
if timer % 2 > 1 and math.floor(ease.ease(0) + 0.5) ~= math.floor(ease.ease(1) + 0.5) then
|
if timer % 2 > 1 and math.floor(ease.ease(0) + 0.5) ~= math.floor(ease.ease(1) + 0.5) then
|
||||||
da = 1 - da
|
da = 1 - da
|
||||||
end
|
end
|
||||||
if minEase then
|
if minEase then
|
||||||
da = da / 2 + 0.5
|
da = da / 2 + 0.5
|
||||||
end
|
end
|
||||||
|
|
||||||
love.graphics.ellipse('fill', x + margin + (w - margin * 2) * da, y + h + padding * 2 + csize/2, csize * (1 + math.min(math.abs(a1 - a2), 3) * 1.2), csize)
|
love.graphics.ellipse('fill', x + margin + (w - margin * 2) * da, y + h + padding * 2 + csize/2, csize * (1 + math.min(math.abs(a1 - a2), 3) * 1.2), csize)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue