[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] PATCH: display.c



Hi folks,

I'm using pygame for my project and I'm quite happy with it. And now finally the time has come that I can give something back :)

[quote SDL_SetVideoMode docs]
As of SDL 1.2.10, if width and height are both 0, it will use the width and height of the current video mode (or the desktop mode, if no mode has been set).
[/quote]

I was always missing this feature in pygame and now that I found out that it is already available in SDL I thought it couldn't be too hard to do in pygame... so here is my patch :)

with the ability to pass (0, 0) to display.set_mode I made it optional.
So now pygame.display.set_mode() will create a window with the same dimentions as your desktop.


sincerely yours
//Lorenz


PS: I already submitted this to the bug tracker but the tracker seems pretty dead and I wasn't sure if anybody was paying attention to it so I wrote this additional mail.
--- display.c	2008-03-08 16:48:41.000000000 +0100
+++ display_patched.c	2008-03-08 16:40:58.000000000 +0100
@@ -443,15 +443,30 @@
     SDL_Surface* surf;
     int depth = 0;
     int flags = SDL_SWSURFACE;
-    int w, h, hasbuf;
+    int w = 0;
+    int h = 0;
+    int hasbuf;
     char *title, *icontitle;
 
-    if (!PyArg_ParseTuple (arg, "(ii)|ii", &w, &h, &flags, &depth))
+    if (!PyArg_ParseTuple (arg, "|(ii)ii", &w, &h, &flags, &depth))
         return NULL;
 
-    if (w <= 0 || h <= 0)
-        return RAISE (PyExc_SDLError, "Cannot set 0 sized display mode");
-		
+    if (w < 0 || h < 0)
+        return RAISE (PyExc_SDLError, "Cannot set negative sized display mode");
+
+    if (w == 0 || h == 0)
+    {
+        SDL_version versioninfo;
+        SDL_VERSION (&versioninfo);
+        if (!(w == 0 && h == 0) ||
+            !(versioninfo.major > 1 || 
+              (versioninfo.major == 1 && versioninfo.minor > 2) || 
+              (versioninfo.major == 1 && versioninfo.minor == 2 && versioninfo.patch >= 10 )))
+        {
+            return RAISE (PyExc_SDLError, "Cannot set 0 sized display mode");
+        }
+    }
+
     if (!SDL_WasInit (SDL_INIT_VIDEO))
     {
         /*note SDL works special like this too*/