From 110c0bf19de08a228082b480c9830fdac88b465d Mon Sep 17 00:00:00 2001 From: jill Date: Sat, 18 Sep 2021 00:57:41 +0300 Subject: [PATCH 1/7] vscode stuff --- .vscode/settings.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..742a33b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "Lua.runtime.version": "LuaJIT", + "Lua.workspace.library": [ + "${3rd}/love2d/library" + ], + "Lua.workspace.checkThirdParty": false +} \ No newline at end of file From 4ad840fb1f7d14aa330b6afc8be3add35f101fd4 Mon Sep 17 00:00:00 2001 From: jill Date: Sat, 18 Sep 2021 01:25:14 +0300 Subject: [PATCH 2/7] split dropdown into its own module --- dropdown.lua | 235 ++++++++++++++++++++++++++++++++++++++++++++++ main.lua | 258 +++++++-------------------------------------------- 2 files changed, 268 insertions(+), 225 deletions(-) create mode 100644 dropdown.lua diff --git a/dropdown.lua b/dropdown.lua new file mode 100644 index 0000000..bef1599 --- /dev/null +++ b/dropdown.lua @@ -0,0 +1,235 @@ +local self = {} + +local dropdowns = {} + +local dropdownValueCache = {} + +local maxDropdown = 16 + +self.openDropdown = 0 +local dropdownScroll = 0 +local dropdownScrollE = 0 + +local function skeys(t) + local k = {} + for n,v in pairs(t) do table.insert(k, {n, v}) end + table.sort(k, function(a, b) return a[2].i < b[2].i end) + local k2 = {} + for _,v in ipairs(k) do table.insert(k2, v[1]) end + return k2 +end + +function self.get(index) + return dropdowns[index] +end + +function self.selected(index) + return dropdowns[index].options[dropdowns[index].selected] +end + +function self.kget(key) + for _, v in ipairs(dropdowns) do + if v.name == key then + return v + end + end +end + +function self.kselected(key) + for _, v in ipairs(dropdowns) do + if v.name == key then + return v.options[v.selected] + end + end +end + +local dropdownId +local function insertDropdown(tab, f) + dropdownId = dropdownId + 1 + f.selected = (self.kget(f.name) or dropdownValueCache[f.name] or {selected = 1}).selected + f.selected = (f.selected - 1) % #f.options + 1 + return table.insert(tab, f) +end +function self.createDropdowns() + local d = {} + dropdownId = 0 + insertDropdown(d, { + x = padding, + y = padding, + width = 128, + options = { + 'Preview Ease', + 'Mix Eases', + 'Create Ease' + }, + name = 'mode' + }) + + if d[dropdownId].selected == 1 then -- preview ease + insertDropdown(d, { + x = padding + 128 + padding, + y = padding, + width = 128, + options = skeys(eases), + name = 'ease1' + }) + ease = eases[d[dropdownId].options[d[dropdownId].selected]].f + elseif d[dropdownId].selected == 2 then -- mix eases + insertDropdown(d, { + x = padding + 128 + padding, + y = padding, + width = 128, + options = skeys(eases), + name = 'ease1' + }) + insertDropdown(d, { + x = padding + 128 + padding + 128 + padding, + y = padding, + width = 128, + options = skeys(eases), + name = 'ease2' + }) + ease = mixEase(eases[d[dropdownId - 1].options[d[dropdownId - 1].selected]].f, eases[d[dropdownId].options[d[dropdownId].selected]].f, mixpoint) + elseif d[dropdownId].selected == 3 then -- create eases + insertDropdown(d, { + x = padding + 128 + padding, + y = padding, + width = 128, + options = skeys(eases), + name = 'ease1' + }) + end + + dropdowns = d + minEase = (self.kselected('ease1') and eases[self.kselected('ease1')].min == -1) or (self.kselected('ease2') and eases[self.kselected('ease2')].min == -1) + + return ease, minEase +end + +function self.update(dt) + if self.openDropdown ~= 0 then + dropdownScroll = math.max(dropdownScroll, -(#self.get(self.openDropdown).options - maxDropdown)) + dropdownScroll = math.min(dropdownScroll, 0) + dropdownScrollE = mix(dropdownScrollE, dropdownScroll, dt * 10) + end +end + +function self.render() + local mx, my = love.mouse.getPosition() + for i,v in ipairs(dropdowns) do + local x, y, w, h = v.x, v.y, v.width, love.graphics.getFont():getHeight() + margin + + love.graphics.setColor(0, 0, 0, 0.3) + if love.mouse.getX() > x and love.mouse.getX() < x + w and love.mouse.getY() > y and love.mouse.getY() < y + h then + love.graphics.setColor(0.8, 0.8, 1, love.mouse.isDown(1) and 0.4 or 0.3) + end + love.graphics.rectangle('fill', x, y, w, h) + + love.graphics.setColor(1, 1, 1, 1) + + love.graphics.rectangle('line', x, y, w, h) + love.graphics.print(self.selected(i), x + margin/2, y + margin/2) + love.graphics.rectangle('line', x + w - h, y, h, h) + love.graphics.polygon('line', x + w - h/2 + 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2 - 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2, y + h/2 + 0.3 * h) + + if self.openDropdown == i then + for i,o in ipairs(v.options) do + local x, y, w, h = x, y + i * h, w, h + + y = y + dropdownScrollE * h + local gi = y / h + if gi > maxDropdown or gi < 1 then + goto continue + end + + local a = 1 - math.min(math.max((1 - (maxDropdown - gi)) * (1 - (math.abs(dropdownScrollE) /(#v.options - maxDropdown))), 0), 1) + + love.graphics.setColor(0, 0, 0, 0.3 * a) + if mx > x and mx < x + w and my > y and my < y + h then + love.graphics.setColor(0.8, 0.8, 1, (love.mouse.isDown(1) and 0.4 or 0.3) * a) + end + love.graphics.rectangle('fill', x, y, w, h) + + love.graphics.setColor(1, 1, 1, 0.75 * a) + love.graphics.rectangle('line', x, y, w, h) + + love.graphics.setColor(1, 1, 1, 1 * a) + love.graphics.print(v.options[i], x + 2, y + 2) + + ::continue:: + end + + -- scrollwheel + + if #v.options > maxDropdown then + local displayed = maxDropdown / #v.options + local scroll = math.abs(dropdownScrollE) / (#v.options - maxDropdown) + local size = margin + + love.graphics.setColor(1, 1, 1, 0.9) + love.graphics.rectangle('fill', x + w - size, y + h + scroll * (1 - displayed) * (maxDropdown - 1) * h, size, displayed * (maxDropdown - 1) * h) + end + end + end +end + +function self.mousepressed(x, y, m) + local clickedDropdown = false + for i,v in ipairs(dropdowns) do + local h = love.graphics.getFont():getHeight() + margin + if self.openDropdown == 0 then + if x > v.x and x < v.x + v.width and y > v.y and y < v.y + h + margin then + if m == 1 then + self.openDropdown = i + clickedDropdown = true + dropdownScroll = 0 + dropdownScrollE = 0 + elseif m == 3 then + dropdowns[i].selected = math.random(1, #dropdowns[i].options) + self.createDropdowns() + end + end + elseif self.openDropdown == i then + if x > v.x and x < v.x + v.width and y > v.y + h and y < v.y + h * (math.min(#v.options, maxDropdown) + 1) and m == 1 then + clickedDropdown = true + end + end + end + + if not clickedDropdown and m == 1 then + self.openDropdown = 0 + return true + end +end + +function self.mousereleased(x, y, m) + for i,v in ipairs(dropdowns) do + local h = love.graphics.getFont():getHeight() + margin + if self.openDropdown == i then + if x > v.x and x < v.x + v.width and y > v.y + h and y < v.y + h * (math.min(#v.options, maxDropdown) + 1) and m == 1 then + v.selected = math.floor((y - v.y) / h - dropdownScrollE) + self.openDropdown = 0 + dropdownValueCache[v.name] = {selected = v.selected} + self.createDropdowns() + end + end + end +end + +function self.wheelmoved(x, y) + if self.openDropdown ~= 0 then + dropdownScroll = dropdownScroll + y + else + local mx, my = love.mouse.getPosition() + for i,v in ipairs(dropdowns) do + local h = love.graphics.getFont():getHeight() + margin + if mx > v.x and mx < v.x + v.width and my > v.y and my < v.y + h + margin then + dropdowns[i].selected = dropdowns[i].selected - math.floor(y) + dropdowns[i].selected = (dropdowns[i].selected - 1) % #dropdowns[i].options + 1 + self.createDropdowns() + end + end + end +end + +return self \ No newline at end of file diff --git a/main.lua b/main.lua index 14a104e..7c072c9 100644 --- a/main.lua +++ b/main.lua @@ -1,28 +1,21 @@ +local default_G = {} +for k, v in pairs(_G) do + table.insert(default_G, k) +end + local easelib = require 'easelib' +local dropdown = require 'dropdown' + -- utils -local function keys(t) - local k = {} - for n in pairs(t) do table.insert(k, n) end - return k -end -local function skeys(t) - local k = {} - for n,v in pairs(t) do table.insert(k, {n, v}) end - table.sort(k, function(a, b) return a[2].i < b[2].i end) - local k2 = {} - for _,v in ipairs(k) do table.insert(k2, v[1]) end - return k2 -end - -local function mix(x, y, a) +function mix(x, y, a) return x * (1 - a) + y * a end -- eases -local function mixEase(e1, e2, point) +function mixEase(e1, e2, point) if not point then point = 0.5 end return function(a) @@ -34,7 +27,7 @@ local function mixEase(e1, e2, point) end end -local eases = {} +eases = {} for i,v in pairs(easelib) do local min = 0 @@ -52,122 +45,31 @@ for i,v in pairs(easelib) do } end -local ease -local minEase = false +ease = nil +minEase = false -- rendering constants -local padding = 6 -local margin = 4 -local quality = 256 +padding = 6 +margin = 4 +local quality = 256 local mixpoint = 0.5 local oldmixpoint = 0.5 local mixpointtimer = 0 -- easter egg thing local mixpointspin = 0 -local maxDropdown = 16 - -- graph local graph = {} -- dropdown bullshit -local dropdowns = {} - -local dropdownValueCache = {} - -local openDropdown = 0 -local dropdownScroll = 0 -local dropdownScrollE = 0 - -local function selected(index) - return dropdowns[index].options[dropdowns[index].selected] -end - -local function kget(key) - for _, v in ipairs(dropdowns) do - if v.name == key then - return v - end - end -end - -local function kselected(key) - for _, v in ipairs(dropdowns) do - if v.name == key then - return v.options[v.selected] - end - end -end - -local dropdownId -local function insertDropdown(tab, f) - dropdownId = dropdownId + 1 - f.selected = (kget(f.name) or dropdownValueCache[f.name] or {selected = 1}).selected - f.selected = (f.selected - 1) % #f.options + 1 - return table.insert(tab, f) -end -local function createDropdowns() - local d = {} - dropdownId = 0 - insertDropdown(d, { - x = padding, - y = padding, - width = 128, - options = { - 'Preview Ease', - 'Mix Eases', - 'Create Ease' - }, - name = 'mode' - }) - - if d[dropdownId].selected == 1 then -- preview ease - insertDropdown(d, { - x = padding + 128 + padding, - y = padding, - width = 128, - options = skeys(eases), - name = 'ease1' - }) - ease = eases[d[dropdownId].options[d[dropdownId].selected]].f - elseif d[dropdownId].selected == 2 then -- mix eases - insertDropdown(d, { - x = padding + 128 + padding, - y = padding, - width = 128, - options = skeys(eases), - name = 'ease1' - }) - insertDropdown(d, { - x = padding + 128 + padding + 128 + padding, - y = padding, - width = 128, - options = skeys(eases), - name = 'ease2' - }) - ease = mixEase(eases[d[dropdownId - 1].options[d[dropdownId - 1].selected]].f, eases[d[dropdownId].options[d[dropdownId].selected]].f, mixpoint) - elseif d[dropdownId].selected == 3 then -- create eases - insertDropdown(d, { - x = padding + 128 + padding, - y = padding, - width = 128, - options = skeys(eases), - name = 'ease1' - }) - end - - minEase = (kselected('ease1') and eases[kselected('ease1')].min == -1) or (kselected('ease2') and eases[kselected('ease2')].min == -1) - - dropdowns = d -end -- rendering function love.load() - createDropdowns() + dropdown.createDropdowns() end function love.update(dt) @@ -196,15 +98,11 @@ function love.update(dt) mixpointspin = mix(mixpointspin, 0, dt * 3) - if openDropdown ~= 0 then - dropdownScroll = math.max(dropdownScroll, -(#dropdowns[openDropdown].options - maxDropdown)) - dropdownScroll = math.min(dropdownScroll, 0) - dropdownScrollE = mix(dropdownScrollE, dropdownScroll, dt * 10) - end + dropdown.update(dt) end function love.draw() - local mode = kget('mode').selected + local mode = dropdown.kget('mode').selected local sw, sh = love.graphics.getDimensions() local mx, my = love.mouse.getPosition() @@ -255,68 +153,13 @@ function love.draw() end -- dropdowns - for i,v in ipairs(dropdowns) do - local x, y, w, h = v.x, v.y, v.width, love.graphics.getFont():getHeight() + margin - - love.graphics.setColor(0, 0, 0, 0.3) - if love.mouse.getX() > x and love.mouse.getX() < x + w and love.mouse.getY() > y and love.mouse.getY() < y + h then - love.graphics.setColor(0.8, 0.8, 1, love.mouse.isDown(1) and 0.4 or 0.3) - end - love.graphics.rectangle('fill', x, y, w, h) - - love.graphics.setColor(1, 1, 1, 1) - - love.graphics.rectangle('line', x, y, w, h) - love.graphics.print(selected(i), x + margin/2, y + margin/2) - love.graphics.rectangle('line', x + w - h, y, h, h) - love.graphics.polygon('line', x + w - h/2 + 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2 - 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2, y + h/2 + 0.3 * h) - - if openDropdown == i then - for i,o in ipairs(v.options) do - local x, y, w, h = x, y + i * h, w, h - - y = y + dropdownScrollE * h - local gi = y / h - if gi > maxDropdown or gi < 1 then - goto continue - end - - local a = 1 - math.min(math.max((1 - (maxDropdown - gi)) * (1 - (math.abs(dropdownScrollE) /(#v.options - maxDropdown))), 0), 1) - - love.graphics.setColor(0, 0, 0, 0.3 * a) - if mx > x and mx < x + w and my > y and my < y + h then - love.graphics.setColor(0.8, 0.8, 1, (love.mouse.isDown(1) and 0.4 or 0.3) * a) - end - love.graphics.rectangle('fill', x, y, w, h) - - love.graphics.setColor(1, 1, 1, 0.75 * a) - love.graphics.rectangle('line', x, y, w, h) - - love.graphics.setColor(1, 1, 1, 1 * a) - love.graphics.print(v.options[i], x + 2, y + 2) - - ::continue:: - end - - -- scrollwheel - - if #v.options > maxDropdown then - local displayed = maxDropdown / #v.options - local scroll = math.abs(dropdownScrollE) / (#v.options - maxDropdown) - local size = margin - - love.graphics.setColor(1, 1, 1, 0.9) - love.graphics.rectangle('fill', x + w - size, y + h + scroll * (1 - displayed) * (maxDropdown - 1) * h, size, displayed * (maxDropdown - 1) * h) - end - end - end - + dropdown.render() -- graph if mode == 1 or mode == 2 then local csize = 10 -- preview point size - local size = math.min((sw - padding) - ((kget('ease2') or kget('ease1')).x + 128 + padding), sh - padding * 5 - csize) + local size = math.min((sw - padding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + 128 + padding), sh - padding * 5 - csize) local x, y, w, h = sw - padding - size, padding, size, size love.graphics.setColor(1, 1, 1, 1) @@ -384,62 +227,27 @@ function love.draw() end function love.mousepressed(x, y, m) - local clickedDropdown = false - for i,v in ipairs(dropdowns) do - local h = love.graphics.getFont():getHeight() + margin - if openDropdown == 0 then - if x > v.x and x < v.x + v.width and y > v.y and y < v.y + h + margin then - if m == 1 then - openDropdown = i - clickedDropdown = true - dropdownScroll = 0 - dropdownScrollE = 0 - elseif m == 3 then - dropdowns[i].selected = math.random(1, #dropdowns[i].options) - createDropdowns() - end - end - end - if openDropdown == i then - if x > v.x and x < v.x + v.width and y > v.y + h and y < v.y + h * (math.min(#v.options, maxDropdown) + 1) and m == 1 then - clickedDropdown = true - end - end - end - - if not clickedDropdown and m == 1 then - openDropdown = 0 - end + if dropdown.mousepressed(x, y, m) then return end end function love.mousereleased(x, y, m) - for i,v in ipairs(dropdowns) do - local h = love.graphics.getFont():getHeight() + margin - if openDropdown == i then - if x > v.x and x < v.x + v.width and y > v.y + h and y < v.y + h * (math.min(#v.options, maxDropdown) + 1) and m == 1 then - v.selected = math.floor((y - v.y) / h - dropdownScrollE) - openDropdown = 0 - dropdownValueCache[v.name] = {selected = v.selected} - createDropdowns() - end - end - end + if dropdown.mousereleased(x, y, m) then return end end function love.wheelmoved(x, y) if y == 0 then return end - if openDropdown ~= 0 then - dropdownScroll = dropdownScroll + y - else - local mx, my = love.mouse.getPosition() - for i,v in ipairs(dropdowns) do - local h = love.graphics.getFont():getHeight() + margin - if mx > v.x and mx < v.x + v.width and my > v.y and my < v.y + h + margin then - dropdowns[i].selected = dropdowns[i].selected - math.floor(y) - dropdowns[i].selected = (dropdowns[i].selected - 1) % #dropdowns[i].options + 1 - createDropdowns() + if dropdown.wheelmoved(x, y) then return end +end + +function love.keypressed(key) + if key == 'f6' then -- print all globals + for k, v in pairs(_G) do + for _, g in ipairs(default_G) do + if g == k then goto continue end end + print(k, v) + ::continue:: end end -end +end \ No newline at end of file From 83d23d8d72147a4a13c336ceb5148658407254ed Mon Sep 17 00:00:00 2001 From: jill Date: Sat, 18 Sep 2021 01:34:16 +0300 Subject: [PATCH 3/7] split graph into its own module --- graph.lua | 95 +++++++++++++++++++++++++++++++++++++++++++++++++ main.lua | 103 ++++++------------------------------------------------ 2 files changed, 106 insertions(+), 92 deletions(-) create mode 100644 graph.lua diff --git a/graph.lua b/graph.lua new file mode 100644 index 0000000..fc90ada --- /dev/null +++ b/graph.lua @@ -0,0 +1,95 @@ +local self = {} + +local quality = 256 +local graph = {} + +function self.update(dt) + for i = 1, quality do + local a = (i - 1) / (quality - 1) + if not graph[i] then + graph[i] = ease(a) + end + end + for i,v in ipairs(graph) do + local a = (i - 1) / (quality - 1) + local b = ease(a) + if minEase then + b = b / 2 + 0.5 + end + graph[i] = mix(v, b, math.min(dt * 18, 1)) + end +end + +function self.render() + local sw, sh = love.graphics.getDimensions() + + if mode == 1 or mode == 2 then + local csize = 10 -- preview point size + local size = math.min((sw - padding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + 128 + padding), sh - padding * 5 - csize) + + local x, y, w, h = sw - padding - size, padding, size, size + love.graphics.setColor(1, 1, 1, 1) + love.graphics.rectangle('line', x, y, w, h) + + -- grid + love.graphics.setColor(0.2, 0.2, 0.4, 0.2) + local gridsize = 64 + for gx = 1, gridsize - 2 do + love.graphics.line(x + margin + gx * w/gridsize, y + margin, x + margin + gx * w/gridsize, y + h - margin) + end + for gy = 1, gridsize - 2 do + love.graphics.line(x + margin, y + margin + gy * h/gridsize, x + w - margin, y + margin + gy * h/gridsize) + end + + -- mixease point + if mode == 2 then + love.graphics.setColor(1, 1, 1, 0.8) + love.graphics.line(x + margin + mixpoint * w, y, x + margin + mixpoint * w, y + h) + end + + -- preview point + local t = love.timer.getTime() % 1 + love.graphics.setColor(0.4, 0.4, 1, 0.4) + love.graphics.line(x + margin + t * w, y, x + margin + t * w, y + h) + + -- y = 0 point + -- todo: this will break with eases that dont have the first point at y0 + local py = graph[1] + love.graphics.setColor(0.7, 0.7, 0.7, 0.4 * (1 - math.abs(py - 0.5) / 0.5)) + love.graphics.line(x, y + h - py * h, x + w, y + py * h) + + -- 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) + local last = graph[1] or 0 + for gx = 1, quality - 1 do + local a = gx/quality + local b = graph[gx + 1] or 0 + 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) + if math.abs(b - last) < 1 then + love.graphics.line(ox, oy, px, py) + end + last = b + end + + -- preview + love.graphics.setColor(1, 1, 1, 0.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.4, 0.4, 1, 1) + local a1 = ease(t) + local a2 = ease(math.max(math.min(t - 0.1, 1), 0)) + local da = a1 + if love.timer.getTime() % 2 < 1 and math.floor(ease(0) + 0.5) ~= math.floor(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) + end +end + +return self \ No newline at end of file diff --git a/main.lua b/main.lua index 7c072c9..0d95453 100644 --- a/main.lua +++ b/main.lua @@ -5,7 +5,8 @@ end local easelib = require 'easelib' -local dropdown = require 'dropdown' +dropdown = require 'dropdown' +graph = require 'graph' -- utils @@ -53,16 +54,13 @@ minEase = false padding = 6 margin = 4 -local quality = 256 -local mixpoint = 0.5 -local oldmixpoint = 0.5 +mixpoint = 0.5 +oldmixpoint = 0.5 local mixpointtimer = 0 -- easter egg thing local mixpointspin = 0 -- graph -local graph = {} - -- dropdown bullshit @@ -73,21 +71,9 @@ function love.load() end function love.update(dt) - for i = 1, quality do - local a = (i - 1) / (quality - 1) - if not graph[i] then - graph[i] = ease(a) - end - end - for i,v in ipairs(graph) do - local a = (i - 1) / (quality - 1) - local b = ease(a) - if minEase then - b = b / 2 + 0.5 - end - graph[i] = mix(v, b, math.min(dt * 18, 1)) - end + graph.update(dt) + -- slider mixpointtimer = mix(mixpointtimer + math.abs(mixpoint - oldmixpoint), 0, math.min(dt * 8)) oldmixpoint = mix(oldmixpoint, mixpoint, math.min(dt * 20, 1)) @@ -102,7 +88,7 @@ function love.update(dt) end function love.draw() - local mode = dropdown.kget('mode').selected + mode = dropdown.kget('mode').selected local sw, sh = love.graphics.getDimensions() local mx, my = love.mouse.getPosition() @@ -132,7 +118,7 @@ function love.draw() love.graphics.rotate((mixpoint - oldmixpoint) * 4 + mixpointspin * math.pi * 2) love.graphics.setColor(0, 0, 0, 1) - if mx > sx - ssize/2 and mx < sx + ssize/2 and my > sy - ssize/2 and my < sy + ssize/2 and openDropdown == 0 then + if mx > sx - ssize/2 and mx < sx + ssize/2 and my > sy - ssize/2 and my < sy + ssize/2 and dropdown.openDropdown == 0 then love.graphics.setColor(0.2, 0.2, 0.3, 1) end love.graphics.rectangle('fill', -ssize/2, -ssize/2, ssize, ssize) @@ -146,9 +132,9 @@ function love.draw() love.graphics.pop() - if mx > x and mx < x + w and my > y and my < y + h and love.mouse.isDown(1) and openDropdown == 0 then + if mx > x and mx < x + w and my > y and my < y + h and love.mouse.isDown(1) and dropdown.openDropdown == 0 then mixpoint = (mx - x) / w - createDropdowns() + dropdown.createDropdowns() end end @@ -156,74 +142,7 @@ function love.draw() dropdown.render() -- graph - - if mode == 1 or mode == 2 then - local csize = 10 -- preview point size - local size = math.min((sw - padding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + 128 + padding), sh - padding * 5 - csize) - - local x, y, w, h = sw - padding - size, padding, size, size - love.graphics.setColor(1, 1, 1, 1) - love.graphics.rectangle('line', x, y, w, h) - - -- grid - love.graphics.setColor(0.2, 0.2, 0.4, 0.2) - local gridsize = 64 - for gx = 1, gridsize - 2 do - love.graphics.line(x + margin + gx * w/gridsize, y + margin, x + margin + gx * w/gridsize, y + h - margin) - end - for gy = 1, gridsize - 2 do - love.graphics.line(x + margin, y + margin + gy * h/gridsize, x + w - margin, y + margin + gy * h/gridsize) - end - - -- mixease point - if mode == 2 then - love.graphics.setColor(1, 1, 1, 0.8) - love.graphics.line(x + margin + mixpoint * w, y, x + margin + mixpoint * w, y + h) - end - - -- preview point - local t = love.timer.getTime() % 1 - love.graphics.setColor(0.4, 0.4, 1, 0.4) - love.graphics.line(x + margin + t * w, y, x + margin + t * w, y + h) - - -- y = 0 point - -- todo: this will break with eases that dont have the first point at y0 - local py = graph[1] - love.graphics.setColor(0.7, 0.7, 0.7, 0.4 * (1 - math.abs(py - 0.5) / 0.5)) - love.graphics.line(x, y + h - py * h, x + w, y + py * h) - - -- 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) - local last = graph[1] or 0 - for gx = 1, quality - 1 do - local a = gx/quality - local b = graph[gx + 1] or 0 - 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) - if math.abs(b - last) < 1 then - love.graphics.line(ox, oy, px, py) - end - last = b - end - - -- preview - love.graphics.setColor(1, 1, 1, 0.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.4, 0.4, 1, 1) - local a1 = ease(t) - local a2 = ease(math.max(math.min(t - 0.1, 1), 0)) - local da = a1 - if love.timer.getTime() % 2 < 1 and math.floor(ease(0) + 0.5) ~= math.floor(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) - end + graph.render() end function love.mousepressed(x, y, m) From 63b1a08df8c190d4dfef0812592f7e15ba444a26 Mon Sep 17 00:00:00 2001 From: jill Date: Sat, 18 Sep 2021 01:38:04 +0300 Subject: [PATCH 4/7] consistent formatting --- dropdown.lua | 28 ++++++------- easelib.lua | 114 +++++++++++++++++++++++++-------------------------- graph.lua | 18 ++++---- main.lua | 47 ++++++++++----------- 4 files changed, 102 insertions(+), 105 deletions(-) diff --git a/dropdown.lua b/dropdown.lua index bef1599..001949f 100644 --- a/dropdown.lua +++ b/dropdown.lua @@ -118,54 +118,54 @@ function self.render() local mx, my = love.mouse.getPosition() for i,v in ipairs(dropdowns) do local x, y, w, h = v.x, v.y, v.width, love.graphics.getFont():getHeight() + margin - + love.graphics.setColor(0, 0, 0, 0.3) if love.mouse.getX() > x and love.mouse.getX() < x + w and love.mouse.getY() > y and love.mouse.getY() < y + h then love.graphics.setColor(0.8, 0.8, 1, love.mouse.isDown(1) and 0.4 or 0.3) end love.graphics.rectangle('fill', x, y, w, h) - + love.graphics.setColor(1, 1, 1, 1) - + love.graphics.rectangle('line', x, y, w, h) love.graphics.print(self.selected(i), x + margin/2, y + margin/2) love.graphics.rectangle('line', x + w - h, y, h, h) love.graphics.polygon('line', x + w - h/2 + 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2 - 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2, y + h/2 + 0.3 * h) - + if self.openDropdown == i then for i,o in ipairs(v.options) do local x, y, w, h = x, y + i * h, w, h - + y = y + dropdownScrollE * h local gi = y / h if gi > maxDropdown or gi < 1 then goto continue end - + local a = 1 - math.min(math.max((1 - (maxDropdown - gi)) * (1 - (math.abs(dropdownScrollE) /(#v.options - maxDropdown))), 0), 1) - + love.graphics.setColor(0, 0, 0, 0.3 * a) if mx > x and mx < x + w and my > y and my < y + h then love.graphics.setColor(0.8, 0.8, 1, (love.mouse.isDown(1) and 0.4 or 0.3) * a) end love.graphics.rectangle('fill', x, y, w, h) - + love.graphics.setColor(1, 1, 1, 0.75 * a) love.graphics.rectangle('line', x, y, w, h) - + love.graphics.setColor(1, 1, 1, 1 * a) love.graphics.print(v.options[i], x + 2, y + 2) - + ::continue:: end - + -- scrollwheel - + if #v.options > maxDropdown then local displayed = maxDropdown / #v.options local scroll = math.abs(dropdownScrollE) / (#v.options - maxDropdown) local size = margin - + love.graphics.setColor(1, 1, 1, 0.9) love.graphics.rectangle('fill', x + w - size, y + h + scroll * (1 - displayed) * (maxDropdown - 1) * h, size, displayed * (maxDropdown - 1) * h) end @@ -195,7 +195,7 @@ function self.mousepressed(x, y, m) end end end - + if not clickedDropdown and m == 1 then self.openDropdown = 0 return true diff --git a/easelib.lua b/easelib.lua index 320ed59..ceb5933 100644 --- a/easelib.lua +++ b/easelib.lua @@ -33,100 +33,100 @@ table.insert(self, {'spike', function(t) return exp(-10 * abs(2 * t - 1)) end}) table.insert(self, {'inverse', function(t) return t * t * (1 - t) * (1 - t) / (0.5 - t) end}) table.insert(self, {'inSine', function(x) - return 1 - cos(x * (pi * 0.5)) + return 1 - cos(x * (pi * 0.5)) end}) table.insert(self, {'outSine', function(x) - return sin(x * (pi * 0.5)) + return sin(x * (pi * 0.5)) end}) table.insert(self, {'inOutSine', function(x) - return 0.5 - 0.5 * cos(x * pi) + return 0.5 - 0.5 * cos(x * pi) end}) table.insert(self, {'inQuad', function(t) return t * t end}) table.insert(self, {'outQuad', function(t) return -t * (t - 2) end}) table.insert(self, {'inOutQuad', function(t) - t = t * 2 - if t < 1 then - return 0.5 * t ^ 2 - else - return 1 - 0.5 * (2 - t) ^ 2 - end + t = t * 2 + if t < 1 then + return 0.5 * t ^ 2 + else + return 1 - 0.5 * (2 - t) ^ 2 + end end}) table.insert(self, {'inCubic', function(t) return t * t * t end}) table.insert(self, {'outCubic', function(t) return 1 - (1 - t) ^ 3 end}) table.insert(self, {'inOutCubic', function(t) - t = t * 2 - if t < 1 then - return 0.5 * t ^ 3 - else - return 1 - 0.5 * (2 - t) ^ 3 - end + t = t * 2 + if t < 1 then + return 0.5 * t ^ 3 + else + return 1 - 0.5 * (2 - t) ^ 3 + end end}) table.insert(self, {'inQuart', function(t) return t * t * t * t end}) table.insert(self, {'outQuart', function(t) return 1 - (1 - t) ^ 4 end}) table.insert(self, {'inOutQuart', function(t) - t = t * 2 - if t < 1 then - return 0.5 * t ^ 4 - else - return 1 - 0.5 * (2 - t) ^ 4 - end + t = t * 2 + if t < 1 then + return 0.5 * t ^ 4 + else + return 1 - 0.5 * (2 - t) ^ 4 + end end}) table.insert(self, {'inQuint', function(t) return t ^ 5 end}) table.insert(self, {'outQuint', function(t) return 1 - (1 - t) ^ 5 end}) table.insert(self, {'inOutQuint', function(t) - t = t * 2 - if t < 1 then - return 0.5 * t ^ 5 - else - return 1 - 0.5 * (2 - t) ^ 5 - end + t = t * 2 + if t < 1 then + return 0.5 * t ^ 5 + else + return 1 - 0.5 * (2 - t) ^ 5 + end end}) table.insert(self, {'inExpo', function(t) return 1000 ^ (t - 1) - 0.001 end}) table.insert(self, {'outExpo', function(t) return 1.001 - 1000 ^ -t end}) table.insert(self, {'inOutExpo', function(t) - t = t * 2 - if t < 1 then - return 0.5 * 1000 ^ (t - 1) - 0.0005 - else - return 1.0005 - 0.5 * 1000 ^ (1 - t) - end + t = t * 2 + if t < 1 then + return 0.5 * 1000 ^ (t - 1) - 0.0005 + else + return 1.0005 - 0.5 * 1000 ^ (1 - t) + end end}) table.insert(self, {'inCirc', function(t) return 1 - sqrt(1 - t * t) end}) table.insert(self, {'outCirc', function(t) return sqrt(-t * t + 2 * t) end}) table.insert(self, {'inOutCirc', function(t) - t = t * 2 - if t < 1 then - return 0.5 - 0.5 * sqrt(1 - t * t) - else - t = t - 2 - return 0.5 + 0.5 * sqrt(1 - t * t) - end + t = t * 2 + if t < 1 then + return 0.5 - 0.5 * sqrt(1 - t * t) + else + t = t - 2 + return 0.5 + 0.5 * sqrt(1 - t * t) + end end}) table.insert(self, {'outBounce', function(t) - if t < 1 / 2.75 then - return 7.5625 * t * t - elseif t < 2 / 2.75 then - t = t - 1.5 / 2.75 - return 7.5625 * t * t + 0.75 - elseif t < 2.5 / 2.75 then - t = t - 2.25 / 2.75 - return 7.5625 * t * t + 0.9375 - else - t = t - 2.625 / 2.75 - return 7.5625 * t * t + 0.984375 - end + if t < 1 / 2.75 then + return 7.5625 * t * t + elseif t < 2 / 2.75 then + t = t - 1.5 / 2.75 + return 7.5625 * t * t + 0.75 + elseif t < 2.5 / 2.75 then + t = t - 2.25 / 2.75 + return 7.5625 * t * t + 0.9375 + else + t = t - 2.625 / 2.75 + return 7.5625 * t * t + 0.984375 + end end}) table.insert(self, {'inBounce', function(t) return 1 - self.outBounce(1 - t) end}) table.insert(self, {'inOutBounce', function(t) - if t < 0.5 then - return self.inBounce(t * 2) * 0.5 - else - return self.outBounce(t * 2 - 1) * 0.5 + 0.5 - end + if t < 0.5 then + return self.inBounce(t * 2) * 0.5 + else + return self.outBounce(t * 2 - 1) * 0.5 + 0.5 + end end}) return self diff --git a/graph.lua b/graph.lua index fc90ada..6d2c8a0 100644 --- a/graph.lua +++ b/graph.lua @@ -26,11 +26,11 @@ function self.render() if mode == 1 or mode == 2 then local csize = 10 -- preview point size local size = math.min((sw - padding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + 128 + padding), sh - padding * 5 - csize) - + local x, y, w, h = sw - padding - size, padding, size, size love.graphics.setColor(1, 1, 1, 1) love.graphics.rectangle('line', x, y, w, h) - + -- grid love.graphics.setColor(0.2, 0.2, 0.4, 0.2) local gridsize = 64 @@ -40,24 +40,24 @@ function self.render() for gy = 1, gridsize - 2 do love.graphics.line(x + margin, y + margin + gy * h/gridsize, x + w - margin, y + margin + gy * h/gridsize) end - + -- mixease point if mode == 2 then love.graphics.setColor(1, 1, 1, 0.8) love.graphics.line(x + margin + mixpoint * w, y, x + margin + mixpoint * w, y + h) end - + -- preview point local t = love.timer.getTime() % 1 love.graphics.setColor(0.4, 0.4, 1, 0.4) love.graphics.line(x + margin + t * w, y, x + margin + t * w, y + h) - + -- y = 0 point -- todo: this will break with eases that dont have the first point at y0 local py = graph[1] love.graphics.setColor(0.7, 0.7, 0.7, 0.4 * (1 - math.abs(py - 0.5) / 0.5)) love.graphics.line(x, y + h - py * h, x + w, y + py * h) - + -- 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) @@ -72,11 +72,11 @@ function self.render() end last = b end - + -- preview love.graphics.setColor(1, 1, 1, 0.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.4, 0.4, 1, 1) local a1 = ease(t) local a2 = ease(math.max(math.min(t - 0.1, 1), 0)) @@ -87,7 +87,7 @@ function self.render() 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) end end diff --git a/main.lua b/main.lua index 0d95453..99b7548 100644 --- a/main.lua +++ b/main.lua @@ -54,16 +54,13 @@ minEase = false padding = 6 margin = 4 +-- slider + mixpoint = 0.5 oldmixpoint = 0.5 local mixpointtimer = 0 -- easter egg thing local mixpointspin = 0 --- graph - --- dropdown bullshit - - -- rendering function love.load() @@ -72,18 +69,18 @@ end function love.update(dt) graph.update(dt) - + -- slider mixpointtimer = mix(mixpointtimer + math.abs(mixpoint - oldmixpoint), 0, math.min(dt * 8)) oldmixpoint = mix(oldmixpoint, mixpoint, math.min(dt * 20, 1)) - + if mixpointtimer > 2 then mixpointtimer = mixpointtimer - 2 mixpointspin = mixpointspin + 4 end - + mixpointspin = mix(mixpointspin, 0, dt * 3) - + dropdown.update(dt) end @@ -91,32 +88,32 @@ function love.draw() mode = dropdown.kget('mode').selected local sw, sh = love.graphics.getDimensions() local mx, my = love.mouse.getPosition() - + 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) - + love.graphics.setColor(1, 1, 1, 1) love.graphics.print('Box of Eases by oatmealine', padding, sh - love.graphics.getFont():getHeight() - padding) - + -- sliders -- yeah we do a lil' hardcoding - + if mode == 2 then local x, y, w, h = padding, padding * 2 + love.graphics.getFont():getHeight() + margin, 128, 32 - + love.graphics.setColor(0.7, 0.7, 0.7, 0.4) love.graphics.line(x, y + h/2, x + w, y + h/2) - + local sx, sy = x + w * oldmixpoint, y + h/2 local ssize = h * 0.5 - + love.graphics.push() - + love.graphics.translate(sx, sy) love.graphics.rotate((mixpoint - oldmixpoint) * 4 + mixpointspin * math.pi * 2) - + love.graphics.setColor(0, 0, 0, 1) if mx > sx - ssize/2 and mx < sx + ssize/2 and my > sy - ssize/2 and my < sy + ssize/2 and dropdown.openDropdown == 0 then love.graphics.setColor(0.2, 0.2, 0.3, 1) @@ -124,23 +121,23 @@ function love.draw() love.graphics.rectangle('fill', -ssize/2, -ssize/2, ssize, ssize) love.graphics.setColor(1, 1, 1, 1) love.graphics.rectangle('line', -ssize/2, -ssize/2, ssize, ssize) - + love.graphics.rotate((mixpoint - oldmixpoint) * -2) - + love.graphics.setColor(1, 1, 1, 1) love.graphics.printf(math.floor(mixpoint * 100)/100, -ssize * 6, ssize - 2, ssize * 12, 'center') - + love.graphics.pop() - + if mx > x and mx < x + w and my > y and my < y + h and love.mouse.isDown(1) and dropdown.openDropdown == 0 then mixpoint = (mx - x) / w dropdown.createDropdowns() end end - + -- dropdowns dropdown.render() - + -- graph graph.render() end @@ -155,7 +152,7 @@ end function love.wheelmoved(x, y) if y == 0 then return end - + if dropdown.wheelmoved(x, y) then return end end From f73073a9c656dd570d23a6eb076f503c6e08de54 Mon Sep 17 00:00:00 2001 From: jill Date: Sat, 18 Sep 2021 01:44:26 +0300 Subject: [PATCH 5/7] create util & ease libs --- dropdown.lua | 16 +++++++--------- ease.lua | 38 ++++++++++++++++++++++++++++++++++++++ graph.lua | 10 +++++----- main.lua | 41 ++--------------------------------------- util.lua | 3 +++ 5 files changed, 55 insertions(+), 53 deletions(-) create mode 100644 ease.lua create mode 100644 util.lua diff --git a/dropdown.lua b/dropdown.lua index 001949f..0b4b60a 100644 --- a/dropdown.lua +++ b/dropdown.lua @@ -70,40 +70,38 @@ function self.createDropdowns() x = padding + 128 + padding, y = padding, width = 128, - options = skeys(eases), + options = skeys(ease.eases), name = 'ease1' }) - ease = eases[d[dropdownId].options[d[dropdownId].selected]].f + ease.ease = ease.eases[d[dropdownId].options[d[dropdownId].selected]].f elseif d[dropdownId].selected == 2 then -- mix eases insertDropdown(d, { x = padding + 128 + padding, y = padding, width = 128, - options = skeys(eases), + options = skeys(ease.eases), name = 'ease1' }) insertDropdown(d, { x = padding + 128 + padding + 128 + padding, y = padding, width = 128, - options = skeys(eases), + options = skeys(ease.eases), name = 'ease2' }) - ease = mixEase(eases[d[dropdownId - 1].options[d[dropdownId - 1].selected]].f, eases[d[dropdownId].options[d[dropdownId].selected]].f, mixpoint) + ease.ease = ease.mixEase(ease.eases[d[dropdownId - 1].options[d[dropdownId - 1].selected]].f, ease.eases[d[dropdownId].options[d[dropdownId].selected]].f, mixpoint) elseif d[dropdownId].selected == 3 then -- create eases insertDropdown(d, { x = padding + 128 + padding, y = padding, width = 128, - options = skeys(eases), + options = skeys(ease.eases), name = 'ease1' }) end dropdowns = d - minEase = (self.kselected('ease1') and eases[self.kselected('ease1')].min == -1) or (self.kselected('ease2') and eases[self.kselected('ease2')].min == -1) - - return ease, minEase + minEase = (self.kselected('ease1') and ease.eases[self.kselected('ease1')].min == -1) or (self.kselected('ease2') and ease.eases[self.kselected('ease2')].min == -1) end function self.update(dt) diff --git a/ease.lua b/ease.lua new file mode 100644 index 0000000..ff73894 --- /dev/null +++ b/ease.lua @@ -0,0 +1,38 @@ +local self = {} + +local easelib = require 'easelib' + +function self.mixEase(e1, e2, point) + if not point then point = 0.5 end + + return function(a) + if a < point then + return e1(a / point) * point + else + return e2((a - point) / (1 - point)) * (1 - point) + point + end + end +end + +self.eases = {} +for i,v in pairs(easelib) do + local min = 0 + + local q = 10 + for i = 0, q do + local s = v[2](i / q) + if s < 0 then min = -1 end + end + + self.eases[v[1]] = { + f = v[2], + max = 1, + min = min, + i = i + } +end + +self.ease = nil +self.minEase = false + +return self \ No newline at end of file diff --git a/graph.lua b/graph.lua index 6d2c8a0..62b6ac9 100644 --- a/graph.lua +++ b/graph.lua @@ -7,12 +7,12 @@ function self.update(dt) for i = 1, quality do local a = (i - 1) / (quality - 1) if not graph[i] then - graph[i] = ease(a) + graph[i] = ease.ease(a) end end for i,v in ipairs(graph) do local a = (i - 1) / (quality - 1) - local b = ease(a) + local b = ease.ease(a) if minEase then b = b / 2 + 0.5 end @@ -78,10 +78,10 @@ function self.render() love.graphics.line(x + margin, y + h + padding * 2 + csize/2, x + w - margin, y + h + padding * 2 + csize/2) love.graphics.setColor(0.4, 0.4, 1, 1) - local a1 = ease(t) - local a2 = ease(math.max(math.min(t - 0.1, 1), 0)) + local a1 = ease.ease(t) + local a2 = ease.ease(math.max(math.min(t - 0.1, 1), 0)) local da = a1 - if love.timer.getTime() % 2 < 1 and math.floor(ease(0) + 0.5) ~= math.floor(ease(1) + 0.5) then + if love.timer.getTime() % 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 diff --git a/main.lua b/main.lua index 99b7548..b113fd9 100644 --- a/main.lua +++ b/main.lua @@ -3,52 +3,15 @@ for k, v in pairs(_G) do table.insert(default_G, k) end -local easelib = require 'easelib' +ease = require 'ease' dropdown = require 'dropdown' graph = require 'graph' --- utils - -function mix(x, y, a) - return x * (1 - a) + y * a -end +require 'util' -- exports into global table -- eases -function mixEase(e1, e2, point) - if not point then point = 0.5 end - - return function(a) - if a < point then - return e1(a / point) * point - else - return e2((a - point) / (1 - point)) * (1 - point) + point - end - end -end - -eases = {} -for i,v in pairs(easelib) do - local min = 0 - - local q = 10 - for i = 0, q do - local s = v[2](i / q) - if s < 0 then min = -1 end - end - - eases[v[1]] = { - f = v[2], - max = 1, - min = min, - i = i - } -end - -ease = nil -minEase = false - -- rendering constants padding = 6 diff --git a/util.lua b/util.lua new file mode 100644 index 0000000..b6e5ccf --- /dev/null +++ b/util.lua @@ -0,0 +1,3 @@ +function mix(x, y, a) + return x * (1 - a) + y * a +end \ No newline at end of file From 05bfac2221307cd195fa02a9ba5d664ab5c7fb33 Mon Sep 17 00:00:00 2001 From: jill Date: Sat, 18 Sep 2021 01:51:42 +0300 Subject: [PATCH 6/7] unhardcore some rendering constants --- dropdown.lua | 30 +++++++++++++++--------------- graph.lua | 4 ++-- main.lua | 12 ++++++------ 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/dropdown.lua b/dropdown.lua index 0b4b60a..8a3bff5 100644 --- a/dropdown.lua +++ b/dropdown.lua @@ -54,9 +54,9 @@ function self.createDropdowns() local d = {} dropdownId = 0 insertDropdown(d, { - x = padding, - y = padding, - width = 128, + x = outerpadding, + y = outerpadding, + width = dropdownWidth, options = { 'Preview Ease', 'Mix Eases', @@ -67,34 +67,34 @@ function self.createDropdowns() if d[dropdownId].selected == 1 then -- preview ease insertDropdown(d, { - x = padding + 128 + padding, - y = padding, - width = 128, + x = outerpadding + dropdownWidth + padding, + y = outerpadding, + width = dropdownWidth, options = skeys(ease.eases), name = 'ease1' }) ease.ease = ease.eases[d[dropdownId].options[d[dropdownId].selected]].f elseif d[dropdownId].selected == 2 then -- mix eases insertDropdown(d, { - x = padding + 128 + padding, - y = padding, - width = 128, + x = outerpadding + dropdownWidth + padding, + y = outerpadding, + width = dropdownWidth, options = skeys(ease.eases), name = 'ease1' }) insertDropdown(d, { - x = padding + 128 + padding + 128 + padding, - y = padding, - width = 128, + x = outerpadding + dropdownWidth + padding + dropdownWidth + padding, + y = outerpadding, + width = dropdownWidth, options = skeys(ease.eases), name = 'ease2' }) ease.ease = ease.mixEase(ease.eases[d[dropdownId - 1].options[d[dropdownId - 1].selected]].f, ease.eases[d[dropdownId].options[d[dropdownId].selected]].f, mixpoint) elseif d[dropdownId].selected == 3 then -- create eases insertDropdown(d, { - x = padding + 128 + padding, - y = padding, - width = 128, + x = outerpadding + dropdownWidth + padding, + y = outerpadding, + width = dropdownWidth, options = skeys(ease.eases), name = 'ease1' }) diff --git a/graph.lua b/graph.lua index 62b6ac9..0ae893d 100644 --- a/graph.lua +++ b/graph.lua @@ -25,9 +25,9 @@ function self.render() if mode == 1 or mode == 2 then local csize = 10 -- preview point size - local size = math.min((sw - padding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + 128 + padding), sh - padding * 5 - csize) + local size = math.min((sw - outerpadding) - ((dropdown.kget('ease2') or dropdown.kget('ease1')).x + dropdownWidth + padding), sh - outerpadding * 2 - padding * 3 - csize) - local x, y, w, h = sw - padding - size, padding, size, size + local x, y, w, h = sw - outerpadding - size, outerpadding, size, size love.graphics.setColor(1, 1, 1, 1) love.graphics.rectangle('line', x, y, w, h) diff --git a/main.lua b/main.lua index b113fd9..a7faa9b 100644 --- a/main.lua +++ b/main.lua @@ -10,12 +10,12 @@ graph = require 'graph' require 'util' -- exports into global table --- eases - -- rendering constants -padding = 6 -margin = 4 +padding = 14 +outerpadding = 22 +margin = 6 +dropdownWidth = 106 -- slider @@ -58,13 +58,13 @@ function love.draw() love.graphics.rectangle('line', 0, 0, sw, sh) love.graphics.setColor(1, 1, 1, 1) - love.graphics.print('Box of Eases by oatmealine', padding, sh - love.graphics.getFont():getHeight() - padding) + love.graphics.print('Box of Eases by oatmealine', outerpadding, sh - love.graphics.getFont():getHeight() - outerpadding) -- sliders -- yeah we do a lil' hardcoding if mode == 2 then - local x, y, w, h = padding, padding * 2 + love.graphics.getFont():getHeight() + margin, 128, 32 + local x, y, w, h = outerpadding, outerpadding * 2 + love.graphics.getFont():getHeight() + margin, dropdownWidth, 32 love.graphics.setColor(0.7, 0.7, 0.7, 0.4) love.graphics.line(x, y + h/2, x + w, y + h/2) From 71e06141d0734d3648224a06b6709c59175e3a08 Mon Sep 17 00:00:00 2001 From: jill Date: Sat, 18 Sep 2021 02:04:26 +0300 Subject: [PATCH 7/7] turns out 1 element in every dropdown wasnt rendering and i never knew --- dropdown.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dropdown.lua b/dropdown.lua index 8a3bff5..11904cd 100644 --- a/dropdown.lua +++ b/dropdown.lua @@ -106,7 +106,7 @@ end function self.update(dt) if self.openDropdown ~= 0 then - dropdownScroll = math.max(dropdownScroll, -(#self.get(self.openDropdown).options - maxDropdown)) + dropdownScroll = math.max(dropdownScroll, -(#self.get(self.openDropdown).options - maxDropdown + 1)) dropdownScroll = math.min(dropdownScroll, 0) dropdownScrollE = mix(dropdownScrollE, dropdownScroll, dt * 10) end @@ -117,7 +117,7 @@ function self.render() for i,v in ipairs(dropdowns) do local x, y, w, h = v.x, v.y, v.width, love.graphics.getFont():getHeight() + margin - love.graphics.setColor(0, 0, 0, 0.3) + love.graphics.setColor(0.06, 0.06, 0.12, 0.3) if love.mouse.getX() > x and love.mouse.getX() < x + w and love.mouse.getY() > y and love.mouse.getY() < y + h then love.graphics.setColor(0.8, 0.8, 1, love.mouse.isDown(1) and 0.4 or 0.3) end @@ -136,13 +136,14 @@ function self.render() y = y + dropdownScrollE * h local gi = y / h - if gi > maxDropdown or gi < 1 then + if gi > (maxDropdown + 1) or gi < 1 then goto continue end - local a = 1 - math.min(math.max((1 - (maxDropdown - gi)) * (1 - (math.abs(dropdownScrollE) /(#v.options - maxDropdown))), 0), 1) + -- help + local a = (1 - math.min(math.max((1 - (maxDropdown - gi)) * (1 - (math.abs(dropdownScrollE) / (#v.options - maxDropdown + 1))), 0), 1)) * math.max(math.min(gi - 1, 1), 0) - love.graphics.setColor(0, 0, 0, 0.3 * a) + love.graphics.setColor(0.06, 0.06, 0.12, 0.3 * a) if mx > x and mx < x + w and my > y and my < y + h then love.graphics.setColor(0.8, 0.8, 1, (love.mouse.isDown(1) and 0.4 or 0.3) * a) end @@ -160,8 +161,8 @@ function self.render() -- scrollwheel if #v.options > maxDropdown then - local displayed = maxDropdown / #v.options - local scroll = math.abs(dropdownScrollE) / (#v.options - maxDropdown) + local displayed = maxDropdown / (#v.options) + local scroll = math.abs(dropdownScrollE) / (#v.options - maxDropdown + 1) local size = margin love.graphics.setColor(1, 1, 1, 0.9)