mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Make roudned rectangle a variant of rectangle
This commit is contained in:
@@ -1206,7 +1206,7 @@ void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1,
|
|||||||
delete[] coords;
|
delete[] coords;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::roundedRectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry, float points)
|
void Graphics::rectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry, float points)
|
||||||
{
|
{
|
||||||
if (points < 1)
|
if (points < 1)
|
||||||
points = 1;
|
points = 1;
|
||||||
@@ -1234,7 +1234,7 @@ void Graphics::roundedRectangle(DrawMode mode, float x, float y, float w, float
|
|||||||
|
|
||||||
for (int i = points + 2; i <= 2 * (points + 2); ++i, phi += angle_shift)
|
for (int i = points + 2; i <= 2 * (points + 2); ++i, phi += angle_shift)
|
||||||
{
|
{
|
||||||
coords[2 * i] = x + w - rx * cosf(phi);
|
coords[2 * i] = x + w - rx * (1 + cosf(phi));
|
||||||
coords[2 * i + 1] = y + ry * (1 - sinf(phi));
|
coords[2 * i + 1] = y + ry * (1 - sinf(phi));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1242,8 +1242,8 @@ void Graphics::roundedRectangle(DrawMode mode, float x, float y, float w, float
|
|||||||
|
|
||||||
for (int i = 2 * (points + 2); i <= 3 * (points + 2); ++i, phi += angle_shift)
|
for (int i = 2 * (points + 2); i <= 3 * (points + 2); ++i, phi += angle_shift)
|
||||||
{
|
{
|
||||||
coords[2 * i] = x + w - rx * cosf(phi);
|
coords[2 * i] = x + w - rx * (1 + cosf(phi));
|
||||||
coords[2 * i + 1] = y + h - ry * sinf(phi);
|
coords[2 * i + 1] = y + h - ry * (1 + sinf(phi));
|
||||||
}
|
}
|
||||||
|
|
||||||
phi = 3 * half_pi;
|
phi = 3 * half_pi;
|
||||||
@@ -1251,7 +1251,7 @@ void Graphics::roundedRectangle(DrawMode mode, float x, float y, float w, float
|
|||||||
for (int i = 3 * (points + 2); i <= 4 * (points + 2); ++i, phi += angle_shift)
|
for (int i = 3 * (points + 2); i <= 4 * (points + 2); ++i, phi += angle_shift)
|
||||||
{
|
{
|
||||||
coords[2 * i] = x + rx * (1 - cosf(phi));
|
coords[2 * i] = x + rx * (1 - cosf(phi));
|
||||||
coords[2 * i + 1] = y + h - ry * sinf(phi);
|
coords[2 * i + 1] = y + h - ry * (1 + sinf(phi));
|
||||||
}
|
}
|
||||||
|
|
||||||
coords[num_coords] = coords[0];
|
coords[num_coords] = coords[0];
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ public:
|
|||||||
void arc(DrawMode mode, float x, float y, float radius, float angle1, float angle2, int points = 10);
|
void arc(DrawMode mode, float x, float y, float radius, float angle1, float angle2, int points = 10);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a rounded rectangle.
|
* Variant of rectanglge that draws a rounded rectangle.
|
||||||
* @param mode The mode of drawing (line/filled).
|
* @param mode The mode of drawing (line/filled).
|
||||||
* @param x X-coordinate of top-left corner
|
* @param x X-coordinate of top-left corner
|
||||||
* @param y Y-coordinate of top-left corner
|
* @param y Y-coordinate of top-left corner
|
||||||
@@ -411,7 +411,7 @@ public:
|
|||||||
* @param ry The radius of the corners on the y axis
|
* @param ry The radius of the corners on the y axis
|
||||||
* @param points The number of points to use per corner
|
* @param points The number of points to use per corner
|
||||||
**/
|
**/
|
||||||
void roundedRectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry, float points = 10);
|
void rectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry, float points = 10);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a polygon with an arbitrary number of vertices.
|
* Draws a polygon with an arbitrary number of vertices.
|
||||||
|
|||||||
@@ -1532,7 +1532,16 @@ int w_rectangle(lua_State *L)
|
|||||||
float y = (float)luaL_checknumber(L, 3);
|
float y = (float)luaL_checknumber(L, 3);
|
||||||
float w = (float)luaL_checknumber(L, 4);
|
float w = (float)luaL_checknumber(L, 4);
|
||||||
float h = (float)luaL_checknumber(L, 5);
|
float h = (float)luaL_checknumber(L, 5);
|
||||||
instance()->rectangle(mode, x, y, w, h);
|
float rx = (float)luaL_optnumber(L, 6, 0.0);
|
||||||
|
float ry = (float)luaL_optnumber(L, 7, 0.0);
|
||||||
|
|
||||||
|
int points;
|
||||||
|
if (lua_isnoneornil(L, 8))
|
||||||
|
points = rx + ry > 20 ? (int)((rx + ry) / 2) : 10;
|
||||||
|
else
|
||||||
|
points = luaL_checkint(L, 8);
|
||||||
|
|
||||||
|
instance()->rectangle(mode, x, y, w, h, rx, ry, points);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1599,29 +1608,6 @@ int w_arc(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w_roundedRectangle(lua_State *L)
|
|
||||||
{
|
|
||||||
Graphics::DrawMode mode;
|
|
||||||
const char *str = luaL_checkstring(L, 1);
|
|
||||||
if (!Graphics::getConstant(str, mode))
|
|
||||||
return luaL_error(L, "Incorrect draw mode %s", str);
|
|
||||||
|
|
||||||
float x = (float)luaL_checknumber(L, 2);
|
|
||||||
float y = (float)luaL_checknumber(L, 3);
|
|
||||||
float w = (float)luaL_checknumber(L, 4);
|
|
||||||
float h = (float)luaL_checknumber(L, 5);
|
|
||||||
float rx = (float)luaL_checknumber(L, 6);
|
|
||||||
float ry = (float)luaL_checknumber(L, 7);
|
|
||||||
int points;
|
|
||||||
if (lua_isnoneornil(L, 8))
|
|
||||||
points = rx + ry > 20 ? (int)((rx + ry) / 2) : 10;
|
|
||||||
else
|
|
||||||
points = luaL_checkint(L, 8);
|
|
||||||
|
|
||||||
instance()->roundedRectangle(mode, x, y, w, h, rx, ry, points);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int w_polygon(lua_State *L)
|
int w_polygon(lua_State *L)
|
||||||
{
|
{
|
||||||
int args = lua_gettop(L) - 1;
|
int args = lua_gettop(L) - 1;
|
||||||
@@ -1810,7 +1796,6 @@ static const luaL_Reg functions[] =
|
|||||||
{ "circle", w_circle },
|
{ "circle", w_circle },
|
||||||
{ "ellipse", w_ellipse },
|
{ "ellipse", w_ellipse },
|
||||||
{ "arc", w_arc },
|
{ "arc", w_arc },
|
||||||
{ "roundedRectangle", w_roundedRectangle },
|
|
||||||
|
|
||||||
{ "polygon", w_polygon },
|
{ "polygon", w_polygon },
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,6 @@ int w_rectangle(lua_State *L);
|
|||||||
int w_circle(lua_State *L);
|
int w_circle(lua_State *L);
|
||||||
int w_ellipse(lua_State *L);
|
int w_ellipse(lua_State *L);
|
||||||
int w_arc(lua_State *L);
|
int w_arc(lua_State *L);
|
||||||
int w_roundedRectangle(lua_State *L);
|
|
||||||
int w_polygon(lua_State *L);
|
int w_polygon(lua_State *L);
|
||||||
int w_push(lua_State *L);
|
int w_push(lua_State *L);
|
||||||
int w_pop(lua_State *L);
|
int w_pop(lua_State *L);
|
||||||
|
|||||||
Reference in New Issue
Block a user