forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.cpp
More file actions
96 lines (75 loc) · 1.5 KB
/
document.cpp
File metadata and controls
96 lines (75 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Aseprite Document Library
// Copyright (c) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doc/document.h"
#include "base/fs.h"
#include "doc/context.h"
#include "doc/sprite.h"
namespace doc {
Document::Document()
: Object(ObjectType::Document)
, m_sprites(this)
, m_ctx(NULL)
{
}
Document::~Document()
{
removeFromContext();
}
void Document::setContext(Context* ctx)
{
if (ctx == m_ctx)
return;
removeFromContext();
m_ctx = ctx;
if (ctx)
ctx->documents().add(this);
onContextChanged();
}
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);
}
void Document::setFilename(const std::string& filename)
{
// Normalize the path (if the filename has a path)
if (!base::get_file_path(filename).empty())
m_filename = base::normalize_path(filename);
else
m_filename = filename;
notify_observers(&DocumentObserver::onFileNameChanged, this);
}
void Document::close()
{
removeFromContext();
}
void Document::onContextChanged()
{
// Do nothing
}
void Document::removeFromContext()
{
if (m_ctx) {
m_ctx->documents().remove(this);
m_ctx = NULL;
onContextChanged();
}
}
} // namespace doc