[Scummvm-cvs-logs] CVS: scummvm/backends/sdl events.cpp,1.19,1.20 graphics.cpp,1.51,1.52 sdl-common.h,1.82,1.83

Max Horn fingolfin at users.sourceforge.net
Mon Jul 11 03:56:25 CEST 2005


Update of /cvsroot/scummvm/scummvm/backends/sdl
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28407

Modified Files:
	events.cpp graphics.cpp sdl-common.h 
Log Message:
Move scaler key handling to a separate method (this helps to fix a GCC 4.0 warning, makes pollEvent() cleaner); fixed some code formatting issues

Index: events.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/events.cpp,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- events.cpp	5 Jul 2005 20:22:36 -0000	1.19
+++ events.cpp	11 Jul 2005 10:54:53 -0000	1.20
@@ -255,85 +255,12 @@
 			// Ctrl-Alt-<key> will change the GFX mode
 			if ((b & (KBD_CTRL|KBD_ALT)) == (KBD_CTRL|KBD_ALT)) {
 				
-				// Ctrl-Alt-a toggles aspect ratio correction
-				if (ev.key.keysym.sym == 'a') {
-					setFeatureState(kFeatureAspectRatioCorrection, !_adjustAspectRatio);
-#ifdef USE_OSD
-					char buffer[128];
-					if (_adjustAspectRatio)
-						sprintf(buffer, "Enabled aspect ratio correction\n%d x %d -> %d x %d",
-							_screenWidth, _screenHeight,
-							_hwscreen->w, _hwscreen->h
-							);
-					else
-						sprintf(buffer, "Disabled aspect ratio correction\n%d x %d -> %d x %d",
-							_screenWidth, _screenHeight,
-							_hwscreen->w, _hwscreen->h
-							);
-					displayMessageOnOSD(buffer);
-#endif
-
-					break;
-				}
-
-
-				int newMode = -1;
-				int factor = _scaleFactor - 1;
-				
-				// Increase/decrease the scale factor
-				if (ev.key.keysym.sym == SDLK_EQUALS || ev.key.keysym.sym == SDLK_PLUS || ev.key.keysym.sym == SDLK_MINUS ||
-					ev.key.keysym.sym == SDLK_KP_PLUS || ev.key.keysym.sym == SDLK_KP_MINUS) {
-					factor += (ev.key.keysym.sym == SDLK_MINUS || ev.key.keysym.sym == SDLK_KP_MINUS) ? -1 : +1;
-					if (0 <= factor && factor <= 3) {
-						newMode = s_gfxModeSwitchTable[_scalerType][factor];
-					}
-				}
-				
-				const bool isNormalNumber = (SDLK_1 <= ev.key.keysym.sym && ev.key.keysym.sym <= SDLK_9);
-				const bool isKeypadNumber = (SDLK_KP1 <= ev.key.keysym.sym && ev.key.keysym.sym <= SDLK_KP9);
-				if (isNormalNumber || isKeypadNumber) {
-					_scalerType = ev.key.keysym.sym - (isNormalNumber ? SDLK_1 : SDLK_KP1);
-					if (_scalerType >= ARRAYSIZE(s_gfxModeSwitchTable))
-						break;
-					
-					while (s_gfxModeSwitchTable[_scalerType][factor] < 0) {
-						assert(factor > 0);
-						factor--;
-					}
-					newMode = s_gfxModeSwitchTable[_scalerType][factor];
-				}
-				
-				if (newMode >= 0) {
-					setGraphicsMode(newMode);
-#ifdef USE_OSD
-					if (_osdSurface) {
-						const char *newScalerName = 0;
-						const GraphicsMode *g = getSupportedGraphicsModes();
-						while (g->name) {
-							if (g->id == _mode) {
-								newScalerName = g->description;
-								break;
-							}
-							g++;
-						}
-						if (newScalerName) {
-							char buffer[128];
-							sprintf(buffer, "Active graphics filter: %s\n%d x %d -> %d x %d",
-								newScalerName,
-								_screenWidth, _screenHeight,
-								_hwscreen->w, _hwscreen->h
-								);
-							displayMessageOnOSD(buffer);
-						}
-					}
-#endif
-
-				}
+				handleScalerHotkeys(ev.key);
 				break;
 			}
-			const bool event_complete= remapKey(ev,event);
+			const bool event_complete = remapKey(ev,event);
 			
-			if(event_complete)
+			if (event_complete)
 				return true;
 
 			event.type = EVENT_KEYDOWN;
@@ -344,9 +271,9 @@
 			}
 		case SDL_KEYUP:
 			{
-			const bool event_complete= remapKey(ev,event);
+			const bool event_complete = remapKey(ev,event);
 			
-			if(event_complete)
+			if (event_complete)
 				return true;
 
 			event.type = EVENT_KEYUP;
@@ -517,71 +444,71 @@
 	return false;
 }
 
-bool OSystem_SDL::remapKey(SDL_Event &ev,Event &event){
+bool OSystem_SDL::remapKey(SDL_Event &ev,Event &event) {
 #ifdef LINUPY
-			// On Yopy map the End button to quit
-			if ((ev.key.keysym.sym == 293)) {
-				event.type = EVENT_QUIT;
-				return true;
-			}
-			// Map menu key to f5 (scumm menu)
-			if (ev.key.keysym.sym == 306) {
-				event.type = EVENT_KEYDOWN;
-				event.kbd.keycode = SDLK_F5;
-				event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0);
-				return true;
-			}
-			// Map action key to action
-			if (ev.key.keysym.sym == 291) {
-				event.type = EVENT_KEYDOWN;
-				event.kbd.keycode = SDLK_TAB;
-				event.kbd.ascii = mapKey(SDLK_TAB, ev.key.keysym.mod, 0);
-				return true;
-			}
-			// Map OK key to skip cinematic
-			if (ev.key.keysym.sym == 292) {
-				event.type = EVENT_KEYDOWN;
-				event.kbd.keycode = SDLK_ESCAPE;
-				event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0);
-				return true;
-			}
+	// On Yopy map the End button to quit
+	if ((ev.key.keysym.sym == 293)) {
+		event.type = EVENT_QUIT;
+		return true;
+	}
+	// Map menu key to f5 (scumm menu)
+	if (ev.key.keysym.sym == 306) {
+		event.type = EVENT_KEYDOWN;
+		event.kbd.keycode = SDLK_F5;
+		event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0);
+		return true;
+	}
+	// Map action key to action
+	if (ev.key.keysym.sym == 291) {
+		event.type = EVENT_KEYDOWN;
+		event.kbd.keycode = SDLK_TAB;
+		event.kbd.ascii = mapKey(SDLK_TAB, ev.key.keysym.mod, 0);
+		return true;
+	}
+	// Map OK key to skip cinematic
+	if (ev.key.keysym.sym == 292) {
+		event.type = EVENT_KEYDOWN;
+		event.kbd.keycode = SDLK_ESCAPE;
+		event.kbd.ascii = mapKey(SDLK_ESCAPE, ev.key.keysym.mod, 0);
+		return true;
+	}
 #endif
 
 #ifdef QTOPIA
-			// quit on fn+backspace on zaurus
-			if (ev.key.keysym.sym == 127) {
-				event.type = EVENT_QUIT;
-				return true;
-			}
+	// Quit on fn+backspace on zaurus
+	if (ev.key.keysym.sym == 127) {
+		event.type = EVENT_QUIT;
+		return true;
+	}
 
-			// map menu key (f11) to f5 (scumm menu)
-			if (ev.key.keysym.sym == SDLK_F11) {
-				event.type = EVENT_KEYDOWN;
-				event.kbd.keycode = SDLK_F5;
-				event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0);
-			}
-			// map center (space) to tab (default action )
-			// I wanted to map the calendar button but the calendar comes up
-			//
-			else if (ev.key.keysym.sym == SDLK_SPACE) {
-				event.type = EVENT_KEYDOWN;
-				event.kbd.keycode = SDLK_TAB;
-				event.kbd.ascii = mapKey(SDLK_TAB, ev.key.keysym.mod, 0);
-			}
-			// since we stole space (pause) above we'll rebind it to the tab key on the keyboard
-			else if (ev.key.keysym.sym == SDLK_TAB) {
-				event.type = EVENT_KEYDOWN;
-				event.kbd.keycode = SDLK_SPACE;
-				event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0);
-			} else {
-			// let the events fall through if we didn't change them, this may not be the best way to
-			// set it up, but i'm not sure how sdl would like it if we let if fall through then redid it though.
-			// and yes i have an huge terminal size so i dont wrap soon enough.
-				event.type = EVENT_KEYDOWN;
-				event.kbd.keycode = ev.key.keysym.sym;
-				event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
-			}
+	// Map menu key (f11) to f5 (scumm menu)
+	if (ev.key.keysym.sym == SDLK_F11) {
+		event.type = EVENT_KEYDOWN;
+		event.kbd.keycode = SDLK_F5;
+		event.kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0);
+	}
+	// Nap center (space) to tab (default action )
+	// I wanted to map the calendar button but the calendar comes up
+	//
+	else if (ev.key.keysym.sym == SDLK_SPACE) {
+		event.type = EVENT_KEYDOWN;
+		event.kbd.keycode = SDLK_TAB;
+		event.kbd.ascii = mapKey(SDLK_TAB, ev.key.keysym.mod, 0);
+	}
+	// Since we stole space (pause) above we'll rebind it to the tab key on the keyboard
+	else if (ev.key.keysym.sym == SDLK_TAB) {
+		event.type = EVENT_KEYDOWN;
+		event.kbd.keycode = SDLK_SPACE;
+		event.kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0);
+	} else {
+	// Let the events fall through if we didn't change them, this may not be the best way to
+	// set it up, but i'm not sure how sdl would like it if we let if fall through then redid it though.
+	// and yes i have an huge terminal size so i dont wrap soon enough.
+		event.type = EVENT_KEYDOWN;
+		event.kbd.keycode = ev.key.keysym.sym;
+		event.kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode);
+	}
 #endif
-			return false;
+	return false;
 }
 

Index: graphics.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/graphics.cpp,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- graphics.cpp	9 Jul 2005 06:44:00 -0000	1.51
+++ graphics.cpp	11 Jul 2005 10:54:53 -0000	1.52
@@ -59,6 +59,17 @@
 #endif
 };
 
+static const int s_gfxModeSwitchTable[][4] = {
+		{ GFX_NORMAL, GFX_DOUBLESIZE, GFX_TRIPLESIZE, -1 },
+		{ GFX_NORMAL, GFX_ADVMAME2X, GFX_ADVMAME3X, -1 },
+		{ GFX_NORMAL, GFX_HQ2X, GFX_HQ3X, -1 },
+		{ GFX_NORMAL, GFX_2XSAI, -1, -1 },
+		{ GFX_NORMAL, GFX_SUPER2XSAI, -1, -1 },
+		{ GFX_NORMAL, GFX_SUPEREAGLE, -1, -1 },
+		{ GFX_NORMAL, GFX_TV2X, -1, -1 },
+		{ GFX_NORMAL, GFX_DOTMATRIX, -1, -1 }
+	};
+
 static int cursorStretch200To240(uint8 *buf, uint32 pitch, int width, int height, int srcX, int srcY, int origSrcY);
 
 const OSystem::GraphicsMode *OSystem_SDL::getSupportedGraphicsModes() const {
@@ -1535,7 +1546,7 @@
 }
 
 #pragma mark -
-#pragma mark --- Mouse ---
+#pragma mark --- On Screen Display ---
 #pragma mark -
 
 #ifdef USE_OSD
@@ -1619,3 +1630,85 @@
 	_forceFull = true;
 }
 #endif
+
+
+#pragma mark -
+#pragma mark --- Misc ---
+#pragma mark -
+
+void OSystem_SDL::handleScalerHotkeys(const SDL_KeyboardEvent &key) {
+	// Ctrl-Alt-a toggles aspect ratio correction
+	if (key.keysym.sym == 'a') {
+		setFeatureState(kFeatureAspectRatioCorrection, !_adjustAspectRatio);
+#ifdef USE_OSD
+		char buffer[128];
+		if (_adjustAspectRatio)
+			sprintf(buffer, "Enabled aspect ratio correction\n%d x %d -> %d x %d",
+				_screenWidth, _screenHeight,
+				_hwscreen->w, _hwscreen->h
+				);
+		else
+			sprintf(buffer, "Disabled aspect ratio correction\n%d x %d -> %d x %d",
+				_screenWidth, _screenHeight,
+				_hwscreen->w, _hwscreen->h
+				);
+		displayMessageOnOSD(buffer);
+#endif
+
+		return;
+	}
+
+	int newMode = -1;
+	int factor = _scaleFactor - 1;
+	
+	// Increase/decrease the scale factor
+	if (key.keysym.sym == SDLK_EQUALS || key.keysym.sym == SDLK_PLUS || key.keysym.sym == SDLK_MINUS ||
+		key.keysym.sym == SDLK_KP_PLUS || key.keysym.sym == SDLK_KP_MINUS) {
+		factor += (key.keysym.sym == SDLK_MINUS || key.keysym.sym == SDLK_KP_MINUS) ? -1 : +1;
+		if (0 <= factor && factor <= 3) {
+			newMode = s_gfxModeSwitchTable[_scalerType][factor];
+		}
+	}
+	
+	const bool isNormalNumber = (SDLK_1 <= key.keysym.sym && key.keysym.sym <= SDLK_9);
+	const bool isKeypadNumber = (SDLK_KP1 <= key.keysym.sym && key.keysym.sym <= SDLK_KP9);
+	if (isNormalNumber || isKeypadNumber) {
+		_scalerType = key.keysym.sym - (isNormalNumber ? SDLK_1 : SDLK_KP1);
+		if (_scalerType >= ARRAYSIZE(s_gfxModeSwitchTable))
+			return;
+		
+		while (s_gfxModeSwitchTable[_scalerType][factor] < 0) {
+			assert(factor > 0);
+			factor--;
+		}
+		newMode = s_gfxModeSwitchTable[_scalerType][factor];
+	}
+	
+	if (newMode >= 0) {
+		setGraphicsMode(newMode);
+#ifdef USE_OSD
+		if (_osdSurface) {
+			const char *newScalerName = 0;
+			const GraphicsMode *g = getSupportedGraphicsModes();
+			while (g->name) {
+				if (g->id == _mode) {
+					newScalerName = g->description;
+					break;
+				}
+				g++;
+			}
+			if (newScalerName) {
+				char buffer[128];
+				sprintf(buffer, "Active graphics filter: %s\n%d x %d -> %d x %d",
+					newScalerName,
+					_screenWidth, _screenHeight,
+					_hwscreen->w, _hwscreen->h
+					);
+				displayMessageOnOSD(buffer);
+			}
+		}
+#endif
+
+	}
+
+}

Index: sdl-common.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/sdl/sdl-common.h,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -d -r1.82 -r1.83
--- sdl-common.h	5 Jul 2005 20:22:36 -0000	1.82
+++ sdl-common.h	11 Jul 2005 10:54:53 -0000	1.83
@@ -52,17 +52,6 @@
 	GFX_DOTMATRIX = 11
 };
 
-static const int s_gfxModeSwitchTable[][4] = {
-		{ GFX_NORMAL, GFX_DOUBLESIZE, GFX_TRIPLESIZE, -1 },
-		{ GFX_NORMAL, GFX_ADVMAME2X, GFX_ADVMAME3X, -1 },
-		{ GFX_NORMAL, GFX_HQ2X, GFX_HQ3X, -1 },
-		{ GFX_NORMAL, GFX_2XSAI, -1, -1 },
-		{ GFX_NORMAL, GFX_SUPER2XSAI, -1, -1 },
-		{ GFX_NORMAL, GFX_SUPEREAGLE, -1, -1 },
-		{ GFX_NORMAL, GFX_TV2X, -1, -1 },
-		{ GFX_NORMAL, GFX_DOTMATRIX, -1, -1 }
-	};
-
 
 class OSystem_SDL : public OSystem {
 public:
@@ -196,8 +185,6 @@
 #endif
 
 protected:
-	virtual bool remapKey(SDL_Event &ev, Event &event);
-
 	bool _inited;
 
 #ifdef USE_OSD
@@ -380,6 +367,10 @@
 
 	void setupIcon();
 	void handleKbdMouse();
+
+	virtual bool remapKey(SDL_Event &ev, Event &event);
+
+	void handleScalerHotkeys(const SDL_KeyboardEvent &key);
 };
 
 #endif





More information about the Scummvm-git-logs mailing list