Evdev joystick plugin
[lsnes.git] / lua / gui-rectangle.cpp
blobf2b52edecb08d6f803dec88a4b7bdbf2c5a5896b
1 #include "lua-int.hpp"
2 #include "render.hpp"
4 namespace
6 struct render_object_rectangle : public render_object
8 render_object_rectangle(int32_t _x, int32_t _y, uint32_t _width, uint32_t _height,
9 premultiplied_color _outline, premultiplied_color _fill, uint32_t _thickness) throw()
10 : x(_x), y(_y), width(_width), height(_height), outline(_outline), fill(_fill),
11 thickness(_thickness) {}
12 ~render_object_rectangle() throw() {}
13 void operator()(struct screen& scr) throw()
15 int32_t xmin = 0;
16 int32_t xmax = width;
17 int32_t ymin = 0;
18 int32_t ymax = height;
19 clip_range(scr.originx, scr.width, x, xmin, xmax);
20 clip_range(scr.originy, scr.height, y, ymin, ymax);
21 for(int32_t r = ymin; r < ymax; r++) {
22 uint32_t* rptr = scr.rowptr(y + r + scr.originy);
23 size_t eptr = x + xmin + scr.originx;
24 for(int32_t c = xmin; c < xmax; c++, eptr++)
25 if(r < thickness || c < thickness || r >= height - thickness ||
26 c >= width - thickness)
27 outline.apply(rptr[eptr]);
28 else
29 fill.apply(rptr[eptr]);
32 private:
33 int32_t x;
34 int32_t y;
35 uint32_t width;
36 uint32_t height;
37 premultiplied_color outline;
38 premultiplied_color fill;
39 uint32_t thickness;
42 function_ptr_luafun gui_rectangle("gui.rectangle", [](lua_State* LS, const std::string& fname) -> int {
43 if(!lua_render_ctx)
44 return 0;
45 int64_t outline = 0xFFFFFFU;
46 int64_t fill = -1;
47 uint32_t thickness = 1;
48 int32_t x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
49 int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
50 uint32_t width = get_numeric_argument<uint32_t>(LS, 3, fname.c_str());
51 uint32_t height = get_numeric_argument<uint32_t>(LS, 4, fname.c_str());
52 get_numeric_argument<uint32_t>(LS, 5, thickness, fname.c_str());
53 get_numeric_argument<int64_t>(LS, 6, outline, fname.c_str());
54 get_numeric_argument<int64_t>(LS, 7, fill, fname.c_str());
55 premultiplied_color poutline(outline);
56 premultiplied_color pfill(fill);
57 lua_render_ctx->queue->add(*new render_object_rectangle(x, y, width, height, poutline, pfill,
58 thickness));
59 return 0;
60 });