aseprite/src/doc/document.cpp

88 lines
1.3 KiB
C++
Raw Normal View History

2014-03-13 06:25:09 +08:00
// Aseprite Document Library
// Copyright (c) 2014 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
2014-03-13 06:25:09 +08:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doc/document.h"
#include "base/path.h"
#include "doc/context.h"
#include "doc/export_data.h"
#include "doc/sprite.h"
2014-03-13 06:25:09 +08:00
namespace doc {
Document::Document()
: m_ctx(NULL)
, m_sprites(this)
2014-03-13 06:25:09 +08:00
{
}
Document::~Document()
{
removeFromContext();
}
void Document::setContext(Context* ctx)
{
if (ctx == m_ctx)
return;
removeFromContext();
m_ctx = ctx;
if (ctx)
ctx->documents().add(this);
}
int Document::width() const
{
return sprite()->width();
}
int Document::height() const
{
return sprite()->height();
}
ColorMode Document::colorMode() const
{
return (ColorMode)sprite()->pixelFormat();
}
std::string Document::name() const
{
return base::get_file_name(m_filename);
}
2014-03-13 06:25:09 +08:00
void Document::setFilename(const std::string& filename)
{
m_filename = filename;
notifyObservers(&DocumentObserver::onFileNameChanged, this);
2014-03-13 06:25:09 +08:00
}
void Document::setExportData(const ExportDataPtr& data)
{
m_exportData = data;
}
void Document::close()
{
removeFromContext();
}
void Document::removeFromContext()
{
if (m_ctx) {
m_ctx->documents().remove(this);
m_ctx = NULL;
}
}
2014-03-13 06:25:09 +08:00
} // namespace doc