Premultiplied_color default constructor (transparent color)
[lsnes.git] / src / lua / gui-text.cpp
blob6b2598366168904d16001ba71f4d09d600a38021
1 #include "core/lua-int.hpp"
2 #include "core/render.hpp"
4 namespace
6 struct render_object_text : public render_object
8 render_object_text(int32_t _x, int32_t _y, const std::string& _text, premultiplied_color _fg,
9 premultiplied_color _bg, bool _hdbl = false, bool _vdbl = false) throw()
10 : x(_x), y(_y), text(_text), fg(_fg), bg(_bg), hdbl(_hdbl), vdbl(_vdbl) {}
11 ~render_object_text() throw() {}
12 void operator()(struct screen& scr) throw()
14 fg.set_palette(scr);
15 bg.set_palette(scr);
16 render_text(scr, x, y, text, fg, bg, hdbl, vdbl);
18 private:
19 int32_t x;
20 int32_t y;
21 premultiplied_color fg;
22 premultiplied_color bg;
23 std::string text;
24 bool hdbl;
25 bool vdbl;
28 int internal_gui_text(lua_State* LS, const std::string& fname, bool hdbl, bool vdbl)
30 if(!lua_render_ctx)
31 return 0;
32 int64_t fgc = 0xFFFFFFU;
33 int64_t bgc = -1;
34 int32_t _x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
35 int32_t _y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
36 get_numeric_argument<int64_t>(LS, 4, fgc, fname.c_str());
37 get_numeric_argument<int64_t>(LS, 5, bgc, fname.c_str());
38 std::string text = get_string_argument(LS, 3, fname.c_str());
39 premultiplied_color fg(fgc);
40 premultiplied_color bg(bgc);
41 lua_render_ctx->queue->add(*new render_object_text(_x, _y, text, fg, bg, hdbl, vdbl));
42 return 0;
45 function_ptr_luafun gui_text("gui.text", [](lua_State* LS, const std::string& fname) -> int {
46 internal_gui_text(LS, fname, false, false);
47 });
49 function_ptr_luafun gui_textH("gui.textH", [](lua_State* LS, const std::string& fname) -> int {
50 internal_gui_text(LS, fname, true, false);
51 });
53 function_ptr_luafun gui_textV("gui.textV", [](lua_State* LS, const std::string& fname) -> int {
54 internal_gui_text(LS, fname, false, true);
55 });
57 function_ptr_luafun gui_textHV("gui.textHV", [](lua_State* LS, const std::string& fname) -> int {
58 internal_gui_text(LS, fname, true, true);
59 });