forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument_exporter.h
More file actions
142 lines (120 loc) · 4.15 KB
/
document_exporter.h
File metadata and controls
142 lines (120 loc) · 4.15 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Aseprite
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_DOCUMENT_EXPORTER_H_INCLUDED
#define APP_DOCUMENT_EXPORTER_H_INCLUDED
#pragma once
#include "app/sprite_sheet_type.h"
#include "base/disable_copying.h"
#include "doc/image_buffer.h"
#include "doc/object_id.h"
#include "gfx/fwd.h"
#include <iosfwd>
#include <map>
#include <string>
#include <utility>
#include <vector>
namespace doc {
class FrameTag;
class Image;
class Layer;
}
namespace app {
class Document;
class DocumentExporter {
public:
enum DataFormat {
JsonHashDataFormat,
JsonArrayDataFormat,
DefaultDataFormat = JsonHashDataFormat
};
enum TextureFormat {
JsonTextureFormat,
DefaultTextureFormat = JsonTextureFormat
};
enum ScaleMode {
DefaultScaleMode
};
DocumentExporter();
void setDataFormat(DataFormat format) { m_dataFormat = format; }
void setDataFilename(const std::string& filename) { m_dataFilename = filename; }
void setTextureFormat(TextureFormat format) { m_textureFormat = format; }
void setTextureFilename(const std::string& filename) { m_textureFilename = filename; }
void setTextureWidth(int width) { m_textureWidth = width; }
void setTextureHeight(int height) { m_textureHeight = height; }
void setSpriteSheetType(SpriteSheetType type) { m_sheetType = type; }
void setScale(double scale) { m_scale = scale; }
void setScaleMode(ScaleMode mode) { m_scaleMode = mode; }
void setIgnoreEmptyCels(bool ignore) { m_ignoreEmptyCels = ignore; }
void setBorderPadding(int padding) { m_borderPadding = padding; }
void setShapePadding(int padding) { m_shapePadding = padding; }
void setInnerPadding(int padding) { m_innerPadding = padding; }
void setTrimCels(bool trim) { m_trimCels = trim; }
void setFilenameFormat(const std::string& format) { m_filenameFormat = format; }
void setListFrameTags(bool value) { m_listFrameTags = value; }
void setListLayers(bool value) { m_listLayers = value; }
void addDocument(Document* document,
doc::Layer* layer = nullptr,
doc::FrameTag* tag = nullptr,
bool temporalTag = false) {
m_documents.push_back(Item(document, layer, tag, temporalTag));
}
Document* exportSheet();
private:
class Sample;
class Samples;
class LayoutSamples;
class SimpleLayoutSamples;
class BestFitLayoutSamples;
void captureSamples(Samples& samples);
Document* createEmptyTexture(const Samples& samples);
void renderTexture(const Samples& samples, doc::Image* textureImage);
void createDataFile(const Samples& samples, std::ostream& os, doc::Image* textureImage);
void renderSample(const Sample& sample, doc::Image* dst, int x, int y);
class Item {
public:
Document* doc;
doc::Layer* layer;
doc::FrameTag* frameTag;
bool temporalTag;
Item(Document* doc,
doc::Layer* layer,
doc::FrameTag* frameTag,
bool temporalTag)
: doc(doc), layer(layer), frameTag(frameTag)
, temporalTag(temporalTag) {
}
int frames() const;
int fromFrame() const;
int toFrame() const;
};
typedef std::vector<Item> Items;
DataFormat m_dataFormat;
std::string m_dataFilename;
TextureFormat m_textureFormat;
std::string m_textureFilename;
int m_textureWidth;
int m_textureHeight;
SpriteSheetType m_sheetType;
double m_scale;
ScaleMode m_scaleMode;
bool m_ignoreEmptyCels;
int m_borderPadding;
int m_shapePadding;
int m_innerPadding;
bool m_trimCels;
Items m_documents;
std::string m_filenameFormat;
doc::ImageBufferPtr m_sampleRenderBuf;
bool m_listFrameTags;
bool m_listLayers;
// Displacement for each tag from/to frames in case we export
// them. It's used in case we trim frames outside tags and they
// will not be exported at all in the final result.
std::map<doc::ObjectId, std::pair<int, int> > m_tagDelta;
DISABLE_COPYING(DocumentExporter);
};
} // namespace app
#endif