1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 09:39:43 +01:00

Implement scaling modes manually

For future PRs, it'll be very nice to have full control over how VVVVVV
gets drawn to the window. This means we can use the entire window size
for things like touch input, drawing borders, or anything we want.
This commit is contained in:
AllyTally 2024-01-28 20:04:02 -04:00 committed by Misa Elizabeth Kai
parent 935db27d39
commit 77a571017d
5 changed files with 67 additions and 51 deletions

View file

@ -3458,9 +3458,12 @@ void Graphics::screenshake(void)
set_render_target(NULL);
set_blendmode(SDL_BLENDMODE_NONE);
clear();
draw_window_background();
copy_texture(tempShakeTexture, NULL, NULL, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE);
SDL_Rect rect;
get_stretch_info(&rect);
copy_texture(tempShakeTexture, NULL, &rect, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE);
}
void Graphics::updatescreenshake(void)
@ -3469,6 +3472,54 @@ void Graphics::updatescreenshake(void)
screenshake_y = static_cast<Sint32>((fRandom() * 7) - 4);
}
void Graphics::draw_window_background(void)
{
clear();
}
void Graphics::get_stretch_info(SDL_Rect* rect)
{
int width;
int height;
gameScreen.GetScreenSize(&width, &height);
switch (gameScreen.scalingMode)
{
case SCALING_INTEGER:
{
int scale = SDL_min(width / SCREEN_WIDTH_PIXELS, height / SCREEN_HEIGHT_PIXELS);
rect->x = (width - SCREEN_WIDTH_PIXELS * scale) / 2;
rect->y = (height - SCREEN_HEIGHT_PIXELS * scale) / 2;
rect->w = SCREEN_WIDTH_PIXELS * scale;
rect->h = SCREEN_HEIGHT_PIXELS * scale;
}
break;
case SCALING_LETTERBOX:
if (width * SCREEN_HEIGHT_PIXELS > height * SCREEN_WIDTH_PIXELS)
{
rect->x = (width - height * SCREEN_WIDTH_PIXELS / SCREEN_HEIGHT_PIXELS) / 2;
rect->y = 0;
rect->w = height * SCREEN_WIDTH_PIXELS / SCREEN_HEIGHT_PIXELS;
rect->h = height;
}
else
{
rect->x = 0;
rect->y = (height - width * SCREEN_HEIGHT_PIXELS / SCREEN_WIDTH_PIXELS) / 2;
rect->w = width;
rect->h = width * SCREEN_HEIGHT_PIXELS / SCREEN_WIDTH_PIXELS;
}
break;
case SCALING_STRETCH:
/* Could pass NULL to copy_texture instead, but this feels better */
rect->x = 0;
rect->y = 0;
rect->w = width;
rect->h = height;
break;
}
}
void Graphics::render(void)
{
draw_screenshot_border();
@ -3480,9 +3531,13 @@ void Graphics::render(void)
set_render_target(NULL);
set_blendmode(SDL_BLENDMODE_NONE);
clear();
copy_texture(gameTexture, NULL, NULL, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE);
draw_window_background();
SDL_Rect rect;
get_stretch_info(&rect);
copy_texture(gameTexture, NULL, &rect, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE);
}
void Graphics::renderwithscreeneffects(void)

View file

@ -258,6 +258,10 @@ public:
int screenshake_x;
int screenshake_y;
void draw_window_background(void);
void get_stretch_info(SDL_Rect* rect);
void render(void);
void renderwithscreeneffects(void);
void renderfixedpre(void);

View file

@ -548,21 +548,11 @@ void KeyPoll::Poll(void)
toggleFullscreen();
}
if (gameScreen.scalingMode == SCALING_STRETCH)
{
/* In this mode specifically, we have to fix the mouse coordinates */
int actualscreenwidth;
int actualscreenheight;
gameScreen.GetScreenSize(&actualscreenwidth, &actualscreenheight);
SDL_Rect rect;
graphics.get_stretch_info(&rect);
mousex = raw_mousex * SCREEN_WIDTH_PIXELS / actualscreenwidth;
mousey = raw_mousey * SCREEN_HEIGHT_PIXELS / actualscreenheight;
}
else
{
mousex = raw_mousex;
mousey = raw_mousey;
}
mousex = (raw_mousex - rect.x) * SCREEN_WIDTH_PIXELS / rect.w;
mousey = (raw_mousey - rect.y) * SCREEN_HEIGHT_PIXELS / rect.h;
active_input_device_changed = keyboard_was_active != BUTTONGLYPHS_keyboard_is_active();
should_recompute_textboxes |= active_input_device_changed;

View file

@ -247,39 +247,8 @@ void Screen::GetScreenSize(int* x, int* y)
}
}
void Screen::UpdateScaling(void)
{
int width;
int height;
if (scalingMode == SCALING_STRETCH)
{
GetScreenSize(&width, &height);
}
else
{
width = SCREEN_WIDTH_PIXELS;
height = SCREEN_HEIGHT_PIXELS;
}
int result = SDL_RenderSetLogicalSize(m_renderer, width, height);
if (result != 0)
{
vlog_error("Error: could not set logical size: %s", SDL_GetError());
return;
}
result = SDL_RenderSetIntegerScale(m_renderer, (SDL_bool) (scalingMode == SCALING_INTEGER));
if (result != 0)
{
vlog_error("Error: could not set scale: %s", SDL_GetError());
}
}
void Screen::RenderPresent(void)
{
/* In certain cases, the window size might mismatch with the logical size.
* So it's better to just always call this. */
UpdateScaling();
SDL_RenderPresent(m_renderer);
graphics.clear();
}
@ -299,7 +268,6 @@ void Screen::toggleFullScreen(void)
void Screen::toggleScalingMode(void)
{
scalingMode = (scalingMode + 1) % NUM_SCALING_MODES;
UpdateScaling();
}
void Screen::toggleLinearFilter(void)

View file

@ -19,7 +19,6 @@ public:
void ResizeToNearestMultiple(void);
void GetScreenSize(int* x, int* y);
void UpdateScaling(void);
void RenderPresent(void);
void toggleFullScreen(void);