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_circle
: public framebuffer::object
10 render_object_circle(int32_t _x
, int32_t _y
, uint32_t _radius
,
11 framebuffer::color _outline
, framebuffer::color _fill
, uint32_t _thickness
) throw()
12 : x(_x
), y(_y
), outline(_outline
), fill(_fill
)
15 radius2
= static_cast<uint64_t>(_radius
) * _radius
;
16 if(_thickness
> _radius
)
19 iradius2
= static_cast<uint64_t>(_radius
- _thickness
) *
20 (_radius
- _thickness
);
22 ~render_object_circle() throw() {}
23 template<bool X
> void op(struct framebuffer::fb
<X
>& scr
) throw()
25 uint32_t oX
= x
+ scr
.get_origin_x();
26 uint32_t oY
= y
+ scr
.get_origin_y();
27 range bX
= (range::make_w(scr
.get_width()) - oX
) & range::make_b(-radius
, radius
+ 1);
28 range bY
= (range::make_w(scr
.get_height()) - oY
) & range::make_b(-radius
, radius
+ 1);
29 for(uint32_t r
= bY
.low(); r
!= bY
.high(); r
++) {
30 uint64_t pd2
= static_cast<int64_t>(r
) * r
;
31 typename
framebuffer::fb
<X
>::element_t
* rptr
= scr
.rowptr(oY
+ r
);
32 size_t eptr
= oX
+ bX
.low();
33 for(uint32_t c
= bX
.low(); c
!= bX
.high(); c
++, eptr
++) {
34 uint64_t fd2
= pd2
+ static_cast<int64_t>(c
) * c
;
37 else if(fd2
>= iradius2
)
38 outline
.apply(rptr
[eptr
]);
40 fill
.apply(rptr
[eptr
]);
44 void operator()(struct framebuffer::fb
<true>& scr
) throw() { op(scr
); }
45 void operator()(struct framebuffer::fb
<false>& scr
) throw() { op(scr
); }
46 void clone(framebuffer::queue
& q
) const throw(std::bad_alloc
) { q
.clone_helper(this); }
53 framebuffer::color outline
;
54 framebuffer::color fill
;
57 int circle(lua::state
& L
, lua::parameters
& P
)
60 uint32_t radius
, thickness
;
61 framebuffer::color poutline
, pfill
;
63 if(!lua_render_ctx
) return 0;
65 P(x
, y
, radius
, P
.optional(thickness
, 1), P
.optional(poutline
, 0xFFFFFFU
), P
.optional(pfill
, -1));
67 lua_render_ctx
->queue
->create_add
<render_object_circle
>(x
, y
, radius
, poutline
, pfill
, thickness
);
71 lua::functions
circle_fns(lua_func_misc
, "gui", {