From 2b3372df0e45c25986f1c7ce6c31150fd9b58eaa Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Tue, 4 Apr 2023 09:54:38 -0300 Subject: [PATCH] Fix backward compatibility with Image:drawImage(image, x, y) was broken (fix #3788) --- src/app/script/image_class.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/app/script/image_class.cpp b/src/app/script/image_class.cpp index b2d716a38..0872ddca2 100644 --- a/src/app/script/image_class.cpp +++ b/src/app/script/image_class.cpp @@ -251,14 +251,23 @@ int Image_drawImage(lua_State* L) auto sprite = get_obj(L, 2); gfx::Point pos = convert_args_into_point(L, 3); + // Arguments index fix to support the following cases: + // - Image:drawImage(image, x, y, opacity, blendMode) + // - Image:drawImage(image, Point(x, y), opacity, blendMode) + // - Image:drawImage(image, {x, y}, opacity, blendMode) + // - Image:drawImage(image, {x=x1, y=y1}, opacity, blendMode) + int argsFix = 0; + if (lua_isinteger(L, 3)) + argsFix = 1; + int opacity = 255; - if (lua_isinteger(L, 4)) - opacity = std::clamp(int(lua_tointeger(L, 4)), 0, 255); + if (lua_isinteger(L, 4 + argsFix)) + opacity = std::clamp(int(lua_tointeger(L, 4 + argsFix)), 0, 255); doc::BlendMode blendMode = doc::BlendMode::NORMAL; - if (lua_isinteger(L, 5)) { + if (lua_isinteger(L, 5 + argsFix)) { blendMode = base::convert_to( - app::script::BlendMode(lua_tointeger(L, 5))); + app::script::BlendMode(lua_tointeger(L, 5 + argsFix))); } Image* dst = obj->image(L);