Upload UI
[lsnes.git] / src / lua / gui-crosshair.cpp
blob54b3e8390e45989322c6043f7660597eff0e9ad0
1 #include "lua/internal.hpp"
2 #include "library/framebuffer.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 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); }
31 void clone(render_queue& q) const throw(std::bad_alloc) { q.clone_helper(this); }
32 private:
33 int32_t x;
34 int32_t y;
35 premultiplied_color color;
36 uint32_t length;
39 function_ptr_luafun gui_crosshair(lua_func_misc, "gui.crosshair", [](lua_state& L, const std::string& fname)
40 -> int {
41 if(!lua_render_ctx)
42 return 0;
43 int64_t color = 0xFFFFFFU;
44 uint32_t length = 10;
45 int32_t x = L.get_numeric_argument<int32_t>(1, fname.c_str());
46 int32_t y = L.get_numeric_argument<int32_t>(2, fname.c_str());
47 L.get_numeric_argument<uint32_t>(3, length, fname.c_str());
48 L.get_numeric_argument<int64_t>(4, color, fname.c_str());
49 premultiplied_color pcolor(color);
50 lua_render_ctx->queue->create_add<render_object_crosshair>(x, y, pcolor, length);
51 return 0;
52 });