1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
|
/* 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.
*
*/
#include "backends/graphics/sdl/resvm-sdl-graphics.h"
#include "backends/platform/sdl/sdl-sys.h"
#include "backends/events/sdl/sdl-events.h"
#include "common/config-manager.h"
#include "common/textconsole.h"
static const OSystem::GraphicsMode s_supportedGraphicsModes[] = {
{0, 0, 0}
};
ResVmSdlGraphicsManager::ResVmSdlGraphicsManager(SdlEventSource *source, SdlWindow *window, const Capabilities &capabilities) :
SdlGraphicsManager(source, window),
_fullscreen(false),
_lockAspectRatio(true),
_overlayVisible(false),
_overlayWidth(0),
_overlayHeight(0),
_screenChangeCount(0),
_capabilities(capabilities),
_engineRequestedWidth(0),
_engineRequestedHeight(0) {
ConfMan.registerDefault("fullscreen_res", "desktop");
ConfMan.registerDefault("aspect_ratio", true);
ConfMan.registerDefault("vsync", true);
}
ResVmSdlGraphicsManager::~ResVmSdlGraphicsManager() {
}
void ResVmSdlGraphicsManager::activateManager() {
SdlGraphicsManager::activateManager();
// 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);
}
SdlGraphicsManager::deactivateManager();
}
ResVmSdlGraphicsManager::GameRenderTarget ResVmSdlGraphicsManager::selectGameRenderTarget(bool fullscreen,
bool accel3d,
bool engineSupportsArbitraryResolutions,
bool framebufferSupported,
bool lockAspectRatio) {
if (!fullscreen) {
return kScreen;
}
if (!accel3d && lockAspectRatio) {
return kSubScreen;
}
if (!engineSupportsArbitraryResolutions && framebufferSupported) {
return kFramebuffer;
}
return kScreen;
}
Math::Rect2d ResVmSdlGraphicsManager::computeGameRect(GameRenderTarget gameRenderTarget, uint gameWidth, uint gameHeight,
uint effectiveWidth, uint effectiveHeight) {
switch (gameRenderTarget) {
case kScreen:
// The game occupies the whole screen
return Math::Rect2d(Math::Vector2d(0, 0), Math::Vector2d(1, 1));
case kSubScreen:
// The game is centered on the screen
return Math::Rect2d(
Math::Vector2d((effectiveWidth - gameWidth) / 2, (effectiveHeight - gameHeight) / 2),
Math::Vector2d((effectiveWidth + gameWidth) / 2, (effectiveHeight + gameHeight) / 2)
);
case kFramebuffer:
if (_lockAspectRatio) {
// The game is scaled to fit the screen, keeping the same aspect ratio
float scale = MIN(effectiveHeight / float(gameHeight), effectiveWidth / float(gameWidth));
float scaledW = scale * (gameWidth / float(effectiveWidth));
float scaledH = scale * (gameHeight / float(effectiveHeight));
return Math::Rect2d(
Math::Vector2d(0.5 - (0.5 * scaledW), 0.5 - (0.5 * scaledH)),
Math::Vector2d(0.5 + (0.5 * scaledW), 0.5 + (0.5 * scaledH))
);
} else {
// The game occupies the whole screen
return Math::Rect2d(Math::Vector2d(0, 0), Math::Vector2d(1, 1));
}
default:
error("Unhandled game render target '%d'", gameRenderTarget);
}
}
bool ResVmSdlGraphicsManager::canUsePreferredResolution(GameRenderTarget gameRenderTarget,
bool engineSupportsArbitraryResolutions) {
switch (gameRenderTarget) {
case kScreen:
// If the game supports arbitrary resolutions, use the preferred mode as the game mode
return engineSupportsArbitraryResolutions;
case kSubScreen:
case kFramebuffer:
return true;
default:
error("Unhandled game render target '%d'", gameRenderTarget);
}
}
Common::Rect ResVmSdlGraphicsManager::getPreferredFullscreenResolution() {
// Default to the desktop resolution ...
uint preferredWidth = _capabilities.desktopWidth;
uint preferredHeight = _capabilities.desktopHeight;
// ... unless the user has set a resolution in the configuration file
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) {
preferredWidth = newW;
preferredHeight = newH;
} else {
warning("Could not parse 'fullscreen_res' option: expected WWWxHHH, got %s", fsres.c_str());
}
}
return Common::Rect(preferredWidth, preferredHeight);
}
void ResVmSdlGraphicsManager::resetGraphicsScale() {
setGraphicsMode(0);
}
void ResVmSdlGraphicsManager::setFeatureState(OSystem::Feature f, bool enable) {
switch (f) {
case OSystem::kFeatureAspectRatioCorrection:
_lockAspectRatio = enable;
break;
default:
break;
}
}
bool ResVmSdlGraphicsManager::getFeatureState(OSystem::Feature f) {
switch (f) {
case OSystem::kFeatureFullscreenMode:
return _fullscreen;
case OSystem::kFeatureAspectRatioCorrection:
return _lockAspectRatio;
default:
return false;
}
}
const OSystem::GraphicsMode *ResVmSdlGraphicsManager::getSupportedGraphicsModes() const {
return s_supportedGraphicsModes;
}
int ResVmSdlGraphicsManager::getDefaultGraphicsMode() const {
return 0;// ResidualVM: not use it
}
void ResVmSdlGraphicsManager::beginGFXTransaction() {
// ResidualVM: not use it
}
OSystem::TransactionError ResVmSdlGraphicsManager::endGFXTransaction() {
// ResidualVM: not use it
return OSystem::kTransactionSuccess;
}
#ifdef USE_RGB_COLOR
Common::List<Graphics::PixelFormat> ResVmSdlGraphicsManager::getSupportedFormats() const {
// ResidualVM: not use it
return _supportedFormats;
}
#endif
bool ResVmSdlGraphicsManager::setGraphicsMode(int mode) {
// ResidualVM: not use it
return true;
}
int ResVmSdlGraphicsManager::getGraphicsMode() const {
// ResidualVM: not use it
return 0;
}
void ResVmSdlGraphicsManager::initSize(uint w, uint h, const Graphics::PixelFormat *format) {
// ResidualVM: not use it
}
void ResVmSdlGraphicsManager::copyRectToScreen(const void *src, int pitch, int x, int y, int w, int h) {
// ResidualVM: not use it
}
Graphics::Surface *ResVmSdlGraphicsManager::lockScreen() {
return NULL; // ResidualVM: not use it
}
void ResVmSdlGraphicsManager::unlockScreen() {
// ResidualVM: not use it
}
void ResVmSdlGraphicsManager::fillScreen(uint32 col) {
// ResidualVM: not use it
}
void ResVmSdlGraphicsManager::setPalette(const byte *colors, uint start, uint num) {
// ResidualVM: not use it
}
void ResVmSdlGraphicsManager::grabPalette(byte *colors, uint start, uint num) {
// ResidualVM: not use it
}
void ResVmSdlGraphicsManager::setCursorPalette(const byte *colors, uint start, uint num) {
// ResidualVM: not use it
}
void ResVmSdlGraphicsManager::setShakePos(int shake_pos) {
// ResidualVM: not use it
}
void ResVmSdlGraphicsManager::setFocusRectangle(const Common::Rect &rect) {
// ResidualVM: not use it
}
void ResVmSdlGraphicsManager::clearFocusRectangle() {
// ResidualVM: not use it
}
#pragma mark -
#pragma mark --- Mouse ---
#pragma mark -
bool ResVmSdlGraphicsManager::showMouse(bool visible) {
SDL_ShowCursor(visible);
return true;
}
// ResidualVM specific method
bool ResVmSdlGraphicsManager::lockMouse(bool lock) {
#if SDL_VERSION_ATLEAST(2, 0, 0)
if (lock)
SDL_SetRelativeMouseMode(SDL_TRUE);
else
SDL_SetRelativeMouseMode(SDL_FALSE);
#else
if (lock)
SDL_WM_GrabInput(SDL_GRAB_ON);
else
SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif
return true;
}
void ResVmSdlGraphicsManager::setMouseCursor(const void *buf, uint w, uint h, int hotspot_x, int hotspot_y, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format) {
// ResidualVM: not use it
}
#pragma mark -
#pragma mark --- On Screen Display ---
#pragma mark -
#ifdef USE_OSD
void OpenGLResVmSdlGraphicsManager::displayMessageOnOSD(const char *msg) {
// ResidualVM: not use it
}
#endif
bool ResVmSdlGraphicsManager::notifyEvent(const Common::Event &event) {
//ResidualVM specific:
switch ((int)event.type) {
case Common::EVENT_KEYDOWN:
break;
case Common::EVENT_KEYUP:
break;
default:
break;
}
return false;
}
void ResVmSdlGraphicsManager::notifyVideoExpose() {
//ResidualVM specific:
updateScreen();
}
void ResVmSdlGraphicsManager::notifyMousePos(Common::Point mouse) {
transformMouseCoordinates(mouse);
// ResidualVM: not use that:
//setMousePos(mouse.x, mouse.y);
}
|