mirror of
https://github.com/aseprite/aseprite.git
synced 2024-10-05 06:20:10 +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)
|
if (m_exporter)
|
||||||
m_exporter->setTextureFilename(value.value());
|
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
|
// --split-layers
|
||||||
else if (opt == &options.splitLayers()) {
|
else if (opt == &options.splitLayers()) {
|
||||||
splitLayers = true;
|
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_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_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_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_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_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)"))
|
, 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& scale() const { return m_scale; }
|
||||||
const Option& data() const { return m_data; }
|
const Option& data() const { return m_data; }
|
||||||
const Option& sheet() const { return m_sheet; }
|
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& splitLayers() const { return m_splitLayers; }
|
||||||
const Option& importLayer() const { return m_importLayer; }
|
const Option& importLayer() const { return m_importLayer; }
|
||||||
|
|
||||||
@ -74,6 +76,8 @@ private:
|
|||||||
Option& m_scale;
|
Option& m_scale;
|
||||||
Option& m_data;
|
Option& m_data;
|
||||||
Option& m_sheet;
|
Option& m_sheet;
|
||||||
|
Option& m_sheetWidth;
|
||||||
|
Option& m_sheetHeight;
|
||||||
Option& m_splitLayers;
|
Option& m_splitLayers;
|
||||||
Option& m_importLayer;
|
Option& m_importLayer;
|
||||||
|
|
||||||
|
@ -113,13 +113,13 @@ private:
|
|||||||
class DocumentExporter::LayoutSamples {
|
class DocumentExporter::LayoutSamples {
|
||||||
public:
|
public:
|
||||||
virtual ~LayoutSamples() { }
|
virtual ~LayoutSamples() { }
|
||||||
virtual void layoutSamples(Samples& samples) = 0;
|
virtual void layoutSamples(Samples& samples, int width, int height) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DocumentExporter::SimpleLayoutSamples :
|
class DocumentExporter::SimpleLayoutSamples :
|
||||||
public DocumentExporter::LayoutSamples {
|
public DocumentExporter::LayoutSamples {
|
||||||
public:
|
public:
|
||||||
void layoutSamples(Samples& samples) override {
|
void layoutSamples(Samples& samples, int width, int height) override {
|
||||||
const Sprite* oldSprite = NULL;
|
const Sprite* oldSprite = NULL;
|
||||||
const Layer* oldLayer = NULL;
|
const Layer* oldLayer = NULL;
|
||||||
|
|
||||||
@ -129,10 +129,24 @@ public:
|
|||||||
const Layer* layer = sample.layer();
|
const Layer* layer = sample.layer();
|
||||||
gfx::Size size(sprite->width(), sprite->height());
|
gfx::Size size(sprite->width(), sprite->height());
|
||||||
|
|
||||||
|
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.
|
// New sprite or layer, go to next row.
|
||||||
if (oldSprite && (oldSprite != sprite || oldLayer != layer)) {
|
if (oldSprite != sprite || oldLayer != layer) {
|
||||||
framePt.x = 0;
|
framePt.x = 0;
|
||||||
framePt.y += size.h;
|
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);
|
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()
|
void DocumentExporter::exportSheet()
|
||||||
{
|
{
|
||||||
// We output the metadata to std::cout if the user didn't specify a file.
|
// 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.
|
// 2) Layout those samples in a texture field.
|
||||||
SimpleLayoutSamples layout;
|
SimpleLayoutSamples layout;
|
||||||
layout.layoutSamples(samples);
|
layout.layoutSamples(samples, m_textureWidth, m_textureHeight);
|
||||||
|
|
||||||
// 3) Create and render the texture.
|
// 3) Create and render the texture.
|
||||||
base::UniquePtr<Document> textureDocument(
|
base::UniquePtr<Document> textureDocument(
|
||||||
@ -236,7 +260,7 @@ Document* DocumentExporter::createEmptyTexture(const Samples& samples)
|
|||||||
{
|
{
|
||||||
Palette* palette = NULL;
|
Palette* palette = NULL;
|
||||||
PixelFormat pixelFormat = IMAGE_INDEXED;
|
PixelFormat pixelFormat = IMAGE_INDEXED;
|
||||||
gfx::Rect fullTextureBounds;
|
gfx::Rect fullTextureBounds(0, 0, m_textureWidth, m_textureHeight);
|
||||||
int maxColors = 256;
|
int maxColors = 256;
|
||||||
|
|
||||||
for (Samples::const_iterator
|
for (Samples::const_iterator
|
||||||
|
@ -51,12 +51,7 @@ namespace app {
|
|||||||
DefaultScaleMode
|
DefaultScaleMode
|
||||||
};
|
};
|
||||||
|
|
||||||
DocumentExporter() :
|
DocumentExporter();
|
||||||
m_dataFormat(DefaultDataFormat),
|
|
||||||
m_textureFormat(DefaultTextureFormat),
|
|
||||||
m_scaleMode(DefaultScaleMode),
|
|
||||||
m_scale(1.0) {
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDataFormat(DataFormat format) {
|
void setDataFormat(DataFormat format) {
|
||||||
m_dataFormat = format;
|
m_dataFormat = format;
|
||||||
@ -74,6 +69,14 @@ namespace app {
|
|||||||
m_textureFilename = filename;
|
m_textureFilename = filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setTextureWidth(int width) {
|
||||||
|
m_textureWidth = width;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTextureHeight(int height) {
|
||||||
|
m_textureHeight = height;
|
||||||
|
}
|
||||||
|
|
||||||
void setScale(double scale) {
|
void setScale(double scale) {
|
||||||
m_scale = scale;
|
m_scale = scale;
|
||||||
}
|
}
|
||||||
@ -113,6 +116,8 @@ namespace app {
|
|||||||
std::string m_dataFilename;
|
std::string m_dataFilename;
|
||||||
TextureFormat m_textureFormat;
|
TextureFormat m_textureFormat;
|
||||||
std::string m_textureFilename;
|
std::string m_textureFilename;
|
||||||
|
int m_textureWidth;
|
||||||
|
int m_textureHeight;
|
||||||
double m_scale;
|
double m_scale;
|
||||||
ScaleMode m_scaleMode;
|
ScaleMode m_scaleMode;
|
||||||
Items m_documents;
|
Items m_documents;
|
||||||
|
Loading…
Reference in New Issue
Block a user