2016-06-17 19:59:42 +02:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-09-25 14:23:30 +02:00
|
|
|
#include "backends/graphics/resvm-sdl/resvm-sdl-graphics.h"
|
2016-06-17 19:59:42 +02:00
|
|
|
#include "backends/platform/sdl/sdl-sys.h"
|
2020-05-09 20:05:54 +02:00
|
|
|
#include "backends/events/sdl/resvm-sdl-events.h"
|
2019-02-12 14:43:18 +08:00
|
|
|
#include "backends/platform/sdl/sdl.h"
|
2020-09-25 14:23:30 +02:00
|
|
|
#include "backends/keymapper/action.h"
|
|
|
|
#include "backends/keymapper/keymap.h"
|
2016-06-17 19:59:42 +02:00
|
|
|
#include "common/config-manager.h"
|
2020-09-25 14:23:30 +02:00
|
|
|
#include "common/fs.h"
|
2016-06-17 19:59:42 +02:00
|
|
|
#include "common/textconsole.h"
|
2020-09-25 14:23:30 +02:00
|
|
|
#include "common/translation.h"
|
2019-02-12 14:43:18 +08:00
|
|
|
#include "common/file.h"
|
2016-06-17 19:59:42 +02:00
|
|
|
|
2020-05-12 23:46:03 +02:00
|
|
|
ResVmSdlGraphicsManager::ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window) :
|
2020-09-25 14:23:30 +02:00
|
|
|
_eventSource(source), _window(window) {
|
2016-06-17 19:59:42 +02:00
|
|
|
ConfMan.registerDefault("fullscreen_res", "desktop");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResVmSdlGraphicsManager::activateManager() {
|
2020-09-25 14:23:30 +02:00
|
|
|
_eventSource->setGraphicsManager(this);
|
2016-06-17 19:59:42 +02:00
|
|
|
|
|
|
|
// Register the graphics manager as a event observer
|
|
|
|
g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResVmSdlGraphicsManager::deactivateManager() {
|
|
|
|
// Unregister the event observer
|
|
|
|
if (g_system->getEventManager()->getEventDispatcher()) {
|
|
|
|
g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);
|
|
|
|
}
|
|
|
|
|
2020-09-25 14:23:30 +02:00
|
|
|
_eventSource->setGraphicsManager(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ResVmSdlGraphicsManager::State ResVmSdlGraphicsManager::getState() const {
|
|
|
|
State state;
|
|
|
|
|
|
|
|
state.screenWidth = getWidth();
|
|
|
|
state.screenHeight = getHeight();
|
|
|
|
state.aspectRatio = getFeatureState(OSystem::kFeatureAspectRatioCorrection);
|
|
|
|
state.fullscreen = getFeatureState(OSystem::kFeatureFullscreenMode);
|
|
|
|
state.cursorPalette = getFeatureState(OSystem::kFeatureCursorPalette);
|
|
|
|
#ifdef USE_RGB_COLOR
|
|
|
|
state.pixelFormat = getScreenFormat();
|
|
|
|
#endif
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ResVmSdlGraphicsManager::setState(const State &state) {
|
|
|
|
beginGFXTransaction();
|
|
|
|
#ifdef USE_RGB_COLOR
|
|
|
|
initSize(state.screenWidth, state.screenHeight, &state.pixelFormat);
|
|
|
|
#else
|
|
|
|
initSize(state.screenWidth, state.screenHeight, nullptr);
|
|
|
|
#endif
|
|
|
|
setFeatureState(OSystem::kFeatureAspectRatioCorrection, state.aspectRatio);
|
|
|
|
setFeatureState(OSystem::kFeatureFullscreenMode, state.fullscreen);
|
|
|
|
setFeatureState(OSystem::kFeatureCursorPalette, state.cursorPalette);
|
|
|
|
|
|
|
|
if (endGFXTransaction() != OSystem::kTransactionSuccess) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Common::Keymap *ResVmSdlGraphicsManager::getKeymap() {
|
|
|
|
using namespace Common;
|
|
|
|
|
|
|
|
Keymap *keymap = new Keymap(Keymap::kKeymapTypeGlobal, "sdl-graphics", _("Graphics"));
|
|
|
|
Action *act;
|
|
|
|
|
|
|
|
if (g_system->hasFeature(OSystem::kFeatureFullscreenMode)) {
|
|
|
|
act = new Action("FULS", _("Toggle fullscreen"));
|
|
|
|
act->addDefaultInputMapping("A+RETURN");
|
|
|
|
act->addDefaultInputMapping("A+KP_ENTER");
|
|
|
|
act->setCustomBackendActionEvent(kActionToggleFullscreen);
|
|
|
|
keymap->addAction(act);
|
|
|
|
}
|
|
|
|
|
|
|
|
act = new Action("SCRS", _("Save screenshot"));
|
|
|
|
act->addDefaultInputMapping("A+s");
|
|
|
|
act->setCustomBackendActionEvent(kActionSaveScreenshot);
|
|
|
|
keymap->addAction(act);
|
|
|
|
|
|
|
|
return keymap;
|
2016-06-17 19:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() {
|
2020-05-10 23:03:57 +02:00
|
|
|
// Default to the desktop resolution, unless the user has set a
|
|
|
|
// resolution in the configuration file
|
2016-06-17 19:59:42 +02:00
|
|
|
const Common::String &fsres = ConfMan.get("fullscreen_res");
|
|
|
|
if (fsres != "desktop") {
|
|
|
|
uint newW, newH;
|
|
|
|
int converted = sscanf(fsres.c_str(), "%ux%u", &newW, &newH);
|
|
|
|
if (converted == 2) {
|
2020-05-10 23:03:57 +02:00
|
|
|
return Common::Rect(newW, newH);
|
2016-06-17 19:59:42 +02:00
|
|
|
} else {
|
|
|
|
warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-10 23:03:57 +02:00
|
|
|
return _window->getDesktopResolution();
|
2016-06-17 19:59:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark --- Mouse ---
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
bool ResVmSdlGraphicsManager::showMouse(bool visible) {
|
|
|
|
SDL_ShowCursor(visible);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ResVmSdlGraphicsManager::lockMouse(bool lock) {
|
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
if (lock)
|
2016-07-22 21:18:39 +02:00
|
|
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
2016-06-17 19:59:42 +02:00
|
|
|
else
|
2016-07-22 21:18:39 +02:00
|
|
|
SDL_SetRelativeMouseMode(SDL_FALSE);
|
2016-06-17 19:59:42 +02:00
|
|
|
#else
|
|
|
|
if (lock)
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_ON);
|
|
|
|
else
|
|
|
|
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-20 20:22:42 +01:00
|
|
|
bool ResVmSdlGraphicsManager::isMouseLocked() const {
|
|
|
|
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
|
|
|
return SDL_GetRelativeMouseMode() == SDL_TRUE;
|
|
|
|
#else
|
|
|
|
return SDL_GrabMode() == SDL_GRAB_ON;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-04-01 21:11:43 +03:00
|
|
|
bool ResVmSdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
|
2016-06-17 19:59:42 +02:00
|
|
|
transformMouseCoordinates(mouse);
|
2020-05-12 23:46:03 +02:00
|
|
|
|
2017-12-03 18:33:19 +01:00
|
|
|
return true;
|
2016-06-17 19:59:42 +02:00
|
|
|
}
|
2019-02-12 14:43:18 +08:00
|
|
|
|
|
|
|
void ResVmSdlGraphicsManager::saveScreenshot() {
|
2020-05-09 20:05:54 +02:00
|
|
|
Common::String filename;
|
2019-02-12 14:43:18 +08:00
|
|
|
|
2020-05-09 20:05:54 +02:00
|
|
|
Common::String screenshotsPath;
|
|
|
|
OSystem_SDL *sdl_g_system = dynamic_cast<OSystem_SDL*>(g_system);
|
|
|
|
if (sdl_g_system)
|
|
|
|
screenshotsPath = sdl_g_system->getScreenshotsPath();
|
|
|
|
|
|
|
|
// Use the name of the running target as a base for screenshot file names
|
|
|
|
Common::String currentTarget = ConfMan.getActiveDomainName();
|
2019-02-12 14:43:18 +08:00
|
|
|
|
|
|
|
#ifdef USE_PNG
|
2020-05-09 20:05:54 +02:00
|
|
|
const char *extension = "png";
|
2019-02-12 14:43:18 +08:00
|
|
|
#else
|
2020-05-09 20:05:54 +02:00
|
|
|
const char *extension = "bmp";
|
2019-02-12 14:43:18 +08:00
|
|
|
#endif
|
|
|
|
|
2020-05-09 20:05:54 +02:00
|
|
|
for (int n = 0;; n++) {
|
2020-08-29 15:14:40 +02:00
|
|
|
filename = Common::String::format("residualvm%s%s-%05d.%s", currentTarget.empty() ? "" : "-",
|
2020-05-09 20:05:54 +02:00
|
|
|
currentTarget.c_str(), n, extension);
|
2019-02-12 14:43:18 +08:00
|
|
|
|
2020-05-09 20:05:54 +02:00
|
|
|
Common::FSNode file = Common::FSNode(screenshotsPath + filename);
|
|
|
|
if (!file.exists()) {
|
|
|
|
break;
|
2019-02-12 14:43:18 +08:00
|
|
|
}
|
|
|
|
}
|
2020-05-09 20:05:54 +02:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int ResVmSdlGraphicsManager::getGraphicsModeScale(int mode) const {
|
|
|
|
return -1;
|
2019-02-12 14:43:18 +08:00
|
|
|
}
|