Compare commits

...

2 Commits

Author SHA1 Message Date
jill 6dabb64d53 avoid showing eases out-of-bounds 2021-09-19 21:34:14 +03:00
jill 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
fontHeight = love.graphics.getFont():getHeight()
screenshot = false
screenshotCanvas = nil
screenshotsize = 512
-- global for convinience's sake
mode = nil
@ -60,6 +64,33 @@ function love.draw()
local sw, sh = love.graphics.getDimensions()
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
love.graphics.setDefaultFilter('linear', 'linear')

View File

@ -115,6 +115,18 @@ function self.createButtons()
love.system.setClipboardText(s)
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
buttons = s

View File

@ -55,7 +55,15 @@ function self.render()
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)
if screenshot then
size = screenshotsize - outerpadding * 2
end
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.rectangle('line', x, y, w, h)
@ -77,8 +85,10 @@ function self.render()
-- preview point
local t = timer % 1
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)
if not screenshot then
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
-- todo: this will break with eases that dont have the first point at y0
@ -89,18 +99,20 @@ function self.render()
-- polygone
-- 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.setScissor(x + margin, y + margin, w - (margin * 2), h - (margin * 2))
local last = (((graph[1] or 0) - 0.5) * zoome) + 0.5
for gx = 1, quality - 1 do
local a = gx/quality
local b = graph[gx + 1] or 0
b = ((b - 0.5) * zoome) + 0.5
local px, py = x + margin + gx * ((w - margin)/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 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 * 2)/quality), y + h - margin - last * (h - margin * 2)
if math.abs(b - last) < 1 then
love.graphics.line(ox, oy, px, py)
end
last = b
end
love.graphics.setScissor()
-- zoom lines
local a = math.min(math.abs(zoome - 1) * 10, 1)
@ -116,23 +128,27 @@ function self.render()
end
-- preview
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.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)
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.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.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)
local a1 = ease.ease(t)
local a2 = ease.ease(math.max(math.min(t - 0.1, 1), 0))
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
da = 1 - da
end
if minEase then
da = da / 2 + 0.5
end
love.graphics.setColor(0.4, 0.4, 1, 1)
local a1 = ease.ease(t)
local a2 = ease.ease(math.max(math.min(t - 0.1, 1), 0))
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
da = 1 - da
end
if minEase then
da = da / 2 + 0.5
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