[Scummvm-cvs-logs] scummvm master -> 42d3b8fcbda7793bf3ef8435db5ed78f7350cf4d

lordhoto lordhoto at gmail.com
Thu Mar 17 18:37:21 CET 2011


This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e08683d939 OPENGL: Refactor warpMouse.
019aa63b15 OPENGL: Fix "Original" mode by setting up the corret screen dimensions.
3c656916f1 OPENGL: Always properly set the overlay dimensions in loadGFXMode.
372af10a7b OPENGL: Update the OSD texture when visible while the output mode changes.
42d3b8fcbd OPENGL: Fix compilation when USE_OSD is not defined.


Commit: e08683d939d621f20b0376f9da561f06c4944e31
    https://github.com/scummvm/scummvm/commit/e08683d939d621f20b0376f9da561f06c4944e31
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-03-17T09:37:42-07:00

Commit Message:
OPENGL: Refactor warpMouse.

Now subclasses will not need to worry about the scaling logic themselves, but
just need to implement setInternalMousePosition, which should handles setting
the system's mouse coordinates.

Changed paths:
    backends/graphics/opengl/opengl-graphics.cpp
    backends/graphics/opengl/opengl-graphics.h
    backends/graphics/openglsdl/openglsdl-graphics.cpp
    backends/graphics/openglsdl/openglsdl-graphics.h



diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 9a2efe3..6bd7902 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -540,13 +540,53 @@ bool OpenGLGraphicsManager::showMouse(bool visible) {
 	return last;
 }
 
-void OpenGLGraphicsManager::setMousePos(int x, int y) {
-	_cursorState.x = x;
-	_cursorState.y = y;
-}
-
 void OpenGLGraphicsManager::warpMouse(int x, int y) {
-	setMousePos(x, y);
+	int scaledX = x;
+	int scaledY = y;
+
+	int16 currentX = _cursorState.x;
+	int16 currentY = _cursorState.y;
+
+	adjustMousePosition(currentX, currentY);
+
+	// Do not adjust the real screen position, when the current game / overlay
+	// coordinates match the requested coordinates. This avoids a slight
+	// movement which might occur otherwise when the mouse is at a subpixel
+	// position.
+	if (x == currentX && y == currentY)
+		return;
+
+	if (_videoMode.mode == OpenGL::GFX_NORMAL) {
+		if (_videoMode.hardwareWidth != _videoMode.overlayWidth)
+			scaledX = scaledX * _videoMode.hardwareWidth / _videoMode.overlayWidth;
+		if (_videoMode.hardwareHeight != _videoMode.overlayHeight)
+			scaledY = scaledY * _videoMode.hardwareHeight / _videoMode.overlayHeight;
+
+		if (!_overlayVisible) {
+			scaledX *= _videoMode.scaleFactor;
+			scaledY *= _videoMode.scaleFactor;
+		}
+	} else {
+		if (_overlayVisible) {
+			if (_displayWidth != _videoMode.overlayWidth)
+				scaledX = scaledX * _displayWidth / _videoMode.overlayWidth;
+			if (_displayHeight != _videoMode.overlayHeight)
+				scaledY = scaledY * _displayHeight / _videoMode.overlayHeight;
+		} else {
+			if (_displayWidth != _videoMode.screenWidth)
+				scaledX = scaledX * _displayWidth / _videoMode.screenWidth;
+			if (_displayHeight != _videoMode.screenHeight)
+				scaledY = scaledY * _displayHeight / _videoMode.screenHeight;
+		}
+
+		scaledX += _displayX;
+		scaledY += _displayY;
+	}
+
+	setInternalMousePosition(scaledX, scaledY);
+
+	_cursorState.x = scaledX;
+	_cursorState.y = scaledY;
 }
 
 void OpenGLGraphicsManager::setMouseCursor(const byte *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, int cursorTargetScale, const Graphics::PixelFormat *format) {
@@ -1249,8 +1289,10 @@ void OpenGLGraphicsManager::adjustMousePosition(int16 &x, int16 &y) {
 bool OpenGLGraphicsManager::notifyEvent(const Common::Event &event) {
 	switch (event.type) {
 	case Common::EVENT_MOUSEMOVE:
-		if (!event.synthetic)
-			setMousePos(event.mouse.x, event.mouse.y);
+		if (!event.synthetic) {
+			_cursorState.x = event.mouse.x;
+			_cursorState.y = event.mouse.y;
+		}
 	case Common::EVENT_LBUTTONDOWN:
 	case Common::EVENT_RBUTTONDOWN:
 	case Common::EVENT_WHEELUP:
diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h
index b4084e8..d048c91 100644
--- a/backends/graphics/opengl/opengl-graphics.h
+++ b/backends/graphics/opengl/opengl-graphics.h
@@ -272,6 +272,15 @@ protected:
 
 	virtual void refreshCursor();
 	virtual void refreshCursorScale();
+
+	/**
+	 * Set up the mouse position for the (event) system.
+	 *
+	 * @param x X coordinate in native coordinates.
+	 * @param y Y coordinate in native coordinates.
+	 */
+	virtual void setInternalMousePosition(int x, int y) = 0;
+
 	/**
 	 * Adjusts hardware screen coordinates to either overlay or game screen
 	 * coordinates depending on whether the overlay is visible or not.
@@ -280,7 +289,6 @@ protected:
 	 * @param y Y coordinate of the mouse position.
 	 */
 	virtual void adjustMousePosition(int16 &x, int16 &y);
-	virtual void setMousePos(int x, int y);
 
 	//
 	// Misc
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index cbc152a..0c7e539 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -192,52 +192,8 @@ void OpenGLSdlGraphicsManager::detectSupportedFormats() {
 
 #endif
 
-void OpenGLSdlGraphicsManager::warpMouse(int x, int y) {
-	int scaledX = x;
-	int scaledY = y;
-
-	int16 currentX = _cursorState.x;
-	int16 currentY = _cursorState.y;
-
-	adjustMousePosition(currentX, currentY);
-
-	// Do not adjust the real screen position, when the current game / overlay
-	// coordinates match the requested coordinates. This avoids a slight
-	// movement which might occur otherwise when the mouse is at a subpixel
-	// position.
-	if (x == currentX && y == currentY)
-		return;
-
-	if (_videoMode.mode == OpenGL::GFX_NORMAL) {
-		if (_videoMode.hardwareWidth != _videoMode.overlayWidth)
-			scaledX = scaledX * _videoMode.hardwareWidth / _videoMode.overlayWidth;
-		if (_videoMode.hardwareHeight != _videoMode.overlayHeight)
-			scaledY = scaledY * _videoMode.hardwareHeight / _videoMode.overlayHeight;
-
-		if (!_overlayVisible) {
-			scaledX *= _videoMode.scaleFactor;
-			scaledY *= _videoMode.scaleFactor;
-		}
-	} else {
-		if (_overlayVisible) {
-			if (_displayWidth != _videoMode.overlayWidth)
-				scaledX = scaledX * _displayWidth / _videoMode.overlayWidth;
-			if (_displayHeight != _videoMode.overlayHeight)
-				scaledY = scaledY * _displayHeight / _videoMode.overlayHeight;
-		} else {
-			if (_displayWidth != _videoMode.screenWidth)
-				scaledX = scaledX * _displayWidth / _videoMode.screenWidth;
-			if (_displayHeight != _videoMode.screenHeight)
-				scaledY = scaledY * _displayHeight / _videoMode.screenHeight;
-		}
-
-		scaledX += _displayX;
-		scaledY += _displayY;
-	}
-
-	SDL_WarpMouse(scaledX, scaledY);
-
-	setMousePos(scaledX, scaledY);
+void OpenGLSdlGraphicsManager::setInternalMousePosition(int x, int y) {
+	SDL_WarpMouse(x, y);
 }
 
 void OpenGLSdlGraphicsManager::updateScreen() {
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.h b/backends/graphics/openglsdl/openglsdl-graphics.h
index d39c081..309301c 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.h
+++ b/backends/graphics/openglsdl/openglsdl-graphics.h
@@ -48,8 +48,6 @@ public:
 	virtual Common::List<Graphics::PixelFormat> getSupportedFormats() const;
 #endif
 
-	virtual void warpMouse(int x, int y);
-
 	virtual bool notifyEvent(const Common::Event &event);
 
 	virtual void updateScreen();
@@ -86,6 +84,8 @@ protected:
 	 */
 	virtual bool setupFullscreenMode();
 
+	virtual void setInternalMousePosition(int x, int y);
+
 	int _lastFullscreenModeWidth;
 	int _lastFullscreenModeHeight;
 	int _desktopWidth;


Commit: 019aa63b1580a2b629f45aa436cae47b0b330794
    https://github.com/scummvm/scummvm/commit/019aa63b1580a2b629f45aa436cae47b0b330794
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-03-17T10:35:18-07:00

Commit Message:
OPENGL: Fix "Original" mode by setting up the corret screen dimensions.

Changed paths:
    backends/graphics/opengl/opengl-graphics.cpp



diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 6bd7902..2407f5d 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -903,8 +903,8 @@ void OpenGLGraphicsManager::refreshCursorScale() {
 
 void OpenGLGraphicsManager::calculateDisplaySize(int &width, int &height) {
 	if (_videoMode.mode == OpenGL::GFX_ORIGINAL) {
-		width = _videoMode.overlayWidth;
-		height = _videoMode.overlayHeight;
+		width = _videoMode.screenWidth;
+		height = _videoMode.screenHeight;
 	} else {
 		width = _videoMode.hardwareWidth;
 		height = _videoMode.hardwareHeight;


Commit: 3c656916f169e0428bd62c390a8ccb7b7dbd150f
    https://github.com/scummvm/scummvm/commit/3c656916f169e0428bd62c390a8ccb7b7dbd150f
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-03-17T10:35:32-07:00

Commit Message:
OPENGL: Always properly set the overlay dimensions in loadGFXMode.

Changed paths:
    backends/graphics/openglsdl/openglsdl-graphics.cpp



diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index 0c7e539..b68b55f 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -314,14 +314,6 @@ bool OpenGLSdlGraphicsManager::loadGFXMode() {
 			_videoMode.hardwareHeight = (_videoMode.overlayWidth * 10000  + 5000) / desiredAspectRatio;
 		else if (screenAspectRatio < desiredAspectRatio)
 			_videoMode.hardwareWidth = (_videoMode.overlayHeight * desiredAspectRatio + 5000) / 10000;
-
-		// Only adjust the overlay height if it is bigger than original one. If
-		// the width is modified it can break the overlay.
-		if (_videoMode.hardwareHeight > _videoMode.overlayHeight)
-			_videoMode.overlayHeight = _videoMode.hardwareHeight;
-	} else {
-		_videoMode.overlayWidth = _videoMode.hardwareWidth;
-		_videoMode.overlayHeight = _videoMode.hardwareHeight;
 	}
 
 	_screenResized = false;
@@ -337,11 +329,11 @@ bool OpenGLSdlGraphicsManager::loadGFXMode() {
 		if (!setupFullscreenMode())
 			// Failed setuping a fullscreen mode
 			return false;
-
-		_videoMode.overlayWidth = _videoMode.hardwareWidth;
-		_videoMode.overlayHeight = _videoMode.hardwareHeight;
 	}
 
+	_videoMode.overlayWidth = _videoMode.hardwareWidth;
+	_videoMode.overlayHeight = _videoMode.hardwareHeight;
+
 	uint32 flags = SDL_OPENGL;
 
 	if (_videoMode.fullscreen)


Commit: 372af10a7bf154a625c9af7e65820a007bd43584
    https://github.com/scummvm/scummvm/commit/372af10a7bf154a625c9af7e65820a007bd43584
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-03-17T10:35:32-07:00

Commit Message:
OPENGL: Update the OSD texture when visible while the output mode changes.

This fixes annoying graphics glitches, which occured sometimes when resizing
the Window.

Changed paths:
    backends/graphics/opengl/opengl-graphics.cpp
    backends/graphics/opengl/opengl-graphics.h



diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 2407f5d..108e249 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -33,6 +33,9 @@
 #include "common/file.h"
 #include "common/mutex.h"
 #include "common/translation.h"
+#ifdef USE_OSD
+#include "common/tokenizer.h"
+#endif
 #include "graphics/font.h"
 #include "graphics/fontman.h"
 
@@ -643,61 +646,12 @@ void OpenGLGraphicsManager::displayMessageOnOSD(const char *msg) {
 	assert(_transactionMode == kTransactionNone);
 	assert(msg);
 
-	// The font we are going to use:
-	const Graphics::Font *font = FontMan.getFontByUsage(Graphics::FontManager::kOSDFont);
-
-	if (_osdSurface.w != _osdTexture->getWidth() || _osdSurface.h != _osdTexture->getHeight())
-		_osdSurface.create(_osdTexture->getWidth(), _osdTexture->getHeight(), 2);
-	else
-		// Clear everything
-		memset(_osdSurface.pixels, 0, _osdSurface.h * _osdSurface.pitch);
-
 	// Split the message into separate lines.
-	Common::Array<Common::String> lines;
-	const char *ptr;
-	for (ptr = msg; *ptr; ++ptr) {
-		if (*ptr == '\n') {
-			lines.push_back(Common::String(msg, ptr - msg));
-			msg = ptr + 1;
-		}
-	}
-	lines.push_back(Common::String(msg, ptr - msg));
-
-	// Determine a rect which would contain the message string (clipped to the
-	// screen dimensions).
-	const int vOffset = 6;
-	const int lineSpacing = 1;
-	const int lineHeight = font->getFontHeight() + 2 * lineSpacing;
-	int width = 0;
-	int height = lineHeight * lines.size() + 2 * vOffset;
-	for (uint i = 0; i < lines.size(); i++) {
-		width = MAX(width, font->getStringWidth(lines[i]) + 14);
-	}
-
-	// Clip the rect
-	if (width > _osdSurface.w)
-		width = _osdSurface.w;
-	if (height > _osdSurface.h)
-		height = _osdSurface.h;
+	_osdLines.clear();
 
-	int dstX = (_osdSurface.w - width) / 2;
-	int dstY = (_osdSurface.h - height) / 2;
-
-	// Draw a dark gray rect
-	uint16 color = 0x294B;
-	uint16 *dst = (uint16 *)_osdSurface.pixels + dstY * _osdSurface.w + dstX;
-	for (int i = 0; i < height; i++) {
-		for (int j = 0; j < width; j++)
-			dst[j] = color;
-		dst += _osdSurface.w;
-	}
-
-	// Render the message, centered, and in white
-	for (uint i = 0; i < lines.size(); i++) {
-		font->drawString(&_osdSurface, lines[i],
-							dstX, dstY + i * lineHeight + vOffset + lineSpacing, width,
-							0xFFFF, Graphics::kTextAlignCenter);
-	}
+	Common::StringTokenizer tokenizer(msg, "\n");
+	while (!tokenizer.empty())
+		_osdLines.push_back(tokenizer.nextToken());
 
 	// Request update of the texture
 	_requireOSDUpdate = true;
@@ -1071,9 +1025,7 @@ void OpenGLGraphicsManager::internUpdateScreen() {
 #ifdef USE_OSD
 	if (_osdAlpha > 0) {
 		if (_requireOSDUpdate) {
-			// Update the texture
-			_osdTexture->updateBuffer(_osdSurface.pixels, _osdSurface.pitch, 0, 0, 
-			                          _osdSurface.w, _osdSurface.h);
+			updateOSD();
 			_requireOSDUpdate = false;
 		}
 
@@ -1229,6 +1181,9 @@ void OpenGLGraphicsManager::loadTextures() {
 		_osdTexture->refresh();
 
 	_osdTexture->allocBuffer(_videoMode.overlayWidth, _videoMode.overlayHeight);
+
+	// Update the OSD in case it is used right now
+	_requireOSDUpdate = true;
 #endif
 }
 
@@ -1395,4 +1350,52 @@ void OpenGLGraphicsManager::switchDisplayMode(int mode) {
 	}
 }
 
+#ifdef USE_OSD
+void OpenGLGraphicsManager::updateOSD() {
+	// The font we are going to use:
+	const Graphics::Font *font = FontMan.getFontByUsage(Graphics::FontManager::kOSDFont);
+
+	if (_osdSurface.w != _osdTexture->getWidth() || _osdSurface.h != _osdTexture->getHeight())
+		_osdSurface.create(_osdTexture->getWidth(), _osdTexture->getHeight(), 2);
+	else
+		// Clear everything
+		memset(_osdSurface.pixels, 0, _osdSurface.h * _osdSurface.pitch);
+
+	// Determine a rect which would contain the message string (clipped to the
+	// screen dimensions).
+	const int vOffset = 6;
+	const int lineSpacing = 1;
+	const int lineHeight = font->getFontHeight() + 2 * lineSpacing;
+	int width = 0;
+	int height = lineHeight * _osdLines.size() + 2 * vOffset;
+	for (uint i = 0; i < _osdLines.size(); i++) {
+		width = MAX(width, font->getStringWidth(_osdLines[i]) + 14);
+	}
+
+	// Clip the rect
+	if (width > _osdSurface.w)
+		width = _osdSurface.w;
+	if (height > _osdSurface.h)
+		height = _osdSurface.h;
+
+	int dstX = (_osdSurface.w - width) / 2;
+	int dstY = (_osdSurface.h - height) / 2;
+
+	// Draw a dark gray rect
+	const uint16 color = 0x294B;
+	_osdSurface.fillRect(Common::Rect(dstX, dstY, dstX + width, dstY + height), color);
+
+	// Render the message, centered, and in white
+	for (uint i = 0; i < _osdLines.size(); i++) {
+		font->drawString(&_osdSurface, _osdLines[i],
+		                 dstX, dstY + i * lineHeight + vOffset + lineSpacing, width,
+		                 0xFFFF, Graphics::kTextAlignCenter);
+	}
+ 
+	// Update the texture
+	_osdTexture->updateBuffer(_osdSurface.pixels, _osdSurface.pitch, 0, 0, 
+	                          _osdSurface.w, _osdSurface.h);
+}
+#endif
+
 #endif
diff --git a/backends/graphics/opengl/opengl-graphics.h b/backends/graphics/opengl/opengl-graphics.h
index d048c91..baebb9c 100644
--- a/backends/graphics/opengl/opengl-graphics.h
+++ b/backends/graphics/opengl/opengl-graphics.h
@@ -296,6 +296,16 @@ protected:
 	virtual bool saveScreenshot(const char *filename);
 
 #ifdef USE_OSD
+	/**
+	 * The OSD contents.
+	 */
+	Common::Array<Common::String> _osdLines;
+
+	/**
+	 * Update the OSD texture / surface.
+	 */
+	void updateOSD();
+
 	GLTexture *_osdTexture;
 	Graphics::Surface _osdSurface;
 	uint8 _osdAlpha;


Commit: 42d3b8fcbda7793bf3ef8435db5ed78f7350cf4d
    https://github.com/scummvm/scummvm/commit/42d3b8fcbda7793bf3ef8435db5ed78f7350cf4d
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-03-17T10:35:32-07:00

Commit Message:
OPENGL: Fix compilation when USE_OSD is not defined.

Changed paths:
    backends/graphics/opengl/opengl-graphics.cpp
    backends/graphics/openglsdl/openglsdl-graphics.cpp



diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 108e249..e9942b8 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -646,6 +646,7 @@ void OpenGLGraphicsManager::displayMessageOnOSD(const char *msg) {
 	assert(_transactionMode == kTransactionNone);
 	assert(msg);
 
+#ifdef USE_OSD
 	// Split the message into separate lines.
 	_osdLines.clear();
 
@@ -659,6 +660,7 @@ void OpenGLGraphicsManager::displayMessageOnOSD(const char *msg) {
 	// Init the OSD display parameters, and the fade out
 	_osdAlpha = kOSDInitialAlpha;
 	_osdFadeStartTime = g_system->getMillis() + kOSDFadeOutDelay;
+#endif
 }
 
 //
diff --git a/backends/graphics/openglsdl/openglsdl-graphics.cpp b/backends/graphics/openglsdl/openglsdl-graphics.cpp
index b68b55f..c2ec43b 100644
--- a/backends/graphics/openglsdl/openglsdl-graphics.cpp
+++ b/backends/graphics/openglsdl/openglsdl-graphics.cpp
@@ -565,7 +565,9 @@ bool OpenGLSdlGraphicsManager::notifyEvent(const Common::Event &event) {
 			// Ctrl-Alt-<number key> will change the GFX mode
 			if (isNormalNumber || isKeypadNumber) {
 				if (sdlKey - (isNormalNumber ? SDLK_1 : SDLK_KP1) <= 4) {
+#ifdef USE_OSD
 					int lastMode = _videoMode.mode;
+#endif
 					beginGFXTransaction();
 						_videoMode.mode = sdlKey - (isNormalNumber ? SDLK_1 : SDLK_KP1);
 						_transactionDetails.needRefresh = true;






More information about the Scummvm-git-logs mailing list