mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-16 10:20:50 +00:00
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");
|
||||
|
||||
auto ctx = App::instance()->context();
|
||||
Doc* doc = ctx->activeDocument();
|
||||
if (!doc)
|
||||
Site site = ctx->activeSite();
|
||||
|
||||
// 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");
|
||||
|
||||
// Select tool by name
|
||||
tools::Tool* tool = App::instance()->activeToolManager()->activeTool();
|
||||
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)) {
|
||||
tool = toolArg;
|
||||
ink = tool->getInk(0);
|
||||
@ -222,7 +251,10 @@ int App_useTool(lua_State* L)
|
||||
type = lua_getfield(L, 1, "points");
|
||||
if (type == LUA_TTABLE) {
|
||||
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::Pointer lastPointer;
|
||||
bool first = true;
|
||||
|
@ -686,21 +686,20 @@ tools::ToolLoop* create_tool_loop(
|
||||
|
||||
tools::ToolLoop* create_tool_loop_for_script(
|
||||
Context* context,
|
||||
const Site& site,
|
||||
tools::Tool* tool,
|
||||
tools::Ink* ink,
|
||||
const app::Color& color)
|
||||
{
|
||||
ASSERT(tool);
|
||||
ASSERT(ink);
|
||||
|
||||
Site site = context->activeSite();
|
||||
if (!site.layer())
|
||||
return nullptr;
|
||||
|
||||
try {
|
||||
tools::ToolLoop::Button toolLoopButton = tools::ToolLoop::Left;
|
||||
const tools::ToolLoop::Button toolLoopButton = tools::ToolLoop::Left;
|
||||
tools::Controller* controller = tool->getController(toolLoopButton);
|
||||
BrushRef brush;
|
||||
BrushRef brush(nullptr);
|
||||
#ifdef ENABLE_UI
|
||||
if (App::instance()->contextBar())
|
||||
brush = App::instance()->contextBar()->activeBrush(tool, ink);
|
||||
@ -710,8 +709,7 @@ tools::ToolLoop* create_tool_loop_for_script(
|
||||
|
||||
return new ToolLoopImpl(
|
||||
nullptr, site, context,
|
||||
tool, ink, controller,
|
||||
brush,
|
||||
tool, ink, controller, brush,
|
||||
toolLoopButton, color, color, false);
|
||||
}
|
||||
catch (const std::exception& ex) {
|
||||
|
@ -21,6 +21,7 @@ namespace app {
|
||||
class Color;
|
||||
class Context;
|
||||
class Editor;
|
||||
class Site;
|
||||
|
||||
namespace tools {
|
||||
class Ink;
|
||||
@ -36,6 +37,7 @@ namespace app {
|
||||
|
||||
tools::ToolLoop* create_tool_loop_for_script(
|
||||
Context* context,
|
||||
const Site& site,
|
||||
tools::Tool* tool,
|
||||
tools::Ink* ink,
|
||||
const app::Color& color);
|
||||
|
Loading…
x
Reference in New Issue
Block a user