mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 17:49: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:
parent
935db27d39
commit
77a571017d
5 changed files with 67 additions and 51 deletions
|
@ -3458,9 +3458,12 @@ void Graphics::screenshake(void)
|
||||||
|
|
||||||
set_render_target(NULL);
|
set_render_target(NULL);
|
||||||
set_blendmode(SDL_BLENDMODE_NONE);
|
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)
|
void Graphics::updatescreenshake(void)
|
||||||
|
@ -3469,6 +3472,54 @@ void Graphics::updatescreenshake(void)
|
||||||
screenshake_y = static_cast<Sint32>((fRandom() * 7) - 4);
|
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)
|
void Graphics::render(void)
|
||||||
{
|
{
|
||||||
draw_screenshot_border();
|
draw_screenshot_border();
|
||||||
|
@ -3480,9 +3531,13 @@ void Graphics::render(void)
|
||||||
|
|
||||||
set_render_target(NULL);
|
set_render_target(NULL);
|
||||||
set_blendmode(SDL_BLENDMODE_NONE);
|
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)
|
void Graphics::renderwithscreeneffects(void)
|
||||||
|
|
|
@ -258,6 +258,10 @@ public:
|
||||||
int screenshake_x;
|
int screenshake_x;
|
||||||
int screenshake_y;
|
int screenshake_y;
|
||||||
|
|
||||||
|
void draw_window_background(void);
|
||||||
|
|
||||||
|
void get_stretch_info(SDL_Rect* rect);
|
||||||
|
|
||||||
void render(void);
|
void render(void);
|
||||||
void renderwithscreeneffects(void);
|
void renderwithscreeneffects(void);
|
||||||
void renderfixedpre(void);
|
void renderfixedpre(void);
|
||||||
|
|
|
@ -548,21 +548,11 @@ void KeyPoll::Poll(void)
|
||||||
toggleFullscreen();
|
toggleFullscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gameScreen.scalingMode == SCALING_STRETCH)
|
SDL_Rect rect;
|
||||||
{
|
graphics.get_stretch_info(&rect);
|
||||||
/* In this mode specifically, we have to fix the mouse coordinates */
|
|
||||||
int actualscreenwidth;
|
|
||||||
int actualscreenheight;
|
|
||||||
gameScreen.GetScreenSize(&actualscreenwidth, &actualscreenheight);
|
|
||||||
|
|
||||||
mousex = raw_mousex * SCREEN_WIDTH_PIXELS / actualscreenwidth;
|
mousex = (raw_mousex - rect.x) * SCREEN_WIDTH_PIXELS / rect.w;
|
||||||
mousey = raw_mousey * SCREEN_HEIGHT_PIXELS / actualscreenheight;
|
mousey = (raw_mousey - rect.y) * SCREEN_HEIGHT_PIXELS / rect.h;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mousex = raw_mousex;
|
|
||||||
mousey = raw_mousey;
|
|
||||||
}
|
|
||||||
|
|
||||||
active_input_device_changed = keyboard_was_active != BUTTONGLYPHS_keyboard_is_active();
|
active_input_device_changed = keyboard_was_active != BUTTONGLYPHS_keyboard_is_active();
|
||||||
should_recompute_textboxes |= active_input_device_changed;
|
should_recompute_textboxes |= active_input_device_changed;
|
||||||
|
|
|
@ -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)
|
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);
|
SDL_RenderPresent(m_renderer);
|
||||||
graphics.clear();
|
graphics.clear();
|
||||||
}
|
}
|
||||||
|
@ -299,7 +268,6 @@ void Screen::toggleFullScreen(void)
|
||||||
void Screen::toggleScalingMode(void)
|
void Screen::toggleScalingMode(void)
|
||||||
{
|
{
|
||||||
scalingMode = (scalingMode + 1) % NUM_SCALING_MODES;
|
scalingMode = (scalingMode + 1) % NUM_SCALING_MODES;
|
||||||
UpdateScaling();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::toggleLinearFilter(void)
|
void Screen::toggleLinearFilter(void)
|
||||||
|
|
|
@ -19,7 +19,6 @@ public:
|
||||||
void ResizeToNearestMultiple(void);
|
void ResizeToNearestMultiple(void);
|
||||||
void GetScreenSize(int* x, int* y);
|
void GetScreenSize(int* x, int* y);
|
||||||
|
|
||||||
void UpdateScaling(void);
|
|
||||||
void RenderPresent(void);
|
void RenderPresent(void);
|
||||||
|
|
||||||
void toggleFullScreen(void);
|
void toggleFullScreen(void);
|
||||||
|
|
Loading…
Reference in a new issue