mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-14 12:40:55 +00:00
[lua] Test Image:flip() with sprite and without sprite (#3854)
This commit is contained in:
parent
ccc57800a8
commit
637d71a276
@ -26,6 +26,7 @@
|
|||||||
#include "app/util/autocrop.h"
|
#include "app/util/autocrop.h"
|
||||||
#include "app/util/resize_image.h"
|
#include "app/util/resize_image.h"
|
||||||
#include "base/fs.h"
|
#include "base/fs.h"
|
||||||
|
#include "doc/algorithm/flip_image.h"
|
||||||
#include "doc/algorithm/flip_type.h"
|
#include "doc/algorithm/flip_type.h"
|
||||||
#include "doc/algorithm/shrink_bounds.h"
|
#include "doc/algorithm/shrink_bounds.h"
|
||||||
#include "doc/cel.h"
|
#include "doc/cel.h"
|
||||||
@ -585,12 +586,17 @@ int Image_flip(lua_State* L)
|
|||||||
auto obj = get_obj<ImageObj>(L, 1);
|
auto obj = get_obj<ImageObj>(L, 1);
|
||||||
doc::Image* img = obj->image(L);
|
doc::Image* img = obj->image(L);
|
||||||
doc::algorithm::FlipType flipType = doc::algorithm::FlipType::FlipHorizontal;
|
doc::algorithm::FlipType flipType = doc::algorithm::FlipType::FlipHorizontal;
|
||||||
if (lua_isinteger(L, 2) && lua_tointeger(L, 2) > 0)
|
if (lua_isinteger(L, 2))
|
||||||
flipType = doc::algorithm::FlipType::FlipVertical;
|
flipType = (doc::algorithm::FlipType)lua_tointeger(L, 2);
|
||||||
|
|
||||||
|
if (obj->cel(L) == nullptr) {
|
||||||
|
doc::algorithm::flip_image(img, img->bounds(), flipType);
|
||||||
|
}
|
||||||
|
else {
|
||||||
Tx tx;
|
Tx tx;
|
||||||
tx(new cmd::FlipImage(img, img->bounds(), flipType));
|
tx(new cmd::FlipImage(img, img->bounds(), flipType));
|
||||||
tx.commit();
|
tx.commit();
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,8 +405,7 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Tests for Image:flip()
|
-- Tests for Image:flip()
|
||||||
do
|
function test_image_flip(img)
|
||||||
local img = Image(3, 3)
|
|
||||||
local r = Color(255, 0, 0).rgbaPixel
|
local r = Color(255, 0, 0).rgbaPixel
|
||||||
local g = Color(0, 255, 0).rgbaPixel
|
local g = Color(0, 255, 0).rgbaPixel
|
||||||
img:clear(0)
|
img:clear(0)
|
||||||
@ -420,6 +419,10 @@ do
|
|||||||
expect_img(img, { 0, 0, g,
|
expect_img(img, { 0, 0, g,
|
||||||
0, r, 0,
|
0, r, 0,
|
||||||
r, 0, 0 })
|
r, 0, 0 })
|
||||||
|
|
||||||
|
-- Without sprite, don't test undo
|
||||||
|
if not app.sprite then return end
|
||||||
|
|
||||||
app.undo()
|
app.undo()
|
||||||
expect_img(img, { g, 0, 0,
|
expect_img(img, { g, 0, 0,
|
||||||
0, r, 0,
|
0, r, 0,
|
||||||
@ -443,3 +446,8 @@ do
|
|||||||
0, r, 0,
|
0, r, 0,
|
||||||
0, 0, r })
|
0, 0, r })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local spr = Sprite(3, 3) -- Test with sprite (with transactions & undo/redo)
|
||||||
|
test_image_flip(app.image)
|
||||||
|
app.sprite = nil -- Test without sprite (without transactions)
|
||||||
|
test_image_flip(Image(3, 3))
|
||||||
|
Loading…
Reference in New Issue
Block a user