Skip to content

Commit

Permalink
feat: improve std.draw.image
Browse files Browse the repository at this point in the history
  • Loading branch information
RodrigoDornelles committed Nov 7, 2024
1 parent e142b2d commit 9c797de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 5 additions & 3 deletions ee/engine/core/ginga/draw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ local function line(std, engine, canvas, x1, y1, x2, y2)
canvas:drawLine(px1, py1, px2, py2)
end

local function image(std, engine, canvas, src, x, y)
local function image(std, engine, canvas, src, pos_x, pos_y)
local image = std.mem.cache('image'..src, function()
return canvas:new('../assets/'..src)
return canvas:new(src)
end)
if image then
canvas:compose(engine.offset_x + x, engine.offset_y + y, image)
local x = engine.offset_x + (pos_x or 0)
local y = engine.offset_y + (pos_y or 0)
canvas:compose(x, y, image)
end
end

Expand Down
4 changes: 3 additions & 1 deletion src/engine/core/love/draw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,13 @@ local function font(std, engine, name, size)
love.graphics.setFont(f)
end

local function image(std, engine, src, x, y)
local function image(std, engine, src, pos_x, pos_y)
local r, g, b, a = love.graphics.getColor()
local image = std.mem.cache('image'..src, function()
return love.graphics.newImage(src)
end)
local x = engine.offset_x + (pos_x or 0)
local y = engine.offset_y + (pos_y or 0)
love.graphics.setColor(0xFF, 0xFF, 0xFF, 0xFF)
love.graphics.draw(image, x, y)
love.graphics.setColor(r, g, b, a)
Expand Down
5 changes: 3 additions & 2 deletions src/engine/core/native/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ end

--! @short std.draw.image
local function image(src, pos_x, pos_y)
local ox, oy = engine.offset_x, engine.offset_y
native_draw_image(src, pos_x + ox, pos_y + oy)
local x = engine.offset_x + (pos_x or 0)
local y = engine.offset_y + (pos_y or 0)
native_draw_image(src, x, y)
end

--! @}
Expand Down

0 comments on commit 9c797de

Please sign in to comment.