Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeysinyavsky committed Apr 22, 2020
1 parent 36ad3c7 commit b746115
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
20 changes: 17 additions & 3 deletions drawpixels/idea_autocomplite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@
---@class DRAW_PIXELS
drawpixels = {}

---Indicates border should be maintained:
function drawpixels.start_fill() end
---Stop border recording:
function drawpixels.stop_fill() end
---Fills the area considering the boundaries:
function drawpixels.fill_area(buffer_info, x,y, red, green, blue, alpha) end
---Method for drawing circle:
function drawpixels.circle(buffer_info, pox_x, pox_y, diameter, red, green, blue, alpha)end
function drawpixels.circle(buffer_info, pox_x, pox_y, diameter, red, green, blue, alpha, antialiasing) end
---Method for drawing filled circle:
function drawpixels.filled_circle(buffer_info, pos_x, pos_y, diameter, red, green, blue, alpha) end
function drawpixels.filled_circle(buffer_info, pos_x, pos_y, diameter, red, green, blue, alpha, antialiasing) end
---Method for drawing rectangle:
function drawpixels.rect(buffer_info, pos_x, pos_y, rect_width, rect_height, red, green, blue, alpha) end
---Method for drawing filled rectangle:
function drawpixels.filled_rect(buffer_info, pos_x, pos_y, rect_width, rect_height, red, green, blue, alpha, angle) end
---Fill buffer with the color:
function drawpixels.fill(buffer_info, red, green, blue, alpha) end
---Draw a line between two points:
function drawpixels.line(buffer_info, x0, y0, x1, y1, red, green, blue, alpha) end
function drawpixels.line(buffer_info, x0, y0, x1, y1, red, green, blue, alpha, antialiasing, width) end
---Draw a gradient line between two points:
function drawpixels.gradient_line(buffer_info, x0, y0, x1, y1, red1, green1, blue1, red2, green2, blue2, alpha, width) end
---Draw a arc between two angles:
function drawpixels.arc(buffer_info, x, y, radius, from, to, red, green, blue, alpha) end
---Draw a filled arc between two angles:
function drawpixels.filled_arc(buffer_info, x, y, radius, from, to, red, green, blue, alpha) end
---Draw a gradient arc between two angles:
function drawpixels.gradient_arc(buffer_info, x, y, radius, from, to, red1, green1, blue1, red2, green2, blue2, alpha) end
---Draw a pixel:
function drawpixels.pixel(buffer_info, x, y, red, green, blue, alpha) end
---Read color from a position in the buffer:
Expand Down
32 changes: 15 additions & 17 deletions drawpixels/src/drawpixels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,14 +997,12 @@ static void draw_arc_vu(int _x, int _y, int radius, float from, float to, int r,
}
}

static void draw_normalized_arc(int32_t posx, int32_t posy, int32_t diameter, float &from, float &to, uint32_t r, uint32_t g, uint32_t b, uint32_t a)
static void draw_normalized_arc(int32_t posx, int32_t posy, int32_t radius, float &from, float &to, uint32_t r, uint32_t g, uint32_t b, uint32_t a)
{
float radius = diameter / 2;
if (abs(from - to) >= PI_2)
{
float fx = radius * cos(from);
float fy = radius * sin(from);
// draw_line_vu(posx, posy, fx + posx, fy + posy, r, g, b, a);
draw_circle_vu(posx, posy, radius, r, g, b, a);
}
else
Expand Down Expand Up @@ -1331,7 +1329,7 @@ static int draw_arc_lua(lua_State *L)
read_and_validate_buffer_info(L, 1);
int32_t posx = luaL_checknumber(L, 2);
int32_t posy = luaL_checknumber(L, 3);
int32_t diameter = luaL_checknumber(L, 4);
int32_t radius = luaL_checknumber(L, 4);
float from = luaL_checknumber(L, 5);
float to = luaL_checknumber(L, 6);
uint32_t r = luaL_checknumber(L, 7);
Expand All @@ -1343,8 +1341,8 @@ static int draw_arc_lua(lua_State *L)
a = luaL_checknumber(L, 10);
}

draw_normalized_arc(posx, posy, diameter, from, to, r, g, b, a);
draw_arc_lines(posx, posy, diameter / 2, from, to, r, g, b, a);
draw_normalized_arc(posx, posy, radius, from, to, r, g, b, a);
draw_arc_lines(posx, posy, radius, from, to, r, g, b, a);

assert(top == lua_gettop(L));
return 0;
Expand All @@ -1357,7 +1355,7 @@ static int draw_filled_arc_lua(lua_State *L)
read_and_validate_buffer_info(L, 1);
int32_t posx = luaL_checknumber(L, 2);
int32_t posy = luaL_checknumber(L, 3);
int32_t diameter = luaL_checknumber(L, 4);
int32_t radius = luaL_checknumber(L, 4);
float from = luaL_checknumber(L, 5);
float to = luaL_checknumber(L, 6);
uint32_t r = luaL_checknumber(L, 7);
Expand All @@ -1369,15 +1367,15 @@ static int draw_filled_arc_lua(lua_State *L)
a = luaL_checknumber(L, 10);
}
start_record_points();
draw_normalized_arc(posx, posy, diameter, from, to, r, g, b, a);
draw_arc_lines(posx, posy, diameter / 2, from, to, r, g, b, a);
draw_normalized_arc(posx, posy, radius, from, to, r, g, b, a);
draw_arc_lines(posx, posy, radius, from, to, r, g, b, a);

float center = (from + to) / 2;
center = from > to ? center - M_PI / 2 : center + M_PI / 2;

fill_area(posx + diameter / 3 * cos(center), posy + diameter / 3 * sin(center), r, g, b, a);
fill_area(posx + radius * 2 / 3 * cos(center), posy + radius * 2 / 3 * sin(center), r, g, b, a);
stop_record_points();
draw_line_vu(posx, posy, posx + diameter / 3 * cos(center), posy + diameter / 3 * sin(center), r, g, b, a, 2);
draw_line_vu(posx, posy, posx + radius * 2 / 3 * cos(center), posy + radius * 2 / 3 * sin(center), r, g, b, a, 2);

assert(top == lua_gettop(L));
return 0;
Expand All @@ -1390,7 +1388,7 @@ static int draw_gradient_arc_lua(lua_State *L)
read_and_validate_buffer_info(L, 1);
int32_t posx = luaL_checknumber(L, 2);
int32_t posy = luaL_checknumber(L, 3);
int32_t diameter = luaL_checknumber(L, 4);
int32_t radius = luaL_checknumber(L, 4);
float from = luaL_checknumber(L, 5);
float to = luaL_checknumber(L, 6);
uint32_t r1 = luaL_checknumber(L, 7);
Expand All @@ -1414,8 +1412,8 @@ static int draw_gradient_arc_lua(lua_State *L)
c2.g = g2;
c2.b = b2;
start_record_points();
draw_normalized_arc(posx, posy, diameter, from, to, r2, g2, b2, a);
draw_gradient_arc_lines(posx, posy, diameter / 2, from, to, c1, c2, a);
draw_normalized_arc(posx, posy, radius, from, to, r2, g2, b2, a);
draw_gradient_arc_lines(posx, posy, radius, from, to, c1, c2, a);

float center = (from + to) / 2;
center = from > to ? center - M_PI / 2 : center + M_PI / 2;
Expand All @@ -1424,9 +1422,9 @@ static int draw_gradient_arc_lua(lua_State *L)
center_point.x = posx;
center_point.y = posy;

gradient_fill_area(posx + diameter / 3 * cos(center), posy + diameter / 3 * sin(center), center_point, (diameter / 2) * (diameter / 2), c1, c2, a);
gradient_fill_area(posx + radius * 2 / 3 * cos(center), posy + radius * 2 / 3 * sin(center), center_point, radius * radius, c1, c2, a);
stop_record_points();
draw_gradient_line_vu(posx, posy, posx + diameter / 2.05 * cos(center), posy + diameter / 2.05 * sin(center), c1, c2, a, 1);
draw_gradient_line_vu(posx, posy, posx + radius * 2 / 2.05 * cos(center), posy + radius * 2 / 2.05 * sin(center), c1, c2, a, 1);

assert(top == lua_gettop(L));
return 0;
Expand Down Expand Up @@ -1743,7 +1741,7 @@ static const luaL_reg Module_methods[] = {
{"start_fill", start_record_points_lua},
{"end_fill", stop_record_points_lua},
{"fill_area", fill_area_lua},
{"triangle", draw_triangle_lua},
// {"triangle", draw_triangle_lua},
{"line", draw_line_lua},
{"gradient_line", draw_gradient_line_lua},
{"arc", draw_arc_lua},
Expand Down

0 comments on commit b746115

Please sign in to comment.