1
0
mirror of https://github.com/aseprite/aseprite.git synced 2025-04-02 13:20:12 +00:00
David Capello 139c5aac49 Add flag to compile CLI-only (fix )
New cmake flag -DENABLE_UI=OFF can be used to turn off the GUI
and compile a CLI-only version of Aseprite.

Requested here too:
https://community.aseprite.org/t/1351
2018-05-07 00:11:50 -03:00

109 lines
2.0 KiB
C++

// Aseprite
// Copyright (C) 2016-2018 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/script/sprite_wrap.h"
#include "app/app.h"
#include "app/cmd/set_sprite_size.h"
#include "app/context.h"
#include "app/document.h"
#include "app/document_api.h"
#include "app/script/image_wrap.h"
#include "app/transaction.h"
#include "app/ui/document_view.h"
#include "doc/site.h"
#include "doc/sprite.h"
namespace app {
SpriteWrap::SpriteWrap(app::Document* doc)
: m_doc(doc)
, m_view(App::instance()->context()->getFirstDocumentView(m_doc))
, m_transaction(nullptr)
{
}
SpriteWrap::~SpriteWrap()
{
for (auto it : m_images)
delete it.second;
if (m_transaction)
delete m_transaction;
}
Transaction& SpriteWrap::transaction()
{
if (!m_transaction) {
m_transaction = new Transaction(App::instance()->context(),
"Script Execution",
ModifyDocument);
}
return *m_transaction;
}
void SpriteWrap::commit()
{
commitImages();
if (m_transaction) {
m_transaction->commit();
delete m_transaction;
m_transaction = nullptr;
}
}
void SpriteWrap::commitImages()
{
for (auto it : m_images)
it.second->commit();
}
app::Document* SpriteWrap::document()
{
return m_doc;
}
doc::Sprite* SpriteWrap::sprite()
{
return m_doc->sprite();
}
ImageWrap* SpriteWrap::activeImage()
{
if (!m_view) {
m_view = App::instance()->context()->getFirstDocumentView(m_doc);
if (!m_view)
return nullptr;
}
#ifdef ENABLE_UI
doc::Site site;
m_view->getSite(&site);
return wrapImage(site.image());
#else
return nullptr;
#endif
}
ImageWrap* SpriteWrap::wrapImage(doc::Image* img)
{
auto it = m_images.find(img->id());
if (it != m_images.end())
return it->second;
else {
auto wrap = new ImageWrap(this, img);
m_images[img->id()] = wrap;
return wrap;
}
}
} // namespace app