diff --git a/driver.h b/driver.h index 9f8b86d31f8..f3721c55576 100644 --- a/driver.h +++ b/driver.h @@ -81,7 +81,7 @@ public: virtual void drawDepthBitmap(int x, int y, int w, int h, char *data) = 0; - virtual void getSnapshot(int x, int y, int w, int h, char **data, int flags) = 0; + virtual Bitmap *getScreenshot(int w, int h) = 0; virtual void enableDim(int x, int y, int w, int h) = 0; virtual void disableDim(int x, int y, int w, int h) = 0; diff --git a/driver_gl.cpp b/driver_gl.cpp index 1b422997a83..f163878a844 100644 --- a/driver_gl.cpp +++ b/driver_gl.cpp @@ -689,7 +689,8 @@ void DriverGL::destroyTextBitmap(TextObjectHandle *handle) { delete[] (GLuint *)handle->texIds; } -void DriverGL::getSnapshot(int x, int y, int w, int h, char **data, int flags) { +Bitmap *DriverGL::getScreenshot(int w, int h) { + return NULL; } void DriverGL::drawDim() { diff --git a/driver_gl.h b/driver_gl.h index b8db4678576..4aa7c4852ad 100644 --- a/driver_gl.h +++ b/driver_gl.h @@ -65,7 +65,7 @@ public: void drawDepthBitmap(int x, int y, int w, int h, char *data); void drawBitmap(); - void getSnapshot(int x, int y, int w, int h, char **data, int flags); + Bitmap *getScreenshot(int w, int h); void enableDim(int x, int y, int w, int h) { _dim = true; } void disableDim(int x, int y, int w, int h) { _dim = false; } diff --git a/driver_tinygl.cpp b/driver_tinygl.cpp index 55b9c78075d..b9419ffbbe4 100644 --- a/driver_tinygl.cpp +++ b/driver_tinygl.cpp @@ -473,7 +473,22 @@ void DriverTinyGL::destroyTextBitmap(TextObjectHandle *handle) { SDL_FreeSurface((SDL_Surface *)handle->surface); } -void DriverTinyGL::getSnapshot(int x, int y, int w, int h, char **data, int flags) { +Bitmap *DriverTinyGL::getScreenshot(int w, int h) { + uint16 *buffer = new uint16[w * h]; + assert(buffer); + + float step_x = 640.0 / w; + float step_y = 480.0 / h; + int step = 0; + for (float y = 0; y < 479; y += step_y) { + for (float x = 0; x < 639; x += step_x) { + buffer[step++] = *((uint16 *)(_screen->pixels) + (int)y * 640 + (int)x); + } + } + + Bitmap *screenshot = new Bitmap((char *)buffer, w, h, "screenshot"); + delete []buffer; + return screenshot; } void DriverTinyGL::drawDim() { diff --git a/driver_tinygl.h b/driver_tinygl.h index 670398d9eba..def77ab7c0c 100644 --- a/driver_tinygl.h +++ b/driver_tinygl.h @@ -67,7 +67,7 @@ public: void drawDepthBitmap(int x, int y, int w, int h, char *data); void drawBitmap(); - void getSnapshot(int x, int y, int w, int h, char **data, int flags); + Bitmap *getScreenshot(int w, int h); void enableDim(int x, int y, int w, int h) { _dim = true; } void disableDim(int x, int y, int w, int h) { _dim = false; } diff --git a/lua.cpp b/lua.cpp index 265c17526b7..f80721ad4b5 100644 --- a/lua.cpp +++ b/lua.cpp @@ -1312,6 +1312,8 @@ static void luaFileFindFirst() { std::string dir_strWin32 = path; g_searchFile = FindFirstFile(dir_strWin32.c_str(), &g_find_file_data); g_firstFind = true; + if (g_searchFile == INVALID_HANDLE_VALUE) + g_searchFile = NULL; #else g_searchFile = opendir(path); #endif @@ -1532,7 +1534,7 @@ static void menuHandler() { * a lot of the operations necessary to use the menu */ bool menuChanged = false, sliderChanged = false; - switch(key) { + switch (key) { case SDLK_ESCAPE: { lua_Object close = getTableFunction(menuTable, "cancel"); @@ -1881,6 +1883,15 @@ static void GetCurrentScript() { } static void ScreenShot() { + int width = check_int(1); + int height = check_int(2); + + Bitmap *screenshot = g_driver->getScreenshot(width, height); + if (screenshot) { + lua_pushusertag(screenshot, MKID('VBUF')); + } else { + lua_pushnil(); + } } static void SubmitSaveGameData() {