I can't name library for android GUI, but this is code what I use:
(I tried to comment in English, my bad if you can't understand well.)
Code: Select all
-- love.touchpressed / love.touchmoved / love.touchreleased
-- Those are essential callback function for android touch event handling
-- But those callback functions won't call if you click mouse at PC, so you have to call it manually if you want to call it.
-- Code below will store touch inputs to touches{} table.
-- touches[id] = {x = x coords, y = y coords, time = how much time it got pressed}
-- You can add another informations if you want.
local touches = {}
function love.load()
count = 0
end
function love.draw()
local k, v
for k, v in pairs(touches) do
love.graphics.print(tostring(k) .. ":" .. math.floor(v.x) .. ":" .. math.floor(v.y) .. ":".. math.floor(v.time), v.x, v.y)
end
love.graphics.print(count, 0, 0)
end
function love.touchpressed(id, x, y)
touches[id] = {x = x, y = y, time = 0}
count = count + 1
end
function love.touchmoved(id, x, y)
if touches[id] ~= nil then
touches[id].x = x
touches[id].y = y
end
end
function love.touchreleased(id, x, y)
touches[id] = nil
count = count - 1
end
function love.update(dt)
-- store time to each touch gestures
local k, v
for k, v in pairs(touches) do
v.time = v.time + dt
end
end
----- callback function for mouse - for PC -----
function love.mousepressed(x, y, button, istouch)
if istouch == false then
love.touchpressed("mouse", x, y)
end
end
function love.mousemoved(x, y, dx, dy, istouch)
if istouch == false then
if love.mouse.isDown(1) then
love.touchmoved("mouse", x, y)
end
end
end
function love.mousereleased(x, y, button, istouch)
if istouch == false then
love.touchreleased("mouse", x, y)
end
end
--------------------------------------------------
So if you want to separate between long press and short-tap, you should set threshold and check touch[id].time like:
Code: Select all
function love.touchreleased(id, x, y)
touches[id] = nil
count = count - 1
-- psudocode warning!
if button.clicked(button.x, button.y, button.width, button.height, x, y) == true then
if touches[id].time >= 1 then -- let's assume threshold is 1 sec
-- long-press
print("user long-pressed button")
else
-- short-tap
print("user short-tapped button")
end
end
end
Not sure if it will solve your problem, but I hope it helped.