pixel alignment for lines

This commit is contained in:
airstruck
2015-10-24 16:05:49 -04:00
parent 571d84f55e
commit 8f604fb79d
3 changed files with 13 additions and 15 deletions

View File

@@ -32,7 +32,7 @@ function Renderer:renderOutline (widget, window)
love.graphics.push('all')
love.graphics.setColor(widget.outline)
love.graphics.rectangle('line', x1, y1, x2 - x1, y2 - y1)
love.graphics.rectangle('line', x1 - 0.5, y1 - 0.5, x2 - x1, y2 - y1)
love.graphics.pop()
end

View File

@@ -214,7 +214,7 @@ function Widget:getRectangle (useMargin, usePadding)
if usePadding then
shrink(self.padding or 0)
end
return x1, y1, x2, y2
return math.floor(x1), math.floor(y1), math.floor(x2), math.floor(y2)
end
function Widget:isAt (x, y)

View File

@@ -22,6 +22,12 @@ function Slider:constructor(layout, data)
local x1, y1, x2, y2 = self:getRectangle(true, true)
local padding = self.padding or 0
local sx1 = math.floor(x1 + position * (x2 - x1) - padding) - 0.5
local sy1 = math.floor(y1 + padding) - 0.5
local sx2 = padding * 2
local sy2 = y2 - y1 - padding
love.graphics.push('all')
love.graphics.setColor(self.outline)
@@ -33,21 +39,13 @@ function Slider:constructor(layout, data)
padding
)
love.graphics.rectangle('line',
x1 + position * (x2 - x1) - padding,
y1 + padding,
padding * 2,
y2 - y1 - padding
)
love.graphics.setColor(self.background)
love.graphics.rectangle('fill',
x1 + position * (x2 - x1) - padding,
y1 + padding,
padding * 2,
y2 - y1 - padding
)
love.graphics.rectangle('fill', sx1, sy1, sx2, sy2)
love.graphics.setColor(self.outline)
love.graphics.rectangle('line', sx1, sy1, sx2, sy2)
love.graphics.pop()