Compare commits

...

2 commits

Author SHA1 Message Date
6dabb64d53 avoid showing eases out-of-bounds 2021-09-19 21:34:14 +03:00
6164974241 screenshot 2021-09-19 21:20:22 +03:00
3 changed files with 78 additions and 19 deletions

View file

@ -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')

View file

@ -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

View file

@ -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
if not screenshot then
love.graphics.setColor(0.4, 0.4, 1, 0.4) 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) 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
@ -89,18 +99,20 @@ function self.render()
-- polygone -- polygone
-- this isnt done with a polygon because else itd waste a Bunch of ram and i kinda, dont want to do that? -- this isnt done with a polygon because else itd waste a Bunch of ram and i kinda, dont want to do that?
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.setScissor(x + margin, y + margin, w - (margin * 2), h - (margin * 2))
local last = (((graph[1] or 0) - 0.5) * zoome) + 0.5 local last = (((graph[1] or 0) - 0.5) * zoome) + 0.5
for gx = 1, quality - 1 do for gx = 1, quality - 1 do
local a = gx/quality local a = gx/quality
local b = graph[gx + 1] or 0 local b = graph[gx + 1] or 0
b = ((b - 0.5) * zoome) + 0.5 b = ((b - 0.5) * zoome) + 0.5
local px, py = x + margin + gx * ((w - margin)/quality), y + h - margin - b * (h - margin * 2) local px, py = x + margin + gx * ((w - margin * 2)/quality), y + h - margin - b * (h - margin * 2)
local ox, oy = x + margin + (gx - 1) * ((w - margin)/quality), y + h - margin - last * (h - margin * 2) local ox, oy = x + margin + (gx - 1) * ((w - margin * 2)/quality), y + h - margin - last * (h - margin * 2)
if math.abs(b - last) < 1 then if math.abs(b - last) < 1 then
love.graphics.line(ox, oy, px, py) love.graphics.line(ox, oy, px, py)
end end
last = b last = b
end end
love.graphics.setScissor()
-- zoom lines -- zoom lines
local a = math.min(math.abs(zoome - 1) * 10, 1) local a = math.min(math.abs(zoome - 1) * 10, 1)
@ -116,6 +128,8 @@ function self.render()
end end
-- preview -- preview
if not screenshot then
love.graphics.setScissor(x - margin, 0, w + margin * 2, sh)
love.graphics.setColor(0.16, 0.16, 0.17, 1) love.graphics.setColor(0.16, 0.16, 0.17, 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, y + h + padding * 2 + csize/2, x + w - margin, y + h + padding * 2 + csize/2)
love.graphics.setColor(0.3, 0.3, 0.31, 1) love.graphics.setColor(0.3, 0.3, 0.31, 1)
@ -133,6 +147,8 @@ function self.render()
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)
love.graphics.setScissor()
end
end end
end end