mobile + port everything to use getSafeArea when possible
This commit is contained in:
parent
ee2b499017
commit
60fedd28d7
6 changed files with 64 additions and 14 deletions
56
main.lua
56
main.lua
|
@ -18,6 +18,28 @@ function getFont(size, italic)
|
||||||
return fontCache[size][italic]
|
return fontCache[size][italic]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function getMousePosition()
|
||||||
|
local x, y = love.mouse.getPosition()
|
||||||
|
|
||||||
|
local sx, sy, sw, sh = 0, 0, love.graphics.getWidth(), love.graphics.getHeight()
|
||||||
|
if love.isVersionCompatible('11.3') then sx, sy, sw, sh = love.window.getSafeArea() end
|
||||||
|
sx, sy, sw, sh = 100, 100, love.graphics.getWidth() - 200, love.graphics.getHeight() - 200
|
||||||
|
|
||||||
|
x, y = ((x - sx) / sw) * love.graphics.getWidth(), ((y - sy) / sh) * love.graphics.getHeight()
|
||||||
|
|
||||||
|
return x, y
|
||||||
|
end
|
||||||
|
|
||||||
|
function getMouseX()
|
||||||
|
local x, y = getMousePosition()
|
||||||
|
return x
|
||||||
|
end
|
||||||
|
|
||||||
|
function getMouseY()
|
||||||
|
local x, y = getMousePosition()
|
||||||
|
return y
|
||||||
|
end
|
||||||
|
|
||||||
ease = require 'src.ease'
|
ease = require 'src.ease'
|
||||||
|
|
||||||
slider = require 'src.slider'
|
slider = require 'src.slider'
|
||||||
|
@ -54,6 +76,8 @@ screenshot = false
|
||||||
screenshotCanvas = nil
|
screenshotCanvas = nil
|
||||||
screenshotsize = 512
|
screenshotsize = 512
|
||||||
|
|
||||||
|
mobile = love.system.getOS() == 'iOS' or love.system.getOS() == 'Android'
|
||||||
|
|
||||||
-- global for convinience's sake
|
-- global for convinience's sake
|
||||||
|
|
||||||
mode = nil
|
mode = nil
|
||||||
|
@ -62,6 +86,10 @@ function love.load()
|
||||||
love.graphics.setFont(interfaceFont)
|
love.graphics.setFont(interfaceFont)
|
||||||
fontHeight = love.graphics.getFont():getHeight()
|
fontHeight = love.graphics.getFont():getHeight()
|
||||||
createUI()
|
createUI()
|
||||||
|
|
||||||
|
if mobile then
|
||||||
|
love.window.setMode(640, 360, {borderless = true, resizable = false, minwidth = 705, minheight = 510, fullscreen = true})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
|
@ -73,7 +101,9 @@ function love.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
local sw, sh = love.graphics.getDimensions()
|
local sx, sy, sw, sh = 0, 0, love.graphics.getWidth(), love.graphics.getHeight()
|
||||||
|
if love.isVersionCompatible('11.3') then sx, sy, sw, sh = love.window.getSafeArea() end
|
||||||
|
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = love.mouse.getPosition()
|
||||||
|
|
||||||
if screenshot then
|
if screenshot then
|
||||||
|
@ -109,9 +139,15 @@ function love.draw()
|
||||||
love.graphics.setLineWidth(2)
|
love.graphics.setLineWidth(2)
|
||||||
|
|
||||||
love.graphics.setColor(0.09, 0.09, 0.12, 1)
|
love.graphics.setColor(0.09, 0.09, 0.12, 1)
|
||||||
love.graphics.rectangle('fill', 0, 0, sw, sh)
|
love.graphics.rectangle('fill', 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||||
love.graphics.setColor(0.08, 0.08, 0.1, 1)
|
love.graphics.setColor(0.08, 0.08, 0.1, 1)
|
||||||
love.graphics.rectangle('line', 0, 0, sw, sh)
|
love.graphics.rectangle('line', 0, 0, love.graphics.getWidth(), love.graphics.getHeight())
|
||||||
|
|
||||||
|
love.graphics.push()
|
||||||
|
love.graphics.translate(sx, sy)
|
||||||
|
love.graphics.scale(sw/love.graphics.getWidth(), sh/love.graphics.getHeight())
|
||||||
|
|
||||||
|
sw, sh = love.graphics.getDimensions()
|
||||||
|
|
||||||
love.graphics.setColor(0.2, 0.2, 0.3, 1)
|
love.graphics.setColor(0.2, 0.2, 0.3, 1)
|
||||||
love.graphics.print('Box of Eases by oatmealine', outerpadding, sh - fontHeight - outerpadding)
|
love.graphics.print('Box of Eases by oatmealine', outerpadding, sh - fontHeight - outerpadding)
|
||||||
|
@ -127,14 +163,26 @@ function love.draw()
|
||||||
graph.render()
|
graph.render()
|
||||||
|
|
||||||
tooltips.render()
|
tooltips.render()
|
||||||
|
|
||||||
|
love.graphics.pop()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.mousepressed(x, y, m)
|
function love.mousepressed(x, y, m)
|
||||||
|
local sx, sy, sw, sh = 0, 0, love.graphics.getWidth(), love.graphics.getHeight()
|
||||||
|
if love.isVersionCompatible('11.3') then sx, sy, sw, sh = love.window.getSafeArea() end
|
||||||
|
|
||||||
|
x, y = ((x - sx) / sw) * love.graphics.getWidth(), ((y - sy) / sh) * love.graphics.getHeight()
|
||||||
|
|
||||||
if dropdown.mousepressed(x, y, m) then return end
|
if dropdown.mousepressed(x, y, m) then return end
|
||||||
button.mousepressed(x, y, m)
|
button.mousepressed(x, y, m)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.mousereleased(x, y, m)
|
function love.mousereleased(x, y, m)
|
||||||
|
local sx, sy, sw, sh = 0, 0, love.graphics.getWidth(), love.graphics.getHeight()
|
||||||
|
if love.isVersionCompatible('11.3') then sx, sy, sw, sh = love.window.getSafeArea() end
|
||||||
|
|
||||||
|
x, y = ((x - sx) / sw) * love.graphics.getWidth(), ((y - sy) / sh) * love.graphics.getHeight()
|
||||||
|
|
||||||
if dropdown.mousereleased(x, y, m) then return end
|
if dropdown.mousereleased(x, y, m) then return end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -154,6 +202,8 @@ function love.keypressed(key)
|
||||||
print(k, v)
|
print(k, v)
|
||||||
::continue::
|
::continue::
|
||||||
end
|
end
|
||||||
|
elseif key == 'f2' then -- mobile mode
|
||||||
|
mobile = not mobile
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,7 @@ end
|
||||||
|
|
||||||
function self.update(dt)
|
function self.update(dt)
|
||||||
for i, v in ipairs(buttons) do
|
for i, v in ipairs(buttons) do
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = getMousePosition()
|
||||||
|
|
||||||
local targetsize = 1
|
local targetsize = 1
|
||||||
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 mx > v.x and mx < v.x + v.size and my > v.y and my < v.y + v.size and dropdown.openDropdown == 0 then
|
||||||
|
@ -173,7 +173,7 @@ function self.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function self.render()
|
function self.render()
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = getMousePosition()
|
||||||
|
|
||||||
for i, v in ipairs(buttons) do
|
for i, v in ipairs(buttons) do
|
||||||
local x, y, w, h = v.x, v.y, v.size, v.size
|
local x, y, w, h = v.x, v.y, v.size, v.size
|
||||||
|
|
|
@ -215,7 +215,7 @@ function self.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
if love.mouse.isDown(1) then
|
if love.mouse.isDown(1) then
|
||||||
local x, y = love.mouse.getPosition()
|
local x, y = getMousePosition()
|
||||||
for i,v in ipairs(dropdowns) do
|
for i,v in ipairs(dropdowns) do
|
||||||
local h = fontHeight + margin
|
local h = fontHeight + margin
|
||||||
if self.openDropdown == i then
|
if self.openDropdown == i then
|
||||||
|
@ -228,12 +228,12 @@ function self.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function self.render()
|
function self.render()
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = getMousePosition()
|
||||||
for i,v in ipairs(dropdowns) do
|
for i,v in ipairs(dropdowns) do
|
||||||
local x, y, w, h = v.x, v.y, v.width, fontHeight + margin
|
local x, y, w, h = v.x, v.y, v.width, fontHeight + margin
|
||||||
|
|
||||||
love.graphics.setColor(0.06, 0.06, 0.12, 0.6)
|
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
|
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)
|
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
|
if v.tooltip then tooltips.show(v.tooltip) end
|
||||||
end
|
end
|
||||||
|
@ -367,7 +367,7 @@ function self.wheelmoved(x, y)
|
||||||
if self.openDropdown ~= 0 then
|
if self.openDropdown ~= 0 then
|
||||||
dropdownScroll = dropdownScroll + y
|
dropdownScroll = dropdownScroll + y
|
||||||
else
|
else
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = getMousePosition()
|
||||||
for i,v in ipairs(dropdowns) do
|
for i,v in ipairs(dropdowns) do
|
||||||
local h = fontHeight + margin
|
local h = fontHeight + margin
|
||||||
if mx > v.x and mx < v.x + v.width and my > v.y and my < v.y + h + margin then
|
if mx > v.x and mx < v.x + v.width and my > v.y and my < v.y + h + margin then
|
||||||
|
|
|
@ -37,7 +37,7 @@ function self.update(dt)
|
||||||
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)
|
||||||
local x, y, w, h = sw - outerpadding - size, outerpadding, size, size
|
local x, y, w, h = sw - outerpadding - size, outerpadding, size, size
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = getMousePosition()
|
||||||
|
|
||||||
if not (love.mouse.isDown(1) and mx > x and mx < x + w and my > y and my < y + h) then
|
if not (love.mouse.isDown(1) and mx > x and mx < x + w and my > y and my < y + h) then
|
||||||
timer = (timer + dt * ((slider.kvalue('bpm') or 120)/120)) % 2
|
timer = (timer + dt * ((slider.kvalue('bpm') or 120)/120)) % 2
|
||||||
|
@ -153,7 +153,7 @@ function self.render()
|
||||||
end
|
end
|
||||||
|
|
||||||
function self.wheelmoved(wx, wy)
|
function self.wheelmoved(wx, wy)
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = getMousePosition()
|
||||||
|
|
||||||
-- may need to abstract this out, somehow
|
-- may need to abstract this out, somehow
|
||||||
-- todo
|
-- todo
|
||||||
|
|
|
@ -126,7 +126,7 @@ function self.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function self.render()
|
function self.render()
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = getMousePosition()
|
||||||
|
|
||||||
for i, v in ipairs(sliders) do
|
for i, v in ipairs(sliders) do
|
||||||
local x, y, w, h = v.x, v.y, v.width, fontHeight * 1.25
|
local x, y, w, h = v.x, v.y, v.width, fontHeight * 1.25
|
||||||
|
|
|
@ -11,7 +11,7 @@ local tooltiptargetwidth = 0
|
||||||
local tooltipframe = false
|
local tooltipframe = false
|
||||||
|
|
||||||
function self.update(dt)
|
function self.update(dt)
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = getMousePosition()
|
||||||
tooltipx = mix(tooltipx, mx, dt * 18)
|
tooltipx = mix(tooltipx, mx, dt * 18)
|
||||||
tooltipy = mix(tooltipy, my, dt * 18)
|
tooltipy = mix(tooltipy, my, dt * 18)
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ local function softlimit(x, f)
|
||||||
end
|
end
|
||||||
|
|
||||||
function self.render()
|
function self.render()
|
||||||
local mx, my = love.mouse.getPosition()
|
local mx, my = getMousePosition()
|
||||||
if not tooltipframe then
|
if not tooltipframe then
|
||||||
tooltiptargetwidth = 0
|
tooltiptargetwidth = 0
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue