Evdev joystick plugin
[lsnes.git] / lua / gui-crosshair.cpp
blob2f1a2c787200976ea15c89fc2ea9cf614ca42932
1 #include "lua-int.hpp"
2 #include "render.hpp"
4 namespace
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 void operator()(struct screen& scr) throw()
13 int32_t xmin = -static_cast<int32_t>(length);
14 int32_t xmax = static_cast<int32_t>(length + 1);
15 int32_t ymin = -static_cast<int32_t>(length);
16 int32_t ymax = static_cast<int32_t>(length + 1);
17 clip_range(scr.originx, scr.width, x, xmin, xmax);
18 clip_range(scr.originy, scr.height, y, ymin, ymax);
19 if(xmin <= 0 && xmax > 0)
20 for(int32_t r = ymin; r < ymax; r++)
21 color.apply(scr.rowptr(y + r + scr.originy)[x + scr.originx]);
22 if(ymin <= 0 && ymax > 0)
23 for(int32_t r = xmin; r < xmax; r++)
24 color.apply(scr.rowptr(y + scr.originy)[x + r + scr.originx]);
26 private:
27 int32_t x;
28 int32_t y;
29 premultiplied_color color;
30 uint32_t length;
33 function_ptr_luafun gui_crosshair("gui.crosshair", [](lua_State* LS, const std::string& fname) -> int {
34 if(!lua_render_ctx)
35 return 0;
36 int64_t color = 0xFFFFFFU;
37 uint32_t length = 10;
38 int32_t x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
39 int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
40 get_numeric_argument<uint32_t>(LS, 3, length, fname.c_str());
41 get_numeric_argument<int64_t>(LS, 4, color, fname.c_str());
42 premultiplied_color pcolor(color);
43 lua_render_ctx->queue->add(*new render_object_crosshair(x, y, pcolor, length));
44 return 0;
45 });