rework mouse buttons, fixes #18

This commit is contained in:
airstruck
2015-12-19 23:54:57 -05:00
parent 0281944066
commit 1ee239b203
14 changed files with 158 additions and 106 deletions

View File

@@ -302,6 +302,18 @@ local isMouseDown = function ()
return sdl.getMouseState(nil, nil) > 0
end
local buttonIds = {
[sdl.BUTTON_LEFT] = 'left',
[sdl.BUTTON_MIDDLE] = 'middle',
[sdl.BUTTON_RIGHT] = 'right',
-- [sdl.BUTTON_X1] = 'x1',
-- [sdl.BUTTON_X2] = 'x2',
}
local function getMouseButtonId (value)
return value and buttonIds[value] or value
end
function Backend.show (layout)
local input = layout.input
@@ -312,10 +324,10 @@ function Backend.show (layout)
return input:handleReshape(layout, width, height)
end)
hook(layout, 'mousepressed', function (x, y, button)
return input:handlePressStart(layout, button, x, y)
return input:handlePressStart(layout, getMouseButtonId(button), x, y)
end)
hook(layout, 'mousereleased', function (x, y, button)
return input:handlePressEnd(layout, button, x, y)
return input:handlePressEnd(layout, getMouseButtonId(button), x, y)
end)
hook(layout, 'mousemoved', function (x, y, dx, dy)
if isMouseDown() then

View File

@@ -90,16 +90,22 @@ local getMouseButtonId, isMouseDown
if love._version_minor < 10 then
getMouseButtonId = function (value)
return value == 'l' and 1
or value == 'r' and 2
or value == 'm' and 3
return value == 'l' and 'left'
or value == 'r' and 'right'
or value == 'm' and 'middle'
or value == 'x1' and 4
or value == 'x2' and 5
or value
end
isMouseDown = function ()
return love.mouse.isDown('l', 'r', 'm')
end
else
getMouseButtonId = function (value)
return value
return value == 1 and 'left'
or value == 2 and 'right'
or value == 3 and 'middle'
or value
end
isMouseDown = function ()
return love.mouse.isDown(1, 2, 3)

View File

@@ -12,7 +12,7 @@ local function renderSingle (self, x, y, font, text, color)
love.graphics.push('all')
love.graphics.setColor(color or { 0, 0, 0 })
love.graphics.setFont(font.loveFont)
love.graphics.print(text, x, y)
love.graphics.print(text, math.floor(x), math.floor(y))
love.graphics.pop()
self.height = font:getLineHeight()
@@ -34,11 +34,14 @@ local function renderMulti (self, x, y, font, text, color, align, limit)
local w = line.width
if align == 'left' then
love.graphics.print(text, x, top + y)
love.graphics.print(text,
math.floor(x), math.floor(top + y))
elseif align == 'right' then
love.graphics.print(text, limit - w + x, top + y)
love.graphics.print(text,
math.floor(limit - w + x), math.floor(top + y))
elseif align == 'center' then
love.graphics.print(text, (limit - w) / 2 + x, top + y)
love.graphics.print(text,
math.floor((limit - w) / 2 + x), math.floor(top + y))
end
end