mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-11 09:40:42 +00:00
Add option to export resizing w/pixel aspect ratio
This commit is contained in:
parent
a39627fe28
commit
d19c033284
@ -310,6 +310,7 @@
|
||||
<option id="resize_scale" type="double" default="1" />
|
||||
<option id="layer" type="std::string" />
|
||||
<option id="frame_tag" type="std::string" />
|
||||
<option id="apply_pixel_ratio" type="bool" default="false" />
|
||||
</section>
|
||||
<section id="sprite_sheet">
|
||||
<option id="defined" type="bool" default="false" />
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
<label id="frames_label" text="Frames:" />
|
||||
<combobox id="frames" text="" cell_align="horizontal" />
|
||||
|
||||
<check id="pixel_ratio" text="Apply pixel ratio" cell_hspan="2" />
|
||||
</grid>
|
||||
</vbox>
|
||||
</gui>
|
||||
|
@ -41,11 +41,13 @@ public:
|
||||
SaveAsCopyDelegate(const Sprite* sprite,
|
||||
const double scale,
|
||||
const std::string& layer,
|
||||
const std::string& frame)
|
||||
const std::string& frame,
|
||||
const bool applyPixelRatio)
|
||||
: m_sprite(sprite),
|
||||
m_resizeScale(scale),
|
||||
m_layer(layer),
|
||||
m_frame(frame) { }
|
||||
m_frame(frame),
|
||||
m_applyPixelRatio(applyPixelRatio) { }
|
||||
|
||||
bool hasResizeCombobox() override {
|
||||
return true;
|
||||
@ -78,11 +80,24 @@ public:
|
||||
m_frame = frame;
|
||||
}
|
||||
|
||||
void setApplyPixelRatio(bool applyPixelRatio) override {
|
||||
m_applyPixelRatio = applyPixelRatio;
|
||||
}
|
||||
|
||||
bool applyPixelRatio() const override {
|
||||
return m_applyPixelRatio;
|
||||
}
|
||||
|
||||
doc::PixelRatio pixelRatio() override {
|
||||
return m_sprite->pixelRatio();
|
||||
}
|
||||
|
||||
private:
|
||||
const Sprite* m_sprite;
|
||||
double m_resizeScale;
|
||||
std::string m_layer;
|
||||
std::string m_frame;
|
||||
bool m_applyPixelRatio;
|
||||
};
|
||||
|
||||
class SaveFileJob : public Job, public IFileOpProgress {
|
||||
@ -167,7 +182,8 @@ bool SaveFileBaseCommand::saveAsDialog(Context* context,
|
||||
// have to mark the file as saved.
|
||||
bool saveCopyAs = (delegate != nullptr);
|
||||
bool markAsSaved = (!saveCopyAs);
|
||||
double scale = 1.0;
|
||||
double xscale = 1.0;
|
||||
double yscale = 1.0;
|
||||
|
||||
if (!m_filename.empty()) {
|
||||
filename = m_filename;
|
||||
@ -187,7 +203,7 @@ bool SaveFileBaseCommand::saveAsDialog(Context* context,
|
||||
filename = newfilename;
|
||||
if (delegate &&
|
||||
delegate->hasResizeCombobox()) {
|
||||
scale = delegate->getResizeScale();
|
||||
xscale = yscale = delegate->getResizeScale();
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,16 +218,24 @@ bool SaveFileBaseCommand::saveAsDialog(Context* context,
|
||||
m_selectedFilename = filename;
|
||||
}
|
||||
|
||||
// Pixel ratio
|
||||
if (delegate &&
|
||||
delegate->applyPixelRatio()) {
|
||||
doc::PixelRatio pr = delegate->pixelRatio();
|
||||
xscale *= pr.w;
|
||||
yscale *= pr.h;
|
||||
}
|
||||
|
||||
// Apply scale
|
||||
bool undoResize = false;
|
||||
if (scale != 1.0) {
|
||||
if (xscale != 1.0 || yscale != 1.0) {
|
||||
Command* resizeCmd = CommandsModule::instance()->getCommandByName(CommandId::SpriteSize);
|
||||
ASSERT(resizeCmd);
|
||||
if (resizeCmd) {
|
||||
int width = document->sprite()->width();
|
||||
int height = document->sprite()->height();
|
||||
int newWidth = int(double(width) * scale);
|
||||
int newHeight = int(double(height) * scale);
|
||||
int newWidth = int(double(width) * xscale);
|
||||
int newHeight = int(double(height) * yscale);
|
||||
if (newWidth < 1) newWidth = 1;
|
||||
if (newHeight < 1) newHeight = 1;
|
||||
if (width != newWidth || height != newHeight) {
|
||||
@ -396,7 +420,8 @@ void SaveFileCopyAsCommand::onExecute(Context* context)
|
||||
document->sprite(),
|
||||
docPref.saveCopy.resizeScale(),
|
||||
docPref.saveCopy.layer(),
|
||||
docPref.saveCopy.frameTag()));
|
||||
docPref.saveCopy.frameTag(),
|
||||
docPref.saveCopy.applyPixelRatio()));
|
||||
}
|
||||
|
||||
// Is a default output filename in the preferences?
|
||||
@ -412,6 +437,7 @@ void SaveFileCopyAsCommand::onExecute(Context* context)
|
||||
docPref.saveCopy.resizeScale(delegate->getResizeScale());
|
||||
docPref.saveCopy.layer(delegate->getLayers());
|
||||
docPref.saveCopy.frameTag(delegate->getFrames());
|
||||
docPref.saveCopy.applyPixelRatio(delegate->applyPixelRatio());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "doc/pixel_ratio.h"
|
||||
|
||||
namespace ui {
|
||||
class ComboBox;
|
||||
}
|
||||
@ -33,6 +35,10 @@ namespace app {
|
||||
virtual std::string getFrames() = 0;
|
||||
virtual void setLayers(const std::string& layers) = 0;
|
||||
virtual void setFrames(const std::string& frames) = 0;
|
||||
|
||||
virtual void setApplyPixelRatio(bool applyPixelRatio) = 0;
|
||||
virtual bool applyPixelRatio() const = 0;
|
||||
virtual doc::PixelRatio pixelRatio() = 0;
|
||||
};
|
||||
|
||||
std::string show_file_selector(
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "app/ui/file_selector.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/string.h"
|
||||
#include "app/app.h"
|
||||
#include "app/console.h"
|
||||
@ -246,13 +247,14 @@ public:
|
||||
addChild(m_extras);
|
||||
m_extras->resize()->setValue(
|
||||
base::convert_to<std::string>(m_delegate->getResizeScale()));
|
||||
|
||||
m_delegate->fillLayersComboBox(m_extras->layers());
|
||||
m_delegate->fillFramesComboBox(m_extras->frames());
|
||||
m_extras->pixelRatio()->setSelected(m_delegate->applyPixelRatio());
|
||||
|
||||
m_extras->resize()->Change.connect(&ExtrasWindow::onUpdateExtras, this);
|
||||
m_extras->layers()->Change.connect(&ExtrasWindow::onUpdateExtras, this);
|
||||
m_extras->frames()->Change.connect(&ExtrasWindow::onUpdateExtras, this);
|
||||
m_extras->pixelRatio()->Click.connect(base::Bind<void>(&ExtrasWindow::onUpdateExtras, this));
|
||||
}
|
||||
|
||||
std::string extrasLabel() const {
|
||||
@ -266,6 +268,15 @@ public:
|
||||
if (frameItem && !frameItem->getValue().empty())
|
||||
label += ", " + frameItem->text();
|
||||
|
||||
if (m_extras->pixelRatio()->isSelected()) {
|
||||
PixelRatio pr = m_delegate->pixelRatio();
|
||||
label += " (";
|
||||
label += base::convert_to<std::string>(pr.w);
|
||||
label += ":";
|
||||
label += base::convert_to<std::string>(pr.h);
|
||||
label += ")";
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
@ -281,6 +292,10 @@ public:
|
||||
return m_extras->frames()->getValue();
|
||||
}
|
||||
|
||||
bool applyPixelRatio() const {
|
||||
return m_extras->pixelRatio()->isSelected();
|
||||
}
|
||||
|
||||
obs::signal<void()> UpdateExtras;
|
||||
|
||||
private:
|
||||
@ -659,6 +674,7 @@ again:
|
||||
m_delegate->setResizeScale(m_extras->resizeValue());
|
||||
m_delegate->setLayers(m_extras->layersValue());
|
||||
m_delegate->setFrames(m_extras->framesValue());
|
||||
m_delegate->setApplyPixelRatio(m_extras->applyPixelRatio());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user