shithub: candycrisis

Download patch

ref: fa3b56a5571fef108333c58c12caf99d200bb6f0
parent: cf21a2e6eaceb08275be5be29f330078c69f8684
author: Iliyas Jorio <iliyas@jor.io>
date: Sun Jan 8 15:39:00 EST 2023

Toggle crisp upscaling in-game

--- a/src/SDLU.cpp
+++ b/src/SDLU.cpp
@@ -122,22 +122,71 @@
             if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST && s_isForeground)
             {
                 FreezeGameTickCount();
-                EnableMusic(false);
+                //EnableMusic(false);
                 s_isForeground = false;
             }
             else if (event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED && !s_isForeground)
             {
                 UnfreezeGameTickCount();
-                EnableMusic(musicOn);
+                //EnableMusic(musicOn);
                 s_isForeground = true;
                 
                 DoFullRepaint();
             }
+            else if (event->window.event == SDL_WINDOWEVENT_RESIZED)
+            {
+                SDLU_CreateRendererTexture();
+            }
             break;
         }
     }
     
     return 1;
+}
+
+
+void SDLU_CreateRendererTexture()
+{
+    if (!g_renderer)
+        return;
+
+    if (!crispUpscaling)
+    {
+        SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");
+        SDL_RenderSetIntegerScale(g_renderer, SDL_FALSE);
+    }
+    else
+    {
+        int minWidth = 640;
+        int minHeight = widescreen ? 360 : 480;
+
+        int currentWidth = 0;
+        int currentHeight = 0;
+#if SDL_VERSION_ATLEAST(2,26,0)
+        SDL_GetWindowSizeInPixels(g_window, &currentWidth, &currentHeight);
+#else
+        SDL_GetWindowSize(g_window, &currentWidth, &currentHeight);
+#endif
+
+        if (currentWidth < minWidth || currentHeight < minHeight)
+        {
+            SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "best");
+            SDL_RenderSetIntegerScale(g_renderer, SDL_FALSE);
+        }
+        else
+        {
+            SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
+            SDL_RenderSetIntegerScale(g_renderer, SDL_TRUE);
+        }
+    }
+
+    if (g_windowTexture)
+        SDL_DestroyTexture(g_windowTexture);
+
+    g_windowTexture = SDL_CreateTexture(g_renderer,
+        SDL_PIXELFORMAT_RGB888,
+        SDL_TEXTUREACCESS_STREAMING,
+        640, 480);
 }
 
 
--- a/src/SDLU.h
+++ b/src/SDLU.h
@@ -24,6 +24,7 @@
 #define MASK_DEPTH 8
 
 void         SDLU_Init();
+void         SDLU_CreateRendererTexture();
 SDL_Rect*    SDLU_MRectToSDLRect( const MRect* in, SDL_Rect* out );
 MRect*       SDLU_SDLRectToMRect( const SDL_Rect* in, MRect* out );
 int          SDLU_BlitSurface( SDL_Surface* src, SDL_Rect* srcrect, SDL_Surface* dst, SDL_Rect* dstrect );
binary files a/src/main.cpp b/src/main.cpp differ
--- a/src/pause.cpp
+++ b/src/pause.cpp
@@ -509,6 +509,7 @@
 
 enum
 { 
+	kWarp = -2,
 	kNothing = -1,
 	
 // main pause screen (kEndGame is reused in continue and register)
@@ -515,7 +516,7 @@
 	kMusic = 0,		kResume,
 	kSound,         kEndGame,
 	kFullscreen,    kControls,
-	kWarp,          kSecret,
+	kScalingMode,   kSecret,
 
 // continue screen
     kContinue,      
@@ -718,7 +719,8 @@
 	int index;
 	const char *line[]  = { "\x01 Music",           "\x03 Resume",
                             "\x01 Sound",           "\x03 End Game",
-                            "\x01 Fullscreen",      "\x03 Controls"
+                            "\x01 Fullscreen",      "\x03 Controls",
+                            "\x01 Crisp Scaling",
 	};
 
     const int itemCount = arrsize(line);
@@ -728,6 +730,7 @@
 	if( !musicOn ) line[kMusic] = "\x02 Music";
 	if( !soundOn ) line[kSound] = "\x02 Sound";
 	if( !fullscreen ) line[kFullscreen] = "\x02 Fullscreen";
+	if (!crispUpscaling) line[kScalingMode] = "\x02 Crisp Scaling";
 
 	SDLU_AcquireSurface( drawSurface );	
 	
@@ -949,6 +952,12 @@
                     SetFullscreen( fullscreen );
                     PlayMono( kClick );
                     return false;
+
+				case kScalingMode:
+					crispUpscaling = !crispUpscaling;
+					SDLU_CreateRendererTexture();
+					PlayMono(kClick);
+					return false;
 
                 case kEndGame:
 				case kResume: