Upload UI
[lsnes.git] / src / lua / gui-text.cpp
bloba32ba381c799463f29b474fce9e439c743c97d5d
1 #include "lua/internal.hpp"
2 #include "fonts/wrapper.hpp"
3 #include "library/framebuffer.hpp"
5 namespace
7 struct render_object_text : public render_object
9 render_object_text(int32_t _x, int32_t _y, const std::string& _text, premultiplied_color _fg,
10 premultiplied_color _bg, bool _hdbl = false, bool _vdbl = false) throw()
11 : x(_x), y(_y), text(_text), fg(_fg), bg(_bg), hdbl(_hdbl), vdbl(_vdbl) {}
12 ~render_object_text() throw() {}
13 template<bool X> void op(struct framebuffer<X>& scr) throw()
15 fg.set_palette(scr);
16 bg.set_palette(scr);
17 main_font.render(scr, x, y, text, fg, bg, hdbl, vdbl);
19 void operator()(struct framebuffer<true>& scr) throw() { op(scr); }
20 void operator()(struct framebuffer<false>& scr) throw() { op(scr); }
21 void clone(render_queue& q) const throw(std::bad_alloc) { q.clone_helper(this); }
22 private:
23 int32_t x;
24 int32_t y;
25 std::string text;
26 premultiplied_color fg;
27 premultiplied_color bg;
28 bool hdbl;
29 bool vdbl;
32 int internal_gui_text(lua_state& L, const std::string& fname, bool hdbl, bool vdbl)
34 if(!lua_render_ctx)
35 return 0;
36 int64_t fgc = 0xFFFFFFU;
37 int64_t bgc = -1;
38 int32_t _x = L.get_numeric_argument<int32_t>(1, fname.c_str());
39 int32_t _y = L.get_numeric_argument<int32_t>(2, fname.c_str());
40 L.get_numeric_argument<int64_t>(4, fgc, fname.c_str());
41 L.get_numeric_argument<int64_t>(5, bgc, fname.c_str());
42 std::string text = L.get_string(3, fname.c_str());
43 premultiplied_color fg(fgc);
44 premultiplied_color bg(bgc);
45 lua_render_ctx->queue->create_add<render_object_text>(_x, _y, text, fg, bg, hdbl, vdbl);
46 return 0;
49 function_ptr_luafun gui_text(lua_func_misc, "gui.text", [](lua_state& L, const std::string& fname) -> int {
50 return internal_gui_text(L, fname, false, false);
51 });
53 function_ptr_luafun gui_textH(lua_func_misc, "gui.textH", [](lua_state& L, const std::string& fname) -> int {
54 return internal_gui_text(L, fname, true, false);
55 });
57 function_ptr_luafun gui_textV(lua_func_misc, "gui.textV", [](lua_state& L, const std::string& fname) -> int {
58 return internal_gui_text(L, fname, false, true);
59 });
61 function_ptr_luafun gui_textHV(lua_func_misc, "gui.textHV", [](lua_state& L, const std::string& fname)
62 -> int {
63 return internal_gui_text(L, fname, true, true);
64 });