Commits

illume committed 6866908

Added current_h and current_w to the display.Info() object.
Added in SDL 1.2.10.
Also added a test to see that it works correctly.

  • Participants
  • Parent commits ae48ea3

Comments (0)

Files changed (3)

 {
 	SDL_VideoInfo* info = &((PyVidInfoObject*)self)->info;
 
+        int current_w = -1;
+        int current_h = -1;
+
+        SDL_version versioninfo;
+	SDL_VERSION(&versioninfo);
+
+        if(versioninfo.major >= 1 && versioninfo.minor >= 2 && versioninfo.patch >= 10 ) {
+            current_w = info->current_w;
+            current_h = info->current_h;
+        }
+
+
+
+
 	if(!strcmp(name, "hw"))
 		return PyInt_FromLong(info->hw_available);
 	else if(!strcmp(name, "wm"))
 	else if(!strcmp(name, "losses"))
 		return Py_BuildValue("(iiii)", info->vfmt->Rloss, info->vfmt->Gloss,
 					info->vfmt->Bloss, info->vfmt->Aloss);
+	else if(!strcmp(name, "current_h"))
+		return PyInt_FromLong(current_h);
+	else if(!strcmp(name, "current_w"))
+		return PyInt_FromLong(current_w);
+
 
 	return RAISE(PyExc_AttributeError, "does not exist in vidinfo");
 }
 PyObject* vidinfo_str(PyObject* self)
 {
 	char str[1024];
+        int current_w = -1;
+        int current_h = -1;
 	SDL_VideoInfo* info = &((PyVidInfoObject*)self)->info;
 
+        SDL_version versioninfo;
+	SDL_VERSION(&versioninfo);
+
+        if(versioninfo.major >= 1 && versioninfo.minor >= 2 && versioninfo.patch >= 10 ) {
+            current_w = info->current_w;
+            current_h = info->current_h;
+        }
+
 	sprintf(str, "<VideoInfo(hw = %d, wm = %d,video_mem = %d\n"
 				 "	     blit_hw = %d, blit_hw_CC = %d, blit_hw_A = %d,\n"
 				 "	     blit_sw = %d, blit_sw_CC = %d, blit_sw_A = %d,\n"
 				 "	     bitsize  = %d, bytesize = %d,\n"
 				 "	     masks =  (%d, %d, %d, %d),\n"
 				 "	     shifts = (%d, %d, %d, %d),\n"
-				 "	     losses =  (%d, %d, %d, %d)>\n",
-				info->hw_available, info->wm_available, info->video_mem,
+				 "	     losses =  (%d, %d, %d, %d),\n"
+				 "	     current_w = %d, current_h = %d\n"
+				 ">\n"
+				,info->hw_available, info->wm_available, info->video_mem,
 				info->blit_hw, info->blit_hw_CC, info->blit_hw_A,
 				info->blit_sw, info->blit_sw_CC, info->blit_sw_A,
 				info->vfmt->BitsPerPixel, info->vfmt->BytesPerPixel,
 				info->vfmt->Rmask, info->vfmt->Gmask, info->vfmt->Bmask, info->vfmt->Amask,
 				info->vfmt->Rshift, info->vfmt->Gshift, info->vfmt->Bshift, info->vfmt->Ashift,
-				info->vfmt->Rloss, info->vfmt->Gloss, info->vfmt->Bloss, info->vfmt->Aloss);
+				info->vfmt->Rloss, info->vfmt->Gloss, info->vfmt->Bloss, info->vfmt->Aloss,
+                                current_w, current_h);
+
+
 
 	return PyString_FromString(str);
 }
   blit_sw:    True if software Surface blitting is accelerated
   blit_sw_CC: True if software Surface colorkey blitting is accelerated
   blit_sw_A:  True if software Surface pixel alpha blitting is acclerated
-
+  current_h, current_h:  Width and height of the current video mode, or of the 
+    desktop mode if called before the display is init.
+    (current_h, current_w are available since SDL 1.2.10, and pygame 1.8.0)
+    They are -1 on error, or if an old SDL is being used.
 <END>
 
 

test/display_test.py

         #pygame.quit()
 
 
+    def test_vid_info( self ):
+        """ 
+        """
+
+
+        pygame.init()
+        inf = pygame.display.Info()
+        print "before a display mode has been set"
+        print inf
+        self.assertNotEqual(inf.current_h, -1)
+        self.assertNotEqual(inf.current_w, -1)
+        #probably have an older SDL than 1.2.10 if -1.
+
+
+        screen = pygame.display.set_mode((100,100))
+        inf = pygame.display.Info()
+        print inf
+        self.assertNotEqual(inf.current_h, -1)
+        self.assertEqual(inf.current_h, 100)
+        self.assertEqual(inf.current_w, 100)
+
+        #pygame.quit()
+
+