ref: d181d80c7da8a80efc6b8f21ed288876077e1b75
parent: 3e27f1b2d0d8f020e9d3509934736ee9055b8c31
author: Jacob Moody <moody@posixcafe.org>
date: Sun Feb 12 15:31:47 EST 2023
restore stretch screen behavior
--- a/src/modexlib.c
+++ b/src/modexlib.c
@@ -49,6 +49,7 @@
SDL_Surface *sdl_surface = NULL;
SDL_Surface *rgba_surface = NULL;
+SDL_Rect screenrect;
SDL_Texture *texture = NULL;
SDL_Window * window = NULL;
@@ -87,6 +88,23 @@
#endif
+static void
+resetscreen(int x, int y)
+{
+ if(sdl_surface != NULL)
+ SDL_FreeSurface(sdl_surface);
+ sdl_surface = SDL_CreateRGBSurface(0,x,y,8,0,0,0,0);
+ if(rgba_surface != NULL)
+ SDL_FreeSurface(rgba_surface);
+ rgba_surface = SDL_CreateRGBSurface(0,x,y,32,0,0,0,0);
+ //if(texture != NULL)
+ //SDL_FreeTexture(texture);
+ texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, x, y);
+ SDL_RenderSetLogicalSize(renderer, x, y);
+ screenrect.w = x;
+ screenrect.h = y;
+}
+
/*
====================
=
@@ -121,19 +139,10 @@
}
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
-
- sdl_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
- SDL_TEXTUREACCESS_STREAMING, iGLOBAL_SCREENWIDTH,
- iGLOBAL_SCREENHEIGHT);
-
- sdl_surface = SDL_CreateRGBSurface(0,iGLOBAL_SCREENWIDTH,iGLOBAL_SCREENHEIGHT,8,0,0,0,0);
- rgba_surface = SDL_CreateRGBSurface(0,iGLOBAL_SCREENWIDTH,iGLOBAL_SCREENHEIGHT,32,0,0,0,0);
- texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT);
-
SDL_SetSurfaceRLE(sdl_surface, 1);
- SDL_RenderSetLogicalSize(renderer, iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT);
+ resetscreen(iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT);
}
@@ -294,7 +303,10 @@
void RenderSurface(void)
{
- SDL_BlitSurface(sdl_surface, NULL, rgba_surface, NULL);
+ if(screenrect.w == iGLOBAL_SCREENWIDTH && screenrect.h == iGLOBAL_SCREENHEIGHT)
+ SDL_BlitSurface(sdl_surface, &screenrect, rgba_surface, NULL);
+ else
+ SDL_SoftStretch(sdl_surface, &screenrect, rgba_surface, NULL);
SDL_UpdateTexture(texture, NULL, rgba_surface->pixels, rgba_surface->pitch);
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, NULL);
@@ -370,10 +382,26 @@
void EnableScreenStretch(void)
{
+
+ if (iGLOBAL_SCREENWIDTH <= 320 || StretchScreen) return;
+ StretchScreen = 1;
+ screenrect.x = 0;
+ screenrect.y = 0;
+ screenrect.w = 320;
+ screenrect.h = 200;
+ return;
+
+
/*
- if (iGLOBAL_SCREENWIDTH <= 320 || StretchScreen) return;
+ displayofs = sdl_surface->pixels;
+ bufferofs = sdl_surface->pixels;
+ page1start = sdl_surface->pixels;
+ page2start = sdl_surface->pixels;
+ page3start = sdl_surface->pixels;
+ StretchScreen = 1;
+
if (unstretch_sdl_surface == NULL)
{
unstretch_sdl_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
@@ -394,14 +422,12 @@
{
if (iGLOBAL_SCREENWIDTH <= 320 || !StretchScreen) return;
- displayofs = sdl_surface->pixels +
- (displayofs - (byte *)unstretch_sdl_surface->pixels);
- bufferofs = sdl_surface->pixels;
- page1start = sdl_surface->pixels;
- page2start = sdl_surface->pixels;
- page3start = sdl_surface->pixels;
StretchScreen = 0;
- SDL_RenderSetLogicalSize(renderer, iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT);
+ screenrect.x = 0;
+ screenrect.y = 0;
+ screenrect.w = iGLOBAL_SCREENWIDTH;
+ screenrect.h = iGLOBAL_SCREENHEIGHT;
+ //SDL_RenderSetLogicalSize(renderer, iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT);
//SDL_RenderSetLogicalSize(renderer, 320, 200);
}