lsnes rr2-β24
[lsnes.git] / src / lua / gui-crosshair.cpp
blobb81ecacd88102fae0972f972d236771efa9ed73a
1 #include "core/instance.hpp"
2 #include "lua/internal.hpp"
3 #include "library/framebuffer.hpp"
4 #include "library/lua-framebuffer.hpp"
5 #include "library/range.hpp"
7 namespace
9 struct render_object_crosshair : public framebuffer::object
11 render_object_crosshair(int32_t _x, int32_t _y, framebuffer::color _color, uint32_t _length) throw()
12 : x(_x), y(_y), color(_color), length(_length) {}
13 ~render_object_crosshair() throw() {}
14 template<bool X> void op(struct framebuffer::fb<X>& scr) throw()
16 uint32_t oX = x + scr.get_origin_x();
17 uint32_t oY = y + scr.get_origin_y();
18 range bX = (range::make_w(scr.get_width()) - oX) & range::make_b(-length, length + 1);
19 range bY = (range::make_w(scr.get_height()) - oY) & range::make_b(-length, length + 1);
20 if(bX.in(0))
21 for(uint32_t r = bY.low(); r != bY.high(); r++)
22 color.apply(scr.rowptr(oY + r)[oX]);
23 if(bY.in(0))
24 for(uint32_t r = bX.low(); r != bX.high(); r++)
25 color.apply(scr.rowptr(oY)[oX + r]);
27 void operator()(struct framebuffer::fb<true>& scr) throw() { op(scr); }
28 void operator()(struct framebuffer::fb<false>& scr) throw() { op(scr); }
29 void clone(framebuffer::queue& q) const throw(std::bad_alloc) { q.clone_helper(this); }
30 private:
31 int32_t x;
32 int32_t y;
33 framebuffer::color color;
34 uint32_t length;
37 int crosshair(lua::state& L, lua::parameters& P)
39 auto& core = CORE();
40 int32_t x, y;
41 uint32_t length;
42 framebuffer::color pcolor;
44 if(!core.lua2->render_ctx) return 0;
46 P(x, y, P.optional(length, 10), P.optional(pcolor, 0xFFFFFFU));
48 core.lua2->render_ctx->queue->create_add<render_object_crosshair>(x, y, pcolor, length);
49 return 0;
52 lua::functions LUA_crosshair_fns(lua_func_misc, "gui", {
53 {"crosshair", crosshair},
54 });