lugre_texatlas_L.cpp
Go to the documentation of this file.00001 #include "lugre_prefix.h"
00002 #include "lugre_luabind.h"
00003 #include "lugre_ogrewrapper.h"
00004 #include "lugre_texatlas.h"
00005 #include "lugre_image.h"
00006 #include <Ogre.h>
00007
00008 extern "C" {
00009 #include "lua.h"
00010 #include "lauxlib.h"
00011 #include "lualib.h"
00012 }
00013
00014 using namespace Ogre;
00015
00016 namespace Lugre {
00017
00018 class cTexAtlas_L : public cLuaBind<cTexAtlas> { public:
00020 virtual void RegisterMethods (lua_State *L) { PROFILE
00021 #define REGISTER_METHOD(methodname) mlMethod.push_back(make_luaL_reg(#methodname,&cTexAtlas_L::methodname));
00022 REGISTER_METHOD(Destroy);
00023 REGISTER_METHOD(AddImage);
00024 REGISTER_METHOD(MakeImage);
00025 REGISTER_METHOD(MakeTexture);
00026 REGISTER_METHOD(LoadToTexture);
00027
00028 lua_register(L,"CreateTexAtlas", &cTexAtlas_L::CreateTexAtlas);
00029 }
00030
00031
00032
00034 static int Destroy (lua_State *L) { PROFILE delete checkudata_alive(L); return 0; }
00035
00036
00037
00041 static int AddImage (lua_State *L) { PROFILE
00042 cImage* pImage = cLuaBind<cImage>::checkudata_alive(L,2);
00043 int iBorderPixels = (lua_gettop(L) >= 3 && !lua_isnil(L,3)) ? luaL_checkint(L,3) : 4;
00044 bool bWrap = (lua_gettop(L) >= 4 && !lua_isnil(L,4)) ? lua_toboolean(L,4) : true;
00045 Ogre::Rectangle r;
00046 if (!checkudata_alive(L)->AddImage(pImage->mImage,r,iBorderPixels,bWrap)) return 0;
00047 lua_pushboolean(L,true);
00048 lua_pushnumber(L,r.left);
00049 lua_pushnumber(L,r.right);
00050 lua_pushnumber(L,r.top);
00051 lua_pushnumber(L,r.bottom);
00052 return 5;
00053 }
00054
00055
00057 static int MakeImage (lua_State *L) { PROFILE
00058 cImage* pImage = cLuaBind<cImage>::checkudata_alive(L,2);
00059 checkudata_alive(L)->MakeImage(pImage->mImage);
00060 return 0;
00061 }
00062
00066 static int MakeTexture (lua_State *L) { PROFILE
00067 std::string sTexName = (lua_gettop(L) >= 2 && !lua_isnil(L,2)) ? luaL_checkstring(L,2) : cOgreWrapper::GetSingleton().GetUniqueName();
00068 checkudata_alive(L)->MakeTexture(sTexName);
00069 lua_pushstring(L,sTexName.c_str());
00070 return 1;
00071 }
00072
00075 static int LoadToTexture (lua_State *L) { PROFILE
00076 std::string sTexName = luaL_checkstring(L,2);
00077 Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().load(sTexName,Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00078 if (tex.isNull()) return 0;
00079 Ogre::Image myImage;
00080 checkudata_alive(L)->MakeImage(myImage);
00081 tex->unload();
00082 tex->loadImage(myImage);
00083 lua_pushboolean(L,true);
00084 return 1;
00085 }
00086
00087
00088
00091 static int CreateTexAtlas (lua_State *L) { PROFILE
00092 int w = luaL_checkint(L,1);
00093 int h = luaL_checkint(L,2);
00094 return CreateUData(L,new cTexAtlas(w,h));
00095 }
00096
00097 virtual const char* GetLuaTypeName () { return "lugre.TexAtlas"; }
00098 };
00099
00101 void cTexAtlas::LuaRegister (lua_State *L) { PROFILE
00102 cLuaBind<cTexAtlas>::GetSingletonPtr(new cTexAtlas_L())->LuaRegister(L);
00103 }
00104
00105 };