ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

resvm-sdl-graphics.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "backends/graphics/sdl/resvm-sdl-graphics.h"
00024 
00025 #include "backends/platform/sdl/sdl-sys.h"
00026 #include "backends/events/sdl/resvm-sdl-events.h"
00027 #include "backends/platform/sdl/sdl.h"
00028 
00029 #include "common/config-manager.h"
00030 #include "common/textconsole.h"
00031 #include "common/file.h"
00032 
00033 ResVmSdlGraphicsManager::ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window) :
00034         SdlGraphicsManager(source, window)  {
00035     ConfMan.registerDefault("fullscreen_res", "desktop");
00036 }
00037 
00038 ResVmSdlGraphicsManager::~ResVmSdlGraphicsManager() {
00039 }
00040 
00041 void ResVmSdlGraphicsManager::activateManager() {
00042     SdlGraphicsManager::activateManager();
00043 
00044     // Register the graphics manager as a event observer
00045     g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false);
00046 }
00047 
00048 void ResVmSdlGraphicsManager::deactivateManager() {
00049     // Unregister the event observer
00050     if (g_system->getEventManager()->getEventDispatcher()) {
00051         g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);
00052     }
00053 
00054     SdlGraphicsManager::deactivateManager();
00055 }
00056 
00057 Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() {
00058     // Default to the desktop resolution, unless the user has set a
00059     // resolution in the configuration file
00060     const Common::String &fsres = ConfMan.get("fullscreen_res");
00061     if (fsres != "desktop") {
00062         uint newW, newH;
00063         int converted = sscanf(fsres.c_str(), "%ux%u", &newW, &newH);
00064         if (converted == 2) {
00065             return Common::Rect(newW, newH);
00066         } else {
00067             warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str());
00068         }
00069     }
00070 
00071     return _window->getDesktopResolution();
00072 }
00073 
00074 #pragma mark -
00075 #pragma mark --- Mouse ---
00076 #pragma mark -
00077 
00078 bool ResVmSdlGraphicsManager::showMouse(bool visible) {
00079     SDL_ShowCursor(visible);
00080     return true;
00081 }
00082 
00083 bool ResVmSdlGraphicsManager::lockMouse(bool lock) {
00084 #if SDL_VERSION_ATLEAST(2, 0, 0)
00085     if (lock)
00086         SDL_SetRelativeMouseMode(SDL_TRUE);
00087     else
00088         SDL_SetRelativeMouseMode(SDL_FALSE);
00089 #else
00090     if (lock)
00091         SDL_WM_GrabInput(SDL_GRAB_ON);
00092     else
00093         SDL_WM_GrabInput(SDL_GRAB_OFF);
00094 #endif
00095     return true;
00096 }
00097 
00098 bool ResVmSdlGraphicsManager::isMouseLocked() const {
00099 #if SDL_VERSION_ATLEAST(2, 0, 0)
00100     return SDL_GetRelativeMouseMode() == SDL_TRUE;
00101 #else
00102     return SDL_GrabMode() == SDL_GRAB_ON;
00103 #endif
00104 }
00105 
00106 bool ResVmSdlGraphicsManager::notifyEvent(const Common::Event &event) {
00107     switch ((int)event.type) {
00108         case Common::EVENT_KEYDOWN:
00109             if (event.kbd.hasFlags(Common::KBD_ALT) && event.kbd.keycode == Common::KEYCODE_s) {
00110                 saveScreenshot();
00111                 return true;
00112             }
00113             break;
00114         case Common::EVENT_KEYUP:
00115             break;
00116         default:
00117             break;
00118     }
00119 
00120     return false;
00121 }
00122 
00123 bool ResVmSdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
00124     transformMouseCoordinates(mouse);
00125 
00126     return true;
00127 }
00128 
00129 void ResVmSdlGraphicsManager::saveScreenshot() {
00130     Common::String filename;
00131 
00132     Common::String screenshotsPath;
00133     OSystem_SDL *sdl_g_system = dynamic_cast<OSystem_SDL*>(g_system);
00134     if (sdl_g_system)
00135         screenshotsPath = sdl_g_system->getScreenshotsPath();
00136 
00137     // Use the name of the running target as a base for screenshot file names
00138     Common::String currentTarget = ConfMan.getActiveDomainName();
00139 
00140 #ifdef USE_PNG
00141     const char *extension = "png";
00142 #else
00143     const char *extension = "bmp";
00144 #endif
00145 
00146     for (int n = 0;; n++) {
00147         filename = Common::String::format("resiudalvm%s%s-%05d.%s", currentTarget.empty() ? "" : "-",
00148                                           currentTarget.c_str(), n, extension);
00149 
00150         Common::FSNode file = Common::FSNode(screenshotsPath + filename);
00151         if (!file.exists()) {
00152             break;
00153         }
00154     }
00155 
00156     if (saveScreenshot(screenshotsPath + filename)) {
00157         if (screenshotsPath.empty())
00158             debug("Saved screenshot '%s' in current directory", filename.c_str());
00159         else
00160             debug("Saved screenshot '%s' in directory '%s'", filename.c_str(), screenshotsPath.c_str());
00161     } else {
00162         if (screenshotsPath.empty())
00163             warning("Could not save screenshot in current directory");
00164         else
00165             warning("Could not save screenshot in directory '%s'", screenshotsPath.c_str());
00166     }
00167 }
00168 
00169 int ResVmSdlGraphicsManager::getGraphicsModeScale(int mode) const {
00170     return -1;
00171 }


Generated on Sat May 23 2020 05:00:28 for ResidualVM by doxygen 1.7.1
curved edge   curved edge