Browse Source

Added SpriteBatch:getColor

Alex Szpakowski 12 years ago
parent
commit
be33d17f89

+ 5 - 0
src/modules/graphics/opengl/SpriteBatch.cpp

@@ -201,6 +201,11 @@ void SpriteBatch::setColor()
 	color = 0;
 }
 
+const Color *SpriteBatch::getColor() const
+{
+	return color;
+}
+
 int SpriteBatch::getCount() const
 {
 	return next;

+ 6 - 0
src/modules/graphics/opengl/SpriteBatch.h

@@ -86,6 +86,12 @@ public:
 	 */
 	void setColor();
 
+	/**
+	 * Get the current color for this SpriteBatch. Returns NULL if no color is
+	 * set.
+	 **/
+	const Color *getColor() const;
+
 	/**
 	 * Get the number of sprites currently in this SpriteBatch.
 	 **/

+ 18 - 0
src/modules/graphics/opengl/wrap_SpriteBatch.cpp

@@ -197,6 +197,23 @@ int w_SpriteBatch_setColor(lua_State *L)
 	return 0;
 }
 
+int w_SpriteBatch_getColor(lua_State *L)
+{
+	SpriteBatch *t = luax_checkspritebatch(L, 1);
+	const Color *color = t->getColor();
+
+	// getColor returns NULL if no color is set.
+	if (!color)
+		return 0;
+
+	lua_pushinteger(L, (lua_Integer) color->r);
+	lua_pushinteger(L, (lua_Integer) color->g);
+	lua_pushinteger(L, (lua_Integer) color->b);
+	lua_pushinteger(L, (lua_Integer) color->a);
+
+	return 4;
+}
+
 int w_SpriteBatch_getCount(lua_State *L)
 {
 	SpriteBatch *t = luax_checkspritebatch(L, 1);
@@ -223,6 +240,7 @@ static const luaL_Reg functions[] =
 	{ "setImage", w_SpriteBatch_setImage },
 	{ "getImage", w_SpriteBatch_getImage },
 	{ "setColor", w_SpriteBatch_setColor },
+	{ "getColor", w_SpriteBatch_getColor },
 	{ "getCount", w_SpriteBatch_getCount },
 	{ "getBufferSize", w_SpriteBatch_getBufferSize },
 	{ 0, 0 }

+ 2 - 1
src/modules/graphics/opengl/wrap_SpriteBatch.h

@@ -33,7 +33,7 @@ namespace opengl
 
 SpriteBatch *luax_checkspritebatch(lua_State *L, int idx);
 int w_SpriteBatch_add(lua_State *L);
-int w_SpriteBatch_addq(lua_State *L);
+int w_SpriteBatch_addg(lua_State *L);
 int w_SpriteBatch_set(lua_State *L);
 int w_SpriteBatch_setg(lua_State *L);
 int w_SpriteBatch_clear(lua_State *L);
@@ -42,6 +42,7 @@ int w_SpriteBatch_unbind(lua_State *L);
 int w_SpriteBatch_setImage(lua_State *L);
 int w_SpriteBatch_getImage(lua_State *L);
 int w_SpriteBatch_setColor(lua_State *L);
+int w_SpriteBatch_getColor(lua_State *L);
 int w_SpriteBatch_getCount(lua_State *L);
 int w_SpriteBatch_getBufferSize(lua_State *L);