# Copyright (C) 2007  Miriam Ruiz <little_miry@yahoo.es>
# Distributed under the same license as the game. See debian/copyright.

Index: mu-cade_0.11.dfsg1/src/abagames/util/sdl/screen3d.d
===================================================================
--- mu-cade_0.11.dfsg1.orig/src/abagames/util/sdl/screen3d.d	2007-08-29 00:07:03.000000000 +0200
+++ mu-cade_0.11.dfsg1/src/abagames/util/sdl/screen3d.d	2007-08-29 00:07:10.000000000 +0200
@@ -23,6 +23,7 @@
   int _width = 640;
   int _height = 480;
   bool _windowMode = true;
+  Uint32 _videoFlags = 0;
 
   protected abstract void init();
   protected abstract void close();
@@ -34,13 +35,12 @@
         "Unable to initialize SDL: " ~ std.string.toString(SDL_GetError()));
     }
     // Create an OpenGL screen.
-    Uint32 videoFlags;
     if (_windowMode) {
-      videoFlags = SDL_OPENGL | SDL_RESIZABLE;
+      _videoFlags = SDL_OPENGL | SDL_RESIZABLE;
     } else {
-      videoFlags = SDL_OPENGL | SDL_FULLSCREEN;
+      _videoFlags = SDL_OPENGL | SDL_FULLSCREEN;
     } 
-    if (SDL_SetVideoMode(_width, _height, 0, videoFlags) == null) {
+    if (SDL_SetVideoMode(_width, _height, 0, _videoFlags) == null) {
       throw new SDLInitFailedException
         ("Unable to create SDL screen: " ~ std.string.toString(SDL_GetError()));
     }
@@ -53,7 +53,20 @@
 
   // Reset a viewport when the screen is resized.
   public void screenResized() {
-    glViewport(0, 0, _width, _height);
+    int screen_width = _width;
+    int screen_height = _height;
+    if (SDL_SetVideoMode(screen_width, screen_height, 0, _videoFlags) == null) {
+      throw new SDLInitFailedException
+        ("Unable to resize SDL screen: " ~ std.string.toString(SDL_GetError()));
+    }
+
+    // adjust width and height to maintain correct aspect ratio
+    if (screen_width * 480 > screen_height * 640)
+      _width = screen_height * 640 / 480;
+    else if (screen_width * 480 < screen_height * 640)
+      _height = screen_width * 480 / 640;
+
+    glViewport((screen_width - _width) / 2, screen_height - _height, _width, _height);
     glMatrixMode(GL_PROJECTION);
     setPerspective();
     glMatrixMode(GL_MODELVIEW);
Index: mu-cade_0.11.dfsg1/src/abagames/mcd/screen.d
===================================================================
--- mu-cade_0.11.dfsg1.orig/src/abagames/mcd/screen.d	2006-02-19 05:57:26.000000000 +0100
+++ mu-cade_0.11.dfsg1/src/abagames/mcd/screen.d	2007-08-29 00:07:10.000000000 +0200
@@ -62,7 +62,6 @@
     else if (lw > 4)
       lw = 4;
     glLineWidth(lw);
-    glViewport(0, 0, width, height);
     if (field)
       field.setLookAt();
   }
