From 28248bf228e5da33a697d4c307cd16923537b29f Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 19 Mar 2020 08:41:29 -0300 Subject: [PATCH] [lua] Add Tag.color property (fix https://github.com/aseprite/api/issues/24) --- src/app/script/api_version.h | 4 ++-- src/app/script/tag_class.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/app/script/api_version.h b/src/app/script/api_version.h index ec60e13cc..7c49ddfca 100644 --- a/src/app/script/api_version.h +++ b/src/app/script/api_version.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // // This program is distributed under the terms of // the End-User License Agreement for Aseprite. @@ -10,6 +10,6 @@ // Increment this value if the scripting API is modified between two // released Aseprite versions. -#define API_VERSION 9 +#define API_VERSION 10 #endif diff --git a/src/app/script/tag_class.cpp b/src/app/script/tag_class.cpp index 6c7791506..bffd158c1 100644 --- a/src/app/script/tag_class.cpp +++ b/src/app/script/tag_class.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2020 Igara Studio S.A. // Copyright (C) 2018 David Capello // // This program is distributed under the terms of @@ -10,6 +10,7 @@ #endif #include "app/cmd/set_tag_anidir.h" +#include "app/cmd/set_tag_color.h" #include "app/cmd/set_tag_name.h" #include "app/cmd/set_tag_range.h" #include "app/script/docobj.h" @@ -82,6 +83,20 @@ int Tag_get_aniDir(lua_State* L) return 1; } +int Tag_get_color(lua_State* L) +{ + auto tag = get_docobj(L, 1); + doc::color_t docColor = tag->color(); + app::Color appColor = app::Color::fromRgb(doc::rgba_getr(docColor), + doc::rgba_getg(docColor), + doc::rgba_getb(docColor), + doc::rgba_geta(docColor)); + if (appColor.getAlpha() == 0) + appColor = app::Color::fromMask(); + push_obj(L, appColor); + return 1; +} + int Tag_set_fromFrame(lua_State* L) { auto tag = get_docobj(L, 1); @@ -127,6 +142,16 @@ int Tag_set_aniDir(lua_State* L) return 0; } +int Tag_set_color(lua_State* L) +{ + auto tag = get_docobj(L, 1); + doc::color_t docColor = convert_args_into_pixel_color(L, 2, doc::IMAGE_RGB); + Tx tx; + tx(new cmd::SetTagColor(tag, docColor)); + tx.commit(); + return 0; +} + const luaL_Reg Tag_methods[] = { { "__eq", Tag_eq }, { nullptr, nullptr } @@ -139,6 +164,7 @@ const Property Tag_properties[] = { { "frames", Tag_get_frames, nullptr }, { "name", Tag_get_name, Tag_set_name }, { "aniDir", Tag_get_aniDir, Tag_set_aniDir }, + { "color", Tag_get_color, Tag_set_color }, { nullptr, nullptr, nullptr } };