Add Lua function gui.circle()
This commit is contained in:
parent
92cc0b0d89
commit
a1f8869f94
2 changed files with 105 additions and 0 deletions
71
lua/gui-circle.cpp
Normal file
71
lua/gui-circle.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include "lua-int.hpp"
|
||||
#include "render.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct render_object_circle : public render_object
|
||||
{
|
||||
render_object_circle(int32_t _x, int32_t _y, uint32_t _radius,
|
||||
premultiplied_color _outline, premultiplied_color _fill, uint32_t _thickness) throw()
|
||||
: x(_x), y(_y), outline(_outline), fill(_fill)
|
||||
{
|
||||
radius = _radius;
|
||||
radius2 = static_cast<uint64_t>(_radius) * _radius;
|
||||
if(_thickness > _radius)
|
||||
iradius2 = 0;
|
||||
else
|
||||
iradius2 = static_cast<uint64_t>(_radius - _thickness) *
|
||||
(_radius - _thickness);
|
||||
}
|
||||
~render_object_circle() throw() {}
|
||||
void operator()(struct screen& scr) throw()
|
||||
{
|
||||
int32_t xmin = -radius;
|
||||
int32_t xmax = radius;
|
||||
int32_t ymin = -radius;
|
||||
int32_t ymax = radius;
|
||||
clip_range(scr.originx, scr.width, x, xmin, xmax);
|
||||
clip_range(scr.originy, scr.height, y, ymin, ymax);
|
||||
for(int32_t r = ymin; r < ymax; r++) {
|
||||
uint64_t pd2 = static_cast<int64_t>(r) * r;
|
||||
uint32_t* rptr = scr.rowptr(y + r + scr.originy);
|
||||
size_t eptr = x + xmin + scr.originx;
|
||||
for(int32_t c = xmin; c < xmax; c++, eptr++) {
|
||||
uint64_t fd2 = pd2 + static_cast<int64_t>(c) * c;
|
||||
if(fd2 > radius2)
|
||||
continue;
|
||||
else if(fd2 >= iradius2)
|
||||
outline.apply(rptr[eptr]);
|
||||
else
|
||||
fill.apply(rptr[eptr]);
|
||||
}
|
||||
}
|
||||
}
|
||||
private:
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t radius;
|
||||
uint64_t radius2;
|
||||
uint64_t iradius2;
|
||||
premultiplied_color outline;
|
||||
premultiplied_color fill;
|
||||
};
|
||||
|
||||
function_ptr_luafun gui_rectangle("gui.circle", [](lua_State* LS, const std::string& fname) -> int {
|
||||
if(!lua_render_ctx)
|
||||
return 0;
|
||||
int64_t outline = 0xFFFFFFU;
|
||||
int64_t fill = -1;
|
||||
uint32_t thickness = 1;
|
||||
int32_t x = get_numeric_argument<int32_t>(LS, 1, fname.c_str());
|
||||
int32_t y = get_numeric_argument<int32_t>(LS, 2, fname.c_str());
|
||||
uint32_t radius = get_numeric_argument<uint32_t>(LS, 3, fname.c_str());
|
||||
get_numeric_argument<uint32_t>(LS, 4, thickness, fname.c_str());
|
||||
get_numeric_argument<int64_t>(LS, 5, outline, fname.c_str());
|
||||
get_numeric_argument<int64_t>(LS, 6, fill, fname.c_str());
|
||||
premultiplied_color poutline(outline);
|
||||
premultiplied_color pfill(fill);
|
||||
lua_render_ctx->queue->add(*new render_object_circle(x, y, radius, poutline, pfill, thickness));
|
||||
return 0;
|
||||
});
|
||||
}
|
34
manual.lyx
34
manual.lyx
|
@ -1982,6 +1982,40 @@ y2: Y-coordinate of the other end.
|
|||
color: Color of the line (default is 0xFFFFFF (white)).
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
gui.circle(number x, number y, number r[, number thick[, number border[,
|
||||
number fil]]])
|
||||
\end_layout
|
||||
|
||||
\begin_layout Standard
|
||||
Draw a circle.
|
||||
Parameters.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
x: X-coordinate of the center
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
y: Y-coordinate of the center
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
r: The radius of the circle
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
thick: Border thickness
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
border: Border color (default is 0xFFFFFF (white))
|
||||
\end_layout
|
||||
|
||||
\begin_layout Itemize
|
||||
fill: Fill color (default is -1 (transparent)).
|
||||
\end_layout
|
||||
|
||||
\begin_layout Subsubsection
|
||||
gui.repaint()
|
||||
\end_layout
|
||||
|
|
Loading…
Add table
Reference in a new issue