2023-04-30 00:03:50 +02:00
|
|
|
/*
|
2023-05-08 12:22:01 +02:00
|
|
|
* ScreenHandler.h, part of VCMI engine
|
2023-04-30 00:03:50 +02:00
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
struct SDL_Texture;
|
|
|
|
struct SDL_Window;
|
|
|
|
struct SDL_Renderer;
|
|
|
|
struct SDL_Surface;
|
|
|
|
|
|
|
|
#include "../../lib/Point.h"
|
2023-05-08 12:22:01 +02:00
|
|
|
#include "../render/IScreenHandler.h"
|
2023-04-30 00:03:50 +02:00
|
|
|
|
|
|
|
enum class EWindowMode
|
|
|
|
{
|
|
|
|
// game runs in a window that covers part of the screen
|
|
|
|
WINDOWED,
|
|
|
|
// game runs in a 'window' that always covers entire screen and uses unmodified desktop resolution
|
|
|
|
// The only mode that is available on mobile devices
|
2023-05-08 12:22:01 +02:00
|
|
|
FULLSCREEN_BORDERLESS_WINDOWED,
|
2023-04-30 00:03:50 +02:00
|
|
|
// game runs in a fullscreen mode with resolution selected by player
|
2023-05-08 12:22:01 +02:00
|
|
|
FULLSCREEN_EXCLUSIVE
|
2023-04-30 00:03:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// This class is responsible for management of game window and its main rendering surface
|
2023-07-05 16:17:43 +02:00
|
|
|
class ScreenHandler final : public IScreenHandler
|
2023-04-30 00:03:50 +02:00
|
|
|
{
|
|
|
|
/// Dimensions of target surfaces/textures, this value is what game logic views as screen size
|
|
|
|
Point getPreferredLogicalResolution() const;
|
|
|
|
|
|
|
|
/// Dimensions of output window, if different from logicalResolution SDL will perform scaling
|
|
|
|
/// This value is what player views as window size
|
2023-07-05 16:17:43 +02:00
|
|
|
Point getPreferredWindowResolution() const;
|
|
|
|
|
2023-04-30 00:03:50 +02:00
|
|
|
EWindowMode getPreferredWindowMode() const;
|
|
|
|
|
|
|
|
/// Returns index of display on which window should be created
|
|
|
|
int getPreferredDisplayIndex() const;
|
|
|
|
|
|
|
|
/// Returns index of rendering driver preferred by player or -1 if no preference
|
|
|
|
int getPreferredRenderingDriver() const;
|
|
|
|
|
|
|
|
/// Creates SDL window with specified parameters
|
2023-04-30 00:38:28 +02:00
|
|
|
SDL_Window * createWindowImpl(Point dimensions, int flags, bool center);
|
2023-04-30 00:03:50 +02:00
|
|
|
|
|
|
|
/// Creates SDL window using OS-specific settings & user-specific config
|
|
|
|
SDL_Window * createWindow();
|
|
|
|
|
2023-05-08 12:22:01 +02:00
|
|
|
/// Manages window and SDL renderer
|
|
|
|
void initializeWindow();
|
2023-04-30 00:03:50 +02:00
|
|
|
void destroyWindow();
|
|
|
|
|
2023-05-08 12:22:01 +02:00
|
|
|
/// Manages surfaces & textures used for
|
|
|
|
void initializeScreenBuffers();
|
|
|
|
void destroyScreenBuffers();
|
|
|
|
|
|
|
|
/// Updates state (e.g. position) of game window after resolution/fullscreen change
|
|
|
|
void updateWindowState();
|
|
|
|
|
|
|
|
/// Initializes or reiniitalizes all screen state
|
|
|
|
void recreateWindowAndScreenBuffers();
|
|
|
|
|
|
|
|
/// Performs validation of settings and updates them to valid values if necessary
|
2023-04-30 00:03:50 +02:00
|
|
|
void validateSettings();
|
|
|
|
public:
|
|
|
|
|
|
|
|
/// Creates and initializes screen, window and SDL state
|
2023-05-08 12:22:01 +02:00
|
|
|
ScreenHandler();
|
2023-04-30 00:03:50 +02:00
|
|
|
|
|
|
|
/// Updates and potentially recreates target screen to match selected fullscreen status
|
2023-05-04 21:33:25 +02:00
|
|
|
void onScreenResize() final;
|
2023-04-30 00:03:50 +02:00
|
|
|
|
|
|
|
/// De-initializes and destroys screen, window and SDL state
|
2023-04-30 17:47:52 +02:00
|
|
|
void close() final;
|
2023-04-30 00:38:28 +02:00
|
|
|
|
|
|
|
/// Fills screen with black color, erasing any existing content
|
2023-04-30 17:47:52 +02:00
|
|
|
void clearScreen() final;
|
|
|
|
|
2023-07-13 19:11:08 +02:00
|
|
|
/// Dimensions of render output, usually same as window size except for high-DPI screens on macOS / iOS
|
|
|
|
Point getRenderResolution() const final;
|
|
|
|
|
2023-04-30 17:47:52 +02:00
|
|
|
std::vector<Point> getSupportedResolutions() const final;
|
|
|
|
std::vector<Point> getSupportedResolutions(int displayIndex) const;
|
2023-05-08 12:22:01 +02:00
|
|
|
std::tuple<int, int> getSupportedScalingRange() const final;
|
2023-07-05 16:17:01 +02:00
|
|
|
Rect convertLogicalPointsToWindow(const Rect & input) const final;
|
2023-04-30 00:03:50 +02:00
|
|
|
};
|