1 #include "lua/internal.hpp"
2 #include "library/framebuffer.hpp"
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();
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
]);
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); }
44 premultiplied_color outline
;
45 premultiplied_color fill
;
49 function_ptr_luafun
gui_rectangle(LS
, "gui.rectangle", [](lua_state
& L
, const std::string
& fname
) -> int {
52 int64_t outline
= 0xFFFFFFU
;
54 uint32_t thickness
= 1;
55 int32_t x
= L
.get_numeric_argument
<int32_t>(1, fname
.c_str());
56 int32_t y
= L
.get_numeric_argument
<int32_t>(2, fname
.c_str());
57 uint32_t width
= L
.get_numeric_argument
<uint32_t>(3, fname
.c_str());
58 uint32_t height
= L
.get_numeric_argument
<uint32_t>(4, fname
.c_str());
59 L
.get_numeric_argument
<uint32_t>(5, thickness
, fname
.c_str());
60 L
.get_numeric_argument
<int64_t>(6, outline
, fname
.c_str());
61 L
.get_numeric_argument
<int64_t>(7, fill
, fname
.c_str());
62 premultiplied_color
poutline(outline
);
63 premultiplied_color
pfill(fill
);
64 lua_render_ctx
->queue
->create_add
<render_object_rectangle
>(x
, y
, width
, height
, poutline
, pfill
,