Evdev joystick plugin
[lsnes.git] / lua / gui-core.cpp
blob7f5d6e868d0490b79834fd36d35d2fa8e9e632d6
1 #include "lua-int.hpp"
2 #include "window.hpp"
4 namespace
6 class lua_gui_resolution : public lua_function
8 public:
9 lua_gui_resolution() : lua_function("gui.resolution") {}
10 int invoke(lua_State* LS)
12 if(!lua_render_ctx)
13 return 0;
14 lua_pushnumber(LS, lua_render_ctx->width);
15 lua_pushnumber(LS, lua_render_ctx->height);
16 return 2;
18 } gui_resolution;
20 template<uint32_t lua_render_context::*gap>
21 class lua_gui_set_gap : public lua_function
23 public:
24 lua_gui_set_gap(const std::string& name) : lua_function(name) {}
25 int invoke(lua_State* LS)
27 if(!lua_render_ctx)
28 return 0;
29 uint32_t g = get_numeric_argument<uint32_t>(LS, 1, fname.c_str());
30 if(g > 8192)
31 return 0; //Ignore ridiculous gap.
32 lua_render_ctx->*gap = g;
33 return 0;
37 lua_gui_set_gap<&lua_render_context::left_gap> lg("gui.left_gap");
38 lua_gui_set_gap<&lua_render_context::right_gap> rg("gui.right_gap");
39 lua_gui_set_gap<&lua_render_context::top_gap> tg("gui.top_gap");
40 lua_gui_set_gap<&lua_render_context::bottom_gap> bg("gui.bottom_gap");
42 function_ptr_luafun gui_repaint("gui.repaint", [](lua_State* LS, const std::string& fname) -> int {
43 lua_requests_repaint = true;
44 return 0;
45 });
47 function_ptr_luafun gui_sfupd("gui.subframe_update", [](lua_State* LS, const std::string& fname) -> int {
48 lua_requests_subframe_paint = get_boolean_argument(LS, 1, fname.c_str());
49 return 0;
50 });
52 function_ptr_luafun gui_color("gui.color", [](lua_State* LS, const std::string& fname) -> int {
53 int64_t a = 256;
54 int64_t r = get_numeric_argument<uint32_t>(LS, 1, fname.c_str());
55 int64_t g = get_numeric_argument<uint32_t>(LS, 2, fname.c_str());
56 int64_t b = get_numeric_argument<uint32_t>(LS, 3, fname.c_str());
57 get_numeric_argument<int64_t>(LS, 4, a, fname.c_str());
58 if(a > 0)
59 lua_pushnumber(LS, ((256 - a) << 24) | (r << 16) | (g << 8) | b);
60 else
61 lua_pushnumber(LS, -1);
62 return 1;
63 });
65 function_ptr_luafun gui_status("gui.status", [](lua_State* LS, const std::string& fname) -> int {
66 std::string name = get_string_argument(LS, 1, fname.c_str());
67 std::string value = get_string_argument(LS, 2, fname.c_str());
68 auto& w = window::get_emustatus();
69 if(value == "")
70 w.erase("L[" + name + "]");
71 else
72 w["L[" + name + "]"] = value;
73 return 1;
74 });