Cleanup lua code by introducing lua::functions
[lsnes.git] / src / lua / gui-pixel.cpp
blob618db1ed833414d69d101acdd2fd361bea3a1642
1 #include "lua/internal.hpp"
2 #include "library/framebuffer.hpp"
3 #include "library/lua-framebuffer.hpp"
5 namespace
7 struct render_object_pixel : public framebuffer::object
9 render_object_pixel(int32_t _x, int32_t _y, framebuffer::color _color) throw()
10 : x(_x), y(_y), color(_color) {}
11 ~render_object_pixel() throw() {}
12 template<bool X> void op(struct framebuffer::fb<X>& scr) throw()
14 color.set_palette(scr);
15 int32_t _x = x + scr.get_origin_x();
16 int32_t _y = y + scr.get_origin_y();
17 if(_x < 0 || static_cast<uint32_t>(_x) >= scr.get_width())
18 return;
19 if(_y < 0 || static_cast<uint32_t>(_y) >= scr.get_height())
20 return;
21 color.apply(scr.rowptr(_y)[_x]);
23 void operator()(struct framebuffer::fb<true>& scr) throw() { op(scr); }
24 void operator()(struct framebuffer::fb<false>& scr) throw() { op(scr); }
25 void clone(framebuffer::queue& q) const throw(std::bad_alloc) { q.clone_helper(this); }
26 private:
27 int32_t x;
28 int32_t y;
29 framebuffer::color color;
32 int pixel(lua::state& L, lua::parameters& P)
34 int32_t x, y;
35 framebuffer::color pcolor;
37 if(!lua_render_ctx) return 0;
39 P(x, y, P.optional(pcolor, 0xFFFFFFU));
41 lua_render_ctx->queue->create_add<render_object_pixel>(x, y, pcolor);
42 return 0;
45 lua::functions pixel_fns(lua_func_misc, "gui", {
46 {"pixel", pixel},
47 });