mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-23 09:41:04 +00:00
lua: Initial support for sprite properties
Frames, Palettes/Color, Layers, Cels, Tags, Slices, etc.
This commit is contained in:
parent
24b28ae064
commit
f456f3cba3
@ -149,17 +149,31 @@ if(ENABLE_SCRIPTING)
|
|||||||
set(scripting_files
|
set(scripting_files
|
||||||
commands/cmd_run_script.cpp
|
commands/cmd_run_script.cpp
|
||||||
script/app_object.cpp
|
script/app_object.cpp
|
||||||
|
script/cel_class.cpp
|
||||||
|
script/cels_class.cpp
|
||||||
|
script/color_class.cpp
|
||||||
script/engine.cpp
|
script/engine.cpp
|
||||||
|
script/frame_class.cpp
|
||||||
|
script/frames_class.cpp
|
||||||
script/image_class.cpp
|
script/image_class.cpp
|
||||||
script/image_iterator_class.cpp
|
script/image_iterator_class.cpp
|
||||||
|
script/layer_class.cpp
|
||||||
|
script/layers_class.cpp
|
||||||
script/luacpp.cpp
|
script/luacpp.cpp
|
||||||
|
script/palette_class.cpp
|
||||||
|
script/palettes_class.cpp
|
||||||
script/pixel_color_object.cpp
|
script/pixel_color_object.cpp
|
||||||
script/point_class.cpp
|
script/point_class.cpp
|
||||||
script/rectangle_class.cpp
|
script/rectangle_class.cpp
|
||||||
script/selection_class.cpp
|
script/selection_class.cpp
|
||||||
script/site_class.cpp
|
script/site_class.cpp
|
||||||
script/size_class.cpp
|
script/size_class.cpp
|
||||||
|
script/slice_class.cpp
|
||||||
|
script/slices_class.cpp
|
||||||
script/sprite_class.cpp
|
script/sprite_class.cpp
|
||||||
|
script/tag_class.cpp
|
||||||
|
script/tags_class.cpp
|
||||||
|
script/userdata_class.cpp
|
||||||
shell.cpp
|
shell.cpp
|
||||||
${scripting_files_ui})
|
${scripting_files_ui})
|
||||||
endif()
|
endif()
|
||||||
|
96
src/app/script/cel_class.cpp
Normal file
96
src/app/script/cel_class.cpp
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/script/engine.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "doc/cel.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
int Cel_get_sprite(lua_State* L)
|
||||||
|
{
|
||||||
|
auto cel = get_ptr<Cel>(L, 1);
|
||||||
|
push_ptr(L, cel->sprite());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Cel_get_layer(lua_State* L)
|
||||||
|
{
|
||||||
|
auto cel = get_ptr<Cel>(L, 1);
|
||||||
|
push_ptr<Layer>(L, (Layer*)cel->layer());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Cel_get_frame(lua_State* L)
|
||||||
|
{
|
||||||
|
auto cel = get_ptr<Cel>(L, 1);
|
||||||
|
lua_pushinteger(L, cel->frame()+1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Cel_get_image(lua_State* L)
|
||||||
|
{
|
||||||
|
auto cel = get_ptr<Cel>(L, 1);
|
||||||
|
push_cel_image(L, cel);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Cel_get_bounds(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto cel = get_ptr<Cel>(L, 1);
|
||||||
|
push_new<gfx::Rect>(L, cel->bounds());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Cel_get_userData(lua_State* L)
|
||||||
|
{
|
||||||
|
auto cel = get_ptr<Cel>(L, 1);
|
||||||
|
push_userdata(L, cel->data());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Cel_methods[] = {
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Property Cel_properties[] = {
|
||||||
|
{ "sprite", Cel_get_sprite, nullptr },
|
||||||
|
{ "layer", Cel_get_layer, nullptr },
|
||||||
|
{ "frame", Cel_get_frame, nullptr },
|
||||||
|
{ "image", Cel_get_image, nullptr },
|
||||||
|
{ "bounds", Cel_get_bounds, nullptr },
|
||||||
|
{ "userData", Cel_get_userData, nullptr },
|
||||||
|
{ nullptr, nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(Cel);
|
||||||
|
|
||||||
|
void register_cel_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Cel = doc::Cel;
|
||||||
|
REG_CLASS(L, Cel);
|
||||||
|
REG_CLASS_PROPERTIES(L, Cel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_sprite_cel(lua_State* L, Cel* cel)
|
||||||
|
{
|
||||||
|
push_ptr<Cel>(L, cel);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
81
src/app/script/cels_class.cpp
Normal file
81
src/app/script/cels_class.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "doc/cels_range.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct CelsObj {
|
||||||
|
Sprite* sprite;
|
||||||
|
CelsObj(Sprite* sprite) : sprite(sprite) { }
|
||||||
|
CelsObj(const CelsObj&) = delete;
|
||||||
|
CelsObj& operator=(const CelsObj&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Cels_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<CelsObj>(L, 1)->~CelsObj();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Cels_len(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<CelsObj>(L, 1);
|
||||||
|
lua_pushinteger(L, obj->sprite->cels().size());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Cels_index(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<CelsObj>(L, 1);
|
||||||
|
const int i = lua_tointeger(L, 2);
|
||||||
|
if (i < 1 || i > obj->sprite->cels().size())
|
||||||
|
return luaL_error(L, "index out of bounds %d", i);
|
||||||
|
|
||||||
|
auto it = obj->sprite->cels().begin();
|
||||||
|
std::advance(it, i-1); // TODO improve this
|
||||||
|
|
||||||
|
push_ptr<Cel>(L, *it);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Cels_methods[] = {
|
||||||
|
{ "__gc", Cels_gc },
|
||||||
|
{ "__len", Cels_len },
|
||||||
|
{ "__index", Cels_index },
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(CelsObj);
|
||||||
|
|
||||||
|
void register_cels_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Cels = CelsObj;
|
||||||
|
REG_CLASS(L, Cels);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_sprite_cels(lua_State* L, Sprite* sprite)
|
||||||
|
{
|
||||||
|
push_new<CelsObj>(L, sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
458
src/app/script/color_class.cpp
Normal file
458
src/app/script/color_class.cpp
Normal file
@ -0,0 +1,458 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/color.h"
|
||||||
|
#include "app/color_utils.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
Color Color_new(lua_State* L, int index)
|
||||||
|
{
|
||||||
|
app::Color color;
|
||||||
|
// Copy other color
|
||||||
|
if (auto color2 = may_get_obj<app::Color>(L, index)) {
|
||||||
|
color = *color2;
|
||||||
|
}
|
||||||
|
// Convert table into a Color
|
||||||
|
else if (lua_istable(L, index)) {
|
||||||
|
// Convert { r, g, b } into a Color
|
||||||
|
if (lua_getfield(L, index, "r") != LUA_TNIL) {
|
||||||
|
lua_getfield(L, index, "g");
|
||||||
|
lua_getfield(L, index, "b");
|
||||||
|
int a = 255;
|
||||||
|
if (lua_getfield(L, index, "a") != LUA_TNIL)
|
||||||
|
a = lua_tointeger(L, -1);
|
||||||
|
color = app::Color::fromRgb(lua_tointeger(L, -4),
|
||||||
|
lua_tointeger(L, -3),
|
||||||
|
lua_tointeger(L, -2), a);
|
||||||
|
lua_pop(L, 4);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
// Convert { red, green, blue } into a Color
|
||||||
|
if (lua_getfield(L, index, "red") != LUA_TNIL) {
|
||||||
|
lua_getfield(L, index, "green");
|
||||||
|
lua_getfield(L, index, "blue");
|
||||||
|
int a = 255;
|
||||||
|
if (lua_getfield(L, index, "alpha") != LUA_TNIL)
|
||||||
|
a = lua_tointeger(L, -1);
|
||||||
|
color = app::Color::fromRgb(lua_tointeger(L, -4),
|
||||||
|
lua_tointeger(L, -3),
|
||||||
|
lua_tointeger(L, -2), a);
|
||||||
|
lua_pop(L, 4);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
// Convert { h, s, v } into a Color
|
||||||
|
if (lua_getfield(L, index, "v") != LUA_TNIL) {
|
||||||
|
lua_getfield(L, index, "s");
|
||||||
|
lua_getfield(L, index, "h");
|
||||||
|
int a = 255;
|
||||||
|
if (lua_getfield(L, index, "a") != LUA_TNIL)
|
||||||
|
a = lua_tointeger(L, -1);
|
||||||
|
color = app::Color::fromHsv(lua_tonumber(L, -2),
|
||||||
|
lua_tonumber(L, -3),
|
||||||
|
lua_tonumber(L, -4), a);
|
||||||
|
lua_pop(L, 4);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
// Convert { hue, saturation, value } into a Color
|
||||||
|
if (lua_getfield(L, index, "value") != LUA_TNIL) {
|
||||||
|
lua_getfield(L, index, "saturation");
|
||||||
|
lua_getfield(L, index, "hue");
|
||||||
|
int a = 255;
|
||||||
|
if (lua_getfield(L, index, "alpha") != LUA_TNIL)
|
||||||
|
a = lua_tointeger(L, -1);
|
||||||
|
color = app::Color::fromHsv(lua_tonumber(L, -2),
|
||||||
|
lua_tonumber(L, -3),
|
||||||
|
lua_tonumber(L, -4), a);
|
||||||
|
lua_pop(L, 4);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
// Convert { h, s, l } into a Color
|
||||||
|
if (lua_getfield(L, index, "l") != LUA_TNIL) {
|
||||||
|
lua_getfield(L, index, "s");
|
||||||
|
lua_getfield(L, index, "h");
|
||||||
|
int a = 255;
|
||||||
|
if (lua_getfield(L, index, "a") != LUA_TNIL)
|
||||||
|
a = lua_tointeger(L, -1);
|
||||||
|
color = app::Color::fromHsl(lua_tonumber(L, -2),
|
||||||
|
lua_tonumber(L, -3),
|
||||||
|
lua_tonumber(L, -4), a);
|
||||||
|
lua_pop(L, 4);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
// Convert { hue, saturation, lightness } into a Color
|
||||||
|
if (lua_getfield(L, index, "lightness") != LUA_TNIL) {
|
||||||
|
lua_getfield(L, index, "saturation");
|
||||||
|
lua_getfield(L, index, "hue");
|
||||||
|
int a = 255;
|
||||||
|
if (lua_getfield(L, index, "alpha") != LUA_TNIL)
|
||||||
|
a = lua_tointeger(L, -1);
|
||||||
|
color = app::Color::fromHsv(lua_tonumber(L, -2),
|
||||||
|
lua_tonumber(L, -3),
|
||||||
|
lua_tonumber(L, -4), a);
|
||||||
|
lua_pop(L, 4);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_pop(L, 1);
|
||||||
|
|
||||||
|
// Convert { gray } into a Color
|
||||||
|
if (lua_getfield(L, index, "gray") != LUA_TNIL) {
|
||||||
|
int a = 255;
|
||||||
|
if (lua_getfield(L, index, "alpha") != LUA_TNIL)
|
||||||
|
a = lua_tointeger(L, -1);
|
||||||
|
color = app::Color::fromGray(lua_tonumber(L, -2), a);
|
||||||
|
lua_pop(L, 2);
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
// raw color into app color
|
||||||
|
else if (!lua_isnone(L, index)) {
|
||||||
|
if (lua_isinteger(L, index) && lua_isnone(L, index+1)) {
|
||||||
|
doc::color_t docColor = lua_tointeger(L, index);
|
||||||
|
color = app::Color::fromRgb(doc::rgba_getr(docColor),
|
||||||
|
doc::rgba_getg(docColor),
|
||||||
|
doc::rgba_getb(docColor),
|
||||||
|
doc::rgba_geta(docColor));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
color = app::Color::fromRgb(lua_tointeger(L, index),
|
||||||
|
lua_tointeger(L, index+1),
|
||||||
|
lua_tointeger(L, index+2),
|
||||||
|
lua_isnone(L, index+3) ?
|
||||||
|
255: lua_tointeger(L, index+3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_new(lua_State* L)
|
||||||
|
{
|
||||||
|
push_obj(L, Color_new(L, 1));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<app::Color>(L, 1)->~Color();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_eq(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto a = get_obj<app::Color>(L, 1);
|
||||||
|
const auto b = get_obj<app::Color>(L, 2);
|
||||||
|
lua_pushboolean(L, *a == *b);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_red(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushinteger(L, color->getRed());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_green(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushinteger(L, color->getGreen());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_blue(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushinteger(L, color->getBlue());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_alpha(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushinteger(L, color->getAlpha());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_hsvHue(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushnumber(L, color->getHsvHue());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_hsvSaturation(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushnumber(L, color->getHsvSaturation());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_hsvValue(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushnumber(L, color->getHsvValue());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_hslHue(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushnumber(L, color->getHslHue());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_hslSaturation(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushnumber(L, color->getHslSaturation());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_hslLightness(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushnumber(L, color->getHslLightness());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_hue(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
if (color->getType() == Color::HslType)
|
||||||
|
return Color_get_hslHue(L);
|
||||||
|
else
|
||||||
|
return Color_get_hsvHue(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_saturation(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
if (color->getType() == Color::HslType)
|
||||||
|
return Color_get_hslSaturation(L);
|
||||||
|
else
|
||||||
|
return Color_get_hsvSaturation(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_gray(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushnumber(L, color->getGray());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_get_index(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
lua_pushnumber(L, color->getIndex());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_red(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromRgb(lua_tointeger(L, 2),
|
||||||
|
color->getGreen(),
|
||||||
|
color->getBlue(),
|
||||||
|
color->getAlpha());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_green(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromRgb(color->getRed(),
|
||||||
|
lua_tointeger(L, 2),
|
||||||
|
color->getBlue(),
|
||||||
|
color->getAlpha());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_blue(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromRgb(color->getRed(),
|
||||||
|
color->getGreen(),
|
||||||
|
lua_tointeger(L, 2),
|
||||||
|
color->getAlpha());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_alpha(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
color->setAlpha(lua_tointeger(L, 2));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_hsvHue(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromHsv(lua_tonumber(L, 2),
|
||||||
|
color->getHsvSaturation(),
|
||||||
|
color->getHsvValue(),
|
||||||
|
color->getAlpha());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_hsvSaturation(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromHsv(color->getHsvHue(),
|
||||||
|
lua_tonumber(L, 2),
|
||||||
|
color->getHsvValue(),
|
||||||
|
color->getAlpha());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_hsvValue(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromHsv(color->getHsvHue(),
|
||||||
|
color->getHsvSaturation(),
|
||||||
|
lua_tonumber(L, 2),
|
||||||
|
color->getAlpha());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_hslHue(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromHsl(lua_tonumber(L, 2),
|
||||||
|
color->getHslSaturation(),
|
||||||
|
color->getHslLightness(),
|
||||||
|
color->getAlpha());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_hslSaturation(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromHsl(color->getHslHue(),
|
||||||
|
lua_tonumber(L, 2),
|
||||||
|
color->getHslLightness(),
|
||||||
|
color->getAlpha());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_hslLightness(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromHsl(color->getHslHue(),
|
||||||
|
color->getHslSaturation(),
|
||||||
|
lua_tonumber(L, 2),
|
||||||
|
color->getAlpha());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_hue(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
if (color->getType() == Color::HslType)
|
||||||
|
return Color_set_hslHue(L);
|
||||||
|
else
|
||||||
|
return Color_set_hsvHue(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_saturation(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto color = get_obj<app::Color>(L, 1);
|
||||||
|
if (color->getType() == Color::HslType)
|
||||||
|
return Color_set_hslSaturation(L);
|
||||||
|
else
|
||||||
|
return Color_set_hsvSaturation(L);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_gray(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromGray(lua_tointeger(L, 2),
|
||||||
|
color->getAlpha());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Color_set_index(lua_State* L)
|
||||||
|
{
|
||||||
|
auto color = get_obj<app::Color>(L, 1);
|
||||||
|
*color = app::Color::fromIndex(lua_tointeger(L, 2));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Color_methods[] = {
|
||||||
|
{ "__gc", Color_gc },
|
||||||
|
{ "__eq", Color_eq },
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Property Color_properties[] = {
|
||||||
|
{ "red", Color_get_red, Color_set_red },
|
||||||
|
{ "green", Color_get_green, Color_set_green },
|
||||||
|
{ "blue", Color_get_blue, Color_set_blue },
|
||||||
|
{ "alpha", Color_get_alpha, Color_set_alpha },
|
||||||
|
{ "hsvHue", Color_get_hsvHue, Color_set_hsvHue },
|
||||||
|
{ "hsvSaturation", Color_get_hsvSaturation, Color_set_hsvSaturation },
|
||||||
|
{ "hsvValue", Color_get_hsvValue, Color_set_hsvValue },
|
||||||
|
{ "hslHue", Color_get_hslHue, Color_set_hslHue },
|
||||||
|
{ "hslSaturation", Color_get_hslSaturation, Color_set_hslSaturation },
|
||||||
|
{ "hslLightness", Color_get_hslLightness, Color_set_hslLightness },
|
||||||
|
{ "hue", Color_get_hue, Color_set_hue },
|
||||||
|
{ "saturation", Color_get_saturation, Color_set_saturation },
|
||||||
|
{ "value", Color_get_hsvValue, Color_set_hsvValue },
|
||||||
|
{ "lightness", Color_get_hslLightness, Color_set_hslLightness },
|
||||||
|
{ "index", Color_get_index, Color_set_index },
|
||||||
|
{ "gray", Color_get_gray, Color_set_gray },
|
||||||
|
{ nullptr, nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(app::Color);
|
||||||
|
|
||||||
|
void register_color_class(lua_State* L)
|
||||||
|
{
|
||||||
|
REG_CLASS(L, Color);
|
||||||
|
REG_CLASS_NEW(L, Color);
|
||||||
|
REG_CLASS_PROPERTIES(L, Color);
|
||||||
|
}
|
||||||
|
|
||||||
|
app::Color convert_args_into_color(lua_State* L, int index)
|
||||||
|
{
|
||||||
|
return Color_new(L, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
doc::color_t convert_args_into_pixel_color(lua_State* L, int index)
|
||||||
|
{
|
||||||
|
app::Color color = convert_args_into_color(L, index);
|
||||||
|
return color_utils::color_for_image(color, doc::IMAGE_RGB);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
@ -81,14 +81,28 @@ int unsupported(lua_State* L)
|
|||||||
void register_app_object(lua_State* L);
|
void register_app_object(lua_State* L);
|
||||||
void register_app_pixel_color_object(lua_State* L);
|
void register_app_pixel_color_object(lua_State* L);
|
||||||
|
|
||||||
|
void register_cel_class(lua_State* L);
|
||||||
|
void register_cels_class(lua_State* L);
|
||||||
|
void register_color_class(lua_State* L);
|
||||||
|
void register_frame_class(lua_State* L);
|
||||||
|
void register_frames_class(lua_State* L);
|
||||||
void register_image_class(lua_State* L);
|
void register_image_class(lua_State* L);
|
||||||
void register_image_iterator_class(lua_State* L);
|
void register_image_iterator_class(lua_State* L);
|
||||||
|
void register_layer_class(lua_State* L);
|
||||||
|
void register_layers_class(lua_State* L);
|
||||||
|
void register_palette_class(lua_State* L);
|
||||||
|
void register_palettes_class(lua_State* L);
|
||||||
void register_point_class(lua_State* L);
|
void register_point_class(lua_State* L);
|
||||||
void register_rect_class(lua_State* L);
|
void register_rect_class(lua_State* L);
|
||||||
void register_selection_class(lua_State* L);
|
void register_selection_class(lua_State* L);
|
||||||
void register_site_class(lua_State* L);
|
void register_site_class(lua_State* L);
|
||||||
void register_size_class(lua_State* L);
|
void register_size_class(lua_State* L);
|
||||||
|
void register_slice_class(lua_State* L);
|
||||||
|
void register_slices_class(lua_State* L);
|
||||||
void register_sprite_class(lua_State* L);
|
void register_sprite_class(lua_State* L);
|
||||||
|
void register_tag_class(lua_State* L);
|
||||||
|
void register_tags_class(lua_State* L);
|
||||||
|
void register_userdata_class(lua_State* L);
|
||||||
|
|
||||||
Engine::Engine()
|
Engine::Engine()
|
||||||
: L(luaL_newstate())
|
: L(luaL_newstate())
|
||||||
@ -137,14 +151,28 @@ Engine::Engine()
|
|||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
|
|
||||||
// Register classes/prototypes
|
// Register classes/prototypes
|
||||||
|
register_cel_class(L);
|
||||||
|
register_cels_class(L);
|
||||||
|
register_color_class(L);
|
||||||
|
register_frame_class(L);
|
||||||
|
register_frames_class(L);
|
||||||
register_image_class(L);
|
register_image_class(L);
|
||||||
register_image_iterator_class(L);
|
register_image_iterator_class(L);
|
||||||
|
register_layer_class(L);
|
||||||
|
register_layers_class(L);
|
||||||
|
register_palette_class(L);
|
||||||
|
register_palettes_class(L);
|
||||||
register_point_class(L);
|
register_point_class(L);
|
||||||
register_rect_class(L);
|
register_rect_class(L);
|
||||||
register_selection_class(L);
|
register_selection_class(L);
|
||||||
register_site_class(L);
|
register_site_class(L);
|
||||||
register_size_class(L);
|
register_size_class(L);
|
||||||
|
register_slice_class(L);
|
||||||
|
register_slices_class(L);
|
||||||
register_sprite_class(L);
|
register_sprite_class(L);
|
||||||
|
register_tag_class(L);
|
||||||
|
register_tags_class(L);
|
||||||
|
register_userdata_class(L);
|
||||||
|
|
||||||
// Check that we have a clean start (without dirty in the stack)
|
// Check that we have a clean start (without dirty in the stack)
|
||||||
ASSERT(lua_gettop(L) == top);
|
ASSERT(lua_gettop(L) == top);
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
#error ENABLE_SCRIPTING must be defined
|
#error ENABLE_SCRIPTING must be defined
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "app/color.h"
|
||||||
|
#include "doc/frame.h"
|
||||||
#include "doc/image_ref.h"
|
#include "doc/image_ref.h"
|
||||||
#include "doc/object_id.h"
|
#include "doc/object_id.h"
|
||||||
#include "gfx/fwd.h"
|
#include "gfx/fwd.h"
|
||||||
@ -24,7 +26,11 @@ struct lua_State;
|
|||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
class Cel;
|
class Cel;
|
||||||
|
class FrameTag;
|
||||||
|
class Layer;
|
||||||
|
class Palette;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
|
class WithUserData;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
@ -59,13 +65,25 @@ namespace app {
|
|||||||
bool m_printLastResult;
|
bool m_printLastResult;
|
||||||
};
|
};
|
||||||
|
|
||||||
void push_sprite_selection(lua_State* L, doc::Sprite* sprite);
|
|
||||||
void push_cel_image(lua_State* L, doc::Cel* cel);
|
|
||||||
int push_image_iterator_function(lua_State* L, const doc::ImageRef& image);
|
int push_image_iterator_function(lua_State* L, const doc::ImageRef& image);
|
||||||
|
void push_cel_image(lua_State* L, doc::Cel* cel);
|
||||||
|
void push_sprite_cel(lua_State* L, doc::Cel* cel);
|
||||||
|
void push_sprite_cels(lua_State* L, doc::Sprite* sprite);
|
||||||
|
void push_sprite_frame(lua_State* L, doc::Sprite* sprite, doc::frame_t frame);
|
||||||
|
void push_sprite_frames(lua_State* L, doc::Sprite* sprite);
|
||||||
|
void push_sprite_layers(lua_State* L, doc::Sprite* sprite);
|
||||||
|
void push_sprite_palette(lua_State* L, doc::Sprite* sprite, doc::Palette* palette);
|
||||||
|
void push_sprite_palettes(lua_State* L, doc::Sprite* sprite);
|
||||||
|
void push_sprite_selection(lua_State* L, doc::Sprite* sprite);
|
||||||
|
void push_sprite_slices(lua_State* L, doc::Sprite* sprite);
|
||||||
|
void push_sprite_tags(lua_State* L, doc::Sprite* sprite);
|
||||||
|
void push_userdata(lua_State* L, doc::WithUserData* userData);
|
||||||
|
|
||||||
gfx::Point convert_args_into_point(lua_State* L, int index);
|
gfx::Point convert_args_into_point(lua_State* L, int index);
|
||||||
gfx::Rect convert_args_into_rect(lua_State* L, int index);
|
gfx::Rect convert_args_into_rect(lua_State* L, int index);
|
||||||
gfx::Size convert_args_into_size(lua_State* L, int index);
|
gfx::Size convert_args_into_size(lua_State* L, int index);
|
||||||
|
app::Color convert_args_into_color(lua_State* L, int index);
|
||||||
|
doc::color_t convert_args_into_pixel_color(lua_State* L, int index);
|
||||||
|
|
||||||
} // namespace script
|
} // namespace script
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
101
src/app/script/frame_class.cpp
Normal file
101
src/app/script/frame_class.cpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/cmd/set_frame_duration.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "app/tx.h"
|
||||||
|
#include "doc/frame.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct FrameObj {
|
||||||
|
Sprite* sprite;
|
||||||
|
frame_t frame;
|
||||||
|
FrameObj(Sprite* sprite, frame_t frame)
|
||||||
|
: sprite(sprite),
|
||||||
|
frame(frame) {
|
||||||
|
}
|
||||||
|
FrameObj(const FrameObj&) = delete;
|
||||||
|
FrameObj& operator=(const FrameObj&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Frame_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<FrameObj>(L, 1)->~FrameObj();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Frame_get_sprite(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<FrameObj>(L, 1);
|
||||||
|
push_ptr<Sprite>(L, obj->sprite);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Frame_get_frame(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<FrameObj>(L, 1);
|
||||||
|
lua_pushinteger(L, obj->frame+1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Frame_get_duration(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<FrameObj>(L, 1);
|
||||||
|
lua_pushnumber(L, obj->sprite->frameDuration(obj->frame) / 1000.0);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Frame_set_duration(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<FrameObj>(L, 1);
|
||||||
|
double duration = lua_tonumber(L, 2) * 1000.0;
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetFrameDuration(obj->sprite, obj->frame, int(duration)));
|
||||||
|
tx.commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Frame_methods[] = {
|
||||||
|
{ "__gc", Frame_gc },
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Property Frame_properties[] = {
|
||||||
|
{ "sprite", Frame_get_sprite, nullptr },
|
||||||
|
{ "frame", Frame_get_frame, nullptr },
|
||||||
|
{ "duration", Frame_get_duration, Frame_set_duration },
|
||||||
|
{ nullptr, nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(FrameObj);
|
||||||
|
|
||||||
|
void register_frame_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Frame = FrameObj;
|
||||||
|
REG_CLASS(L, Frame);
|
||||||
|
REG_CLASS_PROPERTIES(L, Frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_sprite_frame(lua_State* L, Sprite* sprite, frame_t frame)
|
||||||
|
{
|
||||||
|
push_new<FrameObj>(L, sprite, frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
77
src/app/script/frames_class.cpp
Normal file
77
src/app/script/frames_class.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/script/engine.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct FramesObj {
|
||||||
|
Sprite* sprite;
|
||||||
|
FramesObj(Sprite* sprite)
|
||||||
|
: sprite(sprite) {
|
||||||
|
}
|
||||||
|
FramesObj(const FramesObj&) = delete;
|
||||||
|
FramesObj& operator=(const FramesObj&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Frames_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<FramesObj>(L, 1)->~FramesObj();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Frames_len(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<FramesObj>(L, 1);
|
||||||
|
lua_pushinteger(L, obj->sprite->totalFrames());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Frames_index(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<FramesObj>(L, 1);
|
||||||
|
const int i = lua_tonumber(L, 2);
|
||||||
|
if (i < 1 || i > obj->sprite->totalFrames())
|
||||||
|
return luaL_error(L, "index out of bounds %d", i);
|
||||||
|
push_sprite_frame(L, obj->sprite, i-1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Frames_methods[] = {
|
||||||
|
{ "__gc", Frames_gc },
|
||||||
|
{ "__len", Frames_len },
|
||||||
|
{ "__index", Frames_index },
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(FramesObj);
|
||||||
|
|
||||||
|
void register_frames_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Frames = FramesObj;
|
||||||
|
REG_CLASS(L, Frames);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_sprite_frames(lua_State* L, Sprite* sprite)
|
||||||
|
{
|
||||||
|
push_new<FramesObj>(L, sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
@ -64,7 +64,11 @@ int Image_putPixel(lua_State* L)
|
|||||||
auto obj = get_obj<ImageObj>(L, 1);
|
auto obj = get_obj<ImageObj>(L, 1);
|
||||||
const int x = lua_tointeger(L, 2);
|
const int x = lua_tointeger(L, 2);
|
||||||
const int y = lua_tointeger(L, 3);
|
const int y = lua_tointeger(L, 3);
|
||||||
const doc::color_t color = lua_tointeger(L, 4);
|
doc::color_t color;
|
||||||
|
if (lua_isinteger(L, 4))
|
||||||
|
color = lua_tointeger(L, 4);
|
||||||
|
else
|
||||||
|
color = convert_args_into_pixel_color(L, 4);
|
||||||
doc::put_pixel(obj->image.get(), x, y, color);
|
doc::put_pixel(obj->image.get(), x, y, color);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
106
src/app/script/layer_class.cpp
Normal file
106
src/app/script/layer_class.cpp
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/cmd/set_layer_name.h"
|
||||||
|
#include "app/cmd/set_layer_opacity.h"
|
||||||
|
#include "app/script/engine.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "app/tx.h"
|
||||||
|
#include "doc/layer.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
int Layer_get_sprite(lua_State* L)
|
||||||
|
{
|
||||||
|
auto layer = get_ptr<Layer>(L, 1);
|
||||||
|
push_ptr<Sprite>(L, layer->sprite());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Layer_get_name(lua_State* L)
|
||||||
|
{
|
||||||
|
auto layer = get_ptr<Layer>(L, 1);
|
||||||
|
lua_pushstring(L, layer->name().c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Layer_get_opacity(lua_State* L)
|
||||||
|
{
|
||||||
|
auto layer = get_ptr<Layer>(L, 1);
|
||||||
|
if (layer->isImage()) {
|
||||||
|
lua_pushinteger(L, static_cast<LayerImage*>(layer)->opacity());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Layer_get_userData(lua_State* L)
|
||||||
|
{
|
||||||
|
auto layer = get_ptr<Layer>(L, 1);
|
||||||
|
push_userdata(L, layer);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Layer_set_name(lua_State* L)
|
||||||
|
{
|
||||||
|
auto layer = get_ptr<Layer>(L, 1);
|
||||||
|
const char* name = lua_tostring(L, 2);
|
||||||
|
if (name) {
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetLayerName(layer, name));
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Layer_set_opacity(lua_State* L)
|
||||||
|
{
|
||||||
|
auto layer = get_ptr<Layer>(L, 1);
|
||||||
|
const int opacity = lua_tointeger(L, 2);
|
||||||
|
if (layer->isImage()) {
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetLayerOpacity(static_cast<LayerImage*>(layer), opacity));
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Layer_methods[] = {
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Property Layer_properties[] = {
|
||||||
|
{ "sprite", Layer_get_sprite, nullptr },
|
||||||
|
{ "name", Layer_get_name, Layer_set_name },
|
||||||
|
{ "opacity", Layer_get_opacity, Layer_set_opacity },
|
||||||
|
{ "userData", Layer_get_userData, nullptr },
|
||||||
|
{ nullptr, nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(Layer);
|
||||||
|
|
||||||
|
void register_layer_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Layer = doc::Layer;
|
||||||
|
REG_CLASS(L, Layer);
|
||||||
|
REG_CLASS_PROPERTIES(L, Layer);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
80
src/app/script/layers_class.cpp
Normal file
80
src/app/script/layers_class.cpp
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/script/engine.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "doc/layer.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct LayersObj {
|
||||||
|
Sprite* sprite;
|
||||||
|
LayerList layers;
|
||||||
|
LayersObj(Sprite* sprite)
|
||||||
|
: sprite(sprite),
|
||||||
|
layers(sprite->allLayers()) {
|
||||||
|
}
|
||||||
|
LayersObj(const LayersObj&) = delete;
|
||||||
|
LayersObj& operator=(const LayersObj&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Layers_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<LayersObj>(L, 1)->~LayersObj();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Layers_len(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<LayersObj>(L, 1);
|
||||||
|
lua_pushinteger(L, obj->layers.size());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Layers_index(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<LayersObj>(L, 1);
|
||||||
|
const int i = lua_tonumber(L, 2);
|
||||||
|
if (i < 1 || i > int(obj->layers.size()))
|
||||||
|
return luaL_error(L, "index out of bounds %d", i);
|
||||||
|
push_ptr<Layer>(L, obj->layers[i-1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Layers_methods[] = {
|
||||||
|
{ "__gc", Layers_gc },
|
||||||
|
{ "__len", Layers_len },
|
||||||
|
{ "__index", Layers_index },
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(LayersObj);
|
||||||
|
|
||||||
|
void register_layers_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Layers = LayersObj;
|
||||||
|
REG_CLASS(L, Layers);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_sprite_layers(lua_State* L, Sprite* sprite)
|
||||||
|
{
|
||||||
|
push_new<LayersObj>(L, sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
153
src/app/script/palette_class.cpp
Normal file
153
src/app/script/palette_class.cpp
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/cmd/set_palette.h"
|
||||||
|
#include "app/color.h"
|
||||||
|
#include "app/script/engine.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "app/tx.h"
|
||||||
|
#include "doc/palette.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct PaletteObj {
|
||||||
|
Sprite* sprite;
|
||||||
|
Palette* palette;
|
||||||
|
PaletteObj(Sprite* sprite, Palette* palette)
|
||||||
|
: sprite(sprite),
|
||||||
|
palette(palette) {
|
||||||
|
}
|
||||||
|
PaletteObj(const PaletteObj&) = delete;
|
||||||
|
PaletteObj& operator=(const PaletteObj&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Palette_new(lua_State* L)
|
||||||
|
{
|
||||||
|
int ncolors = lua_tointeger(L, 1);
|
||||||
|
push_new<PaletteObj>(L, nullptr, new Palette(0, ncolors));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Palette_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<PaletteObj>(L, 1)->~PaletteObj();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Palette_len(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<PaletteObj>(L, 1);
|
||||||
|
lua_pushinteger(L, obj->palette->size());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Palette_resize(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<PaletteObj>(L, 1);
|
||||||
|
int ncolors = lua_tointeger(L, 2);
|
||||||
|
if (obj->sprite) {
|
||||||
|
Palette newPal(*obj->palette);
|
||||||
|
newPal.resize(ncolors);
|
||||||
|
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetPalette(obj->sprite, obj->palette->frame(), &newPal));
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
obj->palette->resize(ncolors);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Palette_getColor(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<PaletteObj>(L, 1);
|
||||||
|
int i = lua_tointeger(L, 2);
|
||||||
|
if (i < 0 || i >= int(obj->palette->size()))
|
||||||
|
return luaL_error(L, "index out of bounds %d", i);
|
||||||
|
|
||||||
|
doc::color_t docColor = obj->palette->getEntry(i);
|
||||||
|
app::Color appColor = app::Color::fromRgb(doc::rgba_getr(docColor),
|
||||||
|
doc::rgba_getg(docColor),
|
||||||
|
doc::rgba_getb(docColor),
|
||||||
|
doc::rgba_geta(docColor));
|
||||||
|
|
||||||
|
push_obj<app::Color>(L, appColor);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Palette_setColor(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<PaletteObj>(L, 1);
|
||||||
|
int i = lua_tointeger(L, 2);
|
||||||
|
if (i < 0 || i >= int(obj->palette->size()))
|
||||||
|
return luaL_error(L, "index out of bounds %d", i);
|
||||||
|
|
||||||
|
doc::color_t docColor = convert_args_into_pixel_color(L, 3);
|
||||||
|
|
||||||
|
if (obj->sprite) {
|
||||||
|
Palette newPal(*obj->palette);
|
||||||
|
newPal.setEntry(i, docColor);
|
||||||
|
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetPalette(obj->sprite, obj->palette->frame(), &newPal));
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
obj->palette->setEntry(i, docColor);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Palette_get_frame(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<PaletteObj>(L, 1);
|
||||||
|
lua_pushinteger(L, obj->palette->frame()+1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Palette_methods[] = {
|
||||||
|
{ "__gc", Palette_gc },
|
||||||
|
{ "__len", Palette_len },
|
||||||
|
{ "resize", Palette_resize },
|
||||||
|
{ "getColor", Palette_getColor },
|
||||||
|
{ "setColor", Palette_setColor },
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Property Palette_properties[] = {
|
||||||
|
{ "frame", Palette_get_frame, nullptr },
|
||||||
|
{ nullptr, nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(PaletteObj);
|
||||||
|
|
||||||
|
void register_palette_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Palette = PaletteObj;
|
||||||
|
REG_CLASS(L, Palette);
|
||||||
|
REG_CLASS_NEW(L, Palette);
|
||||||
|
REG_CLASS_PROPERTIES(L, Palette);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_sprite_palette(lua_State* L, doc::Sprite* sprite, doc::Palette* palette)
|
||||||
|
{
|
||||||
|
push_new<PaletteObj>(L, sprite, palette);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
78
src/app/script/palettes_class.cpp
Normal file
78
src/app/script/palettes_class.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/script/engine.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct PalettesObj {
|
||||||
|
Sprite* sprite;
|
||||||
|
PalettesObj(Sprite* sprite)
|
||||||
|
: sprite(sprite) {
|
||||||
|
}
|
||||||
|
PalettesObj(const PalettesObj&) = delete;
|
||||||
|
PalettesObj& operator=(const PalettesObj&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Palettes_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<PalettesObj>(L, 1)->~PalettesObj();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Palettes_len(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<PalettesObj>(L, 1);
|
||||||
|
lua_pushinteger(L, obj->sprite->getPalettes().size());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Palettes_index(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<PalettesObj>(L, 1);
|
||||||
|
auto& pals = obj->sprite->getPalettes();
|
||||||
|
int i = lua_tointeger(L, 2);
|
||||||
|
if (i < 1 || i > int(pals.size()))
|
||||||
|
return luaL_error(L, "index out of bounds %d", i);
|
||||||
|
push_sprite_palette(L, obj->sprite, pals[i-1]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Palettes_methods[] = {
|
||||||
|
{ "__gc", Palettes_gc },
|
||||||
|
{ "__len", Palettes_len },
|
||||||
|
{ "__index", Palettes_index },
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(PalettesObj);
|
||||||
|
|
||||||
|
void register_palettes_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Palettes = PalettesObj;
|
||||||
|
REG_CLASS(L, Palettes);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_sprite_palettes(lua_State* L, Sprite* sprite)
|
||||||
|
{
|
||||||
|
push_new<PalettesObj>(L, sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
@ -44,6 +44,12 @@ int Point_new(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Point_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<gfx::Point>(L, 1)->~PointT();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int Point_get_x(lua_State* L)
|
int Point_get_x(lua_State* L)
|
||||||
{
|
{
|
||||||
const auto pt = get_obj<gfx::Point>(L, 1);
|
const auto pt = get_obj<gfx::Point>(L, 1);
|
||||||
@ -73,6 +79,7 @@ int Point_set_y(lua_State* L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const luaL_Reg Point_methods[] = {
|
const luaL_Reg Point_methods[] = {
|
||||||
|
{ "__gc", Point_gc },
|
||||||
{ nullptr, nullptr }
|
{ nullptr, nullptr }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -50,6 +50,12 @@ int Rectangle_new(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Rectangle_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<gfx::Rect>(L, 1)->~RectT();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int Rectangle_get_x(lua_State* L)
|
int Rectangle_get_x(lua_State* L)
|
||||||
{
|
{
|
||||||
const auto rc = get_obj<gfx::Rect>(L, 1);
|
const auto rc = get_obj<gfx::Rect>(L, 1);
|
||||||
@ -114,6 +120,7 @@ int Rectangle_get_isEmpty(lua_State* L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const luaL_Reg Rectangle_methods[] = {
|
const luaL_Reg Rectangle_methods[] = {
|
||||||
|
{ "__gc", Rectangle_gc },
|
||||||
{ nullptr, nullptr }
|
{ nullptr, nullptr }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ int Selection_get_bounds(lua_State* L)
|
|||||||
push_obj(L, doc->mask()->bounds());
|
push_obj(L, doc->mask()->bounds());
|
||||||
}
|
}
|
||||||
else { // Empty rectangle
|
else { // Empty rectangle
|
||||||
push_obj(L, gfx::Rect(0, 0, 0, 0));
|
push_new<gfx::Rect>(L, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -21,12 +21,39 @@ int Site_get_sprite(lua_State* L)
|
|||||||
{
|
{
|
||||||
auto site = get_obj<Site>(L, 1);
|
auto site = get_obj<Site>(L, 1);
|
||||||
if (site->sprite())
|
if (site->sprite())
|
||||||
push_ptr(L, site->sprite());
|
push_ptr<doc::Sprite>(L, site->sprite());
|
||||||
else
|
else
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Site_get_layer(lua_State* L)
|
||||||
|
{
|
||||||
|
auto site = get_obj<Site>(L, 1);
|
||||||
|
if (site->layer())
|
||||||
|
push_ptr<doc::Layer>(L, site->layer());
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Site_get_cel(lua_State* L)
|
||||||
|
{
|
||||||
|
auto site = get_obj<Site>(L, 1);
|
||||||
|
if (site->cel())
|
||||||
|
push_ptr<doc::Cel>(L, site->cel());
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Site_get_frame(lua_State* L)
|
||||||
|
{
|
||||||
|
auto site = get_obj<Site>(L, 1);
|
||||||
|
lua_pushinteger(L, site->frame()+1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int Site_get_image(lua_State* L)
|
int Site_get_image(lua_State* L)
|
||||||
{
|
{
|
||||||
auto site = get_obj<Site>(L, 1);
|
auto site = get_obj<Site>(L, 1);
|
||||||
@ -43,6 +70,9 @@ const luaL_Reg Site_methods[] = {
|
|||||||
|
|
||||||
const Property Site_properties[] = {
|
const Property Site_properties[] = {
|
||||||
{ "sprite", Site_get_sprite, nullptr },
|
{ "sprite", Site_get_sprite, nullptr },
|
||||||
|
{ "layer", Site_get_layer, nullptr },
|
||||||
|
{ "cel", Site_get_cel, nullptr },
|
||||||
|
{ "frame", Site_get_frame, nullptr },
|
||||||
{ "image", Site_get_image, nullptr },
|
{ "image", Site_get_image, nullptr },
|
||||||
{ nullptr, nullptr, nullptr }
|
{ nullptr, nullptr, nullptr }
|
||||||
};
|
};
|
||||||
|
@ -44,6 +44,12 @@ int Size_new(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Size_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<gfx::Size>(L, 1)->~SizeT();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int Size_get_width(lua_State* L)
|
int Size_get_width(lua_State* L)
|
||||||
{
|
{
|
||||||
const auto sz = get_obj<gfx::Size>(L, 1);
|
const auto sz = get_obj<gfx::Size>(L, 1);
|
||||||
@ -77,6 +83,7 @@ int Size_set_height(lua_State* L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const luaL_Reg Size_methods[] = {
|
const luaL_Reg Size_methods[] = {
|
||||||
|
{ "__gc", Size_gc },
|
||||||
{ nullptr, nullptr }
|
{ nullptr, nullptr }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
117
src/app/script/slice_class.cpp
Normal file
117
src/app/script/slice_class.cpp
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/script/engine.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "app/tx.h"
|
||||||
|
#include "doc/slice.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
int Slice_get_sprite(lua_State* L)
|
||||||
|
{
|
||||||
|
auto slice = get_ptr<Slice>(L, 1);
|
||||||
|
push_ptr(L, slice->owner()->sprite());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Slice_get_fromFrame(lua_State* L)
|
||||||
|
{
|
||||||
|
auto slice = get_ptr<Slice>(L, 1);
|
||||||
|
lua_pushinteger(L, slice->fromFrame());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Slice_get_toFrame(lua_State* L)
|
||||||
|
{
|
||||||
|
auto slice = get_ptr<Slice>(L, 1);
|
||||||
|
lua_pushinteger(L, slice->toFrame());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Slice_get_name(lua_State* L)
|
||||||
|
{
|
||||||
|
auto slice = get_ptr<Slice>(L, 1);
|
||||||
|
lua_pushstring(L, slice->name().c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Slice_get_bounds(lua_State* L)
|
||||||
|
{
|
||||||
|
auto slice = get_ptr<Slice>(L, 1);
|
||||||
|
if (!slice->empty())
|
||||||
|
push_new<gfx::Rect>(L, slice->begin()->value()->bounds());
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Slice_get_center(lua_State* L)
|
||||||
|
{
|
||||||
|
auto slice = get_ptr<Slice>(L, 1);
|
||||||
|
if (!slice->empty() && slice->begin()->value()->hasCenter())
|
||||||
|
push_new<gfx::Rect>(L, slice->begin()->value()->center());
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Slice_get_pivot(lua_State* L)
|
||||||
|
{
|
||||||
|
auto slice = get_ptr<Slice>(L, 1);
|
||||||
|
if (!slice->empty() && slice->begin()->value()->hasPivot())
|
||||||
|
push_new<gfx::Point>(L, slice->begin()->value()->pivot());
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Slice_get_userData(lua_State* L)
|
||||||
|
{
|
||||||
|
auto slice = get_ptr<Slice>(L, 1);
|
||||||
|
push_userdata(L, slice);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Slice_methods[] = {
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Property Slice_properties[] = {
|
||||||
|
{ "sprite", Slice_get_sprite, nullptr },
|
||||||
|
{ "fromFrame", Slice_get_fromFrame, nullptr },
|
||||||
|
{ "toFrame", Slice_get_toFrame, nullptr },
|
||||||
|
{ "name", Slice_get_name, nullptr },
|
||||||
|
{ "bounds", Slice_get_bounds, nullptr },
|
||||||
|
{ "center", Slice_get_center, nullptr },
|
||||||
|
{ "pivot", Slice_get_pivot, nullptr },
|
||||||
|
{ "userData", Slice_get_userData, nullptr },
|
||||||
|
{ nullptr, nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(Slice);
|
||||||
|
|
||||||
|
void register_slice_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using doc::Slice;
|
||||||
|
REG_CLASS(L, Slice);
|
||||||
|
REG_CLASS_PROPERTIES(L, Slice);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
76
src/app/script/slices_class.cpp
Normal file
76
src/app/script/slices_class.cpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/script/engine.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct SlicesObj {
|
||||||
|
Sprite* sprite;
|
||||||
|
SlicesObj(Sprite* sprite)
|
||||||
|
: sprite(sprite) {
|
||||||
|
}
|
||||||
|
SlicesObj(const SlicesObj&) = delete;
|
||||||
|
SlicesObj& operator=(const SlicesObj&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Slices_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<SlicesObj>(L, 1)->~SlicesObj();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Slices_len(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<SlicesObj>(L, 1);
|
||||||
|
lua_pushinteger(L, obj->sprite->slices().size());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Slices_index(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<SlicesObj>(L, 1);
|
||||||
|
auto& slices = obj->sprite->slices();
|
||||||
|
const int i = lua_tonumber(L, 2);
|
||||||
|
if (i < 1 || i > int(slices.size()))
|
||||||
|
return luaL_error(L, "index out of bounds %d", i);
|
||||||
|
push_ptr<Slice>(L, *(slices.begin()+i-1));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Slices_methods[] = {
|
||||||
|
{ "__gc", Slices_gc },
|
||||||
|
{ "__len", Slices_len },
|
||||||
|
{ "__index", Slices_index },
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(SlicesObj);
|
||||||
|
|
||||||
|
void register_slices_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Slices = SlicesObj;
|
||||||
|
REG_CLASS(L, Slices);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_sprite_slices(lua_State* L, Sprite* sprite)
|
||||||
|
{
|
||||||
|
push_new<SlicesObj>(L, sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
@ -22,6 +22,7 @@
|
|||||||
#include "app/transaction.h"
|
#include "app/transaction.h"
|
||||||
#include "app/tx.h"
|
#include "app/tx.h"
|
||||||
#include "app/ui/doc_view.h"
|
#include "app/ui/doc_view.h"
|
||||||
|
#include "doc/layer.h"
|
||||||
#include "doc/mask.h"
|
#include "doc/mask.h"
|
||||||
#include "doc/palette.h"
|
#include "doc/palette.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
@ -50,6 +51,14 @@ int Sprite_new(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Sprite_eq(lua_State* L)
|
||||||
|
{
|
||||||
|
const auto a = get_ptr<Sprite>(L, 1);
|
||||||
|
const auto b = get_ptr<Sprite>(L, 2);
|
||||||
|
lua_pushboolean(L, a->id() == b->id());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int Sprite_resize(lua_State* L)
|
int Sprite_resize(lua_State* L)
|
||||||
{
|
{
|
||||||
auto sprite = get_ptr<Sprite>(L, 1);
|
auto sprite = get_ptr<Sprite>(L, 1);
|
||||||
@ -189,6 +198,59 @@ int Sprite_get_selection(lua_State* L)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Sprite_get_frames(lua_State* L)
|
||||||
|
{
|
||||||
|
auto sprite = get_ptr<Sprite>(L, 1);
|
||||||
|
push_sprite_frames(L, sprite);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Sprite_get_palettes(lua_State* L)
|
||||||
|
{
|
||||||
|
auto sprite = get_ptr<Sprite>(L, 1);
|
||||||
|
push_sprite_palettes(L, sprite);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Sprite_get_layers(lua_State* L)
|
||||||
|
{
|
||||||
|
auto sprite = get_ptr<Sprite>(L, 1);
|
||||||
|
push_sprite_layers(L, sprite);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Sprite_get_cels(lua_State* L)
|
||||||
|
{
|
||||||
|
auto sprite = get_ptr<Sprite>(L, 1);
|
||||||
|
push_sprite_cels(L, sprite);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Sprite_get_tags(lua_State* L)
|
||||||
|
{
|
||||||
|
auto sprite = get_ptr<Sprite>(L, 1);
|
||||||
|
push_sprite_tags(L, sprite);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Sprite_get_slices(lua_State* L)
|
||||||
|
{
|
||||||
|
auto sprite = get_ptr<Sprite>(L, 1);
|
||||||
|
push_sprite_slices(L, sprite);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Sprite_get_backgroundLayer(lua_State* L)
|
||||||
|
{
|
||||||
|
auto sprite = get_ptr<Sprite>(L, 1);
|
||||||
|
doc::Layer* layer = sprite->backgroundLayer();
|
||||||
|
if (layer)
|
||||||
|
push_ptr(L, layer);
|
||||||
|
else
|
||||||
|
lua_pushnil(L);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int Sprite_set_width(lua_State* L)
|
int Sprite_set_width(lua_State* L)
|
||||||
{
|
{
|
||||||
auto sprite = get_ptr<Sprite>(L, 1);
|
auto sprite = get_ptr<Sprite>(L, 1);
|
||||||
@ -210,6 +272,7 @@ int Sprite_set_height(lua_State* L)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const luaL_Reg Sprite_methods[] = {
|
const luaL_Reg Sprite_methods[] = {
|
||||||
|
{ "__eq", Sprite_eq },
|
||||||
{ "resize", Sprite_resize },
|
{ "resize", Sprite_resize },
|
||||||
{ "crop", Sprite_crop },
|
{ "crop", Sprite_crop },
|
||||||
{ "save", Sprite_save },
|
{ "save", Sprite_save },
|
||||||
@ -225,6 +288,13 @@ const Property Sprite_properties[] = {
|
|||||||
{ "height", Sprite_get_height, Sprite_set_height },
|
{ "height", Sprite_get_height, Sprite_set_height },
|
||||||
{ "colorMode", Sprite_get_colorMode, nullptr },
|
{ "colorMode", Sprite_get_colorMode, nullptr },
|
||||||
{ "selection", Sprite_get_selection, nullptr },
|
{ "selection", Sprite_get_selection, nullptr },
|
||||||
|
{ "frames", Sprite_get_frames, nullptr },
|
||||||
|
{ "palettes", Sprite_get_palettes, nullptr },
|
||||||
|
{ "layers", Sprite_get_layers, nullptr },
|
||||||
|
{ "cels", Sprite_get_cels, nullptr },
|
||||||
|
{ "tags", Sprite_get_tags, nullptr },
|
||||||
|
{ "slices", Sprite_get_slices, nullptr },
|
||||||
|
{ "backgroundLayer", Sprite_get_backgroundLayer, nullptr },
|
||||||
{ nullptr, nullptr, nullptr }
|
{ nullptr, nullptr, nullptr }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
131
src/app/script/tag_class.cpp
Normal file
131
src/app/script/tag_class.cpp
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/cmd/set_frame_tag_anidir.h"
|
||||||
|
#include "app/cmd/set_frame_tag_name.h"
|
||||||
|
#include "app/cmd/set_frame_tag_range.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "app/tx.h"
|
||||||
|
#include "doc/frame_tag.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
int Tag_get_fromFrame(lua_State* L)
|
||||||
|
{
|
||||||
|
auto tag = get_ptr<FrameTag>(L, 1);
|
||||||
|
lua_pushinteger(L, tag->fromFrame());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tag_get_toFrame(lua_State* L)
|
||||||
|
{
|
||||||
|
auto tag = get_ptr<FrameTag>(L, 1);
|
||||||
|
lua_pushinteger(L, tag->toFrame());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tag_get_frames(lua_State* L)
|
||||||
|
{
|
||||||
|
auto tag = get_ptr<FrameTag>(L, 1);
|
||||||
|
lua_pushinteger(L, tag->frames());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tag_get_name(lua_State* L)
|
||||||
|
{
|
||||||
|
auto tag = get_ptr<FrameTag>(L, 1);
|
||||||
|
lua_pushstring(L, tag->name().c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tag_get_aniDir(lua_State* L)
|
||||||
|
{
|
||||||
|
auto tag = get_ptr<FrameTag>(L, 1);
|
||||||
|
lua_pushinteger(L, (int)tag->aniDir());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tag_set_fromFrame(lua_State* L)
|
||||||
|
{
|
||||||
|
auto tag = get_ptr<FrameTag>(L, 1);
|
||||||
|
const int fromFrame = lua_tointeger(L, 2);
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetFrameTagRange(tag, fromFrame,
|
||||||
|
std::max(fromFrame, tag->toFrame())));
|
||||||
|
tx.commit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tag_set_toFrame(lua_State* L)
|
||||||
|
{
|
||||||
|
auto tag = get_ptr<FrameTag>(L, 1);
|
||||||
|
const int toFrame = lua_tointeger(L, 2);
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetFrameTagRange(tag,
|
||||||
|
std::min(tag->fromFrame(), toFrame),
|
||||||
|
toFrame));
|
||||||
|
tx.commit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tag_set_name(lua_State* L)
|
||||||
|
{
|
||||||
|
auto tag = get_ptr<FrameTag>(L, 1);
|
||||||
|
const char* name = lua_tostring(L, 2);
|
||||||
|
if (name) {
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetFrameTagName(tag, name));
|
||||||
|
tx.commit();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tag_set_aniDir(lua_State* L)
|
||||||
|
{
|
||||||
|
auto tag = get_ptr<FrameTag>(L, 1);
|
||||||
|
const int aniDir = lua_tointeger(L, 2);
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetFrameTagAniDir(tag, (doc::AniDir)aniDir));
|
||||||
|
tx.commit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Tag_methods[] = {
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Property Tag_properties[] = {
|
||||||
|
{ "fromFrame", Tag_get_fromFrame, Tag_set_fromFrame },
|
||||||
|
{ "toFrame", Tag_get_toFrame, Tag_set_toFrame },
|
||||||
|
{ "frames", Tag_get_frames, nullptr },
|
||||||
|
{ "name", Tag_get_name, Tag_set_name },
|
||||||
|
{ "aniDir", Tag_get_aniDir, Tag_set_aniDir },
|
||||||
|
{ nullptr, nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(FrameTag);
|
||||||
|
|
||||||
|
void register_tag_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Tag = doc::FrameTag;
|
||||||
|
REG_CLASS(L, Tag);
|
||||||
|
REG_CLASS_PROPERTIES(L, Tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
78
src/app/script/tags_class.cpp
Normal file
78
src/app/script/tags_class.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/script/engine.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct TagsObj {
|
||||||
|
Sprite* sprite;
|
||||||
|
TagsObj(Sprite* sprite)
|
||||||
|
: sprite(sprite) {
|
||||||
|
}
|
||||||
|
TagsObj(const TagsObj&) = delete;
|
||||||
|
TagsObj& operator=(const TagsObj&) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
int Tags_gc(lua_State* L)
|
||||||
|
{
|
||||||
|
get_obj<TagsObj>(L, 1)->~TagsObj();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tags_len(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<TagsObj>(L, 1);
|
||||||
|
lua_pushinteger(L, obj->sprite->frameTags().size());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Tags_index(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_obj<TagsObj>(L, 1);
|
||||||
|
auto& tags = obj->sprite->frameTags();
|
||||||
|
const int i = lua_tonumber(L, 2);
|
||||||
|
if (i < 1 || i > int(tags.size()))
|
||||||
|
return luaL_error(L, "index out of bounds %d", i);
|
||||||
|
push_ptr<FrameTag>(L, *(tags.begin()+i-1));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg Tags_methods[] = {
|
||||||
|
{ "__gc", Tags_gc },
|
||||||
|
{ "__len", Tags_len },
|
||||||
|
{ "__index", Tags_index },
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(TagsObj);
|
||||||
|
|
||||||
|
void register_tags_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using Tags = TagsObj;
|
||||||
|
REG_CLASS(L, Tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_sprite_tags(lua_State* L, Sprite* sprite)
|
||||||
|
{
|
||||||
|
push_new<TagsObj>(L, sprite);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
97
src/app/script/userdata_class.cpp
Normal file
97
src/app/script/userdata_class.cpp
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
// Aseprite
|
||||||
|
// Copyright (C) 2018 David Capello
|
||||||
|
//
|
||||||
|
// This program is distributed under the terms of
|
||||||
|
// the End-User License Agreement for Aseprite.
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "app/cmd/set_user_data.h"
|
||||||
|
#include "app/color.h"
|
||||||
|
#include "app/color_utils.h"
|
||||||
|
#include "app/script/engine.h"
|
||||||
|
#include "app/script/luacpp.h"
|
||||||
|
#include "app/tx.h"
|
||||||
|
#include "doc/sprite.h"
|
||||||
|
#include "doc/with_user_data.h"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
namespace script {
|
||||||
|
|
||||||
|
using namespace doc;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
int UserData_get_text(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_ptr<WithUserData>(L, 1);
|
||||||
|
lua_pushstring(L, obj->userData().text().c_str());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UserData_get_color(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_ptr<WithUserData>(L, 1);
|
||||||
|
doc::color_t docColor = obj->userData().color();
|
||||||
|
app::Color appColor = app::Color::fromRgb(doc::rgba_getr(docColor),
|
||||||
|
doc::rgba_getg(docColor),
|
||||||
|
doc::rgba_getb(docColor),
|
||||||
|
doc::rgba_geta(docColor));
|
||||||
|
push_obj<app::Color>(L, appColor);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UserData_set_text(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_ptr<WithUserData>(L, 1);
|
||||||
|
const char* text = lua_tostring(L, 2);
|
||||||
|
UserData ud = obj->userData();
|
||||||
|
ud.setText(text);
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetUserData(obj, ud));
|
||||||
|
tx.commit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int UserData_set_color(lua_State* L)
|
||||||
|
{
|
||||||
|
auto obj = get_ptr<WithUserData>(L, 1);
|
||||||
|
doc::color_t docColor = convert_args_into_pixel_color(L, 2);
|
||||||
|
UserData ud = obj->userData();
|
||||||
|
ud.setColor(docColor);
|
||||||
|
Tx tx;
|
||||||
|
tx(new cmd::SetUserData(obj, ud));
|
||||||
|
tx.commit();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const luaL_Reg UserData_methods[] = {
|
||||||
|
{ nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
const Property UserData_properties[] = {
|
||||||
|
{ "text", UserData_get_text, UserData_set_text },
|
||||||
|
{ "color", UserData_get_color, UserData_set_color },
|
||||||
|
{ nullptr, nullptr, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
DEF_MTNAME(doc::WithUserData);
|
||||||
|
|
||||||
|
void register_userdata_class(lua_State* L)
|
||||||
|
{
|
||||||
|
using UserData = doc::WithUserData;
|
||||||
|
REG_CLASS(L, UserData);
|
||||||
|
REG_CLASS_PROPERTIES(L, UserData);
|
||||||
|
}
|
||||||
|
|
||||||
|
void push_userdata(lua_State* L, WithUserData* userData)
|
||||||
|
{
|
||||||
|
push_ptr<WithUserData>(L, userData);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace script
|
||||||
|
} // namespace app
|
@ -34,6 +34,12 @@ namespace doc {
|
|||||||
|
|
||||||
class iterator {
|
class iterator {
|
||||||
public:
|
public:
|
||||||
|
typedef Cel* value_type;
|
||||||
|
typedef std::ptrdiff_t difference_type;
|
||||||
|
typedef Cel** pointer;
|
||||||
|
typedef Cel*& reference;
|
||||||
|
typedef std::forward_iterator_tag iterator_category;
|
||||||
|
|
||||||
iterator(const SelectedFrames& selFrames);
|
iterator(const SelectedFrames& selFrames);
|
||||||
iterator(const Sprite* sprite,
|
iterator(const Sprite* sprite,
|
||||||
const SelectedFrames& selFrames,
|
const SelectedFrames& selFrames,
|
||||||
|
@ -66,6 +66,12 @@ namespace doc {
|
|||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
T* operator->() {
|
||||||
|
if (m_it != m_end)
|
||||||
|
return m_it->value();
|
||||||
|
else
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
iterator m_it, m_next;
|
iterator m_it, m_next;
|
||||||
const iterator m_end;
|
const iterator m_end;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user