pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3805 - in trunk/pingus/src: . display


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3805 - in trunk/pingus/src: . display
Date: Sun, 13 Jul 2008 12:13:49 +0200

Author: grumbel
Date: 2008-07-13 12:13:47 +0200 (Sun, 13 Jul 2008)
New Revision: 3805

Modified:
   trunk/pingus/src/config_manager.cpp
   trunk/pingus/src/display/display.cpp
   trunk/pingus/src/display/display.hpp
Log:
Added some detection to select the next-best video mode for fullscreen instead 
of simply using the window size

Modified: trunk/pingus/src/config_manager.cpp
===================================================================
--- trunk/pingus/src/config_manager.cpp 2008-07-13 10:12:30 UTC (rev 3804)
+++ trunk/pingus/src/config_manager.cpp 2008-07-13 10:13:47 UTC (rev 3805)
@@ -89,8 +89,7 @@
 Size
 ConfigManager::get_resolution()
 {
-  return Size(Display::get_width(),
-              Display::get_height());
+  return Display::get_size();
 }
 
 void
@@ -102,7 +101,8 @@
   if (v != get_fullscreen())
     {
       fullscreen_enabled = v;
-      Display::set_video_mode(screen_width, screen_height, fullscreen_enabled);
+      Size screen_size = Display::get_size();
+      Display::set_video_mode(screen_size.width, screen_size.height, 
fullscreen_enabled);
       on_fullscreen_change(v);
     }
 }

Modified: trunk/pingus/src/display/display.cpp
===================================================================
--- trunk/pingus/src/display/display.cpp        2008-07-13 10:12:30 UTC (rev 
3804)
+++ trunk/pingus/src/display/display.cpp        2008-07-13 10:13:47 UTC (rev 
3805)
@@ -63,7 +63,15 @@
         framebuffer = std::auto_ptr<Framebuffer>(new SDLFramebuffer());
     }
 
-  framebuffer->set_video_mode(width, height, fullscreen);
+  if (fullscreen)
+    {
+      Size size = find_closest_fullscreen_video_mode(Size(width, height));
+      framebuffer->set_video_mode(size.width, size.height, fullscreen);
+    }
+  else
+    {
+      framebuffer->set_video_mode(width, height, fullscreen);
+    }
 }
 
 Framebuffer&
@@ -71,5 +79,79 @@
 {
   return *framebuffer.get(); 
 }
+
+Size
+Display::find_closest_fullscreen_video_mode(const Size& size)
+{
+  SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
+
+  if (modes == (SDL_Rect **)0) 
+    { // No resolutions at all available, bad
+      return size;
+    }
+  else if(modes == (SDL_Rect **)-1) 
+    {  
+      return size;
+    }
+  else 
+    {
+      // FIXME: This might not work that well with different aspect ratios
+      int distance = -1;
+      Size best_fit = size;
+      
+      for(int i = 0; modes[i]; ++i)
+        {
+          int this_distance = abs(size.width - modes[i]->w) + abs(size.height 
- modes[i]->h);
+          
+          //std::cout << "Mode: " << size << " -> " << modes[i]->w << "x" << 
modes[i]->h << " " << this_distance << std::endl;        
+
+          if (distance == -1 || distance > this_distance)
+            {
+              distance = this_distance;
+
+              best_fit.width  = modes[i]->w;
+              best_fit.height = modes[i]->h;
+            }
+        }
+
+      return best_fit;
+    }
+
+}
+
+std::vector<Size>
+Display::get_fullscreen_video_modes()
+{
+  std::vector<Size> video_modes;  
+  SDL_Rect** modes = SDL_ListModes(NULL, SDL_FULLSCREEN);
+
+  if (modes == (SDL_Rect **)0) 
+    { // No resolutions at all available, bad
+      
+    }
+  else if(modes == (SDL_Rect **)-1) 
+    {  // FIXME: Under which OSs is this triggred, if ever?
+
+      // All resolutions should work, so we fall back to hardcoded defaults
+      video_modes.push_back(Size( 640, 480));
+      video_modes.push_back(Size( 800, 600));
+      video_modes.push_back(Size(1024, 768));
+      video_modes.push_back(Size(1152, 864));
+      video_modes.push_back(Size(1280, 960));
+      video_modes.push_back(Size(1280, 1024));
+      video_modes.push_back(Size(1440, 900));
+      video_modes.push_back(Size(1680, 1050));
+      video_modes.push_back(Size(1600, 1200));
+      video_modes.push_back(Size(1920, 1080));
+      video_modes.push_back(Size(1920, 1200));
+    }
+  else 
+    {
+      for(int i = 0; modes[i]; ++i)
+        video_modes.push_back(Size(modes[i]->w,  modes[i]->h));
+    }
+
+  return video_modes;
+}
 
 /* EOF */

Modified: trunk/pingus/src/display/display.hpp
===================================================================
--- trunk/pingus/src/display/display.hpp        2008-07-13 10:12:30 UTC (rev 
3804)
+++ trunk/pingus/src/display/display.hpp        2008-07-13 10:13:47 UTC (rev 
3805)
@@ -43,6 +43,9 @@
   
   static Framebuffer& get_framebuffer();
 
+  static Size find_closest_fullscreen_video_mode(const Size& size);
+  static std::vector<Size> get_fullscreen_video_modes();
+
 private:
   Display ();
   Display (const Display&);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]