aboutsummaryrefslogtreecommitdiff
path: root/backends/graphics/sdl/sdl-graphics.cpp
diff options
context:
space:
mode:
authorCameron Cawley2019-03-10 16:25:25 +0000
committerFilippos Karapetis2019-03-10 18:25:25 +0200
commitf426ba6c36f4d825e427535514eb68855c64c2d1 (patch)
tree0a0ddac623be7ad58a63d52fc22d72c942436d8f /backends/graphics/sdl/sdl-graphics.cpp
parent1c6905217e4c249a67a5ca289868e0fcc68ae9eb (diff)
downloadscummvm-rg350-f426ba6c36f4d825e427535514eb68855c64c2d1.tar.gz
scummvm-rg350-f426ba6c36f4d825e427535514eb68855c64c2d1.tar.bz2
scummvm-rg350-f426ba6c36f4d825e427535514eb68855c64c2d1.zip
SDL: Move fullscreen and screenshot event handling to SdlGraphicsManager (#1522)
Diffstat (limited to 'backends/graphics/sdl/sdl-graphics.cpp')
-rw-r--r--backends/graphics/sdl/sdl-graphics.cpp84
1 files changed, 84 insertions, 0 deletions
diff --git a/backends/graphics/sdl/sdl-graphics.cpp b/backends/graphics/sdl/sdl-graphics.cpp
index 1e37310ca2..767ce24949 100644
--- a/backends/graphics/sdl/sdl-graphics.cpp
+++ b/backends/graphics/sdl/sdl-graphics.cpp
@@ -22,10 +22,14 @@
#include "backends/graphics/sdl/sdl-graphics.h"
#include "backends/platform/sdl/sdl-sys.h"
+#include "backends/platform/sdl/sdl.h"
#include "backends/events/sdl/sdl-events.h"
#include "common/config-manager.h"
#include "common/textconsole.h"
#include "graphics/scaler/aspect.h"
+#ifdef USE_OSD
+#include "common/translation.h"
+#endif
SdlGraphicsManager::SdlGraphicsManager(SdlEventSource *source, SdlWindow *window)
: _eventSource(source), _window(window), _hwScreen(nullptr)
@@ -265,3 +269,83 @@ bool SdlGraphicsManager::createOrUpdateWindow(int width, int height, const Uint3
return true;
}
#endif
+
+void SdlGraphicsManager::saveScreenshot() {
+ Common::String filename;
+
+ Common::String screenshotsPath;
+ OSystem_SDL *sdl_g_system = dynamic_cast<OSystem_SDL*>(g_system);
+ if (sdl_g_system)
+ screenshotsPath = sdl_g_system->getScreenshotsPath();
+
+ for (int n = 0;; n++) {
+ SDL_RWops *file;
+
+#ifdef USE_PNG
+ filename = Common::String::format("scummvm%05d.png", n);
+#else
+ filename = Common::String::format("scummvm%05d.bmp", n);
+#endif
+
+ file = SDL_RWFromFile((screenshotsPath + filename).c_str(), "r");
+
+ if (!file)
+ break;
+ SDL_RWclose(file);
+ }
+
+ if (saveScreenshot(screenshotsPath + filename)) {
+ if (screenshotsPath.empty())
+ debug("Saved screenshot '%s' in current directory", filename.c_str());
+ else
+ debug("Saved screenshot '%s' in directory '%s'", filename.c_str(), screenshotsPath.c_str());
+ } else {
+ if (screenshotsPath.empty())
+ warning("Could not save screenshot in current directory");
+ else
+ warning("Could not save screenshot in directory '%s'", screenshotsPath.c_str());
+ }
+}
+
+bool SdlGraphicsManager::notifyEvent(const Common::Event &event) {
+ switch ((int)event.type) {
+ case Common::EVENT_KEYDOWN:
+ // Alt-Return and Alt-Enter toggle full screen mode
+ if (event.kbd.hasFlags(Common::KBD_ALT) &&
+ (event.kbd.keycode == Common::KEYCODE_RETURN ||
+ event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER)) {
+ beginGFXTransaction();
+ setFeatureState(OSystem::kFeatureFullscreenMode, !getFeatureState(OSystem::kFeatureFullscreenMode));
+ endGFXTransaction();
+#ifdef USE_OSD
+ if (getFeatureState(OSystem::kFeatureFullscreenMode))
+ displayMessageOnOSD(_("Fullscreen mode"));
+ else
+ displayMessageOnOSD(_("Windowed mode"));
+#endif
+ return true;
+ }
+
+ // Alt-S: Create a screenshot
+ if (event.kbd.hasFlags(Common::KBD_ALT) && event.kbd.keycode == 's') {
+ saveScreenshot();
+ return true;
+ }
+
+ break;
+
+ case Common::EVENT_KEYUP:
+ if (event.kbd.hasFlags(Common::KBD_ALT)) {
+ return event.kbd.keycode == Common::KEYCODE_RETURN
+ || event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER
+ || event.kbd.keycode == Common::KEYCODE_s;
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ return false;
+}