From: John L. <jr...@us...> - 2008-01-22 04:04:30
|
Update of /cvsroot/wxlua/wxLua/modules/wxbind/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv25573/wxLua/modules/wxbind/src Modified Files: wxcore_appframe.cpp wxcore_gdi.cpp Log Message: Add new wxBitmap constructor for XBMs using a table. Do not run wxApp::MainLoop() if it is already running. Index: wxcore_gdi.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/src/wxcore_gdi.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** wxcore_gdi.cpp 22 Dec 2007 06:07:13 -0000 1.13 --- wxcore_gdi.cpp 22 Jan 2008 04:04:24 -0000 1.14 *************** *** 7776,7783 **** #if (wxLUA_USE_wxBitmap) && ((defined(__WXMSW__)) && (wxLUA_USE_wxBitmap)) ! #define wxLua_wxBitmap_constructor7 wxLua_wxBitmapFromData_constructor ! static wxLuaArgType s_wxluatypeArray_wxLua_wxBitmap_constructor7[] = { &g_wxluatype_TSTRING, &g_wxluatype_TNUMBER, &g_wxluatype_TNUMBER, &g_wxluatype_TNUMBER, &g_wxluatype_TNUMBER, NULL }; ! static int LUACALL wxLua_wxBitmap_constructor7(lua_State *L); ! // static wxLuaBindCFunc s_wxluafunc_wxLua_wxBitmap_constructor7[1] = {{ wxLua_wxBitmap_constructor7, WXLUAMETHOD_CONSTRUCTOR, 5, 5, s_wxluatypeArray_wxLua_wxBitmap_constructor7 }}; // %override wxLua_wxBitmapFromData_constructor // %win wxBitmap(void* data, int type, int width, int height, int depth = -1) --- 7776,7783 ---- #if (wxLUA_USE_wxBitmap) && ((defined(__WXMSW__)) && (wxLUA_USE_wxBitmap)) ! #define wxLua_wxBitmap_constructor8 wxLua_wxBitmapFromData_constructor ! static wxLuaArgType s_wxluatypeArray_wxLua_wxBitmap_constructor8[] = { &g_wxluatype_TSTRING, &g_wxluatype_TNUMBER, &g_wxluatype_TNUMBER, &g_wxluatype_TNUMBER, &g_wxluatype_TNUMBER, NULL }; ! static int LUACALL wxLua_wxBitmap_constructor8(lua_State *L); ! // static wxLuaBindCFunc s_wxluafunc_wxLua_wxBitmap_constructor8[1] = {{ wxLua_wxBitmap_constructor8, WXLUAMETHOD_CONSTRUCTOR, 5, 5, s_wxluatypeArray_wxLua_wxBitmap_constructor8 }}; // %override wxLua_wxBitmapFromData_constructor // %win wxBitmap(void* data, int type, int width, int height, int depth = -1) *************** *** 7811,7818 **** #endif // (wxLUA_USE_wxBitmap) && ((defined(__WXMSW__)) && (wxLUA_USE_wxBitmap)) ! #define wxLua_wxBitmap_constructor6 wxLua_wxBitmapFromXPMData_constructor ! static wxLuaArgType s_wxluatypeArray_wxLua_wxBitmap_constructor6[] = { &g_wxluatype_TTABLE, NULL }; ! static int LUACALL wxLua_wxBitmap_constructor6(lua_State *L); ! // static wxLuaBindCFunc s_wxluafunc_wxLua_wxBitmap_constructor6[1] = {{ wxLua_wxBitmap_constructor6, WXLUAMETHOD_CONSTRUCTOR, 1, 1, s_wxluatypeArray_wxLua_wxBitmap_constructor6 }}; // %override wxLua_wxBitmapFromXPMData_constructor // %constructor wxXmlResourceGetDefault() --- 7811,7818 ---- #endif // (wxLUA_USE_wxBitmap) && ((defined(__WXMSW__)) && (wxLUA_USE_wxBitmap)) ! #define wxLua_wxBitmap_constructor7 wxLua_wxBitmapFromXPMData_constructor ! static wxLuaArgType s_wxluatypeArray_wxLua_wxBitmap_constructor7[] = { &g_wxluatype_TTABLE, NULL }; ! static int LUACALL wxLua_wxBitmap_constructor7(lua_State *L); ! // static wxLuaBindCFunc s_wxluafunc_wxLua_wxBitmap_constructor7[1] = {{ wxLua_wxBitmap_constructor7, WXLUAMETHOD_CONSTRUCTOR, 1, 1, s_wxluatypeArray_wxLua_wxBitmap_constructor7 }}; // %override wxLua_wxBitmapFromXPMData_constructor // %constructor wxXmlResourceGetDefault() *************** *** 7839,7842 **** --- 7839,7893 ---- + #define wxLua_wxBitmap_constructor6 wxLua_wxBitmapFromBitTable_constructor + static wxLuaArgType s_wxluatypeArray_wxLua_wxBitmap_constructor6[] = { &g_wxluatype_TTABLE, &g_wxluatype_TNUMBER, &g_wxluatype_TNUMBER, &g_wxluatype_TNUMBER, NULL }; + static int LUACALL wxLua_wxBitmap_constructor6(lua_State *L); + // static wxLuaBindCFunc s_wxluafunc_wxLua_wxBitmap_constructor6[1] = {{ wxLua_wxBitmap_constructor6, WXLUAMETHOD_CONSTRUCTOR, 4, 4, s_wxluatypeArray_wxLua_wxBitmap_constructor6 }}; + // %override wxLua_wxBitmapFromBitTable_constructor + // %win wxBitmap(LuaTable charTable, int width, int height, int depth = -1) + static int LUACALL wxLua_wxBitmapFromBitTable_constructor(lua_State *L) + { + // get number of arguments + int argCount = lua_gettop(L); + // int depth = -1 + int depth = (argCount >= 4 ? (int)wxlua_getintegertype(L, 4) : -1); + // int height + int height = (int)wxlua_getintegertype(L, 3); + // int width + int width = (int)wxlua_getintegertype(L, 2); + + if (!wxlua_iswxluatype(lua_type(L, 1), WXLUA_TTABLE)) + wxlua_argerror(L, 1, wxT("a 'table'")); + + // const char* bits + int size = height*width/8; + char *bits = (char*)malloc(size); + + for (int n = 0; n < size; ++n) + { + lua_rawgeti(L, 1, n+1); // Lua array starts at 1 + + if (!wxlua_iswxluatype(lua_type(L, -1), WXLUA_TINTEGER)) + { + free(bits); + wxlua_argerror(L, 1, wxT("a 'table of chars of size width*height/8'")); + } + + bits[n] = (char)lua_tonumber(L, -1); + lua_pop(L, 1); + } + + // call constructor + wxBitmap *returns = new wxBitmap(bits, width, height, depth); + free(bits); + + // add to tracked memory list + wxluaO_addgcobject(L, returns); + // push the constructed class pointer + wxluaT_pushuserdatatype(L, returns, g_wxluatype_wxBitmap); + // return the number of parameters + return 1; + } + + #define wxLua_wxBitmap_constructor5 wxLua_wxBitmapFromBits_constructor static wxLuaArgType s_wxluatypeArray_wxLua_wxBitmap_constructor5[] = { &g_wxluatype_TSTRING, &g_wxluatype_TNUMBER, &g_wxluatype_TNUMBER, &g_wxluatype_TNUMBER, NULL }; *************** *** 7982,7988 **** #if (wxLUA_USE_wxBitmap) && ((defined(__WXMSW__)) && (wxLUA_USE_wxBitmap)) ! { wxLua_wxBitmap_constructor7, WXLUAMETHOD_CONSTRUCTOR, 5, 5, s_wxluatypeArray_wxLua_wxBitmap_constructor7 }, #endif // (wxLUA_USE_wxBitmap) && ((defined(__WXMSW__)) && (wxLUA_USE_wxBitmap)) ! { wxLua_wxBitmap_constructor6, WXLUAMETHOD_CONSTRUCTOR, 1, 1, s_wxluatypeArray_wxLua_wxBitmap_constructor6 }, { wxLua_wxBitmap_constructor5, WXLUAMETHOD_CONSTRUCTOR, 4, 4, s_wxluatypeArray_wxLua_wxBitmap_constructor5 }, --- 8033,8040 ---- #if (wxLUA_USE_wxBitmap) && ((defined(__WXMSW__)) && (wxLUA_USE_wxBitmap)) ! { wxLua_wxBitmap_constructor8, WXLUAMETHOD_CONSTRUCTOR, 5, 5, s_wxluatypeArray_wxLua_wxBitmap_constructor8 }, #endif // (wxLUA_USE_wxBitmap) && ((defined(__WXMSW__)) && (wxLUA_USE_wxBitmap)) ! { wxLua_wxBitmap_constructor7, WXLUAMETHOD_CONSTRUCTOR, 1, 1, s_wxluatypeArray_wxLua_wxBitmap_constructor7 }, ! { wxLua_wxBitmap_constructor6, WXLUAMETHOD_CONSTRUCTOR, 4, 4, s_wxluatypeArray_wxLua_wxBitmap_constructor6 }, { wxLua_wxBitmap_constructor5, WXLUAMETHOD_CONSTRUCTOR, 4, 4, s_wxluatypeArray_wxLua_wxBitmap_constructor5 }, Index: wxcore_appframe.cpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/modules/wxbind/src/wxcore_appframe.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** wxcore_appframe.cpp 20 Jan 2008 19:23:01 -0000 1.9 --- wxcore_appframe.cpp 22 Jan 2008 04:04:24 -0000 1.10 *************** *** 199,203 **** int returns = 0; ! if (!wxLuaState::sm_wxAppMainLoop_will_run) returns = self->MainLoop(); --- 199,203 ---- int returns = 0; ! if (!wxLuaState::sm_wxAppMainLoop_will_run && !wxApp::IsMainLoopRunning()) returns = self->MainLoop(); |