Windows: Add "Save Screenshot" menu command

This commit is contained in:
kichikuou
2020-12-31 14:17:55 +09:00
parent 297ce20a83
commit 75cbb2bcef
5 changed files with 46 additions and 1 deletions
+2
View File
@@ -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
+1
View File
@@ -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
+19 -1
View File
@@ -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" {
+2
View File
@@ -136,6 +136,8 @@ public:
void load_cursor(int page);
void select_cursor();
void save_screenshot(const char* path);
bool dirty;
// ACG.DAT
+22
View File
@@ -1,6 +1,7 @@
#include "nact.h"
#include <windows.h>
#include <windowsx.h>
#include <time.h>
#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;