Change color notation to allow Lua scripts use full truecolor
[lsnes.git] / lua / gui-core.cpp
blob957d77c8d61f446dbaa2f4b961e8296fe83aa058
1 #include "lua-int.hpp"
3 namespace
5 class lua_gui_resolution : public lua_function
7 public:
8 lua_gui_resolution() : lua_function("gui.resolution") {}
9 int invoke(lua_State* LS)
11 if(!lua_render_ctx)
12 return 0;
13 lua_pushnumber(LS, lua_render_ctx->width);
14 lua_pushnumber(LS, lua_render_ctx->height);
15 return 2;
17 } gui_resolution;
19 template<uint32_t lua_render_context::*gap>
20 class lua_gui_set_gap : public lua_function
22 public:
23 lua_gui_set_gap(const std::string& name) : lua_function(name) {}
24 int invoke(lua_State* LS)
26 if(!lua_render_ctx)
27 return 0;
28 uint32_t g = get_numeric_argument<uint32_t>(LS, 1, fname.c_str());
29 if(g > 8192)
30 return 0; //Ignore ridiculous gap.
31 lua_render_ctx->*gap = g;
32 return 0;
36 lua_gui_set_gap<&lua_render_context::left_gap> lg("gui.left_gap");
37 lua_gui_set_gap<&lua_render_context::right_gap> rg("gui.right_gap");
38 lua_gui_set_gap<&lua_render_context::top_gap> tg("gui.top_gap");
39 lua_gui_set_gap<&lua_render_context::bottom_gap> bg("gui.bottom_gap");
41 function_ptr_luafun gui_repaint("gui.repaint", [](lua_State* LS, const std::string& fname) -> int {
42 lua_requests_repaint = true;
43 return 0;
44 });
46 function_ptr_luafun gui_sfupd("gui.subframe_update", [](lua_State* LS, const std::string& fname) -> int {
47 lua_requests_subframe_paint = get_boolean_argument(LS, 1, fname.c_str());
48 return 0;
49 });
51 function_ptr_luafun gui_color("gui.color", [](lua_State* LS, const std::string& fname) -> int {
52 int64_t a = 256;
53 int64_t r = get_numeric_argument<uint32_t>(LS, 1, fname.c_str());
54 int64_t g = get_numeric_argument<uint32_t>(LS, 2, fname.c_str());
55 int64_t b = get_numeric_argument<uint32_t>(LS, 3, fname.c_str());
56 get_numeric_argument<int64_t>(LS, 4, a, fname.c_str());
57 if(a > 0)
58 lua_pushnumber(LS, ((256 - a) << 24) | (r << 16) | (g << 8) | b);
59 else
60 lua_pushnumber(LS, -1);
61 return 1;
62 });