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"
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);
21 for(uint32_t r
= bY
.low(); r
!= bY
.high(); r
++)
22 color
.apply(scr
.rowptr(oY
+ r
)[oX
]);
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); }
33 framebuffer::color color
;
37 int crosshair(lua::state
& L
, lua::parameters
& P
)
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
);
52 lua::functions
LUA_crosshair_fns(lua_func_misc
, "gui", {
53 {"crosshair", crosshair
},