mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-14 04:19:12 +00:00
[lua] Add app.theme.dimension/color.id to access theme values
This commit is contained in:
parent
a98f81288d
commit
3d9021d717
@ -164,6 +164,7 @@ if(ENABLE_SCRIPTING)
|
||||
script/app_command_object.cpp
|
||||
script/app_fs_object.cpp
|
||||
script/app_object.cpp
|
||||
script/app_theme_object.cpp
|
||||
script/brush_class.cpp
|
||||
script/canvas_widget.cpp
|
||||
script/cel_class.cpp
|
||||
|
@ -480,6 +480,12 @@ int App_get_events(lua_State* L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int App_get_theme(lua_State* L)
|
||||
{
|
||||
push_app_theme(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int App_get_activeSprite(lua_State* L)
|
||||
{
|
||||
app::Context* ctx = App::instance()->context();
|
||||
@ -761,6 +767,7 @@ const Property App_properties[] = {
|
||||
{ "isUIAvailable", App_get_isUIAvailable, nullptr },
|
||||
{ "defaultPalette", App_get_defaultPalette, App_set_defaultPalette },
|
||||
{ "events", App_get_events, nullptr },
|
||||
{ "theme", App_get_theme, nullptr },
|
||||
{ nullptr, nullptr, nullptr }
|
||||
};
|
||||
|
||||
|
107
src/app/script/app_theme_object.cpp
Normal file
107
src/app/script/app_theme_object.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
// Aseprite
|
||||
// Copyright (c) 2022 Igara Studio S.A.
|
||||
//
|
||||
// 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"
|
||||
#include "app/ui/skin/skin_theme.h"
|
||||
|
||||
namespace app {
|
||||
namespace script {
|
||||
|
||||
namespace {
|
||||
|
||||
struct Theme { };
|
||||
struct ThemeDimension { };
|
||||
struct ThemeColor { };
|
||||
|
||||
int ThemeDimension_index(lua_State* L)
|
||||
{
|
||||
const char* id = lua_tostring(L, 2);
|
||||
if (!id)
|
||||
return luaL_error(L, "id in app.theme.dimension.id must be a string");
|
||||
|
||||
#ifdef ENABLE_UI
|
||||
const int value = skin::SkinTheme::instance()->getDimensionById(id);
|
||||
lua_pushinteger(L, value);
|
||||
#else
|
||||
lua_pushinteger(L, 0);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ThemeColor_index(lua_State* L)
|
||||
{
|
||||
const char* id = lua_tostring(L, 2);
|
||||
if (!id)
|
||||
return luaL_error(L, "id in app.theme.color.id must be a string");
|
||||
|
||||
#ifdef ENABLE_UI
|
||||
const gfx::Color uiColor = skin::SkinTheme::instance()->getColorById(id);
|
||||
push_obj<app::Color>(L, color_utils::color_from_ui(uiColor));
|
||||
#else
|
||||
push_obj<app::Color>(L, app::Color::fromMask());
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Theme_get_dimension(lua_State* L)
|
||||
{
|
||||
push_obj<ThemeDimension>(L, ThemeDimension());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Theme_get_color(lua_State* L)
|
||||
{
|
||||
push_obj<ThemeColor>(L, ThemeColor());
|
||||
return 1;
|
||||
}
|
||||
|
||||
const luaL_Reg Theme_methods[] = {
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
const Property Theme_properties[] = {
|
||||
{ "dimension", Theme_get_dimension, nullptr },
|
||||
{ "color", Theme_get_color, nullptr },
|
||||
{ nullptr, nullptr, nullptr }
|
||||
};
|
||||
|
||||
const luaL_Reg ThemeDimension_methods[] = {
|
||||
{ "__index", ThemeDimension_index },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
const luaL_Reg ThemeColor_methods[] = {
|
||||
{ "__index", ThemeColor_index },
|
||||
{ nullptr, nullptr }
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
DEF_MTNAME(Theme);
|
||||
DEF_MTNAME(ThemeDimension);
|
||||
DEF_MTNAME(ThemeColor);
|
||||
|
||||
void register_theme_classes(lua_State* L)
|
||||
{
|
||||
REG_CLASS(L, Theme);
|
||||
REG_CLASS(L, ThemeDimension);
|
||||
REG_CLASS(L, ThemeColor);
|
||||
REG_CLASS_PROPERTIES(L, Theme);
|
||||
}
|
||||
|
||||
void push_app_theme(lua_State* L)
|
||||
{
|
||||
push_obj<Theme>(L, Theme());
|
||||
}
|
||||
|
||||
} // namespace script
|
||||
} // namespace app
|
@ -186,6 +186,7 @@ void register_sprite_class(lua_State* L);
|
||||
void register_sprites_class(lua_State* L);
|
||||
void register_tag_class(lua_State* L);
|
||||
void register_tags_class(lua_State* L);
|
||||
void register_theme_classes(lua_State* L);
|
||||
void register_tileset_class(lua_State* L);
|
||||
void register_tilesets_class(lua_State* L);
|
||||
void register_tool_class(lua_State* L);
|
||||
@ -440,6 +441,7 @@ Engine::Engine()
|
||||
register_sprites_class(L);
|
||||
register_tag_class(L);
|
||||
register_tags_class(L);
|
||||
register_theme_classes(L);
|
||||
register_tileset_class(L);
|
||||
register_tilesets_class(L);
|
||||
register_tool_class(L);
|
||||
|
@ -135,6 +135,7 @@ namespace app {
|
||||
};
|
||||
|
||||
void push_app_events(lua_State* L);
|
||||
void push_app_theme(lua_State* L);
|
||||
int push_image_iterator_function(lua_State* L, const doc::Image* image, int extraArgIndex);
|
||||
void push_brush(lua_State* L, const doc::BrushRef& brush);
|
||||
void push_cel_image(lua_State* L, doc::Cel* cel);
|
||||
|
Loading…
x
Reference in New Issue
Block a user