Add gridBounds parameter to NewLayer command

This commit is contained in:
David Capello 2023-04-19 13:25:54 -03:00
parent 1c6e583c87
commit 6cbde57470
3 changed files with 26 additions and 7 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2023 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -61,6 +61,7 @@ struct NewLayerParams : public NewParams {
Param<bool> group { this, false, "group" };
Param<bool> reference { this, false, "reference" };
Param<bool> tilemap { this, false, "tilemap" };
Param<gfx::Rect> gridBounds { this, gfx::Rect(), "gridBounds" };
Param<bool> ask { this, false, "ask" };
Param<bool> fromFile { this, false, { "fromFile", "from-file" } };
Param<bool> fromClipboard { this, false, "fromClipboard" };
@ -203,7 +204,9 @@ void NewLayerCommand::onExecute(Context* context)
// Information about the tileset to be used for new tilemaps
TilesetSelector::Info tilesetInfo;
tilesetInfo.newTileset = true;
tilesetInfo.grid = context->activeSite().grid();
tilesetInfo.grid = (params().gridBounds().isEmpty() ?
context->activeSite().grid():
doc::Grid(params().gridBounds()));
tilesetInfo.baseIndex = 1;
#ifdef ENABLE_UI

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2019-2021 Igara Studio S.A.
// Copyright (c) 2019-2023 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -32,6 +32,12 @@ Grid Grid::MakeRect(const gfx::Size& sz)
return Grid(sz);
}
// static
Grid Grid::MakeRect(const gfx::Rect& rc)
{
return Grid(rc);
}
// Converts a tile position into a canvas position
gfx::Point Grid::tileToCanvas(const gfx::Point& tile) const
{

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2019-2020 Igara Studio S.A.
// Copyright (c) 2019-2023 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -17,16 +17,26 @@ namespace doc {
class Grid {
public:
Grid(const gfx::Size& sz = gfx::Size(16, 16))
explicit Grid(const gfx::Size& sz = gfx::Size(16, 16))
: m_tileSize(sz)
, m_origin(0, 0)
, m_tileCenter(gfx::Point(sz.w/2, sz.h/2))
, m_tileOffset(gfx::Point(sz.w, sz.h))
, m_tileCenter(sz.w/2, sz.h/2)
, m_tileOffset(sz)
, m_oddRowOffset(0, 0)
, m_oddColOffset(0, 0)
, m_mask(nullptr) { }
explicit Grid(const gfx::Rect& rc)
: m_tileSize(rc.size())
, m_origin(rc.origin())
, m_tileCenter(m_tileSize.w/2, m_tileSize.h/2)
, m_tileOffset(m_tileSize)
, m_oddRowOffset(0, 0)
, m_oddColOffset(0, 0)
, m_mask(nullptr) { }
static Grid MakeRect(const gfx::Size& sz);
static Grid MakeRect(const gfx::Rect& rc);
bool isEmpty() const { return m_tileSize.w == 0 || m_tileSize.h == 0; }