From c44579b508edb6c26cd8a0e1111c4fdf52ff1970 Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 01:11:44 +0300 Subject: [PATCH 01/11] unhardcode modes --- graph.lua | 4 ++-- main.lua | 6 ++++++ slider.lua | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/graph.lua b/graph.lua index a65818c..6400ae5 100644 --- a/graph.lua +++ b/graph.lua @@ -46,7 +46,7 @@ end function self.render() local sw, sh = love.graphics.getDimensions() - if mode == 1 or mode == 2 then + if mode == modes.preview or mode == modes.mix then 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) @@ -65,7 +65,7 @@ function self.render() end -- mixease point - if mode == 2 and slider.kget('mix') then + if mode == modes.mix and slider.kget('mix') then love.graphics.setColor(1, 1, 1, 0.2 + self.touchtimer * 0.6) love.graphics.line(x + margin + slider.kvalue('mix') * w, y, x + margin + slider.kvalue('mix') * w, y + h) end diff --git a/main.lua b/main.lua index ddd2940..6eae66a 100644 --- a/main.lua +++ b/main.lua @@ -12,6 +12,12 @@ slider = require 'slider' dropdown = require 'dropdown' graph = require 'graph' +modes = { + preview = 1, + mix = 2, + create = 3 +} + function createUI() dropdown.createDropdowns() slider.createSliders() diff --git a/slider.lua b/slider.lua index cd9828d..a81e5ce 100644 --- a/slider.lua +++ b/slider.lua @@ -38,7 +38,7 @@ function self.createSliders() local s = {} sliderId = 0 - if mode == 2 then -- mix eases + if mode == modes.mix then -- mix eases insertSlider(s, { x = outerpadding, y = outerpadding + fontHeight * 2.5 + padding, @@ -50,7 +50,7 @@ function self.createSliders() displayname = 'Mix' }) end - if mode == 1 or mode == 2 then -- bpm slider + if mode == modes.preview or mode == modes.mix then -- bpm slider insertSlider(s, { x = outerpadding, y = love.graphics.getHeight() - outerpadding - fontHeight * 3 - padding, From fbd5277cdb8e8476273b6b455806b45450b29ac7 Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 13:16:27 +0300 Subject: [PATCH 02/11] multiply mode --- dropdown.lua | 36 +++++++++++++++++++++++++++++++++--- graph.lua | 2 +- main.lua | 3 ++- slider.lua | 2 +- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/dropdown.lua b/dropdown.lua index ddd79c8..455a389 100644 --- a/dropdown.lua +++ b/dropdown.lua @@ -89,6 +89,7 @@ function self.createDropdowns() options = { 'Preview Ease', 'Mix Eases', + 'Multiply Eases', 'Create Ease' }, name = 'mode' @@ -99,7 +100,7 @@ function self.createDropdowns() local eases = skeys(ease.eases) - if d[dropdownId].selected == 1 then -- preview ease + if d[dropdownId].selected == modes.preview then -- preview ease insertDropdown(d, { x = outerpadding + dropdownWidth + padding, y = outerpadding, @@ -115,7 +116,7 @@ function self.createDropdowns() ease.ease = function(x) return _e.f(x, param1[1], param1[2]) end - elseif d[dropdownId].selected == 2 then -- mix eases + elseif d[dropdownId].selected == modes.mix then -- mix eases insertDropdown(d, { x = outerpadding + dropdownWidth + padding, y = outerpadding, @@ -142,7 +143,36 @@ function self.createDropdowns() param2[1] = slider.kvalue(_e2.name .. 'param21') or (_e2.params[1] and _e2.params[1].default) or 1 param2[2] = slider.kvalue(_e2.name .. 'param22') or (_e2.params[2] and _e2.params[2].default) or 1 ease.ease = ease.mixEase(_e1.f, _e2.f, slider.kvalue('mix'), param1, param2) - elseif d[dropdownId].selected == 3 then -- create eases + elseif d[dropdownId].selected == modes.multiply then -- mult eases + insertDropdown(d, { + x = outerpadding + dropdownWidth + padding, + y = outerpadding, + width = dropdownWidth, + options = eases, + name = 'ease1', + icons = icons(eases), + params = params(eases) + }) + insertDropdown(d, { + x = outerpadding + dropdownWidth + padding + dropdownWidth + padding, + y = outerpadding, + width = dropdownWidth, + options = eases, + name = 'ease2', + icons = icons(eases), + params = params(eases) + }) + + local _e1 = ease.eases[d[dropdownId - 1].options[d[dropdownId - 1].selected]] + local _e2 = ease.eases[d[dropdownId].options[d[dropdownId].selected]] + param1[1] = slider.kvalue(_e1.name .. 'param11') or (_e1.params[1] and _e1.params[1].default) or 1 + param1[2] = slider.kvalue(_e1.name .. 'param12') or (_e1.params[2] and _e1.params[2].default) or 1 + param2[1] = slider.kvalue(_e2.name .. 'param21') or (_e2.params[1] and _e2.params[1].default) or 1 + param2[2] = slider.kvalue(_e2.name .. 'param22') or (_e2.params[2] and _e2.params[2].default) or 1 + ease.ease = function(x) + return _e2.f(_e1.f(x, param1[1], param1[2]), param2[1], param2[2]) + end + elseif d[dropdownId].selected == modes.create then -- create eases insertDropdown(d, { x = outerpadding + dropdownWidth + padding, y = outerpadding, diff --git a/graph.lua b/graph.lua index 6400ae5..a0165e1 100644 --- a/graph.lua +++ b/graph.lua @@ -46,7 +46,7 @@ end function self.render() local sw, sh = love.graphics.getDimensions() - if mode == modes.preview or mode == modes.mix then + if mode == modes.preview or mode == modes.mix or mode == modes.multiply then 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) diff --git a/main.lua b/main.lua index 6eae66a..1d41e88 100644 --- a/main.lua +++ b/main.lua @@ -15,7 +15,8 @@ graph = require 'graph' modes = { preview = 1, mix = 2, - create = 3 + multiply = 3, + create = 4 } function createUI() diff --git a/slider.lua b/slider.lua index a81e5ce..b16b3ff 100644 --- a/slider.lua +++ b/slider.lua @@ -50,7 +50,7 @@ function self.createSliders() displayname = 'Mix' }) end - if mode == modes.preview or mode == modes.mix then -- bpm slider + if mode == modes.preview or mode == modes.mix or mode == modes.multiply then -- bpm slider insertSlider(s, { x = outerpadding, y = love.graphics.getHeight() - outerpadding - fontHeight * 3 - padding, From 57ac1247fa4a1764c780ee8d3fe8c74cbc5b2f9d Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 13:32:12 +0300 Subject: [PATCH 03/11] create buttons --- button.lua | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ main.lua | 5 ++++ 2 files changed, 86 insertions(+) create mode 100644 button.lua diff --git a/button.lua b/button.lua new file mode 100644 index 0000000..3597f3a --- /dev/null +++ b/button.lua @@ -0,0 +1,81 @@ +local self = {} + +local buttons = {} + +function self.get(index) + return buttons[index] +end + +function self.kget(key) + for _, v in ipairs(buttons) do + if v.name == key then + return v + end + end +end + +local buttonId +local function insertButton(tab, f) + buttonId = buttonId + 1 + f.press = (self.kget(f.name) or {press = 1}).press + return table.insert(tab, f) +end +function self.createButtons() + local s = {} + buttonId = 0 + + --[[ + insertButton(s, { + x = outerpadding, + y = love.graphics.getHeight() - outerpadding - fontHeight * 4 - padding * 2 - 32, + size = 32, + name = 'clipboard', + displayname = 'Copy to Clipboard' + }) + ]] + + buttons = s +end + +function self.update(dt) + for i, v in ipairs(buttons) do + local mx, my = love.mouse.getPosition() + + local targetsize = 1 + if mx > v.x and mx < v.x + v.size and my > v.y and my < v.y + v.size then + if love.mouse.isDown(1) then + targetsize = 0.8 + else + targetsize = 0.95 + end + end + + v.press = mix(v.press, targetsize, dt * 12) + end +end + +function self.render() + local mx, my = love.mouse.getPosition() + + for i, v in ipairs(buttons) do + local x, y, w, h = v.x, v.y, v.size, v.size + + w = w * v.press + h = h * v.press + x = x + (v.size - w) / 2 + y = y + (v.size - h) / 2 + + local hovering = mx > x and mx < x + w and my > y and my < y + h and dropdown.openDropdown == 0 + local clicking = hovering and love.mouse.isDown(1) + + love.graphics.setColor(0, 0, 0, 1) + if hovering or dragging then + love.graphics.setColor(0.2, 0.2, 0.3, 1) + end + love.graphics.rectangle('fill', x, y, w, h) + love.graphics.setColor(1, 1, 1, 1) + love.graphics.rectangle('line', x, y, w, h) + end +end + +return self \ No newline at end of file diff --git a/main.lua b/main.lua index 1d41e88..fdbe5d7 100644 --- a/main.lua +++ b/main.lua @@ -11,6 +11,7 @@ ease = require 'ease' slider = require 'slider' dropdown = require 'dropdown' graph = require 'graph' +button = require 'button' modes = { preview = 1, @@ -22,6 +23,7 @@ modes = { function createUI() dropdown.createDropdowns() slider.createSliders() + button.createButtons() end require 'util' -- exports into global table @@ -49,6 +51,7 @@ function love.update(dt) graph.update(dt) slider.update(dt) dropdown.update(dt) + button.update(dt) end function love.draw() @@ -65,6 +68,8 @@ function love.draw() love.graphics.setColor(0.2, 0.2, 0.3, 1) love.graphics.print('Box of Eases by oatmealine', outerpadding, sh - fontHeight - outerpadding) + button.render() + slider.render() dropdown.render() From 94305e5477e173d228144d98fe692acb3befa100 Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 13:56:48 +0300 Subject: [PATCH 04/11] add tooltip class --- button.lua | 3 +-- main.lua | 6 ++++++ tooltips.lua | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 tooltips.lua diff --git a/button.lua b/button.lua index 3597f3a..e154c88 100644 --- a/button.lua +++ b/button.lua @@ -24,7 +24,6 @@ function self.createButtons() local s = {} buttonId = 0 - --[[ insertButton(s, { x = outerpadding, y = love.graphics.getHeight() - outerpadding - fontHeight * 4 - padding * 2 - 32, @@ -32,7 +31,6 @@ function self.createButtons() name = 'clipboard', displayname = 'Copy to Clipboard' }) - ]] buttons = s end @@ -71,6 +69,7 @@ function self.render() love.graphics.setColor(0, 0, 0, 1) if hovering or dragging then love.graphics.setColor(0.2, 0.2, 0.3, 1) + tooltips.show('Copy to Clipboard') end love.graphics.rectangle('fill', x, y, w, h) love.graphics.setColor(1, 1, 1, 1) diff --git a/main.lua b/main.lua index fdbe5d7..d564e73 100644 --- a/main.lua +++ b/main.lua @@ -12,6 +12,7 @@ slider = require 'slider' dropdown = require 'dropdown' graph = require 'graph' button = require 'button' +tooltips = require 'tooltips' modes = { preview = 1, @@ -52,6 +53,7 @@ function love.update(dt) slider.update(dt) dropdown.update(dt) button.update(dt) + tooltips.update(dt) end function love.draw() @@ -68,6 +70,8 @@ function love.draw() love.graphics.setColor(0.2, 0.2, 0.3, 1) love.graphics.print('Box of Eases by oatmealine', outerpadding, sh - fontHeight - outerpadding) + tooltips.prerender() + button.render() slider.render() @@ -75,6 +79,8 @@ function love.draw() dropdown.render() graph.render() + + tooltips.render() end function love.mousepressed(x, y, m) diff --git a/tooltips.lua b/tooltips.lua new file mode 100644 index 0000000..09a5d72 --- /dev/null +++ b/tooltips.lua @@ -0,0 +1,58 @@ +local self = {} + +local tooltipwidth = 0 +local tooltipx = 0 +local tooltipy = 0 + +local tooltipopen = false +local tooltiptext = '' +local tooltiptargetwidth = 0 + +local tooltipframe = false + +function self.update(dt) + local mx, my = love.mouse.getPosition() + tooltipx = mix(tooltipx, mx, dt * 14) + tooltipy = mix(tooltipy, my, dt * 14) + + tooltipwidth = mix(tooltipwidth, tooltiptargetwidth, dt * 12) +end + +function self.prerender() + tooltipframe = false +end + +function self.show(text) + tooltipframe = true + tooltiptext = text + tooltiptargetwidth = love.graphics.newText(love.graphics.getFont(), text):getWidth() +end + +function self.render() + local mx, my = love.mouse.getPosition() + if not tooltipframe then + tooltiptargetwidth = 0 + end + + if tooltipwidth > 1 then + local a = math.min((tooltipwidth - 1) / 6, 1) + + love.graphics.push() + + love.graphics.translate(mx + 16, my + 16) + + love.graphics.setColor(0.2, 0.2, 0.3, a) + love.graphics.rectangle('fill', 0, 0, tooltipwidth + 4 + margin, fontHeight + margin) + + love.graphics.setScissor(0, 0, mx + tooltipwidth + 2 + margin/2 + 16, love.graphics.getHeight()) + + love.graphics.setColor(1, 1, 1, 1) + love.graphics.print(tooltiptext, 2 + margin/2, 2 + margin/2) + + love.graphics.setScissor() + + love.graphics.pop() + end +end + +return self \ No newline at end of file From 1b572c67a53cef1b86363e8c7fcbf35082d64fc6 Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 14:14:38 +0300 Subject: [PATCH 05/11] better looking tooltips --- button.lua | 5 +++-- tooltips.lua | 22 +++++++++++++++++----- util.lua | 6 ++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/button.lua b/button.lua index e154c88..1de64e4 100644 --- a/button.lua +++ b/button.lua @@ -29,7 +29,8 @@ function self.createButtons() y = love.graphics.getHeight() - outerpadding - fontHeight * 4 - padding * 2 - 32, size = 32, name = 'clipboard', - displayname = 'Copy to Clipboard' + displayname = 'Copy to Clipboard', + tooltip = 'Copy to Clipboard' }) buttons = s @@ -69,7 +70,7 @@ function self.render() love.graphics.setColor(0, 0, 0, 1) if hovering or dragging then love.graphics.setColor(0.2, 0.2, 0.3, 1) - tooltips.show('Copy to Clipboard') + if v.tooltip then tooltips.show(v.tooltip) end end love.graphics.rectangle('fill', x, y, w, h) love.graphics.setColor(1, 1, 1, 1) diff --git a/tooltips.lua b/tooltips.lua index 09a5d72..c16eaea 100644 --- a/tooltips.lua +++ b/tooltips.lua @@ -12,8 +12,8 @@ local tooltipframe = false function self.update(dt) local mx, my = love.mouse.getPosition() - tooltipx = mix(tooltipx, mx, dt * 14) - tooltipy = mix(tooltipy, my, dt * 14) + tooltipx = mix(tooltipx, mx, dt * 18) + tooltipy = mix(tooltipy, my, dt * 18) tooltipwidth = mix(tooltipwidth, tooltiptargetwidth, dt * 12) end @@ -28,6 +28,12 @@ function self.show(text) tooltiptargetwidth = love.graphics.newText(love.graphics.getFont(), text):getWidth() end +local function softlimit(x, f) + local sign = math.sign(x) + + return sign * (f - (1.027 ^ (-10 * math.abs(x))) * f) +end + function self.render() local mx, my = love.mouse.getPosition() if not tooltipframe then @@ -37,14 +43,20 @@ function self.render() if tooltipwidth > 1 then local a = math.min((tooltipwidth - 1) / 6, 1) + local x, y, w, h = mx + 8, my + 8, tooltipwidth + 4 + margin, fontHeight + margin + + local easiness = 3 -- hehe. magic numbers + local sx, sy = (w - softlimit(mx - tooltipx, w/easiness)/easiness) / w, (h - softlimit(my - tooltipy, h/easiness)/easiness) / h + love.graphics.push() - love.graphics.translate(mx + 16, my + 16) + love.graphics.translate(x, y) + love.graphics.scale(sx, sy) love.graphics.setColor(0.2, 0.2, 0.3, a) - love.graphics.rectangle('fill', 0, 0, tooltipwidth + 4 + margin, fontHeight + margin) + love.graphics.rectangle('fill', 0, 0, w, h) - love.graphics.setScissor(0, 0, mx + tooltipwidth + 2 + margin/2 + 16, love.graphics.getHeight()) + love.graphics.setScissor(0, 0, math.max(mx + (tooltipwidth + 2 + margin/2 + 16) * sx, 0), love.graphics.getHeight()) love.graphics.setColor(1, 1, 1, 1) love.graphics.print(tooltiptext, 2 + margin/2, 2 + margin/2) diff --git a/util.lua b/util.lua index b6e5ccf..2e6c9a2 100644 --- a/util.lua +++ b/util.lua @@ -1,3 +1,9 @@ function mix(x, y, a) return x * (1 - a) + y * a +end + +function math.sign(x) + if x < 0 then return -1 end + if x > 0 then return 1 end + return 0 end \ No newline at end of file From 775d97ef2a618762d85db8ae95dc202f69b41c0d Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 14:22:47 +0300 Subject: [PATCH 06/11] add more tooltips & tweak visuals --- dropdown.lua | 7 +++++-- slider.lua | 4 +++- tooltips.lua | 8 +++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/dropdown.lua b/dropdown.lua index 455a389..9d76d6a 100644 --- a/dropdown.lua +++ b/dropdown.lua @@ -151,7 +151,8 @@ function self.createDropdowns() options = eases, name = 'ease1', icons = icons(eases), - params = params(eases) + params = params(eases), + tooltip = 'The a in b(a(x))' }) insertDropdown(d, { x = outerpadding + dropdownWidth + padding + dropdownWidth + padding, @@ -160,7 +161,8 @@ function self.createDropdowns() options = eases, name = 'ease2', icons = icons(eases), - params = params(eases) + params = params(eases), + tooltip = 'The b in b(a(x))' }) local _e1 = ease.eases[d[dropdownId - 1].options[d[dropdownId - 1].selected]] @@ -212,6 +214,7 @@ function self.render() love.graphics.setColor(0.06, 0.06, 0.12, 0.6) 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) + if v.tooltip then tooltips.show(v.tooltip) end end love.graphics.rectangle('fill', x, y, w, h) diff --git a/slider.lua b/slider.lua index b16b3ff..21bb29c 100644 --- a/slider.lua +++ b/slider.lua @@ -47,7 +47,8 @@ function self.createSliders() max = 1, default = 0.5, name = 'mix', - displayname = 'Mix' + displayname = 'Mix', + tooltip = 'The point at which the first ease snaps into the second one' }) end if mode == modes.preview or mode == modes.mix or mode == modes.multiply then -- bpm slider @@ -150,6 +151,7 @@ function self.render() love.graphics.setColor(0, 0, 0, 1) if hovering or dragging then love.graphics.setColor(0.2, 0.2, 0.3, 1) + if v.tooltip then tooltips.show(v.tooltip) end end love.graphics.rectangle('fill', -ssize/2, -ssize/2, ssize, ssize) love.graphics.setColor(1, 1, 1, 1) diff --git a/tooltips.lua b/tooltips.lua index c16eaea..1c98e7c 100644 --- a/tooltips.lua +++ b/tooltips.lua @@ -23,6 +23,7 @@ function self.prerender() end function self.show(text) + if love.mouse.isDown(1) or dropdown.openDropdown ~= 0 then return end tooltipframe = true tooltiptext = text tooltiptargetwidth = love.graphics.newText(love.graphics.getFont(), text):getWidth() @@ -43,10 +44,11 @@ function self.render() if tooltipwidth > 1 then local a = math.min((tooltipwidth - 1) / 6, 1) - local x, y, w, h = mx + 8, my + 8, tooltipwidth + 4 + margin, fontHeight + margin + local x, y, w, h = mx + 8, my + 8, (tooltipwidth + 4 + margin), (fontHeight + margin) local easiness = 3 -- hehe. magic numbers - local sx, sy = (w - softlimit(mx - tooltipx, w/easiness)/easiness) / w, (h - softlimit(my - tooltipy, h/easiness)/easiness) / h + local scale = 0.8 + local sx, sy = ((w - softlimit(mx - tooltipx, w/easiness)/easiness) / w) * scale, ((h - softlimit(my - tooltipy, h/easiness)/easiness) / h) * scale love.graphics.push() @@ -58,7 +60,7 @@ function self.render() love.graphics.setScissor(0, 0, math.max(mx + (tooltipwidth + 2 + margin/2 + 16) * sx, 0), love.graphics.getHeight()) - love.graphics.setColor(1, 1, 1, 1) + love.graphics.setColor(1, 1, 1, a) love.graphics.print(tooltiptext, 2 + margin/2, 2 + margin/2) love.graphics.setScissor() From fd30c294b09ef92216a508b2b296390b8aae3d60 Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 14:24:00 +0300 Subject: [PATCH 07/11] dont do button animation if dropdown is open --- button.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/button.lua b/button.lua index 1de64e4..b721dc0 100644 --- a/button.lua +++ b/button.lua @@ -41,7 +41,7 @@ function self.update(dt) local mx, my = love.mouse.getPosition() local targetsize = 1 - if mx > v.x and mx < v.x + v.size and my > v.y and my < v.y + v.size then + if mx > v.x and mx < v.x + v.size and my > v.y and my < v.y + v.size and dropdown.openDropdown == 0 then if love.mouse.isDown(1) then targetsize = 0.8 else From 7aeb9afb89f1a2d01316b294a7a639f1c76b01d5 Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 14:25:23 +0300 Subject: [PATCH 08/11] change default filter to linear for non-textures --- main.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.lua b/main.lua index d564e73..0a77eda 100644 --- a/main.lua +++ b/main.lua @@ -60,6 +60,9 @@ function love.draw() local sw, sh = love.graphics.getDimensions() local mx, my = love.mouse.getPosition() + -- this is fine to do since all textures are already loaded with nearest + love.graphics.setDefaultFilter('linear', 'linear') + love.graphics.setLineWidth(2) love.graphics.setColor(0.09, 0.09, 0.12, 1) From 0266e2c2e9b267cb5f1c84a1182fcb5532147c7a Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 14:37:46 +0300 Subject: [PATCH 09/11] actually implement buttons --- button.lua | 13 ++++++++++++- dropdown.lua | 1 - main.lua | 1 + slider.lua | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/button.lua b/button.lua index b721dc0..5e40c95 100644 --- a/button.lua +++ b/button.lua @@ -30,7 +30,10 @@ function self.createButtons() size = 32, name = 'clipboard', displayname = 'Copy to Clipboard', - tooltip = 'Copy to Clipboard' + tooltip = 'Copy to Clipboard', + func = function() + love.system.setClipboardText('ease function goes here') + end }) buttons = s @@ -78,4 +81,12 @@ function self.render() end end +function self.mousepressed(x, y, m) + for i, v in ipairs(buttons) do + if x > v.x and x < v.x + v.size and y > v.y and y < v.y + v.size and m == 1 then + if v.func then v.func() end + end + end +end + return self \ No newline at end of file diff --git a/dropdown.lua b/dropdown.lua index 9d76d6a..5be76ca 100644 --- a/dropdown.lua +++ b/dropdown.lua @@ -327,7 +327,6 @@ function self.mousepressed(x, y, m) if not clickedDropdown and m == 1 then dropdownScrollCache[self.openDropdown] = dropdownScroll self.openDropdown = 0 - return true end end diff --git a/main.lua b/main.lua index 0a77eda..c540901 100644 --- a/main.lua +++ b/main.lua @@ -88,6 +88,7 @@ end function love.mousepressed(x, y, m) if dropdown.mousepressed(x, y, m) then return end + button.mousepressed(x, y, m) end function love.mousereleased(x, y, m) diff --git a/slider.lua b/slider.lua index 21bb29c..f1fcfd9 100644 --- a/slider.lua +++ b/slider.lua @@ -62,6 +62,7 @@ function self.createSliders() name = 'bpm', displayname = 'BPM', snap = 1, + tooltip = 'The speed of the preview dot in Beats Per Minute' }) end From 15316b918fcaaa9cd97cf017f346a83893a3353e Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 15:04:31 +0300 Subject: [PATCH 10/11] make copy to clipboard button --- button.lua | 80 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 11 deletions(-) diff --git a/button.lua b/button.lua index 5e40c95..74bb8de 100644 --- a/button.lua +++ b/button.lua @@ -24,17 +24,75 @@ function self.createButtons() local s = {} buttonId = 0 - insertButton(s, { - x = outerpadding, - y = love.graphics.getHeight() - outerpadding - fontHeight * 4 - padding * 2 - 32, - size = 32, - name = 'clipboard', - displayname = 'Copy to Clipboard', - tooltip = 'Copy to Clipboard', - func = function() - love.system.setClipboardText('ease function goes here') - end - }) + if mode == modes.mix or mode == modes.preview or mode == modes.multiply then + insertButton(s, { + x = outerpadding, + y = love.graphics.getHeight() - outerpadding - fontHeight * 4 - padding * 2 - 32, + size = 32, + name = 'clipboard', + displayname = 'Copy to Clipboard', + tooltip = 'Copy to Clipboard', + func = function() + local s = '' + + local param1 = {} + local param2 = {} + + if mode == modes.preview then + local e = ease.eases[dropdown.kselected('ease1')] + + param1[1] = slider.kvalue(e.name .. 'param11') or (e.params[1] and e.params[1].default) or 1 + param1[2] = slider.kvalue(e.name .. 'param12') or (e.params[2] and e.params[2].default) or 1 + + local p1 = '' + for i,v in ipairs(param1) do + p1 = p1 .. (i > 1 and (', ' .. v) or v) + end + + s = e.name .. (p1 ~= '' and ('.params(' .. p1 .. ')') or '') + elseif mode == modes.mix then + local e1 = ease.eases[dropdown.kselected('ease1')] + local e2 = ease.eases[dropdown.kselected('ease2')] + + param1[1] = slider.kvalue(e1.name .. 'param11') or (e1.params[1] and e1.params[1].default) or 1 + param1[2] = slider.kvalue(e1.name .. 'param12') or (e1.params[2] and e1.params[2].default) or 1 + param2[1] = slider.kvalue(e2.name .. 'param21') or (e2.params[1] and e2.params[1].default) or 1 + param2[2] = slider.kvalue(e2.name .. 'param22') or (e2.params[2] and e2.params[2].default) or 1 + + local p1 = '' + for i,v in ipairs(param1) do + p1 = p1 .. (i > 1 and (', ' .. v) or v) + end + local p2 = '' + for i,v in ipairs(param2) do + p2 = p2 .. (i > 1 and (', ' .. v) or v) + end + + s = 'mixEase(' .. e1.name .. (p1 ~= '' and ('.params(' .. p1 .. ')') or '') .. ', ' .. e2.name .. (p2 ~= '' and ('.params(' .. p2 .. ')') or '') .. ', ' .. slider.kvalue('mix') .. ')' + elseif mode == modes.multiply then + local e1 = ease.eases[dropdown.kselected('ease1')] + local e2 = ease.eases[dropdown.kselected('ease2')] + + param1[1] = slider.kvalue(_e1.name .. 'param11') or (_e1.params[1] and _e1.params[1].default) or 1 + param1[2] = slider.kvalue(_e1.name .. 'param12') or (_e1.params[2] and _e1.params[2].default) or 1 + param2[1] = slider.kvalue(_e2.name .. 'param21') or (_e2.params[1] and _e2.params[1].default) or 1 + param2[2] = slider.kvalue(_e2.name .. 'param22') or (_e2.params[2] and _e2.params[2].default) or 1 + + local p1 = '' + for i,v in ipairs(param1) do + p1 = p1 .. (i > 1 and (', ' .. v) or v) + end + local p2 = '' + for i,v in ipairs(param2) do + p2 = p2 .. (i > 1 and (', ' .. v) or v) + end + + s = 'function(x) ' .. e2.name .. (p2 ~= '' and ('.params(' .. p2 .. ')') or '') .. '(' .. e1.name .. (p1 ~= '' and ('.params(' .. p1 .. ')') or '') .. '(x)) end' + end + love.system.setClipboardText(s) + end + }) + end buttons = s end From f9cf2769521cac45cfaf91d1f1347259456f2380 Mon Sep 17 00:00:00 2001 From: jill Date: Sun, 19 Sep 2021 15:07:12 +0300 Subject: [PATCH 11/11] add snapping to most sliders this will add a bit of impercision, but will be better for both the user and the internals --- slider.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/slider.lua b/slider.lua index f1fcfd9..94543f9 100644 --- a/slider.lua +++ b/slider.lua @@ -48,6 +48,7 @@ function self.createSliders() default = 0.5, name = 'mix', displayname = 'Mix', + snap = 0.01, tooltip = 'The point at which the first ease snaps into the second one' }) end @@ -82,7 +83,8 @@ function self.createSliders() max = v.max, default = v.default, name = ease1.name .. 'param1' .. i, - displayname = 'Parameter ' .. v.name + displayname = 'Parameter ' .. v.name, + snap = 0.001 }) end end @@ -96,7 +98,8 @@ function self.createSliders() max = v.max, default = v.default, name = ease2.name .. 'param2' .. i, - displayname = 'Parameter ' .. v.name + displayname = 'Parameter ' .. v.name, + snap = 0.001 }) end end