1 #include "lua/internal.hpp"
2 #include "library/framebuffer.hpp"
6 struct render_object_crosshair
: public render_object
8 render_object_crosshair(int32_t _x
, int32_t _y
, premultiplied_color _color
, uint32_t _length
) throw()
9 : x(_x
), y(_y
), color(_color
), length(_length
) {}
10 ~render_object_crosshair() throw() {}
11 template<bool X
> void op(struct framebuffer
<X
>& scr
) throw()
13 color
.set_palette(scr
);
14 uint32_t originx
= scr
.get_origin_x();
15 uint32_t originy
= scr
.get_origin_y();
16 int32_t xmin
= -static_cast<int32_t>(length
);
17 int32_t xmax
= static_cast<int32_t>(length
+ 1);
18 int32_t ymin
= -static_cast<int32_t>(length
);
19 int32_t ymax
= static_cast<int32_t>(length
+ 1);
20 clip_range(originx
, scr
.get_width(), x
, xmin
, xmax
);
21 clip_range(originy
, scr
.get_height(), y
, ymin
, ymax
);
22 if(xmin
<= 0 && xmax
> 0)
23 for(int32_t r
= ymin
; r
< ymax
; r
++)
24 color
.apply(scr
.rowptr(y
+ r
+ originy
)[x
+ originx
]);
25 if(ymin
<= 0 && ymax
> 0)
26 for(int32_t r
= xmin
; r
< xmax
; r
++)
27 color
.apply(scr
.rowptr(y
+ originy
)[x
+ r
+ originx
]);
29 void operator()(struct framebuffer
<true>& scr
) throw() { op(scr
); }
30 void operator()(struct framebuffer
<false>& scr
) throw() { op(scr
); }
34 premultiplied_color color
;
38 function_ptr_luafun
gui_crosshair(LS
, "gui.crosshair", [](lua_state
& L
, const std::string
& fname
) -> int {
41 int64_t color
= 0xFFFFFFU
;
43 int32_t x
= L
.get_numeric_argument
<int32_t>(1, fname
.c_str());
44 int32_t y
= L
.get_numeric_argument
<int32_t>(2, fname
.c_str());
45 L
.get_numeric_argument
<uint32_t>(3, length
, fname
.c_str());
46 L
.get_numeric_argument
<int64_t>(4, color
, fname
.c_str());
47 premultiplied_color
pcolor(color
);
48 lua_render_ctx
->queue
->create_add
<render_object_crosshair
>(x
, y
, pcolor
, length
);