Make roudned rectangle a variant of rectangle

This commit is contained in:
muddmaker
2015-05-23 17:05:03 -07:00
parent cb3ae86726
commit 0119e47f87
4 changed files with 17 additions and 33 deletions
+5 -5
View File
@@ -1206,7 +1206,7 @@ void Graphics::arc(DrawMode mode, float x, float y, float radius, float angle1,
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)
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)
{
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));
}
@@ -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)
{
coords[2 * i] = x + w - rx * cosf(phi);
coords[2 * i + 1] = y + h - ry * sinf(phi);
coords[2 * i] = x + w - rx * (1 + cosf(phi));
coords[2 * i + 1] = y + h - ry * (1 + sinf(phi));
}
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)
{
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];
+2 -2
View File
@@ -401,7 +401,7 @@ public:
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 x X-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 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.
+10 -25
View File
@@ -1532,7 +1532,16 @@ int w_rectangle(lua_State *L)
float y = (float)luaL_checknumber(L, 3);
float w = (float)luaL_checknumber(L, 4);
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;
}
@@ -1598,29 +1607,6 @@ int w_arc(lua_State *L)
instance()->arc(mode, x, y, radius, angle1, angle2, points);
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)
{
@@ -1810,7 +1796,6 @@ static const luaL_Reg functions[] =
{ "circle", w_circle },
{ "ellipse", w_ellipse },
{ "arc", w_arc },
{ "roundedRectangle", w_roundedRectangle },
{ "polygon", w_polygon },
@@ -111,7 +111,6 @@ int w_rectangle(lua_State *L);
int w_circle(lua_State *L);
int w_ellipse(lua_State *L);
int w_arc(lua_State *L);
int w_roundedRectangle(lua_State *L);
int w_polygon(lua_State *L);
int w_push(lua_State *L);
int w_pop(lua_State *L);