Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions playdate/graphics.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function module.setPattern(pattern)
end
end
end

playbit.graphics.shader:send("pattern", unpack(pixels))
end

Expand Down Expand Up @@ -151,6 +151,10 @@ function module.setLineWidth(width)
love.graphics.setLineWidth(width)
end

function module.getLineWidth()
return love.graphics.getLineWidth()
end

function module.drawRect(x, y, width, height)
playbit.graphics.shader:send("mode", 8)

Expand Down Expand Up @@ -201,21 +205,28 @@ function module.drawLine(x1, y1, x2, y2)
end

function module.drawArc(x, y, radius, startAngle, endAngle)

local function normalizeAngle(deg)
return (deg % 360 + 360) % 360
end

playbit.graphics.shader:send("mode", 8)

-- Bring angles to interval [0, 360)
startAngle = normalizeAngle(startAngle)
endAngle = normalizeAngle(endAngle)

-- PD always draws from startAngle to endAngle clockwise.
if startAngle >= endAngle then
endAngle = endAngle + 360
end

-- 0 degrees is 270 when drawing an arc on PD...
startAngle = startAngle - 90
endAngle = endAngle - 90

if startAngle == endAngle then
-- if startAngle and endAngle are the same, PD draws a full circle
love.graphics.arc("line", "open", x, y, radius, math.rad(startAngle), math.rad(endAngle + 360), 16)
elseif startAngle > endAngle then
-- love2d adjusts for when the startAngle is larger, but PD does not, so we need to compensate
love.graphics.arc("line", "open", x, y, radius, math.rad(startAngle), math.rad(endAngle + 360), 16)
else
love.graphics.arc("line", "open", x, y, radius, math.rad(endAngle), math.rad(startAngle), 16)
end
love.graphics.arc("line", "open", x, y, radius, math.rad(startAngle), math.rad(endAngle), 32)

playbit.graphics.updateContext()

module.setImageDrawMode(playbit.graphics.drawMode)
Expand Down Expand Up @@ -247,7 +258,7 @@ function module.getTextSize(str, fontFamily, leadingAdjustment)
return font:getWidth(str), font:getHeight()
end

-- playdate.graphics.drawTextInRect(str, x, y, width, height, [leadingAdjustment, [truncationString, [alignment, [font]]]])
-- playdate.graphics.drawTextInRect(str, x, y, width, height, [leadingAdjustment, [truncationString, [alignment, [font]]]])
function module.drawTextInRect(text, x, ...)
local y, width, height, leadingAdjustment, truncationString, textAlignment, font
if type(x) == "number" then
Expand Down Expand Up @@ -317,7 +328,7 @@ function module.pushContext(image)
if not image._canvas then
image._canvas = love.graphics.newCanvas(image:getSize())
end

-- push context
table.insert(playbit.graphics.contextStack, image)

Expand Down