From 21dce1573efaddb9b758c5f7bf62bf74bffc234f Mon Sep 17 00:00:00 2001
From: johns <>
Date: Fri, 26 Jul 2002 17:42:32 +0000
Subject: [PATCH] New flag for PlayMovie: keep the movie aspect ratio while
 zooming.

---
 src/include/movie.h         |  1 +
 src/stratagus/stratagus.cpp |  3 ++-
 src/video/movie.cpp         | 26 ++++++++++++++++++++------
 3 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/include/movie.h b/src/include/movie.h
index 7f4d38369..c4f57748c 100644
--- a/src/include/movie.h
+++ b/src/include/movie.h
@@ -46,6 +46,7 @@
 enum _play_movie_flags_ {
     PlayMovieFullScreen = 1,		/// Switch to full screen
     PlayMovieZoomScreen = 2,		/// Zoom to screen size
+    PlayMovieKeepAspect = 4,		/// Keep the aspect while zooming
 };
 
 /**
diff --git a/src/stratagus/stratagus.cpp b/src/stratagus/stratagus.cpp
index ce89447b4..bea096d5c 100644
--- a/src/stratagus/stratagus.cpp
+++ b/src/stratagus/stratagus.cpp
@@ -1186,7 +1186,8 @@ Use it at your own risk.\n\n");
     i=1;
     SetClipping(0,0,VideoWidth-1,VideoHeight-1);
     if( TitleScreen ) {
-	if( (i=PlayMovie(TitleScreen,PlayMovieZoomScreen)) ) {
+	if( (i=PlayMovie(TitleScreen,
+		PlayMovieZoomScreen|PlayMovieKeepAspect)) ) {
 	    DisplayPicture(TitleScreen);
 	    Invalidate();
 	}
diff --git a/src/video/movie.cpp b/src/video/movie.cpp
index 8268d9080..496e73a38 100644
--- a/src/video/movie.cpp
+++ b/src/video/movie.cpp
@@ -257,16 +257,30 @@ global int PlayMovie(const char *name, int flags)
     callbacks.SoundReady=WriteSound;
 
     if (flags & PlayMovieZoomScreen) {
-	rect.x = 0;
-	rect.y = 0;
-	rect.w = VideoWidth;
-	rect.h = VideoHeight;
+	if (flags & PlayMovieKeepAspect) {
+	    int wa;
+	    int ha;
+
+	    wa = VideoWidth * 100 / avi->Width;
+	    ha = VideoHeight * 100 / avi->Height;
+	    DebugLevel0Fn(" %d x %d\n" _C_ wa _C_ ha);
+	    if( wa < ha ) {			// Keep the aspect ratio
+		rect.w = VideoWidth;
+		rect.h = avi->Height * wa / 100;
+	    } else {
+		rect.w = avi->Width * ha / 100;
+		rect.h = VideoHeight;
+	    }
+	} else {			// Just zoom to max
+	    rect.w = VideoWidth;
+	    rect.h = VideoHeight;
+	}
     } else {
-	rect.x = (VideoWidth - avi->Width) / 2;
-	rect.y = (VideoHeight - avi->Height) / 2;
 	rect.w = avi->Width;
 	rect.h = avi->Height;
     }
+    rect.x = (VideoWidth - rect.w) / 2;
+    rect.y = (VideoHeight - rect.h) / 2;
 
     if( 1 ) {
 	int i;