1 #include "lua/internal.hpp"
2 #include "core/render.hpp"
6 struct render_object_circle
: public render_object
8 render_object_circle(int32_t _x
, int32_t _y
, uint32_t _radius
,
9 premultiplied_color _outline
, premultiplied_color _fill
, uint32_t _thickness
) throw()
10 : x(_x
), y(_y
), outline(_outline
), fill(_fill
)
13 radius2
= static_cast<uint64_t>(_radius
) * _radius
;
14 if(_thickness
> _radius
)
17 iradius2
= static_cast<uint64_t>(_radius
- _thickness
) *
18 (_radius
- _thickness
);
20 ~render_object_circle() throw() {}
21 template<bool X
> void op(struct screen
<X
>& scr
) throw()
23 outline
.set_palette(scr
);
24 fill
.set_palette(scr
);
25 int32_t xmin
= -radius
;
26 int32_t xmax
= radius
;
27 int32_t ymin
= -radius
;
28 int32_t ymax
= radius
;
29 clip_range(scr
.originx
, scr
.width
, x
, xmin
, xmax
);
30 clip_range(scr
.originy
, scr
.height
, y
, ymin
, ymax
);
31 for(int32_t r
= ymin
; r
< ymax
; r
++) {
32 uint64_t pd2
= static_cast<int64_t>(r
) * r
;
33 typename screen
<X
>::element_t
* rptr
= scr
.rowptr(y
+ r
+ scr
.originy
);
34 size_t eptr
= x
+ xmin
+ scr
.originx
;
35 for(int32_t c
= xmin
; c
< xmax
; c
++, eptr
++) {
36 uint64_t fd2
= pd2
+ static_cast<int64_t>(c
) * c
;
39 else if(fd2
>= iradius2
)
40 outline
.apply(rptr
[eptr
]);
42 fill
.apply(rptr
[eptr
]);
46 void operator()(struct screen
<true>& scr
) throw() { op(scr
); }
47 void operator()(struct screen
<false>& scr
) throw() { op(scr
); }
54 premultiplied_color outline
;
55 premultiplied_color fill
;
58 function_ptr_luafun
gui_rectangle("gui.circle", [](lua_State
* LS
, const std::string
& fname
) -> int {
61 int64_t outline
= 0xFFFFFFU
;
63 uint32_t thickness
= 1;
64 int32_t x
= get_numeric_argument
<int32_t>(LS
, 1, fname
.c_str());
65 int32_t y
= get_numeric_argument
<int32_t>(LS
, 2, fname
.c_str());
66 uint32_t radius
= get_numeric_argument
<uint32_t>(LS
, 3, fname
.c_str());
67 get_numeric_argument
<uint32_t>(LS
, 4, thickness
, fname
.c_str());
68 get_numeric_argument
<int64_t>(LS
, 5, outline
, fname
.c_str());
69 get_numeric_argument
<int64_t>(LS
, 6, fill
, fname
.c_str());
70 premultiplied_color
poutline(outline
);
71 premultiplied_color
pfill(fill
);
72 lua_render_ctx
->queue
->add(*new render_object_circle(x
, y
, radius
, poutline
, pfill
, thickness
));