Experimental mouse support

This commit is contained in:
SoniEx2 2019-02-12 21:25:06 -02:00
parent 1d8014b6cb
commit 3fcdf3a76d
1 changed files with 40 additions and 3 deletions

View File

@ -118,6 +118,43 @@ function setback(pos, highlight)
end
end
local in_mouse = false
function love.mousepressed(x, y, button, istouch, presses)
if button == 1 then
if visual_start then
for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do
setback(i, false)
end
visual_start = false
else
setback(cp, false)
end
local x, y = math.floor(x / 36), math.floor(y / 36)
if x > 15 or y > 15 then return end
cp = y * 16 + x + 1
setback(cp, true)
backimage:replacePixels(backimagedata)
in_mouse = true
end
end
function love.mousereleased(x, y, button, istouch, presses)
in_mouse = false
end
function love.mousemoved(x, y, dx, dy, istouch)
if in_mouse then
if visual_start then
local x, y = math.floor(x / 36), math.floor(y / 36)
if x > 15 or y > 15 then return end
cp = y * 16 + x + 1
else
visual_start = cp
end
end
end
function love.update(dt)
local function ktup(key, func)
if kt[key] then
@ -284,14 +321,14 @@ function love.update(dt)
image:replacePixels(imagedata)
end
local function visual()
visual_start = not visual_start and cp
if not visual_start then
for i=1,255 do
if visual_start then
for i=math.min(visual_start or cp, cp), math.max(visual_start or cp, cp) do
setback(i, false)
end
setback(cp, true)
backimage:replacePixels(backimagedata)
end
visual_start = not visual_start and cp
end
ktup('k', imgup)
ktup('up', imgup)