Add export_sprite_sheet.xml widget

This commit is contained in:
David Capello 2014-08-11 07:27:10 -03:00
parent a767eb187d
commit c936a792ab
2 changed files with 52 additions and 78 deletions

View File

@ -0,0 +1,24 @@
<!-- ASEPRITE -->
<!-- Copyright (C) 2001-2014 by David Capello -->
<gui>
<window id="export_sprite_sheet" text="Export Sprite Sheet">
<grid columns="4">
<label text="Sheet Type:" />
<combobox id="sheet_type" cell_hspan="3" />
<label id="columns_label" text="Columns:" />
<entry id="columns" text="4" maxsize="4" cell_hspan="3" />
<label text="Export Action:" />
<combobox id="export_action" cell_hspan="3" />
<hbox cell_hspan="4">
<boxfiller />
<hbox homogeneous="true">
<button id="export_button" text="&amp;Export" minwidth="60" magnet="true" closewindow="true" />
<button text="&amp;Cancel" minwidth="60" closewindow="true" />
</hbox>
</hbox>
</grid>
</window>
</gui>

View File

@ -47,76 +47,48 @@
#include "raster/stock.h" #include "raster/stock.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "generated_export_sprite_sheet.h"
#include <limits> #include <limits>
namespace app { namespace app {
using namespace ui; using namespace ui;
class ExportSpriteSheetWindow : public Window { class ExportSpriteSheetWindow : public app::gen::ExportSpriteSheet {
public: public:
typedef ExportSpriteSheetCommand::SpriteSheetType SpriteSheetType; typedef ExportSpriteSheetCommand::SpriteSheetType SpriteSheetType;
typedef ExportSpriteSheetCommand::ExportAction ExportAction; typedef ExportSpriteSheetCommand::ExportAction ExportAction;
ExportSpriteSheetWindow(Context* context) ExportSpriteSheetWindow(Context* context)
: Window(WithTitleBar, "Export Sprite Sheet")
, m_grid(4, false)
, m_columnsLabel("Columns:")
, m_columns(4, "4")
, m_exportActionLabel("Export Action:")
, m_export("&Export")
, m_cancel("&Cancel")
, m_ok(false)
{ {
m_sheetType.addItem("Horizontal Strip"); sheetType()->addItem("Horizontal Strip");
m_sheetType.addItem("Vertical Strip"); sheetType()->addItem("Vertical Strip");
m_sheetType.addItem("Matrix"); sheetType()->addItem("Matrix");
m_exportAction.addItem("Save Copy As..."); exportAction()->addItem("Save Copy As...");
m_exportAction.addItem("Save As..."); exportAction()->addItem("Save As...");
m_exportAction.addItem("Save"); exportAction()->addItem("Save");
m_exportAction.addItem("Do Not Save"); exportAction()->addItem("Do Not Save");
addChild(&m_grid);
m_grid.addChildInCell(new Label("Sheet Type:"), 1, 1, 0);
m_grid.addChildInCell(&m_sheetType, 3, 1, 0);
m_grid.addChildInCell(&m_columnsLabel, 1, 1, 0);
m_grid.addChildInCell(&m_columns, 3, 1, 0);
m_grid.addChildInCell(&m_exportActionLabel, 1, 1, 0);
m_grid.addChildInCell(&m_exportAction, 3, 1, 0);
{
Box* hbox1 = new Box(JI_HORIZONTAL);
Box* hbox2 = new Box(JI_HORIZONTAL | JI_HOMOGENEOUS);
hbox1->addChild(new BoxFiller);
hbox1->addChild(hbox2);
hbox2->addChild(&m_export);
hbox2->addChild(&m_cancel);
m_export.setMinSize(gfx::Size(60, 0));
m_grid.addChildInCell(hbox1, 4, 1, 0);
}
m_sheetType.Change.connect(&ExportSpriteSheetWindow::onSheetTypeChange, this);
m_export.Click.connect(Bind<void>(&ExportSpriteSheetWindow::onExport, this));
m_cancel.Click.connect(Bind<void>(&ExportSpriteSheetWindow::onCancel, this));
sheetType()->Change.connect(&ExportSpriteSheetWindow::onSheetTypeChange, this);
onSheetTypeChange(); onSheetTypeChange();
} }
bool ok() const { bool ok() {
return m_ok; return getKiller() == exportButton();
} }
SpriteSheetType spriteSheetType() const { SpriteSheetType spriteSheetTypeValue() {
return (SpriteSheetType)m_sheetType.getSelectedItemIndex(); return (SpriteSheetType)sheetType()->getSelectedItemIndex();
} }
ExportAction exportAction() const { ExportAction exportActionValue() {
return (ExportAction)m_exportAction.getSelectedItemIndex(); return (ExportAction)exportAction()->getSelectedItemIndex();
} }
int columns() const { int columnsValue() {
return m_columns.getTextInt(); return columns()->getTextInt();
} }
protected: protected:
@ -124,13 +96,13 @@ protected:
void onSheetTypeChange() void onSheetTypeChange()
{ {
bool state = false; bool state = false;
switch (m_sheetType.getSelectedItemIndex()) { switch (sheetType()->getSelectedItemIndex()) {
case ExportSpriteSheetCommand::Matrix: case ExportSpriteSheetCommand::Matrix:
state = true; state = true;
break; break;
} }
m_columnsLabel.setVisible(state); columnsLabel()->setVisible(state);
m_columns.setVisible(state); columns()->setVisible(state);
gfx::Size reqSize = getPreferredSize(); gfx::Size reqSize = getPreferredSize();
moveWindow(gfx::Rect(getOrigin(), reqSize)); moveWindow(gfx::Rect(getOrigin(), reqSize));
@ -138,27 +110,6 @@ protected:
invalidate(); invalidate();
} }
void onExport()
{
m_ok = true;
closeWindow(NULL);
}
void onCancel()
{
closeWindow(NULL);
}
private:
Grid m_grid;
ComboBox m_sheetType;
Label m_columnsLabel;
Entry m_columns;
Label m_exportActionLabel;
ComboBox m_exportAction;
Button m_export;
Button m_cancel;
bool m_ok;
}; };
ExportSpriteSheetCommand::ExportSpriteSheetCommand() ExportSpriteSheetCommand::ExportSpriteSheetCommand()
@ -177,15 +128,14 @@ bool ExportSpriteSheetCommand::onEnabled(Context* context)
void ExportSpriteSheetCommand::onExecute(Context* context) void ExportSpriteSheetCommand::onExecute(Context* context)
{ {
if (m_useUI) { if (m_useUI) {
base::UniquePtr<ExportSpriteSheetWindow> window(new ExportSpriteSheetWindow(context)); ExportSpriteSheetWindow window(context);
window->openWindowInForeground(); window.openWindowInForeground();
if (!window.ok())
if (!window->ok())
return; return;
setType(window->spriteSheetType()); setType(window.spriteSheetTypeValue());
setAction(window->exportAction()); setAction(window.exportActionValue());
setColumns(window->columns()); setColumns(window.columnsValue());
} }
Document* document(context->activeDocument()); Document* document(context->activeDocument());