1 #include "lua/internal.hpp"
2 #include "library/framebuffer.hpp"
3 #include "library/range.hpp"
4 #include "library/lua-framebuffer.hpp"
8 struct render_object_rectangle
: public framebuffer::object
10 render_object_rectangle(int32_t _x
, int32_t _y
, int32_t _width
, int32_t _height
,
11 framebuffer::color _outline
, framebuffer::color _fill
, int32_t _thickness
) throw()
12 : x(_x
), y(_y
), width(_width
), height(_height
), outline(_outline
), fill(_fill
),
13 thickness(_thickness
) {}
14 ~render_object_rectangle() throw() {}
15 template<bool X
> void op(struct framebuffer::fb
<X
>& scr
) throw()
17 uint32_t oX
= x
+ scr
.get_origin_x();
18 uint32_t oY
= y
+ scr
.get_origin_y();
19 range bX
= (range::make_w(scr
.get_width()) - oX
) & range::make_w(width
);
20 range bY
= (range::make_w(scr
.get_height()) - oY
) & range::make_w(height
);
21 for(uint32_t r
= bY
.low(); r
!= bY
.high(); r
++) {
22 typename
framebuffer::fb
<X
>::element_t
* rptr
= scr
.rowptr(oY
+ r
);
23 size_t eptr
= oX
+ bX
.low();
24 for(uint32_t c
= bX
.low(); c
!= bX
.high(); c
++, eptr
++)
25 if(r
< thickness
|| c
< thickness
|| r
>= height
- thickness
||
26 c
>= width
- thickness
)
27 outline
.apply(rptr
[eptr
]);
29 fill
.apply(rptr
[eptr
]);
32 void operator()(struct framebuffer::fb
<true>& scr
) throw() { op(scr
); }
33 void operator()(struct framebuffer::fb
<false>& scr
) throw() { op(scr
); }
34 void clone(framebuffer::queue
& q
) const throw(std::bad_alloc
) { q
.clone_helper(this); }
40 framebuffer::color outline
;
41 framebuffer::color fill
;
45 int rectangle(lua::state
& L
, lua::parameters
& P
)
48 uint32_t width
, height
, thickness
;
49 framebuffer::color poutline
, pfill
;
51 if(!lua_render_ctx
) return 0;
53 P(x
, y
, width
, height
, P
.optional(thickness
, 1), P
.optional(poutline
, 0xFFFFFFU
),
54 P
.optional(pfill
, -1));
56 lua_render_ctx
->queue
->create_add
<render_object_rectangle
>(x
, y
, width
, height
, poutline
, pfill
,
61 lua::functions
rectangle_fns(lua_func_misc
, "gui", {
62 {"rectangle", rectangle
},