mirror of https://github.com/aseprite/aseprite.git
lua: Add params to app.useTool() to change the cel where we'll draw
This commit is contained in:
parent
1f7f5415cd
commit
2812a95f1e
|
|
@ -197,14 +197,43 @@ int App_useTool(lua_State* L)
|
||||||
return luaL_error(L, "app.useTool() must be called with a table as its first argument");
|
return luaL_error(L, "app.useTool() must be called with a table as its first argument");
|
||||||
|
|
||||||
auto ctx = App::instance()->context();
|
auto ctx = App::instance()->context();
|
||||||
Doc* doc = ctx->activeDocument();
|
Site site = ctx->activeSite();
|
||||||
if (!doc)
|
|
||||||
|
// Draw in a specific cel, layer, or frame
|
||||||
|
int type = lua_getfield(L, 1, "layer");
|
||||||
|
if (type != LUA_TNIL) {
|
||||||
|
if (auto layer = get_docobj<Layer>(L, -1)) {
|
||||||
|
site.document(static_cast<Doc*>(layer->sprite()->document()));
|
||||||
|
site.sprite(layer->sprite());
|
||||||
|
site.layer(layer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
type = lua_getfield(L, 1, "frame");
|
||||||
|
if (type != LUA_TNIL) {
|
||||||
|
site.frame(get_frame_number_from_arg(L, -1));
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
type = lua_getfield(L, 1, "cel");
|
||||||
|
if (type != LUA_TNIL) {
|
||||||
|
if (auto cel = get_docobj<Cel>(L, -1)) {
|
||||||
|
site.document(static_cast<Doc*>(cel->sprite()->document()));
|
||||||
|
site.sprite(cel->sprite());
|
||||||
|
site.layer(cel->layer());
|
||||||
|
site.frame(cel->frame());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
if (!site.document())
|
||||||
return luaL_error(L, "there is no active document to draw with the tool");
|
return luaL_error(L, "there is no active document to draw with the tool");
|
||||||
|
|
||||||
// Select tool by name
|
// Select tool by name
|
||||||
tools::Tool* tool = App::instance()->activeToolManager()->activeTool();
|
tools::Tool* tool = App::instance()->activeToolManager()->activeTool();
|
||||||
tools::Ink* ink = tool->getInk(0);
|
tools::Ink* ink = tool->getInk(0);
|
||||||
int type = lua_getfield(L, 1, "tool");
|
type = lua_getfield(L, 1, "tool");
|
||||||
if (auto toolArg = get_tool_from_arg(L, -1)) {
|
if (auto toolArg = get_tool_from_arg(L, -1)) {
|
||||||
tool = toolArg;
|
tool = toolArg;
|
||||||
ink = tool->getInk(0);
|
ink = tool->getInk(0);
|
||||||
|
|
@ -222,7 +251,10 @@ int App_useTool(lua_State* L)
|
||||||
type = lua_getfield(L, 1, "points");
|
type = lua_getfield(L, 1, "points");
|
||||||
if (type == LUA_TTABLE) {
|
if (type == LUA_TTABLE) {
|
||||||
std::unique_ptr<tools::ToolLoop> loop(
|
std::unique_ptr<tools::ToolLoop> loop(
|
||||||
create_tool_loop_for_script(ctx, tool, ink, color));
|
create_tool_loop_for_script(ctx, site, tool, ink, color));
|
||||||
|
if (!loop)
|
||||||
|
return luaL_error(L, "cannot draw in the active site");
|
||||||
|
|
||||||
tools::ToolLoopManager manager(loop.get());
|
tools::ToolLoopManager manager(loop.get());
|
||||||
tools::Pointer lastPointer;
|
tools::Pointer lastPointer;
|
||||||
bool first = true;
|
bool first = true;
|
||||||
|
|
|
||||||
|
|
@ -686,21 +686,20 @@ tools::ToolLoop* create_tool_loop(
|
||||||
|
|
||||||
tools::ToolLoop* create_tool_loop_for_script(
|
tools::ToolLoop* create_tool_loop_for_script(
|
||||||
Context* context,
|
Context* context,
|
||||||
|
const Site& site,
|
||||||
tools::Tool* tool,
|
tools::Tool* tool,
|
||||||
tools::Ink* ink,
|
tools::Ink* ink,
|
||||||
const app::Color& color)
|
const app::Color& color)
|
||||||
{
|
{
|
||||||
ASSERT(tool);
|
ASSERT(tool);
|
||||||
ASSERT(ink);
|
ASSERT(ink);
|
||||||
|
|
||||||
Site site = context->activeSite();
|
|
||||||
if (!site.layer())
|
if (!site.layer())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
tools::ToolLoop::Button toolLoopButton = tools::ToolLoop::Left;
|
const tools::ToolLoop::Button toolLoopButton = tools::ToolLoop::Left;
|
||||||
tools::Controller* controller = tool->getController(toolLoopButton);
|
tools::Controller* controller = tool->getController(toolLoopButton);
|
||||||
BrushRef brush;
|
BrushRef brush(nullptr);
|
||||||
#ifdef ENABLE_UI
|
#ifdef ENABLE_UI
|
||||||
if (App::instance()->contextBar())
|
if (App::instance()->contextBar())
|
||||||
brush = App::instance()->contextBar()->activeBrush(tool, ink);
|
brush = App::instance()->contextBar()->activeBrush(tool, ink);
|
||||||
|
|
@ -710,8 +709,7 @@ tools::ToolLoop* create_tool_loop_for_script(
|
||||||
|
|
||||||
return new ToolLoopImpl(
|
return new ToolLoopImpl(
|
||||||
nullptr, site, context,
|
nullptr, site, context,
|
||||||
tool, ink, controller,
|
tool, ink, controller, brush,
|
||||||
brush,
|
|
||||||
toolLoopButton, color, color, false);
|
toolLoopButton, color, color, false);
|
||||||
}
|
}
|
||||||
catch (const std::exception& ex) {
|
catch (const std::exception& ex) {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ namespace app {
|
||||||
class Color;
|
class Color;
|
||||||
class Context;
|
class Context;
|
||||||
class Editor;
|
class Editor;
|
||||||
|
class Site;
|
||||||
|
|
||||||
namespace tools {
|
namespace tools {
|
||||||
class Ink;
|
class Ink;
|
||||||
|
|
@ -36,6 +37,7 @@ namespace app {
|
||||||
|
|
||||||
tools::ToolLoop* create_tool_loop_for_script(
|
tools::ToolLoop* create_tool_loop_for_script(
|
||||||
Context* context,
|
Context* context,
|
||||||
|
const Site& site,
|
||||||
tools::Tool* tool,
|
tools::Tool* tool,
|
||||||
tools::Ink* ink,
|
tools::Ink* ink,
|
||||||
const app::Color& color);
|
const app::Color& color);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue