Upload UI
[lsnes.git] / src / lua / gui-rectangle.cpp
blob69c465aba34eed4727afcfbadc67d0f1f15416a6
1 #include "lua/internal.hpp"
2 #include "library/framebuffer.hpp"
4 namespace
6 struct render_object_rectangle : public render_object
8 render_object_rectangle(int32_t _x, int32_t _y, int32_t _width, int32_t _height,
9 premultiplied_color _outline, premultiplied_color _fill, int32_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 framebuffer<X>& scr) throw()
15 outline.set_palette(scr);
16 fill.set_palette(scr);
17 uint32_t originx = scr.get_origin_x();
18 uint32_t originy = scr.get_origin_y();
19 int32_t xmin = 0;
20 int32_t xmax = width;
21 int32_t ymin = 0;
22 int32_t ymax = height;
23 clip_range(originx, scr.get_width(), x, xmin, xmax);
24 clip_range(originy, scr.get_height(), y, ymin, ymax);
25 for(int32_t r = ymin; r < ymax; r++) {
26 typename framebuffer<X>::element_t* rptr = scr.rowptr(y + r + originy);
27 size_t eptr = x + xmin + originx;
28 for(int32_t c = xmin; c < xmax; c++, eptr++)
29 if(r < thickness || c < thickness || r >= height - thickness ||
30 c >= width - thickness)
31 outline.apply(rptr[eptr]);
32 else
33 fill.apply(rptr[eptr]);
36 void operator()(struct framebuffer<true>& scr) throw() { op(scr); }
37 void operator()(struct framebuffer<false>& scr) throw() { op(scr); }
38 void clone(render_queue& q) const throw(std::bad_alloc) { q.clone_helper(this); }
39 private:
40 int32_t x;
41 int32_t y;
42 int32_t width;
43 int32_t height;
44 premultiplied_color outline;
45 premultiplied_color fill;
46 int32_t thickness;
49 function_ptr_luafun gui_rectangle(lua_func_misc, "gui.rectangle", [](lua_state& L, const std::string& fname)
50 -> int {
51 if(!lua_render_ctx)
52 return 0;
53 int64_t outline = 0xFFFFFFU;
54 int64_t fill = -1;
55 uint32_t thickness = 1;
56 int32_t x = L.get_numeric_argument<int32_t>(1, fname.c_str());
57 int32_t y = L.get_numeric_argument<int32_t>(2, fname.c_str());
58 uint32_t width = L.get_numeric_argument<uint32_t>(3, fname.c_str());
59 uint32_t height = L.get_numeric_argument<uint32_t>(4, fname.c_str());
60 L.get_numeric_argument<uint32_t>(5, thickness, fname.c_str());
61 L.get_numeric_argument<int64_t>(6, outline, fname.c_str());
62 L.get_numeric_argument<int64_t>(7, fill, fname.c_str());
63 premultiplied_color poutline(outline);
64 premultiplied_color pfill(fill);
65 lua_render_ctx->queue->create_add<render_object_rectangle>(x, y, width, height, poutline, pfill,
66 thickness);
67 return 0;
68 });