Since window is singleton anyway, get rid of window* parameters
[lsnes.git] / lua / gui-text.cpp
blob31944d3cae70525b09bb0cc42bac701e284e23d8
1 #include "lua-int.hpp"
2 #include "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, uint32_t _fg = 0xFFFFFFFFU,
9 uint16_t _fgalpha = 255, uint32_t _bg = 0, uint16_t _bgalpha = 0) throw(std::bad_alloc);
10 ~render_object_text() throw();
11 void operator()(struct screen& scr) throw();
12 private:
13 int32_t x;
14 int32_t y;
15 uint32_t fg;
16 uint16_t fgalpha;
17 uint32_t bg;
18 uint16_t bgalpha;
19 std::string text;
22 render_object_text::render_object_text(int32_t _x, int32_t _y, const std::string& _text, uint32_t _fg,
23 uint16_t _fgalpha, uint32_t _bg, uint16_t _bgalpha) throw(std::bad_alloc)
24 : x(_x), y(_y), fg(_fg), fgalpha(_fgalpha), bg(_bg), bgalpha(_bgalpha), text(_text)
28 void render_object_text::operator()(struct screen& scr) throw()
30 render_text(scr, x, y, text, fg, fgalpha, bg, bgalpha);
33 render_object_text::~render_object_text() throw()
37 class lua_gui_text : public lua_function
39 public:
40 lua_gui_text() : lua_function("gui.text") {}
41 int invoke(lua_State* LS)
43 if(!lua_render_ctx)
44 return 0;
45 uint32_t x255 = 255;
46 uint32_t fgc = (x255 << lua_render_ctx->rshift) | (x255 << lua_render_ctx->gshift) |
47 (x255 << lua_render_ctx->bshift);
48 uint32_t bgc = 0;
49 uint16_t fga = 256;
50 uint16_t bga = 0;
51 int32_t _x = get_numeric_argument<int32_t>(LS, 1, "gui.text");
52 int32_t _y = get_numeric_argument<int32_t>(LS, 2, "gui.text");
53 get_numeric_argument<uint32_t>(LS, 4, fgc, "gui.text");
54 get_numeric_argument<uint16_t>(LS, 5, fga, "gui.text");
55 get_numeric_argument<uint32_t>(LS, 6, bgc, "gui.text");
56 get_numeric_argument<uint16_t>(LS, 7, bga, "gui.text");
57 std::string text = get_string_argument(LS, 3, "gui.text");
58 lua_render_ctx->queue->add(*new render_object_text(_x, _y, text, fgc, fga, bgc, bga));
59 return 0;
61 } gui_text;