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/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 static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
00034         {0, 0, 0}
00035 };
00036 
00037 ResVmSdlGraphicsManager::ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window, const Capabilities &capabilities) :
00038         SdlGraphicsManager(source, window),
00039         _fullscreen(false),
00040         _lockAspectRatio(true),
00041         _overlayVisible(false),
00042         _screenChangeCount(0),
00043         _capabilities(capabilities),
00044         _engineRequestedWidth(0),
00045         _engineRequestedHeight(0)  {
00046     ConfMan.registerDefault("fullscreen_res", "desktop");
00047     ConfMan.registerDefault("aspect_ratio", true);
00048     ConfMan.registerDefault("vsync", true);
00049 }
00050 
00051 ResVmSdlGraphicsManager::~ResVmSdlGraphicsManager() {
00052 }
00053 
00054 void ResVmSdlGraphicsManager::activateManager() {
00055     SdlGraphicsManager::activateManager();
00056 
00057     // Register the graphics manager as a event observer
00058     g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 10, false);
00059 }
00060 
00061 void ResVmSdlGraphicsManager::deactivateManager() {
00062     // Unregister the event observer
00063     if (g_system->getEventManager()->getEventDispatcher()) {
00064         g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this);
00065     }
00066 
00067     SdlGraphicsManager::deactivateManager();
00068 }
00069 
00070 Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() {
00071     // Default to the desktop resolution ...
00072     uint preferredWidth = _capabilities.desktopWidth;
00073     uint preferredHeight = _capabilities.desktopHeight;
00074 
00075 #if SDL_VERSION_ATLEAST(2, 0, 0)
00076     // When using SDL2, we can query the desktop resolution for the screen our window sits in
00077     int displayIndex = -1;
00078 
00079     SDL_Window *sdlWindow = _window->getSDLWindow();
00080     if (sdlWindow) {
00081         displayIndex = SDL_GetWindowDisplayIndex(sdlWindow);
00082     }
00083 
00084     if (displayIndex >= 0) {
00085         SDL_DisplayMode displayMode;
00086         if (!SDL_GetDesktopDisplayMode(displayIndex, &displayMode)) {
00087             preferredWidth = displayMode.w;
00088             preferredHeight = displayMode.h;
00089         }
00090     }
00091 #endif
00092 
00093     // ... unless the user has set a resolution in the configuration file
00094     const Common::String &fsres = ConfMan.get("fullscreen_res");
00095     if (fsres != "desktop") {
00096         uint newW, newH;
00097         int converted = sscanf(fsres.c_str(), "%ux%u", &newW, &newH);
00098         if (converted == 2) {
00099             preferredWidth = newW;
00100             preferredHeight = newH;
00101         } else {
00102             warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str());
00103         }
00104     }
00105 
00106     return Common::Rect(preferredWidth, preferredHeight);
00107 }
00108 
00109 void ResVmSdlGraphicsManager::resetGraphicsScale() {
00110     setGraphicsMode(0);
00111 }
00112 
00113 void ResVmSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) {
00114     switch (f) {
00115         case OSystem::kFeatureAspectRatioCorrection:
00116             _lockAspectRatio = enable;
00117             break;
00118         default:
00119             break;
00120     }
00121 }
00122 
00123 bool ResVmSdlGraphicsManager::getFeatureState(OSystem::Feature f) const {
00124     switch (f) {
00125         case OSystem::kFeatureFullscreenMode:
00126             return _fullscreen;
00127         case OSystem::kFeatureAspectRatioCorrection:
00128             return _lockAspectRatio;
00129         default:
00130             return false;
00131     }
00132 }
00133 
00134 const OSystem::GraphicsMode *ResVmSdlGraphicsManager::getSupportedGraphicsModes() const {
00135     return s_supportedGraphicsModes;
00136 }
00137 
00138 int ResVmSdlGraphicsManager::getDefaultGraphicsMode() const {
00139     return 0;// ResidualVM: not use it
00140 }
00141 
00142 void ResVmSdlGraphicsManager::beginGFXTransaction() {
00143     // ResidualVM: not use it
00144 }
00145 
00146 OSystem::TransactionError ResVmSdlGraphicsManager::endGFXTransaction() {
00147     // ResidualVM: not use it
00148     return OSystem::kTransactionSuccess;
00149 }
00150 
00151 #ifdef USE_RGB_COLOR
00152 Common::List<Graphics::PixelFormat> ResVmSdlGraphicsManager::getSupportedFormats() const {
00153     // ResidualVM: not use it
00154     return _supportedFormats;
00155 }
00156 #endif
00157 
00158 bool ResVmSdlGraphicsManager::setGraphicsMode(int mode) {
00159     // ResidualVM: not use it
00160     return true;
00161 }
00162 
00163 int ResVmSdlGraphicsManager::getGraphicsMode() const {
00164     // ResidualVM: not use it
00165     return 0;
00166 }
00167 
00168 void ResVmSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) {
00169     // ResidualVM: not use it
00170 }
00171 
00172 void ResVmSdlGraphicsManager::copyRectToScreen(const void *src, int pitch, int x, int y, int w, int h) {
00173     // ResidualVM: not use it
00174 }
00175 
00176 Graphics::Surface *ResVmSdlGraphicsManager::lockScreen() {
00177     return NULL; // ResidualVM: not use it
00178 }
00179 
00180 void ResVmSdlGraphicsManager::unlockScreen() {
00181     // ResidualVM: not use it
00182 }
00183 
00184 void ResVmSdlGraphicsManager::fillScreen(uint32 col) {
00185     // ResidualVM: not use it
00186 }
00187 
00188 void ResVmSdlGraphicsManager::setPalette(const byte *colors, uint start, uint num) {
00189     // ResidualVM: not use it
00190 }
00191 
00192 void ResVmSdlGraphicsManager::grabPalette(byte *colors, uint start, uint num) const {
00193     // ResidualVM: not use it
00194 }
00195 
00196 void ResVmSdlGraphicsManager::setCursorPalette(const byte *colors, uint start, uint num) {
00197     // ResidualVM: not use it
00198 }
00199 
00200 void ResVmSdlGraphicsManager::setShakePos(int shake_pos) {
00201     // ResidualVM: not use it
00202 }
00203 
00204 void ResVmSdlGraphicsManager::setFocusRectangle(const Common::Rect &rect) {
00205     // ResidualVM: not use it
00206 }
00207 
00208 void ResVmSdlGraphicsManager::clearFocusRectangle() {
00209     // ResidualVM: not use it
00210 }
00211 
00212 #pragma mark -
00213 #pragma mark --- Mouse ---
00214 #pragma mark -
00215 
00216 bool ResVmSdlGraphicsManager::showMouse(bool visible) {
00217     SDL_ShowCursor(visible);
00218     return true;
00219 }
00220 
00221 bool ResVmSdlGraphicsManager::lockMouse(bool lock) {
00222 #if SDL_VERSION_ATLEAST(2, 0, 0)
00223     if (lock)
00224         SDL_SetRelativeMouseMode(SDL_TRUE);
00225     else
00226         SDL_SetRelativeMouseMode(SDL_FALSE);
00227 #else
00228     if (lock)
00229         SDL_WM_GrabInput(SDL_GRAB_ON);
00230     else
00231         SDL_WM_GrabInput(SDL_GRAB_OFF);
00232 #endif
00233     return true;
00234 }
00235 
00236 bool ResVmSdlGraphicsManager::isMouseLocked() const {
00237 #if SDL_VERSION_ATLEAST(2, 0, 0)
00238     return SDL_GetRelativeMouseMode() == SDL_TRUE;
00239 #else
00240     return SDL_GrabMode() == SDL_GRAB_ON;
00241 #endif
00242 }
00243 
00244 void ResVmSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {
00245     // ResidualVM: not use it
00246 }
00247 
00248 #pragma mark -
00249 #pragma mark --- On Screen Display ---
00250 #pragma mark -
00251 
00252 #ifdef USE_OSD
00253 void OpenGLResVmSdlGraphicsManager::displayMessageOnOSD(const char *msg) {
00254     // ResidualVM: not use it
00255 }
00256 #endif
00257 
00258 bool ResVmSdlGraphicsManager::notifyEvent(const Common::Event &event) {
00259     //ResidualVM specific:
00260     switch ((int)event.type) {
00261         case Common::EVENT_KEYDOWN:
00262             if (event.kbd.hasFlags(Common::KBD_ALT) && event.kbd.keycode == Common::KEYCODE_s) {
00263                 saveScreenshot();
00264                 return true;
00265             }
00266             break;
00267         case Common::EVENT_KEYUP:
00268             break;
00269         default:
00270             break;
00271     }
00272 
00273     return false;
00274 }
00275 
00276 void ResVmSdlGraphicsManager::notifyVideoExpose() {
00277     //ResidualVM specific:
00278     //updateScreen();
00279 }
00280 
00281 bool ResVmSdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
00282     transformMouseCoordinates(mouse);
00283     // ResidualVM: not use that:
00284     //setMousePos(mouse.x, mouse.y);
00285     return true;
00286 }
00287 
00288 void ResVmSdlGraphicsManager::saveScreenshot() {
00289     OSystem_SDL *g_systemSdl = dynamic_cast<OSystem_SDL*>(g_system);
00290 
00291     if (g_systemSdl) {
00292         Common::String filename;
00293         Common::String path = g_systemSdl->getScreenshotsPath();
00294 
00295         // Find unused filename
00296         int n = 0;
00297         while (true) {
00298 #ifdef USE_PNG
00299             filename = Common::String::format("residualvm%05d.png", n);
00300 #else
00301             filename = Common::String::format("residualvm%05d.bmp", n);
00302 #endif
00303             SDL_RWops *file = SDL_RWFromFile((path + filename).c_str(), "r");
00304             if (!file) {
00305                 break;
00306             }
00307             SDL_RWclose(file);
00308 
00309             ++n;
00310         }
00311 
00312         if (saveScreenshot(path + filename)) {
00313             if (path.empty())
00314                 debug("Saved screenshot '%s' in current directory", filename.c_str());
00315             else
00316                 debug("Saved screenshot '%s' in directory '%s'", filename.c_str(), path.c_str());
00317         } else {
00318             if (path.empty())
00319                 warning("Could not save screenshot in current directory");
00320             else
00321                 warning("Could not save screenshot in directory '%s'", path.c_str());
00322         }
00323     }
00324 }


Generated on Sat Dec 14 2019 05:00:27 for ResidualVM by doxygen 1.7.1
curved edge   curved edge