gfx.draw/fillcircle

This commit is contained in:
jacob1 2013-05-14 16:39:20 -04:00
parent 431f5a0083
commit 2e409f966c
6 changed files with 143 additions and 5 deletions

View File

@ -1876,6 +1876,8 @@ void LuaScriptInterface::initGraphicsAPI()
{"drawLine", graphics_drawLine},
{"drawRect", graphics_drawRect},
{"fillRect", graphics_fillRect},
{"drawCircle", graphics_drawCircle},
{"fillCircle", graphics_fillCircle},
{NULL, NULL}
};
luaL_register(l, "graphics", graphicsAPIMethods);
@ -1953,11 +1955,11 @@ int LuaScriptInterface::graphics_drawLine(lua_State * l)
int LuaScriptInterface::graphics_drawRect(lua_State * l)
{
int x, y, w, h, r, g, b, a;
int x, y, rx, ry, r, g, b, a;
x = lua_tointeger(l, 1);
y = lua_tointeger(l, 2);
w = lua_tointeger(l, 3);
h = lua_tointeger(l, 4);
rx = lua_tointeger(l, 3);
ry = lua_tointeger(l, 4);
r = luaL_optint(l, 5, 255);
g = luaL_optint(l, 6, 255);
b = luaL_optint(l, 7, 255);
@ -1971,11 +1973,35 @@ int LuaScriptInterface::graphics_drawRect(lua_State * l)
if (b>255) b = 255;
if (a<0) a = 0;
if (a>255) a = 255;
luacon_g->drawrect(x, y, w, h, r, g, b, a);
luacon_g->drawrect(x, y, rx, ry, r, g, b, a);
return 0;
}
int LuaScriptInterface::graphics_fillRect(lua_State * l)
{
int x, y, rx, ry, r, g, b, a;
x = lua_tointeger(l, 1);
y = lua_tointeger(l, 2);
rx = lua_tointeger(l, 3);
ry = lua_tointeger(l, 4);
r = luaL_optint(l, 5, 255);
g = luaL_optint(l, 6, 255);
b = luaL_optint(l, 7, 255);
a = luaL_optint(l, 8, 255);
if (r<0) r = 0;
if (r>255) r = 255;
if (g<0) g = 0;
if (g>255) g = 255;
if (b<0) b = 0;
if (b>255) b = 255;
if (a<0) a = 0;
if (a>255) a = 255;
luacon_g->fillrect(x, y, rx, ry, r, g, b, a);
return 0;
}
int LuaScriptInterface::graphics_drawCircle(lua_State * l)
{
int x, y, w, h, r, g, b, a;
x = lua_tointeger(l, 1);
@ -1995,7 +2021,31 @@ int LuaScriptInterface::graphics_fillRect(lua_State * l)
if (b>255) b = 255;
if (a<0) a = 0;
if (a>255) a = 255;
luacon_g->fillrect(x, y, w, h, r, g, b, a);
luacon_g->drawcircle(x, y, w, h, r, g, b, a);
return 0;
}
int LuaScriptInterface::graphics_fillCircle(lua_State * l)
{
int x, y, w, h, r, g, b, a;
x = lua_tointeger(l, 1);
y = lua_tointeger(l, 2);
w = lua_tointeger(l, 3);
h = lua_tointeger(l, 4);
r = luaL_optint(l, 5, 255);
g = luaL_optint(l, 6, 255);
b = luaL_optint(l, 7, 255);
a = luaL_optint(l, 8, 255);
if (r<0) r = 0;
if (r>255) r = 255;
if (g<0) g = 0;
if (g>255) g = 255;
if (b<0) b = 0;
if (b>255) b = 255;
if (a<0) a = 0;
if (a>255) a = 255;
luacon_g->fillcircle(x, y, w, h, r, g, b, a);
return 0;
}

View File

@ -109,6 +109,8 @@ class LuaScriptInterface: public CommandInterface
static int graphics_drawLine(lua_State * l);
static int graphics_drawRect(lua_State * l);
static int graphics_fillRect(lua_State * l);
static int graphics_drawCircle(lua_State * l);
static int graphics_fillCircle(lua_State * l);
void initFileSystemAPI();
static int fileSystem_list(lua_State * l);

View File

@ -239,6 +239,8 @@ public:
void draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a);
void drawrect(int x, int y, int width, int height, int r, int g, int b, int a);
void fillrect(int x, int y, int width, int height, int r, int g, int b, int a);
void drawcircle(int x, int y, int rx, int ry, int r, int g, int b, int a);
void fillcircle(int x, int y, int rx, int ry, int r, int g, int b, int a);
void clearrect(int x, int y, int width, int height);
void gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2);

View File

@ -314,6 +314,47 @@ void PIXELMETHODS_CLASS::fillrect(int x, int y, int width, int height, int r, in
glEnd();
}
void PIXELMETHODS_CLASS::drawcircle(int x, int y, int rx, int ry, int r, int g, int b, int a)
{
int yTop = ry, yBottom, i, j;
for (i = 0; i <= rx; i++) {
yBottom = yTop;
while (pow(i-rx,2.0)*pow(ry,2.0) + pow(yTop-ry,2.0)*pow(rx,2.0) <= pow(rx,2.0)*pow(ry,2.0))
yTop++;
if (yBottom != yTop)
yTop--;
for (int j = yBottom; j <= yTop; j++)
{
blendpixel(x+i, y+j, r, g, b, a);
if (i != rx)
blendpixel(x+2*rx-i, y+j, r, g, b, a);
if (j != ry)
{
blendpixel(x+i, y+2*ry-j, r, g, b, a);
if (i != rx)
blendpixel(x+2*rx-i, y+2*ry-j, r, g, b, a);
}
}
}
}
void PIXELMETHODS_CLASS::fillcircle(int x, int y, int rx, int ry, int r, int g, int b, int a)
{
int yTop = ry+1, yBottom, i, j;
for (i = 0; i <= rx; i++)
{
while (pow(i-rx,2.0)*pow(ry,2.0) + pow(yTop-ry,2.0)*pow(rx,2.0) <= pow(rx,2.0)*pow(ry,2.0))
yTop++;
yBottom = 2*ry - yTop;
for (int j = yBottom+1; j < yTop; j++)
{
blendpixel(x+i, y+j, r, g, b, a);
if (i != rx)
blendpixel(x+2*rx-i, y+j, r, g, b, a);
}
}
}
void PIXELMETHODS_CLASS::gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2)
{
glBegin(GL_QUADS);

View File

@ -356,6 +356,47 @@ void PIXELMETHODS_CLASS::fillrect(int x, int y, int w, int h, int r, int g, int
blendpixel(x+i, y+j, r, g, b, a);
}
void PIXELMETHODS_CLASS::drawcircle(int x, int y, int rx, int ry, int r, int g, int b, int a)
{
int yTop = ry, yBottom, i, j;
for (i = 0; i <= rx; i++) {
yBottom = yTop;
while (pow(i-rx,2.0)*pow(ry,2.0) + pow(yTop-ry,2.0)*pow(rx,2.0) <= pow(rx,2.0)*pow(ry,2.0))
yTop++;
if (yBottom != yTop)
yTop--;
for (int j = yBottom; j <= yTop; j++)
{
blendpixel(x+i, y+j, r, g, b, a);
if (i != rx)
blendpixel(x+2*rx-i, y+j, r, g, b, a);
if (j != ry)
{
blendpixel(x+i, y+2*ry-j, r, g, b, a);
if (i != rx)
blendpixel(x+2*rx-i, y+2*ry-j, r, g, b, a);
}
}
}
}
void PIXELMETHODS_CLASS::fillcircle(int x, int y, int rx, int ry, int r, int g, int b, int a)
{
int yTop = ry+1, yBottom, i, j;
for (i = 0; i <= rx; i++)
{
while (pow(i-rx,2.0)*pow(ry,2.0) + pow(yTop-ry,2.0)*pow(rx,2.0) <= pow(rx,2.0)*pow(ry,2.0))
yTop++;
yBottom = 2*ry - yTop;
for (int j = yBottom+1; j < yTop; j++)
{
blendpixel(x+i, y+j, r, g, b, a);
if (i != rx)
blendpixel(x+2*rx-i, y+j, r, g, b, a);
}
}
}
void PIXELMETHODS_CLASS::gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2)
{

View File

@ -126,6 +126,8 @@ public:
void draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a);
void drawrect(int x, int y, int width, int height, int r, int g, int b, int a);
void fillrect(int x, int y, int width, int height, int r, int g, int b, int a);
void drawcircle(int x, int y, int rx, int ry, int r, int g, int b, int a);
void fillcircle(int x, int y, int rx, int ry, int r, int g, int b, int a);
void clearrect(int x, int y, int width, int height);
void gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2);