From: John L. <jr...@us...> - 2008-01-22 04:04:30
|
Update of /cvsroot/wxlua/wxLua/bindings/wxwidgets In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv25573/wxLua/bindings/wxwidgets Modified Files: wxcore_appframe.i wxcore_gdi.i wxcore_override.hpp Log Message: Add new wxBitmap constructor for XBMs using a table. Do not run wxApp::MainLoop() if it is already running. Index: wxcore_gdi.i =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/wxcore_gdi.i,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** wxcore_gdi.i 22 Dec 2007 06:07:08 -0000 1.3 --- wxcore_gdi.i 22 Jan 2008 04:04:24 -0000 1.4 *************** *** 896,902 **** --- 896,907 ---- wxBitmap(const wxImage &image, int depth = -1) + // %override wxBitmap(lua string, int width, int height, int depth) // C++ Func: wxBitmap(const char bits[], int width, int height, int depth = 1) // Creates a bitmap from an array of bits in the form of a Lua string. %override_name wxLua_wxBitmapFromBits_constructor wxBitmap(const char* mono_bits, int width, int height, int depth /* = 1 */); + // %override wxBitmap(LuaTable charTable, int width, int height, int depth) + // C++ Func: wxBitmap(const char bits[], int width, int height, int depth = 1) + // Creates a bitmap from an array of chars in a Lua table. + %override_name wxLua_wxBitmapFromBitTable_constructor wxBitmap(LuaTable charTable, int width, int height, int depth /* = 1 */); // %override wxBitmap(LuaTable stringTable where each index is a row in the image) Index: wxcore_appframe.i =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/wxcore_appframe.i,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** wxcore_appframe.i 20 Jan 2008 19:23:00 -0000 1.4 --- wxcore_appframe.i 22 Jan 2008 04:04:24 -0000 1.5 *************** *** 43,48 **** // bool Initialized() obsolete in wxWidgets ! // %override int wxApp::MainLoop() : Only calls it if !wxLuaState::sm_wxAppMainLoop_will_run, returns 0 if it is true. // C++ Func: int MainLoop() int MainLoop() --- 43,49 ---- // bool Initialized() obsolete in wxWidgets ! // %override int wxApp::MainLoop() // C++ Func: int MainLoop() + // Only calls it if (!IsMainLoopRuinning() && !wxLuaState::sm_wxAppMainLoop_will_run), returns 0 if not called. int MainLoop() Index: wxcore_override.hpp =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/wxwidgets/wxcore_override.hpp,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** wxcore_override.hpp 20 Jan 2008 19:23:00 -0000 1.17 --- wxcore_override.hpp 22 Jan 2008 04:04:24 -0000 1.18 *************** *** 31,35 **** int returns = 0; ! if (!wxLuaState::sm_wxAppMainLoop_will_run) returns = self->MainLoop(); --- 31,35 ---- int returns = 0; ! if (!wxLuaState::sm_wxAppMainLoop_will_run && !wxApp::IsMainLoopRunning()) returns = self->MainLoop(); *************** *** 1483,1486 **** --- 1483,1533 ---- %end + %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; + } + %end + %override wxLua_wxBitmapFromData_constructor // %win wxBitmap(void* data, int type, int width, int height, int depth = -1) |