summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2013-05-14 20:39:20 (GMT)
committer jacob1 <jfu614@gmail.com>2013-05-14 20:39:20 (GMT)
commit2e409f966cbae3665ac2d6f9a9a0311f3894e3b6 (patch)
tree23c86bdb698caea424e45809dddb0d1bee4fc066 /src
parent431f5a0083dca3da5c881e507908690ebb5a052a (diff)
downloadpowder-2e409f966cbae3665ac2d6f9a9a0311f3894e3b6.zip
powder-2e409f966cbae3665ac2d6f9a9a0311f3894e3b6.tar.gz
gfx.draw/fillcircle
Diffstat (limited to 'src')
-rw-r--r--src/cat/LuaScriptInterface.cpp56
-rw-r--r--src/cat/LuaScriptInterface.h2
-rw-r--r--src/graphics/Graphics.h2
-rw-r--r--src/graphics/OpenGLDrawMethods.inl41
-rw-r--r--src/graphics/RasterDrawMethods.inl41
-rw-r--r--src/graphics/Renderer.h2
6 files changed, 141 insertions, 3 deletions
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index 485f167..15f2def 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -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,6 +1955,54 @@ int LuaScriptInterface::graphics_drawLine(lua_State * l)
int LuaScriptInterface::graphics_drawRect(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->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);
y = lua_tointeger(l, 2);
@@ -1971,11 +2021,11 @@ 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->drawcircle(x, y, w, h, r, g, b, a);
return 0;
}
-int LuaScriptInterface::graphics_fillRect(lua_State * l)
+int LuaScriptInterface::graphics_fillCircle(lua_State * l)
{
int x, y, w, h, r, g, b, a;
x = lua_tointeger(l, 1);
@@ -1995,7 +2045,7 @@ 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->fillcircle(x, y, w, h, r, g, b, a);
return 0;
}
diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h
index fc3f41a..9b54688 100644
--- a/src/cat/LuaScriptInterface.h
+++ b/src/cat/LuaScriptInterface.h
@@ -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);
diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h
index 3a87bb6..2cbdd87 100644
--- a/src/graphics/Graphics.h
+++ b/src/graphics/Graphics.h
@@ -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);
diff --git a/src/graphics/OpenGLDrawMethods.inl b/src/graphics/OpenGLDrawMethods.inl
index bfc338a..2bba731 100644
--- a/src/graphics/OpenGLDrawMethods.inl
+++ b/src/graphics/OpenGLDrawMethods.inl
@@ -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);
diff --git a/src/graphics/RasterDrawMethods.inl b/src/graphics/RasterDrawMethods.inl
index b4de875..c53c0a8 100644
--- a/src/graphics/RasterDrawMethods.inl
+++ b/src/graphics/RasterDrawMethods.inl
@@ -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)
{
diff --git a/src/graphics/Renderer.h b/src/graphics/Renderer.h
index 9251006..8a7120f 100644
--- a/src/graphics/Renderer.h
+++ b/src/graphics/Renderer.h
@@ -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);