From db117de2c84359b48b1fd739f93ab2fb277f49a6 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Tue, 9 Feb 2010 15:18:27 -0500 Subject: [PATCH] Switched Image wrap modes to the new string syntax too. --- src/modules/graphics/Image.cpp | 19 +++++++++++++ src/modules/graphics/Image.h | 9 ++++-- src/modules/graphics/opengl/wrap_Image.cpp | 33 ++++++++++++++++------ 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/modules/graphics/Image.cpp b/src/modules/graphics/Image.cpp index a0ac4b793..ee4eb3053 100644 --- a/src/modules/graphics/Image.cpp +++ b/src/modules/graphics/Image.cpp @@ -38,6 +38,16 @@ namespace graphics return filterModes.find(in, out); } + bool Image::getConstant(const char * in, WrapMode & out) + { + return wrapModes.find(in, out); + } + + bool Image::getConstant(WrapMode in, const char *& out) + { + return wrapModes.find(in, out); + } + StringMap::Entry Image::filterModeEntries[] = { { "linear", Image::FILTER_LINEAR }, @@ -45,6 +55,15 @@ namespace graphics }; StringMap Image::filterModes(Image::filterModeEntries, sizeof(Image::filterModeEntries)); + + StringMap::Entry Image::wrapModeEntries[] = + { + { "clamp", Image::WRAP_CLAMP }, + { "repeat", Image::WRAP_REPEAT }, + }; + + StringMap Image::wrapModes(Image::wrapModeEntries, sizeof(Image::wrapModeEntries)); + } // graphics } // love diff --git a/src/modules/graphics/Image.h b/src/modules/graphics/Image.h index 91a54e613..bd9ba311b 100644 --- a/src/modules/graphics/Image.h +++ b/src/modules/graphics/Image.h @@ -37,8 +37,9 @@ namespace graphics enum WrapMode { - WRAP_CLAMP, - WRAP_REPEAT + WRAP_CLAMP = 1, + WRAP_REPEAT, + WRAP_MAX_ENUM }; enum FilterMode @@ -64,11 +65,15 @@ namespace graphics static bool getConstant(const char * in, FilterMode & out); static bool getConstant(FilterMode in, const char *& out); + static bool getConstant(const char * in, WrapMode & out); + static bool getConstant(WrapMode in, const char *& out); private: static StringMap::Entry filterModeEntries[]; static StringMap filterModes; + static StringMap::Entry wrapModeEntries[]; + static StringMap wrapModes; }; // Image diff --git a/src/modules/graphics/opengl/wrap_Image.cpp b/src/modules/graphics/opengl/wrap_Image.cpp index 897a61219..e84f2680f 100644 --- a/src/modules/graphics/opengl/wrap_Image.cpp +++ b/src/modules/graphics/opengl/wrap_Image.cpp @@ -84,20 +84,37 @@ namespace opengl int w_Image_setWrap(lua_State * L) { - Image * t = luax_checkimage(L, 1); + Image * i = luax_checkimage(L, 1); Image::Wrap w; - w.s = (Image::WrapMode)luaL_checkint(L, 2); - w.t = (Image::WrapMode)luaL_checkint(L, 3); - t->setWrap(w); + Image::WrapMode s; + Image::WrapMode t; + const char * sstr = luaL_checkstring(L, 2); + const char * tstr = luaL_checkstring(L, 3); + if (!Image::getConstant(sstr, s)) + return luaL_error(L, "Invalid wrap mode: %s", sstr); + if (!Image::getConstant(tstr, t)) + return luaL_error(L, "Invalid wrap mode, %s", tstr); + + w.s = s; + w.t = t; + i->setWrap(w); return 0; } int w_Image_getWrap(lua_State * L) { - Image * t = luax_checkimage(L, 1); - Image::Wrap w = t->getWrap(); - lua_pushinteger(L, w.s); - lua_pushinteger(L, w.t); + Image * i = luax_checkimage(L, 1); + Image::Wrap w = i->getWrap(); + Image::WrapMode s = w.s; + Image::WrapMode t = w.t; + const char * sstr; + const char * tstr; + if (!Image::getConstant(s, sstr)) + return luaL_error(L, "Invalid filter mode: %s", sstr); + if (!Image::getConstant(t, tstr)) + return luaL_error(L, "Invalid filter mode: %s", tstr); + lua_pushstring(L, sstr); + lua_pushstring(L, tstr); return 2; }