mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-16 23:42:57 +00:00
Add --sheet-width and --sheet-height command line options to specify the texture size
This commit is contained in:
parent
ce962f4999
commit
1ce2e53cfb
@ -231,6 +231,16 @@ void App::initialize(int argc, const char* argv[])
|
||||
if (m_exporter)
|
||||
m_exporter->setTextureFilename(value.value());
|
||||
}
|
||||
// --sheet-width <width>
|
||||
else if (opt == &options.sheetWidth()) {
|
||||
if (m_exporter)
|
||||
m_exporter->setTextureWidth(strtol(value.value().c_str(), NULL, 0));
|
||||
}
|
||||
// --sheet-height <height>
|
||||
else if (opt == &options.sheetHeight()) {
|
||||
if (m_exporter)
|
||||
m_exporter->setTextureHeight(strtol(value.value().c_str(), NULL, 0));
|
||||
}
|
||||
// --split-layers
|
||||
else if (opt == &options.splitLayers()) {
|
||||
splitLayers = true;
|
||||
|
@ -43,6 +43,8 @@ AppOptions::AppOptions(int argc, const char* argv[])
|
||||
, m_scale(m_po.add("scale").requiresValue("<factor>").description("Scale all opened documents at the moment"))
|
||||
, m_data(m_po.add("data").requiresValue("<filename.json>").description("File to store the sprite sheet metadata"))
|
||||
, m_sheet(m_po.add("sheet").requiresValue("<filename.png>").description("Image file to save the texture"))
|
||||
, m_sheetWidth(m_po.add("sheet-width").requiresValue("<pixels>").description("Sprite sheet width"))
|
||||
, m_sheetHeight(m_po.add("sheet-height").requiresValue("<pixels>").description("Sprite sheet height"))
|
||||
, m_splitLayers(m_po.add("split-layers").description("Import each layer of the next given sprite as\n a separated image in the sheet"))
|
||||
, m_importLayer(m_po.add("import-layer").requiresValue("<name>").description("Import just one layer of the next given sprite"))
|
||||
, m_verbose(m_po.add("verbose").description("Explain what is being done (in stderr or log file)"))
|
||||
|
@ -51,6 +51,8 @@ public:
|
||||
const Option& scale() const { return m_scale; }
|
||||
const Option& data() const { return m_data; }
|
||||
const Option& sheet() const { return m_sheet; }
|
||||
const Option& sheetWidth() const { return m_sheetWidth; }
|
||||
const Option& sheetHeight() const { return m_sheetHeight; }
|
||||
const Option& splitLayers() const { return m_splitLayers; }
|
||||
const Option& importLayer() const { return m_importLayer; }
|
||||
|
||||
@ -74,6 +76,8 @@ private:
|
||||
Option& m_scale;
|
||||
Option& m_data;
|
||||
Option& m_sheet;
|
||||
Option& m_sheetWidth;
|
||||
Option& m_sheetHeight;
|
||||
Option& m_splitLayers;
|
||||
Option& m_importLayer;
|
||||
|
||||
|
@ -113,13 +113,13 @@ private:
|
||||
class DocumentExporter::LayoutSamples {
|
||||
public:
|
||||
virtual ~LayoutSamples() { }
|
||||
virtual void layoutSamples(Samples& samples) = 0;
|
||||
virtual void layoutSamples(Samples& samples, int width, int height) = 0;
|
||||
};
|
||||
|
||||
class DocumentExporter::SimpleLayoutSamples :
|
||||
public DocumentExporter::LayoutSamples {
|
||||
public:
|
||||
void layoutSamples(Samples& samples) override {
|
||||
void layoutSamples(Samples& samples, int width, int height) override {
|
||||
const Sprite* oldSprite = NULL;
|
||||
const Layer* oldLayer = NULL;
|
||||
|
||||
@ -129,10 +129,24 @@ public:
|
||||
const Layer* layer = sample.layer();
|
||||
gfx::Size size(sprite->width(), sprite->height());
|
||||
|
||||
// New sprite or layer, go to next row.
|
||||
if (oldSprite && (oldSprite != sprite || oldLayer != layer)) {
|
||||
framePt.x = 0;
|
||||
framePt.y += size.h;
|
||||
if (oldSprite) {
|
||||
// If the user didn't specified a width for the texture, we put
|
||||
// each sprite/layer in a different row.
|
||||
if (width == 0) {
|
||||
// New sprite or layer, go to next row.
|
||||
if (oldSprite != sprite || oldLayer != layer) {
|
||||
framePt.x = 0;
|
||||
framePt.y += oldSprite->height(); // We're skipping the previous sprite height
|
||||
}
|
||||
}
|
||||
// When a texture width is specified, we can put different
|
||||
// sprites/layers in each row until we reach the texture
|
||||
// right-border.
|
||||
else if (framePt.x+size.w > width) {
|
||||
framePt.x = 0;
|
||||
framePt.y += oldSprite->height();
|
||||
// TODO framePt.y+size.h > height ?
|
||||
}
|
||||
}
|
||||
|
||||
sample.setOriginalSize(size);
|
||||
@ -148,6 +162,16 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
DocumentExporter::DocumentExporter()
|
||||
: m_dataFormat(DefaultDataFormat)
|
||||
, m_textureFormat(DefaultTextureFormat)
|
||||
, m_textureWidth(0)
|
||||
, m_textureHeight(0)
|
||||
, m_scaleMode(DefaultScaleMode)
|
||||
, m_scale(1.0)
|
||||
{
|
||||
}
|
||||
|
||||
void DocumentExporter::exportSheet()
|
||||
{
|
||||
// We output the metadata to std::cout if the user didn't specify a file.
|
||||
@ -173,7 +197,7 @@ void DocumentExporter::exportSheet()
|
||||
|
||||
// 2) Layout those samples in a texture field.
|
||||
SimpleLayoutSamples layout;
|
||||
layout.layoutSamples(samples);
|
||||
layout.layoutSamples(samples, m_textureWidth, m_textureHeight);
|
||||
|
||||
// 3) Create and render the texture.
|
||||
base::UniquePtr<Document> textureDocument(
|
||||
@ -236,7 +260,7 @@ Document* DocumentExporter::createEmptyTexture(const Samples& samples)
|
||||
{
|
||||
Palette* palette = NULL;
|
||||
PixelFormat pixelFormat = IMAGE_INDEXED;
|
||||
gfx::Rect fullTextureBounds;
|
||||
gfx::Rect fullTextureBounds(0, 0, m_textureWidth, m_textureHeight);
|
||||
int maxColors = 256;
|
||||
|
||||
for (Samples::const_iterator
|
||||
|
@ -51,12 +51,7 @@ namespace app {
|
||||
DefaultScaleMode
|
||||
};
|
||||
|
||||
DocumentExporter() :
|
||||
m_dataFormat(DefaultDataFormat),
|
||||
m_textureFormat(DefaultTextureFormat),
|
||||
m_scaleMode(DefaultScaleMode),
|
||||
m_scale(1.0) {
|
||||
}
|
||||
DocumentExporter();
|
||||
|
||||
void setDataFormat(DataFormat format) {
|
||||
m_dataFormat = format;
|
||||
@ -74,6 +69,14 @@ namespace app {
|
||||
m_textureFilename = filename;
|
||||
}
|
||||
|
||||
void setTextureWidth(int width) {
|
||||
m_textureWidth = width;
|
||||
}
|
||||
|
||||
void setTextureHeight(int height) {
|
||||
m_textureHeight = height;
|
||||
}
|
||||
|
||||
void setScale(double scale) {
|
||||
m_scale = scale;
|
||||
}
|
||||
@ -113,6 +116,8 @@ namespace app {
|
||||
std::string m_dataFilename;
|
||||
TextureFormat m_textureFormat;
|
||||
std::string m_textureFilename;
|
||||
int m_textureWidth;
|
||||
int m_textureHeight;
|
||||
double m_scale;
|
||||
ScaleMode m_scaleMode;
|
||||
Items m_documents;
|
||||
|
Loading…
x
Reference in New Issue
Block a user