adonthell-commits
[Top][All Lists]
Advanced

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

[adonthell-commits] master 865f2e4: FIXED flickering border in letterbox


From: Kai Sterker
Subject: [adonthell-commits] master 865f2e4: FIXED flickering border in letterbox mode (again!)
Date: Thu, 4 Aug 2016 18:50:05 +0000 (UTC)

branch: master
commit 865f2e4a55b35c0fc2f122b87f1e3978d7744e55
Author: Kai Sterker <address@hidden>
Commit: Kai Sterker <address@hidden>

    FIXED flickering border in letterbox mode (again!)
---
 src/screen.cc |   28 ++++++++++------------------
 src/screen.h  |   23 +++++++++++++++--------
 2 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/src/screen.cc b/src/screen.cc
index a824545..9a27bb3 100644
--- a/src/screen.cc
+++ b/src/screen.cc
@@ -45,8 +45,7 @@ SDL_Renderer *screen::Renderer = NULL;
 
 u_int8 screen::mode_ = 0;
 u_int8 screen::scale_;
-u_int16 screen::offset_x_;
-u_int16 screen::offset_y_;
+SDL_Rect screen::clip_rect_ = {};
 
 void screen::cleanup()
 {
@@ -295,7 +294,6 @@ u_int8 screen::get_scale_for_display(u_int8 screen, u_int16 
nl, u_int16 nh)
 void screen::update_scale()
 {
        int w, h;
-       static SDL_Rect clip = {};
 
        SDL_GetRendererOutputSize(Renderer, &w, &h);
        if (w != length() * scale_ || h != height() * scale_)
@@ -308,26 +306,20 @@ void screen::update_scale()
                if (mode_ == 1)
                {
                        // center viewport in letterbox mode
-                       offset_x_ = (w - length() * scale_) / 2;
-                       offset_y_ = (h - height() * scale_) / 2;
+                       clip_rect_.x = (w - length() * scale_) / 2;
+                       clip_rect_.y = (h - height() * scale_) / 2;
+                       clip_rect_.w = length() * scale_;
+                       clip_rect_.h = height() * scale_;
 
-                       clip.x = offset_x_;
-                       clip.y = offset_y_;
-                       clip.w = length() * scale_;
-                       clip.h = height() * scale_;
-
-                       // make sure both buffers are clear before setting clip 
rect
-            clear();
-            show();
-            clear();
-
-                       SDL_RenderSetClipRect(Renderer, &clip);
+                       SDL_RenderSetClipRect(Renderer, &clip_rect_);
                }
                else
                {
                        // no rendering offset required when running in window 
or fullscreen modes
-                       offset_x_ = 0;
-                       offset_y_ = 0;
+                       clip_rect_.x = 0;
+                       clip_rect_.y = 0;
+                       clip_rect_.w = length() * scale_;
+                       clip_rect_.h = height() * scale_;
 
                        SDL_RenderSetClipRect(Renderer, NULL);
                }
diff --git a/src/screen.h b/src/screen.h
index f53e68f..53babd9 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -119,7 +119,7 @@ public:
      */
     static u_int16 offset_x()
     {
-       return offset_x_;
+       return clip_rect_.x;
     }
 
     /**
@@ -127,7 +127,7 @@ public:
      */
     static u_int16 offset_y()
     {
-       return offset_y_;
+       return clip_rect_.y;
     }
 
     /** 
@@ -137,7 +137,17 @@ public:
     static void clear () 
     {
         SDL_SetRenderDrawColor(Renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
-        SDL_RenderClear(Renderer);
+        if (clip_rect_.x || clip_rect_.y)
+        {
+               // SDL renderers do not treat clip rect identical when clearing 
screen
+                       SDL_RenderSetClipRect(Renderer, NULL);
+                       SDL_RenderClear(Renderer);
+                       SDL_RenderSetClipRect(Renderer, &clip_rect_);
+        }
+        else
+        {
+                       SDL_RenderClear(Renderer);
+        }
     }
     
     /** Ensure the framebuffer is copied to the physical screen.
@@ -209,11 +219,8 @@ private:
     /// scale factor of the screen
     static u_int8 scale_;
 
-    /// x offset of viewport
-    static u_int16 offset_x_;
-
-    /// y offset of viewport
-    static u_int16 offset_y_;
+    /// clipping rectangle for letterbox mode
+    static SDL_Rect clip_rect_;
 };
 
 



reply via email to

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