adonthell-commits
[Top][All Lists]
Advanced

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

[adonthell-commits] master 33d44d8 4/4: UPDATED true fullscreen mode to


From: Kai Sterker
Subject: [adonthell-commits] master 33d44d8 4/4: UPDATED true fullscreen mode to use the highest available multiple of 320x240 instead being fixed at 640x480
Date: Sat, 30 Sep 2017 18:27:32 -0400 (EDT)

branch: master
commit 33d44d8cbf0619c98ff7b562c4b1fa161b5ddc38
Author: Kai Sterker <address@hidden>
Commit: Kai Sterker <address@hidden>

    UPDATED true fullscreen mode to use the highest available multiple of 
320x240 instead being fixed at 640x480
---
 src/screen.cc | 47 ++++++++++++++++++++++++++++++++++++++++-------
 src/screen.h  |  3 +++
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/src/screen.cc b/src/screen.cc
index 48bffbb..0b8b339 100644
--- a/src/screen.cc
+++ b/src/screen.cc
@@ -52,6 +52,7 @@ SDL_Renderer *screen::Renderer = NULL;
 u_int8 screen::mode_ = 0;
 u_int8 screen::scale_;
 SDL_Rect screen::clip_rect_ = {};
+SDL_DisplayMode screen::fullscreen_mode = {};
 
 void screen::cleanup()
 {
@@ -72,7 +73,7 @@ bool screen::init (u_int16 nl, u_int16 nh, u_int8 depth, 
const config & myconfig
        putenv ((char *) wm_class.c_str ());
 #endif
 
-    if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
+    if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMECONTROLLER) < 
0)
     {
        std::cout << "Couldn't init SDL: " << SDL_GetError () << std::endl;
        return false;
@@ -118,7 +119,6 @@ bool screen::init (u_int16 nl, u_int16 nh, u_int8 depth, 
const config & myconfig
                }
        }
 
-    SDL_DisplayMode fullscreen_mode;
     memset(&fullscreen_mode, 0, sizeof(SDL_DisplayMode));
     fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
 
@@ -208,19 +208,33 @@ string screen::info ()
     return temp.str ();
 }
 
+#ifdef DEBUG
+static const char* get_mode_str(const u_int8 & m)
+{
+       switch(m)
+       {
+       case 0: return "window";
+       case 1: return "letterbox";
+       case 2: return "fullscreen";
+       default: return "unknown";
+       }
+}
+#endif
+
 bool screen::set_fullscreen (const u_int8 & m)
 {
        bool r = false;
     if (mode_ != m)
     {
 #ifdef DEBUG
-       std::cout << "Switching from " << (int)mode_ << " to " << (int)m << 
std::endl;
+       std::cout << "Switching from " << get_mode_str(mode_) << " to " << 
get_mode_str(m) << std::endl;
 #endif
        if (mode_ != 0)
        {
                        r = SDL_SetWindowFullscreen(Window, SDL_FALSE) == 0;
                        if (!r)
                        {
+                       std::cout << "Failed to leave fullscreen mode: " << 
SDL_GetError() << std::endl;
                                return false;
                        }
        }
@@ -264,10 +278,15 @@ bool screen::set_fullscreen (const u_int8 & m)
                {
                update_scale();
                }
+        else
+        {
+               std::cout << "Failed to enter fullscreen mode: " << 
SDL_GetError() << std::endl;
+        }
 
         return r; 
     }
-    return 0; 
+
+    return false;
 }
 
 u_int8 screen::get_scale_for_display(u_int8 screen, u_int16 nl, u_int16 nh)
@@ -290,12 +309,26 @@ u_int8 screen::get_scale_for_display(u_int8 screen, 
u_int16 nl, u_int16 nh)
                }
                case 2:
                {
-                       // fullscreen mode at 640x480
                        bounds.x = 0;
                        bounds.y = 0;
                        bounds.w = nl * 2;
                        bounds.h = nh * 2;
-                       break;
+
+                       // fullscreen mode at highest supported multiple of 
320x240
+                       const int num_modes = SDL_GetNumDisplayModes(screen);
+                       SDL_DisplayMode mode;
+                       for (int i = 0; i < num_modes; ++i)
+                       {
+                               if (SDL_GetDisplayMode(screen, i, &mode) > -1)
+                               {
+                                       if (mode.w % 320 == 0 && mode.h % 240 
== 0)
+                                       {
+                                               bounds.w = mode.w;
+                                               bounds.h = mode.h;
+                                               break;
+                                       }
+                               }
+                       }
                }
        }
 
@@ -338,7 +371,7 @@ void screen::update_scale()
        }
 
 #ifdef DEBUG
-       std::cout << "Mode = " << (int) mode_ << ", X = " << offset_x_ << ", Y 
= " << offset_y_
+       std::cout << "Mode = " << get_mode_str(mode_) << ", X = " << offset_x() 
<< ", Y = " << offset_y()
                        << ", Width = " << w << ", Height = " << h << ", Scale 
= "
                        << (int) (scale_) << std::endl;
 #endif
diff --git a/src/screen.h b/src/screen.h
index a16cc88..56dd7f4 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -227,6 +227,9 @@ private:
 
     /// clipping rectangle for letterbox mode
     static SDL_Rect clip_rect_;
+
+    /// the mode to use for true fullscreen
+    static SDL_DisplayMode fullscreen_mode;
 };
 
 



reply via email to

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