Don't assume that rshift=16, gshift=8, bshift=0 in blending code
[lsnes.git] / src / lua / gui-crosshair.cpp
blob9dd4ecc225964162b736121d331dbd6912629e52
1 #include "core/lua-int.hpp"
2 #include "core/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 color.set_palette(scr);
14 int32_t xmin = -static_cast<int32_t>(length);
15 int32_t xmax = static_cast<int32_t>(length + 1);
16 int32_t ymin = -static_cast<int32_t>(length);
17 int32_t ymax = static_cast<int32_t>(length + 1);
18 clip_range(scr.originx, scr.width, x, xmin, xmax);
19 clip_range(scr.originy, scr.height, y, ymin, ymax);
20 if(xmin <= 0 && xmax > 0)
21 for(int32_t r = ymin; r < ymax; r++)
22 color.apply(scr.rowptr(y + r + scr.originy)[x + scr.originx]);
23 if(ymin <= 0 && ymax > 0)
24 for(int32_t r = xmin; r < xmax; r++)
25 color.apply(scr.rowptr(y + scr.originy)[x + r + scr.originx]);
27 private:
28 int32_t x;
29 int32_t y;
30 premultiplied_color color;
31 uint32_t length;
34 function_ptr_luafun gui_crosshair("gui.crosshair", [](lua_State* LS, const std::string& fname) -> int {
35 if(!lua_render_ctx)
36 return 0;
37 int64_t color = 0xFFFFFFU;
38 uint32_t length = 10;
39 int32_t x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
40 int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
41 get_numeric_argument<uint32_t>(LS, 3, length, fname.c_str());
42 get_numeric_argument<int64_t>(LS, 4, color, fname.c_str());
43 premultiplied_color pcolor(color);
44 lua_render_ctx->queue->add(*new render_object_crosshair(x, y, pcolor, length));
45 return 0;
46 });