ScreenHandler.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * ScreenHandler.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. struct SDL_Texture;
  12. struct SDL_Window;
  13. struct SDL_Renderer;
  14. struct SDL_Surface;
  15. #include "../../lib/Point.h"
  16. #include "../render/IScreenHandler.h"
  17. enum class EWindowMode
  18. {
  19. // game runs in a window that covers part of the screen
  20. WINDOWED,
  21. // game runs in a 'window' that always covers entire screen and uses unmodified desktop resolution
  22. // The only mode that is available on mobile devices
  23. FULLSCREEN_BORDERLESS_WINDOWED,
  24. // game runs in a fullscreen mode with resolution selected by player
  25. FULLSCREEN_EXCLUSIVE
  26. };
  27. /// This class is responsible for management of game window and its main rendering surface
  28. class ScreenHandler final : public IScreenHandler
  29. {
  30. /// Dimensions of target surfaces/textures, this value is what game logic views as screen size
  31. Point getPreferredLogicalResolution() const;
  32. /// Dimensions of output window, if different from logicalResolution SDL will perform scaling
  33. /// This value is what player views as window size
  34. Point getPreferredWindowResolution() const;
  35. EWindowMode getPreferredWindowMode() const;
  36. /// Returns index of display on which window should be created
  37. int getPreferredDisplayIndex() const;
  38. /// Returns index of rendering driver preferred by player or -1 if no preference
  39. int getPreferredRenderingDriver() const;
  40. /// Creates SDL window with specified parameters
  41. SDL_Window * createWindowImpl(Point dimensions, int flags, bool center);
  42. /// Creates SDL window using OS-specific settings & user-specific config
  43. SDL_Window * createWindow();
  44. /// Manages window and SDL renderer
  45. void initializeWindow();
  46. void destroyWindow();
  47. /// Manages surfaces & textures used for
  48. void initializeScreenBuffers();
  49. void destroyScreenBuffers();
  50. /// Updates state (e.g. position) of game window after resolution/fullscreen change
  51. void updateWindowState();
  52. /// Initializes or reiniitalizes all screen state
  53. void recreateWindowAndScreenBuffers();
  54. /// Performs validation of settings and updates them to valid values if necessary
  55. void validateSettings();
  56. public:
  57. /// Creates and initializes screen, window and SDL state
  58. ScreenHandler();
  59. /// Updates and potentially recreates target screen to match selected fullscreen status
  60. void onScreenResize() final;
  61. /// De-initializes and destroys screen, window and SDL state
  62. void close() final;
  63. /// Fills screen with black color, erasing any existing content
  64. void clearScreen() final;
  65. /// Dimensions of render output, usually same as window size except for high-DPI screens on macOS / iOS
  66. Point getRenderResolution() const final;
  67. std::vector<Point> getSupportedResolutions() const final;
  68. std::vector<Point> getSupportedResolutions(int displayIndex) const;
  69. std::tuple<int, int> getSupportedScalingRange() const final;
  70. Rect convertLogicalPointsToWindow(const Rect & input) const final;
  71. };