Add SpriteWrap::commitImages() to commit changes to images

This might be useful to use before we execute commands like Sprite.resize
or Sprite.crop, which they need all images in the most updated state.
This commit is contained in:
David Capello 2016-04-16 21:29:57 -03:00
parent 573f68451a
commit 84d8a7a4ec
4 changed files with 20 additions and 4 deletions

View File

@ -39,6 +39,9 @@ void ImageWrap::commit()
m_backup.get(),
m_modifiedRegion, 0, 0,
true));
m_backup.reset(nullptr);
m_modifiedRegion.clear();
}
void ImageWrap::modifyRegion(const gfx::Region& rgn)

View File

@ -58,6 +58,8 @@ script::result_t Sprite_resize(script::ContextHandle handle)
auto wrap = (SpriteWrap*)ctx.getThis();
if (wrap) {
wrap->commitImages();
Document* doc = wrap->document();
DocumentApi api(doc, wrap->transaction());
api.setSpriteSize(doc->sprite(), w, h);
@ -76,6 +78,8 @@ script::result_t Sprite_crop(script::ContextHandle handle)
auto wrap = (SpriteWrap*)ctx.getThis();
if (wrap) {
wrap->commitImages();
Document* doc = wrap->document();
DocumentApi api(doc, wrap->transaction());
api.cropSprite(doc->sprite(), gfx::Rect(x, y, w, h));

View File

@ -51,8 +51,7 @@ Transaction& SpriteWrap::transaction()
void SpriteWrap::commit()
{
for (auto it : m_images)
it.second->commit();
commitImages();
if (m_transaction) {
m_transaction->commit();
@ -61,6 +60,12 @@ void SpriteWrap::commit()
}
}
void SpriteWrap::commitImages()
{
for (auto it : m_images)
it.second->commit();
}
app::Document* SpriteWrap::document()
{
return m_doc;
@ -73,8 +78,11 @@ doc::Sprite* SpriteWrap::sprite()
ImageWrap* SpriteWrap::activeImage()
{
if (!m_view)
return nullptr;
if (!m_view) {
m_view = UIContext::instance()->getFirstDocumentView(m_doc);
if (!m_view)
return nullptr;
}
doc::Site site;
m_view->getSite(&site);

View File

@ -32,6 +32,7 @@ namespace app {
~SpriteWrap();
void commit();
void commitImages();
Transaction& transaction();
app::Document* document();