mirror of https://github.com/aseprite/aseprite.git
Compare commits
3 Commits
2f38228cc4
...
95a42fb0ad
Author | SHA1 | Date |
---|---|---|
|
95a42fb0ad | |
|
4bb9239f50 | |
|
27f19959bd |
|
@ -127,12 +127,13 @@ struct Dialog {
|
|||
int showRef = LUA_REFNIL;
|
||||
lua_State* L = nullptr;
|
||||
|
||||
Dialog(const ui::Window::Type windowType, const std::string& title)
|
||||
Dialog(const ui::Window::Type windowType, const std::string& title, bool sizeable)
|
||||
: window(windowType, title)
|
||||
, grid(2, false)
|
||||
, currentGrid(&grid)
|
||||
{
|
||||
window.addChild(&grid);
|
||||
window.setSizeable(sizeable);
|
||||
all_dialogs.push_back(this);
|
||||
}
|
||||
|
||||
|
@ -365,6 +366,7 @@ int Dialog_new(lua_State* L)
|
|||
// Get the title and the type of window (with or without title bar)
|
||||
ui::Window::Type windowType = ui::Window::WithTitleBar;
|
||||
std::string title = "Script";
|
||||
bool sizeable = true;
|
||||
if (lua_isstring(L, 1)) {
|
||||
title = lua_tostring(L, 1);
|
||||
}
|
||||
|
@ -378,9 +380,14 @@ int Dialog_new(lua_State* L)
|
|||
if (type != LUA_TNIL && lua_toboolean(L, -1))
|
||||
windowType = ui::Window::WithoutTitleBar;
|
||||
lua_pop(L, 1);
|
||||
|
||||
type = lua_getfield(L, 1, "resizeable");
|
||||
if (type != LUA_TNIL && !lua_toboolean(L, -1))
|
||||
sizeable = false;
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
auto dlg = push_new<Dialog>(L, windowType, title);
|
||||
auto dlg = push_new<Dialog>(L, windowType, title, sizeable);
|
||||
|
||||
// The uservalue of the dialog userdata will contain a table that
|
||||
// stores all the callbacks to handle events. As these callbacks can
|
||||
|
|
|
@ -2748,7 +2748,10 @@ void Editor::setZoomAndCenterInMouse(const Zoom& zoom,
|
|||
}
|
||||
}
|
||||
|
||||
void Editor::pasteImage(const Image* image, const Mask* mask, const gfx::Point* position)
|
||||
void Editor::pasteImage(const Image* image,
|
||||
const Mask* mask,
|
||||
const gfx::Point* position,
|
||||
const Tileset* srcTileset)
|
||||
{
|
||||
ASSERT(image);
|
||||
|
||||
|
@ -2840,6 +2843,10 @@ void Editor::pasteImage(const Image* image, const Mask* mask, const gfx::Point*
|
|||
PixelsMovementPtr pixelsMovement(
|
||||
new PixelsMovement(UIContext::instance(), site, image, &mask2, "Paste"));
|
||||
|
||||
// Adjust image when copying between tilemap layers
|
||||
if (site.tilemapMode() == TilemapMode::Tiles && srcTileset != nullptr)
|
||||
pixelsMovement->remapTilesForPaste(srcTileset);
|
||||
|
||||
setState(EditorStatePtr(new MovingPixelsState(this, NULL, pixelsMovement, NoHandle)));
|
||||
}
|
||||
|
||||
|
|
|
@ -244,7 +244,8 @@ public:
|
|||
|
||||
void pasteImage(const Image* image,
|
||||
const Mask* mask = nullptr,
|
||||
const gfx::Point* position = nullptr);
|
||||
const gfx::Point* position = nullptr,
|
||||
const Tileset* srcTileset = nullptr);
|
||||
|
||||
void startSelectionTransformation(const gfx::Point& move, double angle);
|
||||
void startFlipTransformation(doc::algorithm::FlipType flipType);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "app/ui/editor/pixels_movement.h"
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/cmd/add_tile.h"
|
||||
#include "app/cmd/clear_mask.h"
|
||||
#include "app/cmd/deselect_mask.h"
|
||||
#include "app/cmd/set_mask.h"
|
||||
|
@ -1356,6 +1357,39 @@ void PixelsMovement::drawTransformedTilemap(const Transformation& transformation
|
|||
draw_row(dst->height() - 1, src->height() - 1, 1);
|
||||
}
|
||||
|
||||
void PixelsMovement::remapTilesForPaste(const Tileset* srcTileset)
|
||||
{
|
||||
// Check that tile size matches before doing anything
|
||||
LayerTilemap* dstLayer = static_cast<LayerTilemap*>(m_site.layer());
|
||||
Tileset* dstTileset = dstLayer->tileset();
|
||||
const doc::Grid& srcGrid = srcTileset->grid();
|
||||
const doc::Grid& dstGrid = dstTileset->grid();
|
||||
if (srcGrid.tileSize() != dstGrid.tileSize())
|
||||
throw base::Exception("Tile size does not match.");
|
||||
|
||||
// Map source to destination
|
||||
tile_index dstSz = dstTileset->size();
|
||||
for (int y = 0; y < m_originalImage->height(); ++y) {
|
||||
for (int x = 0; x < m_originalImage->width(); ++x) {
|
||||
// Blank tile can be skipped
|
||||
const color_t srcTi = m_originalImage->getPixel(x, y);
|
||||
if (!srcTi)
|
||||
continue;
|
||||
|
||||
// Add tile to destination if missing
|
||||
tile_index dstTi;
|
||||
const ImageRef t = srcTileset->get(srcTi);
|
||||
if (!dstTileset->findTileIndex(t, dstTi)) {
|
||||
m_tx(new cmd::AddTile(dstTileset, t, srcTileset->getTileData(srcTi)));
|
||||
dstTi = dstSz++;
|
||||
}
|
||||
|
||||
// Update tile index in image
|
||||
m_originalImage->putPixel(x, y, dstTi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PixelsMovement::onPivotChange()
|
||||
{
|
||||
set_pivot_from_preferences(m_currentData);
|
||||
|
|
|
@ -130,6 +130,9 @@ public:
|
|||
const Transformation& getTransformation() const { return m_currentData; }
|
||||
void setTransformation(const Transformation& t);
|
||||
|
||||
// For copy/paste between tilemap layers
|
||||
void remapTilesForPaste(const Tileset* srcTileset);
|
||||
|
||||
private:
|
||||
void setTransformationBase(const Transformation& t);
|
||||
void adjustPivot();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#endif
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/cmd/add_tileset.h"
|
||||
#include "app/cmd/clear_mask.h"
|
||||
#include "app/cmd/deselect_mask.h"
|
||||
#include "app/cmd/set_mask.h"
|
||||
|
@ -584,7 +585,10 @@ void Clipboard::paste(Context* ctx, const bool interactive, const gfx::Point* po
|
|||
// TODO add post-command parameters (issue #2324)
|
||||
|
||||
// Change to MovingTilemapState
|
||||
editor->pasteImage(m_data->tilemap.get(), m_data->mask.get(), position);
|
||||
editor->pasteImage(m_data->tilemap.get(),
|
||||
m_data->mask.get(),
|
||||
position,
|
||||
m_data->tileset.get());
|
||||
}
|
||||
else {
|
||||
// TODO non-interactive version (for scripts)
|
||||
|
@ -763,7 +767,14 @@ void Clipboard::paste(Context* ctx, const bool interactive, const gfx::Point* po
|
|||
afterThis = dstSpr->root()->lastLayer();
|
||||
|
||||
Layer* newLayer = nullptr;
|
||||
if (srcLayer->isImage())
|
||||
if (srcLayer->isTilemap()) {
|
||||
Tileset* srcTileset = static_cast<LayerTilemap*>(srcLayer)->tileset();
|
||||
Tileset* tilesetCopy = Tileset::MakeCopyCopyingImagesForSprite(srcTileset, dstSpr);
|
||||
const tileset_index tsi = dstSpr->tilesets()->size();
|
||||
tx(new cmd::AddTileset(dstSpr, tilesetCopy));
|
||||
newLayer = new LayerTilemap(dstSpr, tsi);
|
||||
}
|
||||
else if (srcLayer->isImage())
|
||||
newLayer = new LayerImage(dstSpr);
|
||||
else if (srcLayer->isGroup())
|
||||
newLayer = new LayerGroup(dstSpr);
|
||||
|
|
Loading…
Reference in New Issue