Add rx and ry parameters to roudnedRectangle

This commit is contained in:
muddmaker
2015-05-23 16:52:27 -07:00
parent dd41ccfbf7
commit cb3ae86726
3 changed files with 19 additions and 17 deletions
+10 -10
View File
@@ -1206,12 +1206,12 @@ 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 r, float points)
void Graphics::roundedRectangle(DrawMode mode, float x, float y, float w, float h, float rx, float ry, float points)
{
if (points < 1)
points = 1;
if (r == 0)
if (rx == 0 || ry == 0)
{
rectangle(mode, x, y, w, h);
return;
@@ -1226,32 +1226,32 @@ void Graphics::roundedRectangle(DrawMode mode, float x, float y, float w, float
for (int i = 0; i <= points + 2; ++i, phi += angle_shift)
{
coords[2 * i] = x + r * (1 - cosf(phi));
coords[2 * i + 1] = y + r * (1 - sinf(phi));
coords[2 * i] = x + rx * (1 - cosf(phi));
coords[2 * i + 1] = y + ry * (1 - sinf(phi));
}
phi = half_pi;
for (int i = points + 2; i <= 2 * (points + 2); ++i, phi += angle_shift)
{
coords[2 * i] = x + w - r * cosf(phi);
coords[2 * i + 1] = y + r * (1 - sinf(phi));
coords[2 * i] = x + w - rx * cosf(phi);
coords[2 * i + 1] = y + ry * (1 - sinf(phi));
}
phi = 2 * half_pi;
for (int i = 2 * (points + 2); i <= 3 * (points + 2); ++i, phi += angle_shift)
{
coords[2 * i] = x + w - r * cosf(phi);
coords[2 * i + 1] = y + h - r * sinf(phi);
coords[2 * i] = x + w - rx * cosf(phi);
coords[2 * i + 1] = y + h - ry * sinf(phi);
}
phi = 3 * half_pi;
for (int i = 3 * (points + 2); i <= 4 * (points + 2); ++i, phi += angle_shift)
{
coords[2 * i] = x + r * (1 - cosf(phi));
coords[2 * i + 1] = y + h - r * sinf(phi);
coords[2 * i] = x + rx * (1 - cosf(phi));
coords[2 * i + 1] = y + h - ry * sinf(phi);
}
coords[num_coords] = coords[0];
+3 -2
View File
@@ -407,10 +407,11 @@ public:
* @param y Y-coordinate of top-left corner
* @param w The width of the rectangle.
* @param h The height of the rectangle.
* @param r The radius of the corners.
* @param rx The radius of the corners on the x axis
* @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 r, float points = 10);
void roundedRectangle(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.
@@ -1610,14 +1610,15 @@ int w_roundedRectangle(lua_State *L)
float y = (float)luaL_checknumber(L, 3);
float w = (float)luaL_checknumber(L, 4);
float h = (float)luaL_checknumber(L, 5);
float r = (float)luaL_checknumber(L, 6);
float rx = (float)luaL_checknumber(L, 6);
float ry = (float)luaL_checknumber(L, 7);
int points;
if (lua_isnoneornil(L, 7))
points = r > 10 ? (int)(r) : 10;
if (lua_isnoneornil(L, 8))
points = rx + ry > 20 ? (int)((rx + ry) / 2) : 10;
else
points = luaL_checkint(L, 7);
points = luaL_checkint(L, 8);
instance()->roundedRectangle(mode, x, y, w, h, r, points);
instance()->roundedRectangle(mode, x, y, w, h, rx, ry, points);
return 0;
}