mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 13:21:34 +00:00
Add option to include partial tiles in Import Sprite Sheet (fix #1161)
This commit is contained in:
parent
ee1dac0893
commit
67ce9473f8
@ -290,6 +290,7 @@
|
||||
<section id="import_sprite_sheet">
|
||||
<option id="type" type="app::SpriteSheetType" default="app::SpriteSheetType::Rows" />
|
||||
<option id="bounds" type="gfx::Rect" default="gfx::Rect(0, 0, 16, 16)" />
|
||||
<option id="partial_tiles" type="bool" default="false" />
|
||||
</section>
|
||||
<section id="preview" text="Preview">
|
||||
<option id="zoom" type="double" default="1.0" />
|
||||
|
@ -1,5 +1,5 @@
|
||||
<!-- ASEPRITE -->
|
||||
<!-- Copyright (C) 2001-2015 by David Capello -->
|
||||
<!-- Copyright (C) 2001-2016 by David Capello -->
|
||||
<gui>
|
||||
<window id="import_sprite_sheet" text="Import Sprite Sheet">
|
||||
<grid columns="4">
|
||||
@ -18,6 +18,8 @@
|
||||
<label text="Height" />
|
||||
<entry id="height" text="16" maxsize="4" />
|
||||
|
||||
<check id="partial_tiles" text="Include partial tiles at bottom/right edges" cell_hspan="4" />
|
||||
|
||||
<hbox cell_hspan="4">
|
||||
<boxfiller />
|
||||
<hbox>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 David Capello
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@ -92,6 +92,10 @@ public:
|
||||
return (app::SpriteSheetType)(sheetType()->getSelectedItemIndex()+1);
|
||||
}
|
||||
|
||||
bool partialTilesValue() const {
|
||||
return partialTiles()->isSelected();
|
||||
}
|
||||
|
||||
bool ok() const {
|
||||
return closer() == import();
|
||||
}
|
||||
@ -214,6 +218,7 @@ private:
|
||||
sheetType()->setSelectedItemIndex((int)app::SpriteSheetType::Rows-1);
|
||||
|
||||
onChangeRectangle(m_docPref->importSpriteSheet.bounds());
|
||||
partialTiles()->setSelected(m_docPref->importSpriteSheet.partialTiles());
|
||||
onEntriesChange();
|
||||
}
|
||||
}
|
||||
@ -305,6 +310,7 @@ void ImportSpriteSheetCommand::onExecute(Context* context)
|
||||
Document* document = window.document();
|
||||
DocumentPreferences* docPref = window.docPref();
|
||||
gfx::Rect frameBounds = window.frameBounds();
|
||||
bool partialTiles = window.partialTilesValue();
|
||||
auto sheetType = window.sheetTypeValue();
|
||||
|
||||
ASSERT(document);
|
||||
@ -321,21 +327,27 @@ void ImportSpriteSheetCommand::onExecute(Context* context)
|
||||
|
||||
// Each sprite in the sheet
|
||||
std::vector<gfx::Rect> tileRects;
|
||||
int widthStop = sprite->width();
|
||||
int heightStop = sprite->height();
|
||||
if (partialTiles) {
|
||||
widthStop += frameBounds.w-1;
|
||||
heightStop += frameBounds.h-1;
|
||||
}
|
||||
|
||||
switch (sheetType) {
|
||||
case app::SpriteSheetType::Horizontal:
|
||||
for (int x=frameBounds.x; x+frameBounds.w<=sprite->width(); x += frameBounds.w) {
|
||||
for (int x=frameBounds.x; x+frameBounds.w<=widthStop; x += frameBounds.w) {
|
||||
tileRects.push_back(gfx::Rect(x, frameBounds.y, frameBounds.w, frameBounds.h));
|
||||
}
|
||||
break;
|
||||
case app::SpriteSheetType::Vertical:
|
||||
for (int y=frameBounds.y; y+frameBounds.h<=sprite->height(); y += frameBounds.h) {
|
||||
for (int y=frameBounds.y; y+frameBounds.h<=heightStop; y += frameBounds.h) {
|
||||
tileRects.push_back(gfx::Rect(frameBounds.x, y, frameBounds.w, frameBounds.h));
|
||||
}
|
||||
break;
|
||||
case app::SpriteSheetType::Rows:
|
||||
for (int y=frameBounds.y; y+frameBounds.h<=sprite->height(); y += frameBounds.h) {
|
||||
for (int x=frameBounds.x; x+frameBounds.w<=sprite->width(); x += frameBounds.w) {
|
||||
for (int y=frameBounds.y; y+frameBounds.h<=heightStop; y += frameBounds.h) {
|
||||
for (int x=frameBounds.x; x+frameBounds.w<=widthStop; x += frameBounds.w) {
|
||||
tileRects.push_back(gfx::Rect(x, y, frameBounds.w, frameBounds.h));
|
||||
}
|
||||
}
|
||||
@ -411,6 +423,7 @@ void ImportSpriteSheetCommand::onExecute(Context* context)
|
||||
if (docPref) {
|
||||
docPref->importSpriteSheet.type(sheetType);
|
||||
docPref->importSpriteSheet.bounds(frameBounds);
|
||||
docPref->importSpriteSheet.partialTiles(partialTiles);
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user