[Scummvm-cvs-logs] SF.net SVN: scummvm:[51016] scummvm/branches/gsoc2010-opengl/backends/ graphics/opengl

vgvgf at users.sourceforge.net vgvgf at users.sourceforge.net
Mon Jul 19 07:36:10 CEST 2010


Revision: 51016
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51016&view=rev
Author:   vgvgf
Date:     2010-07-19 05:36:10 +0000 (Mon, 19 Jul 2010)

Log Message:
-----------
OPENGL: Add basic scaler handle.

Modified Paths:
--------------
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h
    scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp
    scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.h

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-19 05:33:58 UTC (rev 51015)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-19 05:36:10 UTC (rev 51016)
@@ -555,7 +555,7 @@
 	}
 }
 
-bool OpenGLGraphicsManager::loadGFXMode() {
+void OpenGLGraphicsManager::initGL() {
 	// Check available GL Extensions
 	GLTexture::initGLExtensions();
 
@@ -583,7 +583,11 @@
 	CHECK_GL_ERROR( glOrtho(0, _videoMode.hardwareWidth, _videoMode.hardwareHeight, 0, -1, 1) );
 	CHECK_GL_ERROR( glMatrixMode(GL_MODELVIEW) );
 	CHECK_GL_ERROR( glLoadIdentity() );
+}
 
+bool OpenGLGraphicsManager::loadGFXMode() {
+	initGL();
+
 	if (!_gameTexture) {
 		byte bpp;
 		GLenum format;
@@ -622,6 +626,15 @@
 	return false;
 }
 
+void OpenGLGraphicsManager::setScale(int newScale) {
+	if (newScale == _videoMode.scaleFactor)
+		return;
+
+	_videoMode.scaleFactor = newScale;
+
+	_transactionDetails.sizeChanged = true;
+}
+
 void OpenGLGraphicsManager::adjustMouseEvent(const Common::Event &event) {
 	if (!event.synthetic) {
 		Common::Event newEvent(event);
@@ -651,6 +664,7 @@
 	case Common::EVENT_MBUTTONUP:
 		adjustMouseEvent(event);
 		return !event.synthetic;
+
 	default:
 		break;
 	}
@@ -658,4 +672,8 @@
 	return false;
 }
 
+bool OpenGLGraphicsManager::saveScreenshot(const char *filename) {
+	return false;
+}
+
 #endif

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h	2010-07-19 05:33:58 UTC (rev 51015)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h	2010-07-19 05:36:10 UTC (rev 51016)
@@ -100,6 +100,9 @@
 	bool notifyEvent(const Common::Event &event);
 
 protected:
+
+	virtual void initGL();
+
 	//
 	// GFX and video
 	//
@@ -146,6 +149,8 @@
 	virtual void unloadGFXMode();
 	virtual bool hotswapGFXMode();
 
+	virtual void setScale(int newScale);
+
 	//
 	// Game screen
 	//
@@ -213,6 +218,11 @@
 	virtual void refreshCursor();
 	virtual void adjustMouseEvent(const Common::Event &event);
 	virtual void setMousePos(int x, int y);
+
+	//
+	// Misc
+	//
+	virtual bool saveScreenshot(const char *filename);
 };
 
 #endif

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp	2010-07-19 05:33:58 UTC (rev 51015)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.cpp	2010-07-19 05:36:10 UTC (rev 51016)
@@ -26,6 +26,7 @@
 #ifdef USE_OPENGL
 
 #include "backends/graphics/openglsdl/openglsdl-graphics.h"
+#include "backends/platform/sdl/sdl.h"
 
 OpenGLSdlGraphicsManager::OpenGLSdlGraphicsManager()
 	:
@@ -135,7 +136,7 @@
 	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 
 	_hwscreen = SDL_SetVideoMode(_videoMode.hardwareWidth, _videoMode.hardwareHeight, 32,
-		_videoMode.fullscreen ? (SDL_FULLSCREEN | SDL_OPENGL) : SDL_OPENGL
+		_videoMode.fullscreen ? (SDL_FULLSCREEN | SDL_OPENGL) : (SDL_OPENGL | SDL_RESIZABLE)
 	);
 	if (_hwscreen == NULL) {
 		// DON'T use error(), as this tries to bring up the debug
@@ -169,4 +170,127 @@
 	SDL_GL_SwapBuffers(); 
 }
 
+bool OpenGLSdlGraphicsManager::handleScalerHotkeys(Common::KeyCode key) {
+
+	// Ctrl-Alt-a toggles aspect ratio correction
+	/*if (key == 'a') {
+		beginGFXTransaction();
+			setFeatureState(OSystem::kFeatureAspectRatioCorrection, !_videoMode.aspectRatioCorrection);
+		endGFXTransaction();
+#ifdef USE_OSD
+		char buffer[128];
+		if (_videoMode.aspectRatioCorrection)
+			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;
+	}*/
+
+	SDLKey sdlKey = (SDLKey)key;
+
+	// 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) {
+			beginGFXTransaction();
+				setScale(factor);
+			endGFXTransaction();
+		}	
+	}
+	return false;
+}
+
+void OpenGLSdlGraphicsManager::setFullscreenMode(bool enable) {
+
+}
+
+bool OpenGLSdlGraphicsManager::isScalerHotkey(const Common::Event &event) {
+	if ((event.kbd.flags & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) {
+		const bool isScaleKey = (event.kbd.keycode == Common::KEYCODE_EQUALS || event.kbd.keycode == Common::KEYCODE_PLUS || event.kbd.keycode == Common::KEYCODE_MINUS ||
+			event.kbd.keycode == Common::KEYCODE_KP_PLUS || event.kbd.keycode == Common::KEYCODE_KP_MINUS);
+
+		return (isScaleKey || event.kbd.keycode == 'a');
+	}
+	return false;
+}
+
+void OpenGLSdlGraphicsManager::toggleFullScreen() {
+	beginGFXTransaction();
+		setFullscreenMode(!_videoMode.fullscreen);
+	endGFXTransaction();
+#ifdef USE_OSD
+	if (_videoMode.fullscreen)
+		displayMessageOnOSD("Fullscreen mode");
+	else
+		displayMessageOnOSD("Windowed mode");
+#endif
+}
+
+bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
+	switch ((int)event.type) {
+	case Common::EVENT_KEYDOWN:
+		// Alt-Return and Alt-Enter toggle full screen mode
+		if (event.kbd.hasFlags(Common::KBD_ALT) &&
+			(event.kbd.keycode == Common::KEYCODE_RETURN ||
+			event.kbd.keycode == (Common::KeyCode)SDLK_KP_ENTER)) {
+			toggleFullScreen();
+			return true;
+		}
+
+		// Alt-S: Create a screenshot
+		if (event.kbd.hasFlags(Common::KBD_ALT) && 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;
+		}
+
+		// Ctrl-Alt-<key> will change the GFX mode
+		if ((event.kbd.flags & (Common::KBD_CTRL|Common::KBD_ALT)) == (Common::KBD_CTRL|Common::KBD_ALT)) {
+			if (handleScalerHotkeys(event.kbd.keycode))
+				return true;
+		}
+	case Common::EVENT_KEYUP:
+		return isScalerHotkey(event);
+	/*case OSystem_SDL::kSdlEventExpose:
+		break;*/
+	// HACK: Handle special SDL event
+	case OSystem_SDL::kSdlEventResize:
+		_videoMode.overlayWidth = event.mouse.x;
+		_videoMode.overlayHeight = event.mouse.y;
+		_videoMode.hardwareWidth = event.mouse.x;
+		_videoMode.hardwareHeight = event.mouse.y;
+		initGL();
+		return true;
+
+	default:
+		break;
+	}
+
+	return OpenGLGraphicsManager::notifyEvent(event);
+}
+
+#endif

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.h	2010-07-19 05:33:58 UTC (rev 51015)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/openglsdl/openglsdl-graphics.h	2010-07-19 05:36:10 UTC (rev 51016)
@@ -48,6 +48,8 @@
 
 	virtual void warpMouse(int x, int y);
 
+	virtual bool notifyEvent(const Common::Event &event);
+
 protected:
 	virtual void internUpdateScreen();
 
@@ -55,6 +57,12 @@
 	virtual void unloadGFXMode();
 	virtual bool hotswapGFXMode();
 
+	virtual void setFullscreenMode(bool enable);
+
+	virtual bool handleScalerHotkeys(Common::KeyCode key);
+	virtual bool isScalerHotkey(const Common::Event &event);
+	virtual void toggleFullScreen();
+
 	// Hardware screen
 	SDL_Surface *_hwscreen;
 };


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list