Fix help for +tangent/-tangent to be less obscure
[lsnes.git] / src / lua / gui-box.cpp
blob666008de71622ee4874d0140ce62960f2115cac9
1 #include "core/instance.hpp"
2 #include "lua/internal.hpp"
3 #include "library/framebuffer.hpp"
4 #include "library/range.hpp"
5 #include "library/lua-framebuffer.hpp"
7 namespace
9 struct render_object_box : public framebuffer::object
11 render_object_box(int32_t _x, int32_t _y, int32_t _width, int32_t _height,
12 framebuffer::color _outline1, framebuffer::color _outline2, framebuffer::color _fill,
13 int32_t _thickness) throw()
14 : x(_x), y(_y), width(_width), height(_height), outline1(_outline1), outline2(_outline2),
15 fill(_fill), thickness(_thickness) {}
16 ~render_object_box() throw() {}
17 template<bool X> void op(struct framebuffer::fb<X>& scr) throw()
19 uint32_t oX = x + scr.get_origin_x();
20 uint32_t oY = y + scr.get_origin_y();
21 range bX = (range::make_w(scr.get_width()) - oX) & range::make_w(width);
22 range bY = (range::make_w(scr.get_height()) - oY) & range::make_w(height);
23 for(uint32_t r = bY.low(); r != bY.high(); r++) {
24 typename framebuffer::fb<X>::element_t* rptr = scr.rowptr(oY + r);
25 size_t eptr = oX + bX.low();
26 for(uint32_t c = bX.low(); c != bX.high(); c++, eptr++)
27 if((r < thickness && r <= (width - c)) || (c < thickness && c < (height - r)))
28 outline1.apply(rptr[eptr]);
29 else if(r < thickness || c < thickness || r >= height - thickness ||
30 c >= width - thickness)
31 outline2.apply(rptr[eptr]);
32 else
33 fill.apply(rptr[eptr]);
36 void operator()(struct framebuffer::fb<true>& scr) throw() { op(scr); }
37 void operator()(struct framebuffer::fb<false>& scr) throw() { op(scr); }
38 void clone(framebuffer::queue& q) const throw(std::bad_alloc) { q.clone_helper(this); }
39 private:
40 int32_t x;
41 int32_t y;
42 uint32_t width;
43 uint32_t height;
44 framebuffer::color outline1;
45 framebuffer::color outline2;
46 framebuffer::color fill;
47 uint32_t thickness;
50 int box(lua::state& L, lua::parameters& P)
52 auto& core = CORE();
53 int32_t x, y;
54 uint32_t width, height, thickness;
55 framebuffer::color poutline1, poutline2, pfill;
57 if(!core.lua2->render_ctx) return 0;
59 P(x, y, width, height, P.optional(thickness, 1), P.optional(poutline1, 0xFFFFFFU),
60 P.optional(poutline2, 0x808080U), P.optional(pfill, 0xC0C0C0U));
62 core.lua2->render_ctx->queue->create_add<render_object_box>(x, y, width, height, poutline1, poutline2,
63 pfill, thickness);
64 return 0;
67 lua::functions LUA_box_fns(lua_func_misc, "gui", {
68 {"box", box},
69 });