From 75cbb2bcefa81e25623bba3ccf90236fdc805c2f Mon Sep 17 00:00:00 2001 From: kichikuou Date: Thu, 31 Dec 2020 14:17:27 +0900 Subject: [PATCH] Windows: Add "Save Screenshot" menu command --- src/res3/Script1.rc | 2 ++ src/res3/resource.h | 1 + src/sys/ags.cpp | 20 +++++++++++++++++++- src/sys/ags.h | 2 ++ src/win/nact_win.cpp | 22 ++++++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/res3/Script1.rc b/src/res3/Script1.rc index 2afbae1..c671a55 100644 --- a/src/res3/Script1.rc +++ b/src/res3/Script1.rc @@ -30,6 +30,8 @@ IDR_MENU1 MENU DISCARDABLE BEGIN POPUP "File" BEGIN + MENUITEM "Save Screenshot", ID_SCREENSHOT + MENUITEM SEPARATOR MENUITEM "Restart", ID_RESTART MENUITEM SEPARATOR MENUITEM "Exit", ID_EXIT diff --git a/src/res3/resource.h b/src/res3/resource.h index c48f571..87672f9 100644 --- a/src/res3/resource.h +++ b/src/res3/resource.h @@ -20,6 +20,7 @@ #define IDR_R42 116 #define IDR_RG2 117 #define IDR_T2 118 +#define ID_SCREENSHOT 40000 #define ID_RESTART 40001 #define ID_EXIT 40002 #define ID_SCREEN_WINDOW 40003 diff --git a/src/sys/ags.cpp b/src/sys/ags.cpp index f4ce89a..d839d53 100644 --- a/src/sys/ags.cpp +++ b/src/sys/ags.cpp @@ -517,7 +517,8 @@ void AGS::invalidate_screen(int sx, int sy, int width, int height) dirty = true; } -void AGS::update_screen() { +void AGS::update_screen() +{ if (!dirty) return; SDL_RenderClear(sdlRenderer); @@ -526,6 +527,23 @@ void AGS::update_screen() { dirty = false; } +void AGS::save_screenshot(const char* path) +{ + SDL_Surface* sf = SDL_CreateRGBSurface(0, 640, screen_height, 32, 0, 0, 0, 0); + SDL_Rect r = {0, 0, 640, screen_height}; + SDL_UnlockSurface(hBmpDest); + SDL_BlitSurface(hBmpDest, &r, sf, NULL); + SDL_LockSurface(hBmpDest); + + if (SDL_SaveBMP(sf, path) != 0) { + SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "system3", + SDL_GetError(), g_window); + SDL_ClearError(); + } + + SDL_FreeSurface(sf); +} + #ifdef __EMSCRIPTEN__ extern "C" { diff --git a/src/sys/ags.h b/src/sys/ags.h index f16d953..260b6d7 100644 --- a/src/sys/ags.h +++ b/src/sys/ags.h @@ -136,6 +136,8 @@ public: void load_cursor(int page); void select_cursor(); + void save_screenshot(const char* path); + bool dirty; // ACG.DAT diff --git a/src/win/nact_win.cpp b/src/win/nact_win.cpp index c25daf4..ac9db51 100644 --- a/src/win/nact_win.cpp +++ b/src/win/nact_win.cpp @@ -1,6 +1,7 @@ #include "nact.h" #include #include +#include #include "SDL_syswm.h" #include "ags.h" #include "mako.h" @@ -38,6 +39,24 @@ void init_console(int sys_ver) #endif } +void save_screenshot(AGS* ags) +{ + char pathbuf[MAX_PATH]; + time_t t = time(NULL); + struct tm *lt = localtime(&t); + strftime(pathbuf, sizeof(pathbuf), "system3-%Y%m%d-%H%M%S.bmp", lt); + + OPENFILENAME ofn = {sizeof(OPENFILENAME)}; + ofn.hwndOwner = get_hwnd(g_window); + ofn.lpstrFilter = "Bitmap files (*.bmp)\0*.bmp\0All files (*.*)\0*.*\0"; + ofn.lpstrFile = pathbuf; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR; + + if (GetSaveFileName(&ofn)) + ags->save_screenshot(pathbuf); +} + INT_PTR CALLBACK TextDialogProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { static NACT* nact; @@ -150,6 +169,9 @@ bool NACT::handle_platform_event(const SDL_Event& e) switch (msg->msg.win.msg) { case WM_COMMAND: switch (msg->msg.win.wParam) { + case ID_SCREENSHOT: + save_screenshot(ags); + break; case ID_RESTART: terminate = restart_after_terminate = true; break;