Browse Source

Stop using SDL's fullscreen mode and just use a borderless window

master
C. J. Howard 5 years ago
parent
commit
d2c379feea
Signed by: cjhoward GPG Key ID: 03E1FABA9C3EC195
2 changed files with 26 additions and 6 deletions
  1. +24
    -4
      src/game.cpp
  2. +2
    -2
      src/states/sandbox-state.cpp

+ 24
- 4
src/game.cpp View File

@ -372,7 +372,7 @@ void Game::toggleFullscreen()
if (!toggleFullscreenDisabled) if (!toggleFullscreenDisabled)
{ {
fullscreen = !(*fullscreen); fullscreen = !(*fullscreen);
window->setFullscreen(*fullscreen);
//window->setFullscreen(*fullscreen);
if (!(*fullscreen)) if (!(*fullscreen))
{ {
@ -383,8 +383,25 @@ void Game::toggleFullscreen()
w = (*windowResolution)[0]; w = (*windowResolution)[0];
h = (*windowResolution)[1]; h = (*windowResolution)[1];
window->setBordered(true);
window->setResizable(true);
window->setDimensions(w, h); window->setDimensions(w, h);
window->setPosition((*windowPosition)[0], (*windowPosition)[1]); window->setPosition((*windowPosition)[0], (*windowPosition)[1]);
}
else
{
const Display* display = deviceManager->getDisplays()->front();
int displayWidth = std::get<0>(display->getDimensions());
int displayHeight = std::get<1>(display->getDimensions());
w = displayWidth;
h = displayHeight;
window->setBordered(false);
window->setResizable(false);
window->setPosition(0, 0);
window->setDimensions(w, h);
} }
restringUI(); restringUI();
@ -864,15 +881,17 @@ void Game::setupWindow()
const Display* display = deviceManager->getDisplays()->front(); const Display* display = deviceManager->getDisplays()->front();
int displayWidth = std::get<0>(display->getDimensions()); int displayWidth = std::get<0>(display->getDimensions());
int displayHeight = std::get<1>(display->getDimensions()); int displayHeight = std::get<1>(display->getDimensions());
int flags = 0;
int x; int x;
int y; int y;
if (*fullscreen) if (*fullscreen)
{ {
w = (*fullscreenResolution)[0];
h = (*fullscreenResolution)[1];
w = displayWidth;
h = displayHeight;
x = std::get<0>(display->getPosition()); x = std::get<0>(display->getPosition());
y = std::get<1>(display->getPosition()); y = std::get<1>(display->getPosition());
flags |= WindowFlag::BORDERLESS;
} }
else else
{ {
@ -880,13 +899,14 @@ void Game::setupWindow()
h = (*windowResolution)[1]; h = (*windowResolution)[1];
x = (*windowPosition)[0]; x = (*windowPosition)[0];
y = (*windowPosition)[1]; y = (*windowPosition)[1];
flags |= WindowFlag::RESIZABLE;
} }
// Read title string // Read title string
std::string title = getString("title"); std::string title = getString("title");
// Create window // Create window
window = windowManager->createWindow(title.c_str(), x, y, w, h, *fullscreen, WindowFlag::RESIZABLE);
window = windowManager->createWindow(title.c_str(), x, y, w, h, false, flags);
if (!window) if (!window)
{ {
throw std::runtime_error("Game::Game(): Failed to create window."); throw std::runtime_error("Game::Game(): Failed to create window.");

+ 2
- 2
src/states/sandbox-state.cpp View File

@ -323,8 +323,8 @@ void SandboxState::handleEvent(const MouseMovedEvent& event)
{ {
Vector2 selectorDirection = selectorVector / std::sqrt(lengthSquared); Vector2 selectorDirection = selectorVector / std::sqrt(lengthSquared);
float angle = std::atan2(-selectorDirection.y, selectorDirection.x) + twoPi<float>;
float sectorAngle = twoPi<float> / 8.0f;
float angle = std::atan2(-selectorDirection.y, selectorDirection.x) + two_pi<float>;
float sectorAngle = two_pi<float> / 8.0f;
int sector = static_cast<int>((angle + sectorAngle * 0.5f) / sectorAngle); int sector = static_cast<int>((angle + sectorAngle * 0.5f) / sectorAngle);
game->radialMenuSelectorImage->setRotation(static_cast<float>(sector) * sectorAngle); game->radialMenuSelectorImage->setRotation(static_cast<float>(sector) * sectorAngle);
game->radialMenuImage->setRotation(static_cast<float>(sector) * sectorAngle); game->radialMenuImage->setRotation(static_cast<float>(sector) * sectorAngle);

Loading…
Cancel
Save