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     // ... unless the user has set a resolution in the configuration file
00076     const Common::String &fsres = ConfMan.get("fullscreen_res");
00077     if (fsres != "desktop") {
00078         uint newW, newH;
00079         int converted = sscanf(fsres.c_str(), "%ux%u", &newW, &newH);
00080         if (converted == 2) {
00081             preferredWidth = newW;
00082             preferredHeight = newH;
00083         } else {
00084             warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str());
00085         }
00086     }
00087 
00088     return Common::Rect(preferredWidth, preferredHeight);
00089 }
00090 
00091 void ResVmSdlGraphicsManager::resetGraphicsScale() {
00092     setGraphicsMode(0);
00093 }
00094 
00095 void ResVmSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) {
00096     switch (f) {
00097         case OSystem::kFeatureAspectRatioCorrection:
00098             _lockAspectRatio = enable;
00099             break;
00100         default:
00101             break;
00102     }
00103 }
00104 
00105 bool ResVmSdlGraphicsManager::getFeatureState(OSystem::Feature f) const {
00106     switch (f) {
00107         case OSystem::kFeatureFullscreenMode:
00108             return _fullscreen;
00109         case OSystem::kFeatureAspectRatioCorrection:
00110             return _lockAspectRatio;
00111         default:
00112             return false;
00113     }
00114 }
00115 
00116 const OSystem::GraphicsMode *ResVmSdlGraphicsManager::getSupportedGraphicsModes() const {
00117     return s_supportedGraphicsModes;
00118 }
00119 
00120 int ResVmSdlGraphicsManager::getDefaultGraphicsMode() const {
00121     return 0;// ResidualVM: not use it
00122 }
00123 
00124 void ResVmSdlGraphicsManager::beginGFXTransaction() {
00125     // ResidualVM: not use it
00126 }
00127 
00128 OSystem::TransactionError ResVmSdlGraphicsManager::endGFXTransaction() {
00129     // ResidualVM: not use it
00130     return OSystem::kTransactionSuccess;
00131 }
00132 
00133 #ifdef USE_RGB_COLOR
00134 Common::List<Graphics::PixelFormat> ResVmSdlGraphicsManager::getSupportedFormats() const {
00135     // ResidualVM: not use it
00136     return _supportedFormats;
00137 }
00138 #endif
00139 
00140 bool ResVmSdlGraphicsManager::setGraphicsMode(int mode) {
00141     // ResidualVM: not use it
00142     return true;
00143 }
00144 
00145 int ResVmSdlGraphicsManager::getGraphicsMode() const {
00146     // ResidualVM: not use it
00147     return 0;
00148 }
00149 
00150 void ResVmSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) {
00151     // ResidualVM: not use it
00152 }
00153 
00154 void ResVmSdlGraphicsManager::copyRectToScreen(const void *src, int pitch, int x, int y, int w, int h) {
00155     // ResidualVM: not use it
00156 }
00157 
00158 Graphics::Surface *ResVmSdlGraphicsManager::lockScreen() {
00159     return NULL; // ResidualVM: not use it
00160 }
00161 
00162 void ResVmSdlGraphicsManager::unlockScreen() {
00163     // ResidualVM: not use it
00164 }
00165 
00166 void ResVmSdlGraphicsManager::fillScreen(uint32 col) {
00167     // ResidualVM: not use it
00168 }
00169 
00170 void ResVmSdlGraphicsManager::setPalette(const byte *colors, uint start, uint num) {
00171     // ResidualVM: not use it
00172 }
00173 
00174 void ResVmSdlGraphicsManager::grabPalette(byte *colors, uint start, uint num) const {
00175     // ResidualVM: not use it
00176 }
00177 
00178 void ResVmSdlGraphicsManager::setCursorPalette(const byte *colors, uint start, uint num) {
00179     // ResidualVM: not use it
00180 }
00181 
00182 void ResVmSdlGraphicsManager::setShakePos(int shake_pos) {
00183     // ResidualVM: not use it
00184 }
00185 
00186 void ResVmSdlGraphicsManager::setFocusRectangle(const Common::Rect &rect) {
00187     // ResidualVM: not use it
00188 }
00189 
00190 void ResVmSdlGraphicsManager::clearFocusRectangle() {
00191     // ResidualVM: not use it
00192 }
00193 
00194 #pragma mark -
00195 #pragma mark --- Mouse ---
00196 #pragma mark -
00197 
00198 bool ResVmSdlGraphicsManager::showMouse(bool visible) {
00199     SDL_ShowCursor(visible);
00200     return true;
00201 }
00202 
00203 bool ResVmSdlGraphicsManager::lockMouse(bool lock) {
00204 #if SDL_VERSION_ATLEAST(2, 0, 0)
00205     if (lock)
00206         SDL_SetRelativeMouseMode(SDL_TRUE);
00207     else
00208         SDL_SetRelativeMouseMode(SDL_FALSE);
00209 #else
00210     if (lock)
00211         SDL_WM_GrabInput(SDL_GRAB_ON);
00212     else
00213         SDL_WM_GrabInput(SDL_GRAB_OFF);
00214 #endif
00215     return true;
00216 }
00217 
00218 bool ResVmSdlGraphicsManager::isMouseLocked() const {
00219 #if SDL_VERSION_ATLEAST(2, 0, 0)
00220     return SDL_GetRelativeMouseMode() == SDL_TRUE;
00221 #else
00222     return SDL_GrabMode() == SDL_GRAB_ON;
00223 #endif
00224 }
00225 
00226 void ResVmSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {
00227     // ResidualVM: not use it
00228 }
00229 
00230 #pragma mark -
00231 #pragma mark --- On Screen Display ---
00232 #pragma mark -
00233 
00234 #ifdef USE_OSD
00235 void OpenGLResVmSdlGraphicsManager::displayMessageOnOSD(const char *msg) {
00236     // ResidualVM: not use it
00237 }
00238 #endif
00239 
00240 bool ResVmSdlGraphicsManager::notifyEvent(const Common::Event &event) {
00241     //ResidualVM specific:
00242     switch ((int)event.type) {
00243         case Common::EVENT_KEYDOWN:
00244             if (event.kbd.hasFlags(Common::KBD_ALT) && event.kbd.keycode == Common::KEYCODE_s) {
00245                 saveScreenshot();
00246                 return true;
00247             }
00248             break;
00249         case Common::EVENT_KEYUP:
00250             break;
00251         default:
00252             break;
00253     }
00254 
00255     return false;
00256 }
00257 
00258 void ResVmSdlGraphicsManager::notifyVideoExpose() {
00259     //ResidualVM specific:
00260     //updateScreen();
00261 }
00262 
00263 bool ResVmSdlGraphicsManager::notifyMousePosition(Common::Point &mouse) {
00264     transformMouseCoordinates(mouse);
00265     // ResidualVM: not use that:
00266     //setMousePos(mouse.x, mouse.y);
00267     return true;
00268 }
00269 
00270 void ResVmSdlGraphicsManager::saveScreenshot() {
00271     OSystem_SDL *g_systemSdl = dynamic_cast<OSystem_SDL*>(g_system);
00272 
00273     if (g_systemSdl) {
00274         Common::String filename;
00275         Common::String path = g_systemSdl->getScreenshotsPath();
00276 
00277         // Find unused filename
00278         int n = 0;
00279         while (true) {
00280 #ifdef USE_PNG
00281             filename = Common::String::format("residualvm%05d.png", n);
00282 #else
00283             filename = Common::String::format("residualvm%05d.bmp", n);
00284 #endif
00285             SDL_RWops *file = SDL_RWFromFile((path + filename).c_str(), "r");
00286             if (!file) {
00287                 break;
00288             }
00289             SDL_RWclose(file);
00290 
00291             ++n;
00292         }
00293 
00294         if (saveScreenshot(path + filename)) {
00295             if (path.empty())
00296                 debug("Saved screenshot '%s' in current directory", filename.c_str());
00297             else
00298                 debug("Saved screenshot '%s' in directory '%s'", filename.c_str(), path.c_str());
00299         } else {
00300             if (path.empty())
00301                 warning("Could not save screenshot in current directory");
00302             else
00303                 warning("Could not save screenshot in directory '%s'", path.c_str());
00304         }
00305     }
00306 }


Generated on Sat May 25 2019 05:00:53 for ResidualVM by doxygen 1.7.1
curved edge   curved edge