adonthell-commits
[Top][All Lists]
Advanced

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

[adonthell-commits] master 260a0a1 2/2: FIXED clip rect not correctly re


From: Kai Sterker
Subject: [adonthell-commits] master 260a0a1 2/2: FIXED clip rect not correctly recalculated when changing window mode without changing scale
Date: Mon, 12 Sep 2016 20:21:21 +0000 (UTC)

branch: master
commit 260a0a171ed07089635593709f077c310680e8fb
Author: Kai Sterker <address@hidden>
Commit: Kai Sterker <address@hidden>

    FIXED clip rect not correctly recalculated when changing window mode 
without changing scale
    ADDED setting of SDL_VIDEO_X11_WMCLASS env variable to .desktop file name
---
 src/main.cc   |    2 +-
 src/screen.cc |   54 ++++++++++++++++++++++++++++++------------------------
 src/screen.h  |    6 +++---
 3 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/src/main.cc b/src/main.cc
index 97ed010..0ae7f88 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -190,7 +190,7 @@ int main(int argc, char * argv[])
     achievements::init();
 
     // init video subsystem
-    if (!screen::init (320, 240, 0, myconfig.display, myconfig.screen_mode))
+    if (!screen::init (320, 240, 0, myconfig))
     {
         printf("%s\n", screen::info().c_str());
         SDL_Quit();
diff --git a/src/screen.cc b/src/screen.cc
index b3af49a..4241b0f 100644
--- a/src/screen.cc
+++ b/src/screen.cc
@@ -62,8 +62,16 @@ void screen::cleanup()
     Window = NULL;
 }
 
-bool screen::init (u_int16 nl, u_int16 nh, u_int8 depth, u_int8 screen, u_int8 
screen_mode)
+bool screen::init (u_int16 nl, u_int16 nh, u_int8 depth, const config & 
myconfig)
 {
+       u_int8 screen = myconfig.display;
+       u_int8 screen_mode = myconfig.screen_mode;
+
+#if defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND)
+       std::string wm_class = "SDL_VIDEO_X11_WMCLASS=" + myconfig.game_name;
+       putenv ((char *) wm_class.c_str ());
+#endif
+
     if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
     {
        std::cout << "Couldn't init SDL: " << SDL_GetError () << std::endl;
@@ -302,33 +310,31 @@ void screen::update_scale()
        int w, h;
 
        SDL_GetRendererOutputSize(Renderer, &w, &h);
-       if (w != length() * scale_ || h != height() * scale_)
-       {
-               int scale_x = w / length();
-               int scale_y = h / height();
 
-               scale_ = scale_x > scale_y ? scale_y : scale_x;
+       int scale_x = w / length();
+       int scale_y = h / height();
 
-               if (mode_ == 1)
-               {
-                       // center viewport in letterbox mode
-                       clip_rect_.x = (w - length() * scale_) / 2;
-                       clip_rect_.y = (h - height() * scale_) / 2;
-                       clip_rect_.w = length() * scale_;
-                       clip_rect_.h = height() * scale_;
+       scale_ = scale_x > scale_y ? scale_y : scale_x;
 
-                       SDL_RenderSetClipRect(Renderer, &clip_rect_);
-               }
-               else
-               {
-                       // no rendering offset required when running in window 
or fullscreen modes
-                       clip_rect_.x = 0;
-                       clip_rect_.y = 0;
-                       clip_rect_.w = length() * scale_;
-                       clip_rect_.h = height() * scale_;
+       if (mode_ == 1)
+       {
+               // center viewport in letterbox mode
+               clip_rect_.x = (w - length() * scale_) / 2;
+               clip_rect_.y = (h - height() * scale_) / 2;
+               clip_rect_.w = length() * scale_;
+               clip_rect_.h = height() * scale_;
 
-                       SDL_RenderSetClipRect(Renderer, NULL);
-               }
+               SDL_RenderSetClipRect(Renderer, &clip_rect_);
+       }
+       else
+       {
+               // no rendering offset required when running in window or 
fullscreen modes
+               clip_rect_.x = 0;
+               clip_rect_.y = 0;
+               clip_rect_.w = length() * scale_;
+               clip_rect_.h = height() * scale_;
+
+               SDL_RenderSetClipRect(Renderer, NULL);
        }
 
 #ifdef DEBUG
diff --git a/src/screen.h b/src/screen.h
index 9905fa4..a16cc88 100644
--- a/src/screen.h
+++ b/src/screen.h
@@ -31,6 +31,7 @@
 #define SCREEN_H_
 
 #include "surface.h"
+#include "prefs.h"
 #include <string>
 
 
@@ -72,11 +73,10 @@ public:
      *  @param nl X screen resolution.
      *  @param nh Y screen resolution.
      *  @param depth desired screen depth.
-     *  @param display the display to use.
-     *  @param screen_mode whether to start in window or fullscreen mode
+     *  @param myconfig configuration data.
      *  @return true on success, false otherwise.
      */ 
-    static bool init (u_int16 nl, u_int16 nh, u_int8 depth, u_int8 display, 
u_int8 screen_mode);
+    static bool init (u_int16 nl, u_int16 nh, u_int8 depth, const config & 
myconfig);
 
     /** Returns the length of the screen.
      *  @return length of the screen.



reply via email to

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