Hicolor raw dumping
[lsnes.git] / src / lua / gui-rectangle.cpp
blob24e58910795ae44390097102e46e9a0a5799ddb7
1 #include "lua/internal.hpp"
2 #include "core/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 template<bool X> void op(struct screen<X>& scr) throw()
15 outline.set_palette(scr);
16 fill.set_palette(scr);
17 int32_t xmin = 0;
18 int32_t xmax = width;
19 int32_t ymin = 0;
20 int32_t ymax = height;
21 clip_range(scr.originx, scr.width, x, xmin, xmax);
22 clip_range(scr.originy, scr.height, y, ymin, ymax);
23 for(int32_t r = ymin; r < ymax; r++) {
24 typename screen<X>::element_t* rptr = scr.rowptr(y + r + scr.originy);
25 size_t eptr = x + xmin + scr.originx;
26 for(int32_t c = xmin; c < xmax; c++, eptr++)
27 if(r < thickness || c < thickness || r >= height - thickness ||
28 c >= width - thickness)
29 outline.apply(rptr[eptr]);
30 else
31 fill.apply(rptr[eptr]);
34 void operator()(struct screen<true>& scr) throw() { op(scr); }
35 void operator()(struct screen<false>& scr) throw() { op(scr); }
36 private:
37 int32_t x;
38 int32_t y;
39 uint32_t width;
40 uint32_t height;
41 premultiplied_color outline;
42 premultiplied_color fill;
43 uint32_t thickness;
46 function_ptr_luafun gui_rectangle("gui.rectangle", [](lua_State* LS, const std::string& fname) -> int {
47 if(!lua_render_ctx)
48 return 0;
49 int64_t outline = 0xFFFFFFU;
50 int64_t fill = -1;
51 uint32_t thickness = 1;
52 int32_t x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
53 int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
54 uint32_t width = get_numeric_argument<uint32_t>(LS, 3, fname.c_str());
55 uint32_t height = get_numeric_argument<uint32_t>(LS, 4, fname.c_str());
56 get_numeric_argument<uint32_t>(LS, 5, thickness, fname.c_str());
57 get_numeric_argument<int64_t>(LS, 6, outline, fname.c_str());
58 get_numeric_argument<int64_t>(LS, 7, fill, fname.c_str());
59 premultiplied_color poutline(outline);
60 premultiplied_color pfill(fill);
61 lua_render_ctx->queue->add(*new render_object_rectangle(x, y, width, height, poutline, pfill,
62 thickness));
63 return 0;
64 });