mirror of https://github.com/aseprite/aseprite.git
Add columns and rows parameters
This commit is contained in:
parent
9ca6368088
commit
a0e8f8653c
|
@ -44,18 +44,41 @@ namespace app {
|
||||||
|
|
||||||
using namespace ui;
|
using namespace ui;
|
||||||
|
|
||||||
|
gfx::Size calcFrameSize(gfx::Size availSize,
|
||||||
|
int cols, int rows,
|
||||||
|
const gfx::Point& frameOrigin,
|
||||||
|
const gfx::Size& padding)
|
||||||
|
{
|
||||||
|
if (cols <= 0)
|
||||||
|
cols = 1;
|
||||||
|
if (rows <= 0)
|
||||||
|
rows = 1;
|
||||||
|
|
||||||
|
availSize.w -= (frameOrigin.x + padding.w*(cols-1));
|
||||||
|
availSize.h -= (frameOrigin.y + padding.h*(rows-1));
|
||||||
|
|
||||||
|
return gfx::Size(availSize.w / cols, availSize.h / rows);
|
||||||
|
}
|
||||||
|
|
||||||
struct ImportSpriteSheetParams : public NewParams {
|
struct ImportSpriteSheetParams : public NewParams {
|
||||||
Param<bool> ui { this, true, "ui" };
|
Param<bool> ui { this, true, "ui" };
|
||||||
Param<app::SpriteSheetType> type { this, app::SpriteSheetType::None, "type" };
|
Param<app::SpriteSheetType> type { this, app::SpriteSheetType::None, "type" };
|
||||||
Param<gfx::Rect> frameBounds { this, gfx::Rect(0, 0, 0, 0), "frameBounds" };
|
Param<gfx::Rect> frameBounds { this, gfx::Rect(0, 0, 0, 0), "frameBounds" };
|
||||||
Param<gfx::Size> padding { this, gfx::Size(0, 0), "padding" };
|
Param<gfx::Size> padding { this, gfx::Size(0, 0), "padding" };
|
||||||
Param<bool> partialTiles { this, false, "partialTiles" };
|
Param<bool> partialTiles { this, false, "partialTiles" };
|
||||||
|
// Columns and rows are optional, and they just help in calculating
|
||||||
|
// frameBounds automatically when the number of columns and rows are known
|
||||||
|
// beforehand. So, if these are specified along frameBounds, then frameBounds
|
||||||
|
// width/height might be recalculated.
|
||||||
|
Param<int> columns { this, 0, "columns" };
|
||||||
|
Param<int> rows { this, 0, "rows" };
|
||||||
};
|
};
|
||||||
|
|
||||||
class ImportSpriteSheetWindow : public app::gen::ImportSpriteSheet
|
class ImportSpriteSheetWindow : public app::gen::ImportSpriteSheet
|
||||||
, public SelectBoxDelegate {
|
, public SelectBoxDelegate {
|
||||||
public:
|
public:
|
||||||
ImportSpriteSheetWindow(Context* context)
|
ImportSpriteSheetWindow(const ImportSpriteSheetParams& params,
|
||||||
|
Context* context)
|
||||||
: m_context(context)
|
: m_context(context)
|
||||||
, m_document(NULL)
|
, m_document(NULL)
|
||||||
, m_editor(NULL)
|
, m_editor(NULL)
|
||||||
|
@ -81,8 +104,8 @@ public:
|
||||||
y()->Change.connect([this]{ onEntriesChange(); });
|
y()->Change.connect([this]{ onEntriesChange(); });
|
||||||
width()->Change.connect([this]{ onEntriesChange(); });
|
width()->Change.connect([this]{ onEntriesChange(); });
|
||||||
height()->Change.connect([this]{ onEntriesChange(); });
|
height()->Change.connect([this]{ onEntriesChange(); });
|
||||||
columns()->Change.connect([this]{ onColumnsOrRowsChange(); });
|
columns()->Change.connect([this]{ onColumnsChange(); });
|
||||||
rows()->Change.connect([this]{ onColumnsOrRowsChange(); });
|
rows()->Change.connect([this]{ onRowsChange(); });
|
||||||
paddingEnabled()->Click.connect([this]{ onPaddingEnabledChange(); });
|
paddingEnabled()->Click.connect([this]{ onPaddingEnabledChange(); });
|
||||||
horizontalPadding()->Change.connect([this]{ onEntriesChange(); });
|
horizontalPadding()->Change.connect([this]{ onEntriesChange(); });
|
||||||
verticalPadding()->Change.connect([this]{ onEntriesChange(); });
|
verticalPadding()->Change.connect([this]{ onEntriesChange(); });
|
||||||
|
@ -98,7 +121,40 @@ public:
|
||||||
m_fileOpened = false;
|
m_fileOpened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.type.isSet())
|
||||||
|
sheetType()->setSelectedItemIndex((int)params.type()-1);
|
||||||
|
|
||||||
|
if (params.frameBounds.isSet()) {
|
||||||
|
x()->setTextf("%d", params.frameBounds().x);
|
||||||
|
y()->setTextf("%d", params.frameBounds().y);
|
||||||
|
width()->setTextf("%d", params.frameBounds().w);
|
||||||
|
height()->setTextf("%d", params.frameBounds().h);
|
||||||
|
}
|
||||||
|
|
||||||
|
paddingEnabled()->setSelected(params.padding.isSet());
|
||||||
|
if (params.padding.isSet()) {
|
||||||
|
if (m_docPref)
|
||||||
|
m_docPref->importSpriteSheet.paddingBounds(params.padding());
|
||||||
|
else {
|
||||||
|
horizontalPadding()->setTextf("%d", params.padding().w);
|
||||||
|
verticalPadding()->setTextf("%d", params.padding().h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.partialTiles.isSet())
|
||||||
|
partialTiles()->setSelected(params.partialTiles());
|
||||||
|
|
||||||
onPaddingEnabledChange();
|
onPaddingEnabledChange();
|
||||||
|
|
||||||
|
if (params.columns.isSet()) {
|
||||||
|
columns()->setTextf("%d", params.columns());
|
||||||
|
onColumnsChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.rows.isSet()) {
|
||||||
|
rows()->setTextf("%d", params.rows());
|
||||||
|
onRowsChange();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~ImportSpriteSheetWindow() {
|
~ImportSpriteSheetWindow() {
|
||||||
|
@ -213,32 +269,26 @@ protected:
|
||||||
rows()->setTextf("%d", calcRows());
|
rows()->setTextf("%d", calcRows());
|
||||||
}
|
}
|
||||||
|
|
||||||
void onColumnsOrRowsChange() {
|
#define ON_COLROWS_CHANGE(widtheigth, wh) \
|
||||||
if (!m_editor)
|
if (!m_editor) \
|
||||||
return;
|
return; \
|
||||||
|
auto frameSize = calcFrameSize(m_editor->sprite()->size(), \
|
||||||
// When columns or rows are changed, the width and height might change
|
columns()->textInt(), rows()->textInt(), \
|
||||||
// because we try to use all the available space. Padding and rect origin
|
getRectFromEntries().origin(), \
|
||||||
// are kept unchanged.
|
getPaddingFromEntries()); \
|
||||||
int cols = this->columns()->textInt();
|
widtheigth()->setTextf("%d", frameSize.wh); \
|
||||||
int rows = this->rows()->textInt();
|
|
||||||
if (cols <= 0)
|
|
||||||
cols = 1;
|
|
||||||
if (rows <= 0)
|
|
||||||
rows = 1;
|
|
||||||
|
|
||||||
auto availSize = m_editor->sprite()->size();
|
|
||||||
auto entriesRect = getRectFromEntries();
|
|
||||||
auto entriesPadding = getPaddingFromEntries();
|
|
||||||
|
|
||||||
availSize.w -= (entriesRect.x + entriesPadding.w*(cols-1));
|
|
||||||
availSize.h -= (entriesRect.y + entriesPadding.h*(rows-1));
|
|
||||||
width()->setTextf("%d", availSize.w / cols);
|
|
||||||
height()->setTextf("%d", availSize.h / rows);
|
|
||||||
|
|
||||||
updateRulers();
|
updateRulers();
|
||||||
|
|
||||||
|
void onColumnsChange() {
|
||||||
|
ON_COLROWS_CHANGE(width, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onRowsChange() {
|
||||||
|
ON_COLROWS_CHANGE(height, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef ON_COLROWS_CHANGE
|
||||||
|
|
||||||
bool onProcessMessage(ui::Message* msg) override {
|
bool onProcessMessage(ui::Message* msg) override {
|
||||||
switch (msg->type()) {
|
switch (msg->type()) {
|
||||||
case kCloseMessage:
|
case kCloseMessage:
|
||||||
|
@ -480,9 +530,7 @@ void ImportSpriteSheetCommand::onExecute(Context* context)
|
||||||
auto& params = this->params();
|
auto& params = this->params();
|
||||||
|
|
||||||
if (context->isUIAvailable() && params.ui()) {
|
if (context->isUIAvailable() && params.ui()) {
|
||||||
// TODO use params as input values for the ImportSpriteSheetWindow
|
ImportSpriteSheetWindow window(params, context);
|
||||||
|
|
||||||
ImportSpriteSheetWindow window(context);
|
|
||||||
window.openWindowInForeground();
|
window.openWindowInForeground();
|
||||||
if (!window.ok())
|
if (!window.ok())
|
||||||
return;
|
return;
|
||||||
|
@ -506,6 +554,21 @@ void ImportSpriteSheetCommand::onExecute(Context* context)
|
||||||
document = context->activeDocument();
|
document = context->activeDocument();
|
||||||
if (!document)
|
if (!document)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Sprite* sprite = document->sprite();
|
||||||
|
|
||||||
|
auto newFrameBounds = calcFrameSize(sprite->size(), params.columns(), params.rows(), params.frameBounds().origin(), params.padding());
|
||||||
|
if (params.columns.isSet()) {
|
||||||
|
auto fb = params.frameBounds();
|
||||||
|
fb.w = newFrameBounds.w;
|
||||||
|
params.frameBounds(fb);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.rows.isSet()) {
|
||||||
|
auto fb = params.frameBounds();
|
||||||
|
fb.h = newFrameBounds.h;
|
||||||
|
params.frameBounds(fb);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// The list of frames imported from the sheet
|
// The list of frames imported from the sheet
|
||||||
|
|
Loading…
Reference in New Issue