Exemplo n.º 1
0
bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
	switch ((int)event.type) {
	case Common::EVENT_KEYDOWN:
		if (event.kbd.hasFlags(Common::KBD_ALT)) {
			// Alt-Return and Alt-Enter toggle full screen mode
			if (event.kbd.keycode == Common::KEYCODE_RETURN ||
				event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER) {
				toggleFullScreen(0);
				return true;
			}

			// Alt-S create a screenshot
			if (event.kbd.keycode == 's') {
				char filename[20];

				for (int n = 0;; n++) {
					SDL_RWops *file;

					sprintf(filename, "scummvm%05d.bmp", n);
					file = SDL_RWFromFile(filename, "r");
					if (!file)
						break;
					SDL_RWclose(file);
				}
				if (saveScreenshot(filename))
					debug("Saved screenshot '%s'", filename);
				else
					warning("Could not save screenshot");
				return true;
			}
		}

		if (event.kbd.hasFlags(Common::KBD_CTRL|Common::KBD_ALT)) {
			// Ctrl-Alt-Return and Ctrl-Alt-Enter switch between full screen modes
			if (event.kbd.keycode == Common::KEYCODE_RETURN ||
				event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER) {
				toggleFullScreen(1);
				return true;
			}

			// Ctrl-Alt-a switch between display modes
			if (event.kbd.keycode == 'a') {
				beginGFXTransaction();
					setFeatureState(OSystem::kFeatureAspectRatioCorrection, !getFeatureState(OSystem::kFeatureAspectRatioCorrection));
				endGFXTransaction();
#ifdef USE_OSD
			char buffer[128];
			if (getFeatureState(OSystem::kFeatureAspectRatioCorrection))
				sprintf(buffer, "Enabled aspect ratio correction\n%d x %d -> %d x %d",
				        _videoMode.screenWidth, _videoMode.screenHeight,
				        _hwscreen->w, _hwscreen->h);
			else
				sprintf(buffer, "Disabled aspect ratio correction\n%d x %d -> %d x %d",
				        _videoMode.screenWidth, _videoMode.screenHeight,
				        _hwscreen->w, _hwscreen->h);
			displayMessageOnOSD(buffer);
#endif
				internUpdateScreen();
				return true;
			}

			// Ctrl-Alt-f toggles antialiasing
			if (event.kbd.keycode == 'f') {
				beginGFXTransaction();
					toggleAntialiasing();
				endGFXTransaction();

#ifdef USE_OSD
				// TODO: This makes guesses about what internal antialiasing
				// modes we use, we might want to consider a better way of
				// displaying information to the user.
				if (getAntialiasingState())
					displayMessageOnOSD("Active filter mode: Linear");
				else
					displayMessageOnOSD("Active filter mode: Nearest");
#endif
				return true;
			}

			SDLKey sdlKey = (SDLKey)event.kbd.keycode;

			// Ctrl+Alt+Plus/Minus Increase/decrease the scale factor
			if ((sdlKey == SDLK_EQUALS || sdlKey == SDLK_PLUS || sdlKey == SDLK_MINUS ||
				sdlKey == SDLK_KP_PLUS || sdlKey == SDLK_KP_MINUS)) {
				int factor = getScale();
				factor += (sdlKey == SDLK_MINUS || sdlKey == SDLK_KP_MINUS) ? -1 : +1;
				if (0 < factor && factor < 4) {
					// Check if the desktop resolution has been detected
					if (_desktopWidth > 0 && _desktopHeight > 0)
						// If the new scale factor is too big, do not scale
						if (_videoMode.screenWidth * factor > _desktopWidth || 
							_videoMode.screenHeight * factor > _desktopHeight)
							return false;

					beginGFXTransaction();
						setScale(factor);
					endGFXTransaction();
#ifdef USE_OSD
					displayScaleChangedMsg();
#endif
					return true;
				}
			}

			const bool isNormalNumber = (SDLK_1 <= sdlKey && sdlKey <= SDLK_3);
			const bool isKeypadNumber = (SDLK_KP1 <= sdlKey && sdlKey <= SDLK_KP3);

			// Ctrl-Alt-<number key> will change the GFX mode
			if (isNormalNumber || isKeypadNumber) {
				if (sdlKey - (isNormalNumber ? SDLK_1 : SDLK_KP1) <= 3) {
#ifdef USE_OSD
					int lastMode = _videoMode.mode;
#endif
					// We need to query the scale and set it up, because
					// setGraphicsMode sets the default scale to 2
					int oldScale = getScale();
					beginGFXTransaction();
						setGraphicsMode(sdlKey - (isNormalNumber ? SDLK_1 : SDLK_KP1));
						setScale(oldScale);
					endGFXTransaction();
#ifdef USE_OSD
					if (lastMode != _videoMode.mode)
						displayModeChangedMsg();
#endif
					internUpdateScreen();
				}
			}
		}

		if (event.kbd.hasFlags(Common::KBD_CTRL|Common::KBD_SHIFT)) {
			// Ctrl-Shift-Return and Ctrl-Shift-Enter switch backwards between full screen modes
			if (event.kbd.keycode == Common::KEYCODE_RETURN ||
				event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER) {
				toggleFullScreen(-1);
				return true;
			}
		}
		break;
	case Common::EVENT_KEYUP:
		return isHotkey(event);
	// HACK: Handle special SDL event 
	// The new screen size is saved on the mouse event as part of HACK,
	// there is no common resize event.
	case OSystem_SDL::kSdlEventResize:
		// Do not resize if ignoring resize events.
		if (!_ignoreResizeFrames && !getFullscreenMode()) {
			bool scaleChanged = false;
			beginGFXTransaction();
				_videoMode.hardwareWidth = event.mouse.x;
				_videoMode.hardwareHeight = event.mouse.y;

				if (_videoMode.mode != OpenGL::GFX_ORIGINAL) {
					_screenResized = true;
					calculateDisplaySize(_videoMode.hardwareWidth, _videoMode.hardwareHeight);
				}

				int scale = MIN(_videoMode.hardwareWidth / _videoMode.screenWidth,
				                _videoMode.hardwareHeight / _videoMode.screenHeight);

				if (getScale() != scale) {
					scaleChanged = true;
					setScale(MAX(MIN(scale, 3), 1));
				}

				if (_videoMode.mode == OpenGL::GFX_ORIGINAL) {
					calculateDisplaySize(_videoMode.hardwareWidth, _videoMode.hardwareHeight);
				}

				_transactionDetails.sizeChanged = true;
			endGFXTransaction();
#ifdef USE_OSD
			if (scaleChanged)
				displayScaleChangedMsg();
#endif
		}
		return true;

	default:
		break;
	}

	return OpenGLGraphicsManager::notifyEvent(event);
}
Exemplo n.º 2
0
bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
	switch ((int)event.type) {
	case Common::EVENT_KEYDOWN:
		if (event.kbd.hasFlags(Common::KBD_ALT)) {
			// Alt-Return and Alt-Enter toggle full screen mode
			if (event.kbd.keycode == Common::KEYCODE_RETURN ||
				event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER) {
				toggleFullScreen(0);
				return true;
			}

			// Alt-S create a screenshot
			if (event.kbd.keycode == 's') {
				Common::String filename;

				for (int n = 0;; n++) {
					SDL_RWops *file;

					filename = Common::String::format("scummvm%05d.bmp", n);
					file = SDL_RWFromFile(filename.c_str(), "r");
					if (!file)
						break;
					SDL_RWclose(file);
				}
				if (saveScreenshot(filename.c_str()))
					debug("Saved screenshot '%s'", filename.c_str());
				else
					warning("Could not save screenshot");
				return true;
			}
		}

		if (event.kbd.hasFlags(Common::KBD_CTRL|Common::KBD_ALT)) {
			// Ctrl-Alt-Return and Ctrl-Alt-Enter switch between full screen modes
			if (event.kbd.keycode == Common::KEYCODE_RETURN ||
				event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER) {
				toggleFullScreen(1);
				return true;
			}

			// Ctrl-Alt-a switch between display modes
			if (event.kbd.keycode == 'a') {
				beginGFXTransaction();
					setFeatureState(OSystem::kFeatureAspectRatioCorrection, !getFeatureState(OSystem::kFeatureAspectRatioCorrection));
				endGFXTransaction();
#ifdef USE_OSD
			Common::String osdMessage;
			if (getFeatureState(OSystem::kFeatureAspectRatioCorrection))
				osdMessage = Common::String::format("%s\n%d x %d -> %d x %d",
				        _("Enabled aspect ratio correction"),
				        _videoMode.screenWidth, _videoMode.screenHeight,
				        _hwscreen->w, _hwscreen->h);
			else
				osdMessage = Common::String::format("%s\n%d x %d -> %d x %d",
				        _("Disabled aspect ratio correction"),
				        _videoMode.screenWidth, _videoMode.screenHeight,
				        _hwscreen->w, _hwscreen->h);
			displayMessageOnOSD(osdMessage.c_str());
#endif
				internUpdateScreen();
				return true;
			}

			// Ctrl-Alt-f toggles antialiasing
			if (event.kbd.keycode == 'f') {
				beginGFXTransaction();
					toggleAntialiasing();
				endGFXTransaction();

#ifdef USE_OSD
				// TODO: This makes guesses about what internal antialiasing
				// modes we use, we might want to consider a better way of
				// displaying information to the user.
				if (getAntialiasingState())
					displayMessageOnOSD(_("Active filter mode: Linear"));
				else
					displayMessageOnOSD(_("Active filter mode: Nearest"));
#endif
				return true;
			}

			SDLKey sdlKey = (SDLKey)event.kbd.keycode;

			// Ctrl+Alt+Plus/Minus Increase/decrease the scale factor
			if ((sdlKey == SDLK_EQUALS || sdlKey == SDLK_PLUS || sdlKey == SDLK_MINUS ||
				sdlKey == SDLK_KP_PLUS || sdlKey == SDLK_KP_MINUS)) {
				int factor = getScale();
				factor += (sdlKey == SDLK_MINUS || sdlKey == SDLK_KP_MINUS) ? -1 : +1;
				if (0 < factor && factor < 4) {
					// Check if the desktop resolution has been detected
					if (_desktopWidth > 0 && _desktopHeight > 0)
						// If the new scale factor is too big, do not scale
						if (_videoMode.screenWidth * factor > _desktopWidth ||
							_videoMode.screenHeight * factor > _desktopHeight)
							return false;

					beginGFXTransaction();
						setScale(factor);
					endGFXTransaction();
#ifdef USE_OSD
					displayScaleChangedMsg();
#endif
					return true;
				}
			}

			const bool isNormalNumber = (SDLK_1 <= sdlKey && sdlKey <= SDLK_3);
			const bool isKeypadNumber = (SDLK_KP1 <= sdlKey && sdlKey <= SDLK_KP3);

			// Ctrl-Alt-<number key> will change the GFX mode
			if (isNormalNumber || isKeypadNumber) {
				if (sdlKey - (isNormalNumber ? SDLK_1 : SDLK_KP1) <= 3) {
#ifdef USE_OSD
					int lastMode = _videoMode.mode;
#endif
					// We need to query the scale and set it up, because
					// setGraphicsMode sets the default scale to 2
					int oldScale = getScale();
					beginGFXTransaction();
						setGraphicsMode(sdlKey - (isNormalNumber ? SDLK_1 : SDLK_KP1));
						setScale(oldScale);
					endGFXTransaction();
#ifdef USE_OSD
					if (lastMode != _videoMode.mode)
						displayModeChangedMsg();
#endif
					internUpdateScreen();
				}
			}
		}

		if (event.kbd.hasFlags(Common::KBD_CTRL|Common::KBD_SHIFT)) {
			// Ctrl-Shift-Return and Ctrl-Shift-Enter switch backwards between full screen modes
			if (event.kbd.keycode == Common::KEYCODE_RETURN ||
				event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER) {
				toggleFullScreen(-1);
				return true;
			}
		}
		break;

	case Common::EVENT_KEYUP:
		return isHotkey(event);

	default:
		break;
	}

	return false;
}
Exemplo n.º 3
0
bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
	switch ((int)event.type) {
	case Common::EVENT_KEYDOWN:
		if (event.kbd.hasFlags(Common::KBD_ALT)) {
			// Alt-Return and Alt-Enter toggle full screen mode
			if (event.kbd.keycode == Common::KEYCODE_RETURN ||
				event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER) {
				toggleFullScreen(0);
				return true;
			}

			// Alt-S create a screenshot
			if (event.kbd.keycode == 's') {
				char filename[20];

				for (int n = 0;; n++) {
					SDL_RWops *file;

					sprintf(filename, "scummvm%05d.bmp", n);
					file = SDL_RWFromFile(filename, "r");
					if (!file)
						break;
					SDL_RWclose(file);
				}
				if (saveScreenshot(filename))
					printf("Saved '%s'\n", filename);
				else
					printf("Could not save screenshot!\n");
				return true;
			}
		}

		if (event.kbd.hasFlags(Common::KBD_CTRL|Common::KBD_ALT)) {
			// Ctrl-Alt-Return and Ctrl-Alt-Enter switch between full screen modes
			if (event.kbd.keycode == Common::KEYCODE_RETURN ||
				event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER) {
				toggleFullScreen(1);
				return true;
			}

			// Ctrl-Alt-a switch between display modes
			if (event.kbd.keycode == 'a') {
				beginGFXTransaction();
					switchDisplayMode(-1);
				endGFXTransaction();
#ifdef USE_OSD
				displayModeChangedMsg();
#endif
				internUpdateScreen();
				return true;
			}

			// Ctrl-Alt-f toggles antialiasing
			if (event.kbd.keycode == 'f') {
				beginGFXTransaction();
					_videoMode.antialiasing = !_videoMode.antialiasing;
					_transactionDetails.filterChanged = true;
				endGFXTransaction();
#ifdef USE_OSD
				if (_videoMode.antialiasing)
					displayMessageOnOSD("Active filter mode: Linear");
				else
					displayMessageOnOSD("Active filter mode: Nearest");
#endif
				return true;
			}

			SDLKey sdlKey = (SDLKey)event.kbd.keycode;

			// Ctrl+Alt+Plus/Minus Increase/decrease the scale factor
			if ((sdlKey == SDLK_EQUALS || sdlKey == SDLK_PLUS || sdlKey == SDLK_MINUS ||
				sdlKey == SDLK_KP_PLUS || sdlKey == SDLK_KP_MINUS)) {
				int factor = _videoMode.scaleFactor;
				factor += (sdlKey == SDLK_MINUS || sdlKey == SDLK_KP_MINUS) ? -1 : +1;
				if (0 < factor && factor < 4) {
					// Check if the desktop resolution has been detected
					if (_desktopWidth > 0 && _desktopHeight > 0)
						// If the new scale factor is too big, do not scale
						if (_videoMode.screenWidth * factor > _desktopWidth || 
							_videoMode.screenHeight * factor > _desktopHeight)
							return false;

					beginGFXTransaction();
						setScale(factor);
					endGFXTransaction();
#ifdef USE_OSD
					displayScaleChangedMsg();
#endif
					return true;
				}
			}

			const bool isNormalNumber = (SDLK_1 <= sdlKey && sdlKey <= SDLK_4);
			const bool isKeypadNumber = (SDLK_KP1 <= sdlKey && sdlKey <= SDLK_KP4);

			// Ctrl-Alt-<number key> will change the GFX mode
			if (isNormalNumber || isKeypadNumber) {
				if (sdlKey - (isNormalNumber ? SDLK_1 : SDLK_KP1) <= 4) {
					int lastMode = _videoMode.mode;
					beginGFXTransaction();
						_videoMode.mode = sdlKey - (isNormalNumber ? SDLK_1 : SDLK_KP1);
						_transactionDetails.needRefresh = true;
						_aspectRatioCorrection = false;
					endGFXTransaction();
#ifdef USE_OSD
					if (lastMode != _videoMode.mode)
						displayModeChangedMsg();
#endif
					internUpdateScreen();
				}
			}
		}

		if (event.kbd.hasFlags(Common::KBD_CTRL|Common::KBD_SHIFT)) {
			// Ctrl-Shift-Return and Ctrl-Shift-Enter switch backwards between full screen modes
			if (event.kbd.keycode == Common::KEYCODE_RETURN ||
				event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER) {
				toggleFullScreen(-1);
				return true;
			}

			// Ctrl-Shift-a switch backwards between display modes
			if (event.kbd.keycode == 'a') {
				beginGFXTransaction();
					switchDisplayMode(-2);
				endGFXTransaction();
#ifdef USE_OSD
				displayModeChangedMsg();
#endif
				internUpdateScreen();
				return true;
			}
		}
		break;
	case Common::EVENT_KEYUP:
		return isHotkey(event);
	// HACK: Handle special SDL event 
	// The new screen size is saved on the mouse event as part of HACK,
	// there is no common resize event.
	case OSystem_SDL::kSdlEventResize:
		// Do not resize if ignoring resize events.
		if (!_ignoreResizeFrames && !_videoMode.fullscreen) {
			bool scaleChanged = false;
			beginGFXTransaction();
				_videoMode.hardwareWidth = event.mouse.x;
				_videoMode.hardwareHeight = event.mouse.y;

				if (_videoMode.mode != OpenGL::GFX_ORIGINAL) {
					_screenResized = true;
					calculateDisplaySize(_videoMode.hardwareWidth, _videoMode.hardwareHeight);
				}

				int scale = MIN(_videoMode.hardwareWidth / _videoMode.screenWidth,
							_videoMode.hardwareHeight / _videoMode.screenHeight);
				if (_videoMode.scaleFactor != scale) {
					scaleChanged = true;
					_videoMode.scaleFactor = MAX(MIN(scale, 3), 1);
				}

				if (_videoMode.mode == OpenGL::GFX_ORIGINAL) {
					calculateDisplaySize(_videoMode.hardwareWidth, _videoMode.hardwareHeight);
				}

				_transactionDetails.sizeChanged = true;
			endGFXTransaction();
#ifdef USE_OSD
			if (scaleChanged)
				displayScaleChangedMsg();
#endif
		}
		return true;

	default:
		break;
	}

	return OpenGLGraphicsManager::notifyEvent(event);
}