1 #include "lua/internal.hpp"
2 #include "library/framebuffer.hpp"
3 #include "library/lua-framebuffer.hpp"
7 struct render_object_box
: public framebuffer::object
9 render_object_box(int32_t _x
, int32_t _y
, int32_t _width
, int32_t _height
,
10 framebuffer::color _outline1
, framebuffer::color _outline2
, framebuffer::color _fill
,
11 int32_t _thickness
) throw()
12 : x(_x
), y(_y
), width(_width
), height(_height
), outline1(_outline1
), outline2(_outline2
),
13 fill(_fill
), thickness(_thickness
) {}
14 ~render_object_box() throw() {}
15 template<bool X
> void op(struct framebuffer::fb
<X
>& scr
) throw()
17 outline1
.set_palette(scr
);
18 outline2
.set_palette(scr
);
19 fill
.set_palette(scr
);
20 uint32_t originx
= scr
.get_origin_x();
21 uint32_t originy
= scr
.get_origin_y();
25 int32_t ymax
= height
;
26 framebuffer::clip_range(originx
, scr
.get_width(), x
, xmin
, xmax
);
27 framebuffer::clip_range(originy
, scr
.get_height(), y
, ymin
, ymax
);
28 for(int32_t r
= ymin
; r
< ymax
; r
++) {
29 typename
framebuffer::fb
<X
>::element_t
* rptr
= scr
.rowptr(y
+ r
+ originy
);
30 size_t eptr
= x
+ xmin
+ originx
;
31 for(int32_t c
= xmin
; c
< xmax
; c
++, eptr
++)
32 if((r
< thickness
&& r
<= (width
- c
)) || (c
< thickness
&& c
< (height
- r
)))
33 outline1
.apply(rptr
[eptr
]);
34 else if(r
< thickness
|| c
< thickness
|| r
>= height
- thickness
||
35 c
>= width
- thickness
)
36 outline2
.apply(rptr
[eptr
]);
38 fill
.apply(rptr
[eptr
]);
41 void operator()(struct framebuffer::fb
<true>& scr
) throw() { op(scr
); }
42 void operator()(struct framebuffer::fb
<false>& scr
) throw() { op(scr
); }
43 void clone(framebuffer::queue
& q
) const throw(std::bad_alloc
) { q
.clone_helper(this); }
49 framebuffer::color outline1
;
50 framebuffer::color outline2
;
51 framebuffer::color fill
;
55 int box(lua::state
& L
, lua::parameters
& P
)
58 uint32_t width
, height
, thickness
;
59 framebuffer::color poutline1
, poutline2
, pfill
;
61 if(!lua_render_ctx
) return 0;
63 P(x
, y
, width
, height
, P
.optional(thickness
, 1), P
.optional(poutline1
, 0xFFFFFFU
),
64 P
.optional(poutline2
, 0x808080U
), P
.optional(pfill
, 0xC0C0C0U
));
66 lua_render_ctx
->queue
->create_add
<render_object_box
>(x
, y
, width
, height
, poutline1
, poutline2
,
71 lua::functions
box_fns(lua_func_misc
, "gui", {