mobile + port everything to use getSafeArea when possible

This commit is contained in:
jill 2021-09-19 23:39:05 +03:00
parent ee2b499017
commit 60fedd28d7
6 changed files with 64 additions and 14 deletions

View file

@ -18,6 +18,28 @@ function getFont(size, italic)
return fontCache[size][italic]
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'
slider = require 'src.slider'
@ -54,6 +76,8 @@ screenshot = false
screenshotCanvas = nil
screenshotsize = 512
mobile = love.system.getOS() == 'iOS' or love.system.getOS() == 'Android'
-- global for convinience's sake
mode = nil
@ -62,6 +86,10 @@ function love.load()
love.graphics.setFont(interfaceFont)
fontHeight = love.graphics.getFont():getHeight()
createUI()
if mobile then
love.window.setMode(640, 360, {borderless = true, resizable = false, minwidth = 705, minheight = 510, fullscreen = true})
end
end
function love.update(dt)
@ -73,7 +101,9 @@ function love.update(dt)
end
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()
if screenshot then
@ -109,9 +139,15 @@ function love.draw()
love.graphics.setLineWidth(2)
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.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.print('Box of Eases by oatmealine', outerpadding, sh - fontHeight - outerpadding)
@ -127,14 +163,26 @@ function love.draw()
graph.render()
tooltips.render()
love.graphics.pop()
end
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
button.mousepressed(x, y, m)
end
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
end
@ -154,6 +202,8 @@ function love.keypressed(key)
print(k, v)
::continue::
end
elseif key == 'f2' then -- mobile mode
mobile = not mobile
end
end

View file

@ -157,7 +157,7 @@ end
function self.update(dt)
for i, v in ipairs(buttons) do
local mx, my = love.mouse.getPosition()
local mx, my = getMousePosition()
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
@ -173,7 +173,7 @@ function self.update(dt)
end
function self.render()
local mx, my = love.mouse.getPosition()
local mx, my = getMousePosition()
for i, v in ipairs(buttons) do
local x, y, w, h = v.x, v.y, v.size, v.size

View file

@ -215,7 +215,7 @@ function self.update(dt)
end
if love.mouse.isDown(1) then
local x, y = love.mouse.getPosition()
local x, y = getMousePosition()
for i,v in ipairs(dropdowns) do
local h = fontHeight + margin
if self.openDropdown == i then
@ -228,12 +228,12 @@ function self.update(dt)
end
function self.render()
local mx, my = love.mouse.getPosition()
local mx, my = getMousePosition()
for i,v in ipairs(dropdowns) do
local x, y, w, h = v.x, v.y, v.width, fontHeight + margin
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)
if v.tooltip then tooltips.show(v.tooltip) end
end
@ -367,7 +367,7 @@ function self.wheelmoved(x, y)
if self.openDropdown ~= 0 then
dropdownScroll = dropdownScroll + y
else
local mx, my = love.mouse.getPosition()
local mx, my = getMousePosition()
for i,v in ipairs(dropdowns) do
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

View file

@ -37,7 +37,7 @@ function self.update(dt)
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 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
timer = (timer + dt * ((slider.kvalue('bpm') or 120)/120)) % 2
@ -153,7 +153,7 @@ function self.render()
end
function self.wheelmoved(wx, wy)
local mx, my = love.mouse.getPosition()
local mx, my = getMousePosition()
-- may need to abstract this out, somehow
-- todo

View file

@ -126,7 +126,7 @@ function self.update(dt)
end
function self.render()
local mx, my = love.mouse.getPosition()
local mx, my = getMousePosition()
for i, v in ipairs(sliders) do
local x, y, w, h = v.x, v.y, v.width, fontHeight * 1.25

View file

@ -11,7 +11,7 @@ local tooltiptargetwidth = 0
local tooltipframe = false
function self.update(dt)
local mx, my = love.mouse.getPosition()
local mx, my = getMousePosition()
tooltipx = mix(tooltipx, mx, dt * 18)
tooltipy = mix(tooltipy, my, dt * 18)
@ -36,7 +36,7 @@ local function softlimit(x, f)
end
function self.render()
local mx, my = love.mouse.getPosition()
local mx, my = getMousePosition()
if not tooltipframe then
tooltiptargetwidth = 0
end