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

vgvgf at users.sourceforge.net vgvgf at users.sourceforge.net
Mon Jul 26 06:17:38 CEST 2010


Revision: 51291
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51291&view=rev
Author:   vgvgf
Date:     2010-07-26 04:17:37 +0000 (Mon, 26 Jul 2010)

Log Message:
-----------
OPENGL: Add cursor scaling.

Modified Paths:
--------------
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp
    scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-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-26 02:16:10 UTC (rev 51290)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.cpp	2010-07-26 04:17:37 UTC (rev 51291)
@@ -554,8 +554,11 @@
 	assert(keycolor <= 255);
 #endif
 
+	// Allocate space for cursor data
+	if (_cursorData.w != w || _cursorData.h != h)
+		_cursorData.create(w, h, _cursorFormat.bytesPerPixel);
+
 	// Save cursor data
-	_cursorData.create(w, h, _cursorFormat.bytesPerPixel);
 	memcpy(_cursorData.pixels, buf, h * _cursorData.pitch);
 
 	// Set cursor info
@@ -566,6 +569,8 @@
 	_cursorKeyColor = keycolor;
 	_cursorTargetScale = cursorTargetScale;
 	_cursorNeedsRedraw = true;
+
+	refreshCursorScale();
 }
 
 void OpenGLGraphicsManager::setCursorPalette(const byte *colors, uint start, uint num) {
@@ -719,6 +724,29 @@
 	}
 }
 
+void OpenGLGraphicsManager::refreshCursorScale() {
+	float scaleFactorX = (float)_videoMode.hardwareWidth / _videoMode.screenWidth;
+	float scaleFactorY = (float)_videoMode.hardwareHeight / _videoMode.screenHeight;
+	float scaleFactor = scaleFactorX < scaleFactorY ? scaleFactorX : scaleFactorY;
+
+	if (_cursorTargetScale >= scaleFactor && _videoMode.scaleFactor >= scaleFactor) {
+		_cursorState.rW = _cursorState.w;
+		_cursorState.rH = _cursorState.h;
+		_cursorState.rHotX = _cursorState.hotX;
+		_cursorState.rHotY = _cursorState.hotY;
+	} else {
+		_cursorState.rW = _cursorState.w * scaleFactor;
+		_cursorState.rH = _cursorState.h * scaleFactor;
+		_cursorState.rHotX = _cursorState.hotX * scaleFactor;
+		_cursorState.rHotY = _cursorState.hotY * scaleFactor;
+	}
+
+	_cursorState.vW = _cursorState.w * scaleFactor;
+	_cursorState.vH = _cursorState.h * scaleFactor;
+	_cursorState.vHotX = _cursorState.hotX * scaleFactor;
+	_cursorState.vHotY = _cursorState.hotY * scaleFactor;
+}
+
 void OpenGLGraphicsManager::getGLPixelFormat(Graphics::PixelFormat pixelFormat, byte &bpp, GLenum &glFormat, GLenum &gltype) {
 	if (pixelFormat == Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0)) { // RGBA8888
 		bpp = 4;
@@ -764,7 +792,6 @@
 
 	// Draw the overlay
 	if (_overlayVisible) {
-
 		// Refresh texture if dirty
 		if (_overlayNeedsRedraw || !_overlayDirtyRect.isEmpty())
 			refreshOverlay();
@@ -774,13 +801,16 @@
 
 	// Draw the cursor
 	if (_cursorVisible) {
-
 		// Refresh texture if dirty
 		if (_cursorNeedsRedraw)
 			refreshCursor();
 
-		_cursorTexture->drawTexture(_cursorState.x - _cursorState.hotX,
-		_cursorState.y - _cursorState.hotY,	_cursorState.w, _cursorState.h);
+		if (_overlayVisible)
+			_cursorTexture->drawTexture(_cursorState.x - _cursorState.rHotX,
+				_cursorState.y - _cursorState.rHotY, _cursorState.rW, _cursorState.rH);
+		else
+			_cursorTexture->drawTexture(_cursorState.x - _cursorState.vHotX,
+				_cursorState.y - _cursorState.vHotY, _cursorState.vW, _cursorState.vH);
 	}
 }
 
@@ -886,6 +916,8 @@
 
 	loadTextures();
 
+	refreshCursorScale();
+
 	internUpdateScreen();
 
 	return true;

Modified: scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h
===================================================================
--- scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h	2010-07-26 02:16:10 UTC (rev 51290)
+++ scummvm/branches/gsoc2010-opengl/backends/graphics/opengl/opengl-graphics.h	2010-07-26 04:17:37 UTC (rev 51291)
@@ -205,20 +205,19 @@
 		int16 w, h;
 		int16 hotX, hotY;
 
-		// The size and hotspot of the pre-scaled cursor image, in real
+		// The size and hotspot of the scaled cursor, in real
 		// coordinates.
-		//int16 rW, rH;
-		//int16 rHotX, rHotY;
+		int16 rW, rH;
+		int16 rHotX, rHotY;
 
-		// The size and hotspot of the pre-scaled cursor image, in game
+		// The size and hotspot of the scaled cursor, in game
 		// coordinates.
-		//int16 vW, vH;
-		//int16 vHotX, vHotY;
+		int16 vW, vH;
+		int16 vHotX, vHotY;
 
-		MousePos() : x(0), y(0), w(0), h(0), hotX(0), hotY(0)/*,
+		MousePos() : x(0), y(0), w(0), h(0), hotX(0), hotY(0),
 		             rW(0), rH(0), rHotX(0), rHotY(0), vW(0), vH(0),
-		             vHotX(0), vHotY(0)*/
-			{ }
+		             vHotX(0), vHotY(0)	{}
 	};
 
 	GLTexture* _cursorTexture;
@@ -235,6 +234,7 @@
 	bool _cursorNeedsRedraw;
 
 	virtual void refreshCursor();
+	virtual void refreshCursorScale();
 	virtual void adjustMouseEvent(const Common::Event &event);
 	virtual void setMousePos(int x, int y);
 


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