132 lines
2.3 KiB
C++
132 lines
2.3 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;
|
|
#ifndef __EMSCRIPTEN__
|
|
screen_mode = isFullscreen;
|
|
if (isFullscreen)
|
|
{
|
|
enableFullscreen();
|
|
result = 1;
|
|
}
|
|
else
|
|
{
|
|
disableFullscreen();
|
|
result = 1;
|
|
}
|
|
#endif
|
|
return result;
|
|
}
|
|
|
|
int fullscrn::enableFullscreen()
|
|
{
|
|
if (!display_changed)
|
|
{
|
|
SDL_SetWindowFullscreen(winmain::MainWindow, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
|
display_changed = 1;
|
|
if (display_changed)
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int fullscrn::disableFullscreen()
|
|
{
|
|
if (display_changed)
|
|
{
|
|
SDL_SetWindowFullscreen(winmain::MainWindow, 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);
|
|
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,
|
|
width - OffsetX * 2, height - OffsetY * 2
|
|
};
|
|
}
|