1
0
Fork 0
mirror of https://github.com/k4zmu2a/SpaceCadetPinball.git synced 2024-06-26 07:42:10 +02:00
SpaceCadetPinball/SpaceCadetPinball/fullscrn.cpp
MaikelChan 5789492021
Adjusted screen coordinates so menu doesn't overlap (#66)
* Optimized final blit to the screen render target.

When bumping the table, instead of offseting the table pixels by CPU, just memcpy all the pixels to vScreenTex once, and then render two separate quads from that texture: one for the board and the other for the sidebar. Then change the coordinates of the board quad when bumping.

* Main menu bar doesn't cover game area

* Forgot to also take into account changing UI scale.
2021-10-24 18:38:23 +03:00

133 lines
2.4 KiB
C++

#include "pch.h"
#include "fullscrn.h"
#include "options.h"
#include "pb.h"
#include "render.h"
#include "winmain.h"
int fullscrn::screen_mode;
int fullscrn::display_changed;
int fullscrn::resolution = 0;
const resolution_info fullscrn::resolution_array[3] =
{
{640, 480, 600, 416, 501},
{800, 600, 752, 520, 502},
{1024, 768, 960, 666, 503},
};
float fullscrn::ScaleX = 1;
float fullscrn::ScaleY = 1;
int fullscrn::OffsetX = 0;
int fullscrn::OffsetY = 0;
void fullscrn::init()
{
window_size_changed();
}
void fullscrn::shutdown()
{
if (display_changed)
set_screen_mode(0);
}
int fullscrn::set_screen_mode(int isFullscreen)
{
int result = isFullscreen;
if (isFullscreen == screen_mode)
return result;
screen_mode = isFullscreen;
if (isFullscreen)
{
enableFullscreen();
result = 1;
}
else
{
disableFullscreen();
result = 1;
}
return result;
}
int fullscrn::enableFullscreen()
{
if (!display_changed)
{
if (SDL_SetWindowFullscreen(winmain::MainWindow, SDL_WINDOW_FULLSCREEN_DESKTOP) == 0)
{
display_changed = 1;
return 1;
}
}
return 0;
}
int fullscrn::disableFullscreen()
{
if (display_changed)
{
if (SDL_SetWindowFullscreen(winmain::MainWindow, 0) == 0)
display_changed = 0;
}
return 0;
}
void fullscrn::activate(int flag)
{
if (screen_mode)
{
if (!flag)
{
set_screen_mode(0);
}
}
}
int fullscrn::GetResolution()
{
return resolution;
}
void fullscrn::SetResolution(int value)
{
if (!pb::FullTiltMode)
value = 0;
assertm(value >= 0 && value <= 2, "Resolution value out of bounds");
resolution = value;
}
int fullscrn::GetMaxResolution()
{
return pb::FullTiltMode ? 2 : 0;
}
void fullscrn::window_size_changed()
{
int width, height;
SDL_GetRendererOutputSize(winmain::Renderer, &width, &height);
int menuHeight = options::Options.ShowMenu ? winmain::MainMenuHeight : 0;
height -= menuHeight;
auto res = &resolution_array[resolution];
ScaleX = static_cast<float>(width) / res->TableWidth;
ScaleY = static_cast<float>(height) / res->TableHeight;
OffsetX = OffsetY = 0;
if (options::Options.UniformScaling)
{
ScaleY = ScaleX = std::min(ScaleX, ScaleY);
OffsetX = static_cast<int>(floor((width - res->TableWidth * ScaleX) / 2));
OffsetY = static_cast<int>(floor((height - res->TableHeight * ScaleY) / 2));
}
render::DestinationRect = SDL_Rect
{
OffsetX, OffsetY + menuHeight,
width - OffsetX * 2, height - OffsetY * 2
};
}