[aseprite] 41/134: Add --sheet-width and --sheet-height command line options to specify the texture size
Tobias Hansen
thansen at moszumanska.debian.org
Sat Mar 14 17:10:01 UTC 2015
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository aseprite.
commit 1ce2e53cfb6a2af1d4b294a66a4d2c1159db70b1
Author: David Capello <davidcapello at gmail.com>
Date: Fri Nov 7 01:05:08 2014 -0300
Add --sheet-width and --sheet-height command line options to specify the texture size
---
src/app/app.cpp | 10 ++++++++++
src/app/app_options.cpp | 2 ++
src/app/app_options.h | 4 ++++
src/app/document_exporter.cpp | 40 ++++++++++++++++++++++++++++++++--------
src/app/document_exporter.h | 17 +++++++++++------
5 files changed, 59 insertions(+), 14 deletions(-)
diff --git a/src/app/app.cpp b/src/app/app.cpp
index bfc9a8f..63e6866 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -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;
diff --git a/src/app/app_options.cpp b/src/app/app_options.cpp
index 4f47f71..7507a98 100644
--- a/src/app/app_options.cpp
+++ b/src/app/app_options.cpp
@@ -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)"))
diff --git a/src/app/app_options.h b/src/app/app_options.h
index dc7523a..fbb35f8 100644
--- a/src/app/app_options.h
+++ b/src/app/app_options.h
@@ -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;
diff --git a/src/app/document_exporter.cpp b/src/app/document_exporter.cpp
index 0034748..631e02a 100644
--- a/src/app/document_exporter.cpp
+++ b/src/app/document_exporter.cpp
@@ -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
diff --git a/src/app/document_exporter.h b/src/app/document_exporter.h
index df7e097..c9c2c26 100644
--- a/src/app/document_exporter.h
+++ b/src/app/document_exporter.h
@@ -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;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git
More information about the Pkg-games-commits
mailing list