1 #include "core/lua-int.hpp"
2 #include "core/render.hpp"
6 struct render_object_line
: public render_object
8 render_object_line(int32_t _x1
, int32_t _x2
, int32_t _y1
, int32_t _y2
, premultiplied_color _color
)
10 : x1(_x1
), y1(_y1
), x2(_x2
), y2(_y2
), color(_color
) {}
11 ~render_object_line() throw() {}
12 void operator()(struct screen
& scr
) throw()
14 color
.set_palette(scr
);
15 int32_t xdiff
= x2
- x1
;
16 int32_t ydiff
= y2
- y1
;
24 //Swap points so that x1 < x2.
28 //The slope of the line is (y2 - y1) / (x2 - x1) = +-ydiff / xdiff
31 for(int32_t x
= x1
; x
<= x2
; x
++) {
32 if(x
< 0 || static_cast<uint32_t>(x
) >= scr
.width
)
34 if(y
< 0 || static_cast<uint32_t>(y
) >= scr
.height
)
36 color
.apply(scr
.rowptr(y
)[x
]);
50 //Swap points so that y1 < y2.
54 //The slope of the line is (x2 - x1) / (y2 - y1) = +-xdiff / ydiff
57 for(int32_t y
= y1
; y
<= y2
; y
++) {
58 if(x
< 0 || static_cast<uint32_t>(x
) >= scr
.width
)
60 if(y
< 0 || static_cast<uint32_t>(y
) >= scr
.height
)
62 color
.apply(scr
.rowptr(y
)[x
]);
80 premultiplied_color color
;
83 function_ptr_luafun
gui_pixel("gui.line", [](lua_State
* LS
, const std::string
& fname
) -> int {
86 int64_t color
= 0xFFFFFFU
;
87 int32_t x1
= get_numeric_argument
<int32_t>(LS
, 1, fname
.c_str());
88 int32_t y1
= get_numeric_argument
<int32_t>(LS
, 2, fname
.c_str());
89 int32_t x2
= get_numeric_argument
<int32_t>(LS
, 3, fname
.c_str());
90 int32_t y2
= get_numeric_argument
<int32_t>(LS
, 4, fname
.c_str());
91 get_numeric_argument
<int64_t>(LS
, 5, color
, fname
.c_str());
92 premultiplied_color
pcolor(color
);
93 lua_render_ctx
->queue
->add(*new render_object_line(x1
, x2
, y1
, y2
, pcolor
));