2
0

ScreenHandler.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. enum class EUpscalingFilter
  28. {
  29. AUTO, // used only for loading from config, replaced with autoselected value on init
  30. NONE,
  31. //BILINEAR, // TODO?
  32. //BICUBIC, // TODO?
  33. XBRZ_2,
  34. XBRZ_3,
  35. XBRZ_4,
  36. // NOTE: xbrz also provides x5 and x6 filters, but those would require high-end gaming PC's due to huge memory usage with no visible gain
  37. };
  38. /// This class is responsible for management of game window and its main rendering surface
  39. class ScreenHandler final : public IScreenHandler
  40. {
  41. EUpscalingFilter upscalingFilter = EUpscalingFilter::AUTO;
  42. /// Dimensions of target surfaces/textures, this value is what game logic views as screen size
  43. Point getPreferredLogicalResolution() const;
  44. /// Dimensions of output window, if different from logicalResolution SDL will perform scaling
  45. /// This value is what player views as window size
  46. Point getPreferredWindowResolution() const;
  47. EWindowMode getPreferredWindowMode() const;
  48. /// Returns index of display on which window should be created
  49. int getPreferredDisplayIndex() const;
  50. /// Returns index of rendering driver preferred by player or -1 if no preference
  51. int getPreferredRenderingDriver() const;
  52. /// Creates SDL window with specified parameters
  53. SDL_Window * createWindowImpl(Point dimensions, int flags, bool center);
  54. /// Creates SDL window using OS-specific settings & user-specific config
  55. SDL_Window * createWindow();
  56. /// Manages window and SDL renderer
  57. void initializeWindow();
  58. void destroyWindow();
  59. /// Manages surfaces & textures used for
  60. void initializeScreenBuffers();
  61. void destroyScreenBuffers();
  62. /// Updates state (e.g. position) of game window after resolution/fullscreen change
  63. void updateWindowState();
  64. /// Initializes or reiniitalizes all screen state
  65. void recreateWindowAndScreenBuffers();
  66. /// Performs validation of settings and updates them to valid values if necessary
  67. void validateSettings();
  68. EUpscalingFilter loadUpscalingFilter() const;
  69. void selectDownscalingFilter();
  70. void selectUpscalingFilter();
  71. public:
  72. /// Creates and initializes screen, window and SDL state
  73. ScreenHandler();
  74. /// Updates and potentially recreates target screen to match selected fullscreen status
  75. void onScreenResize() final;
  76. /// De-initializes and destroys screen, window and SDL state
  77. void close() final;
  78. /// Fills screen with black color, erasing any existing content
  79. void clearScreen() final;
  80. /// Dimensions of render output, usually same as window size except for high-DPI screens on macOS / iOS
  81. Point getRenderResolution() const final;
  82. /// Window has focus
  83. bool hasFocus() final;
  84. Point getLogicalResolution() const final;
  85. int getScalingFactor() const final;
  86. std::vector<Point> getSupportedResolutions() const final;
  87. std::vector<Point> getSupportedResolutions(int displayIndex) const;
  88. std::tuple<int, int> getSupportedScalingRange() const final;
  89. Rect convertLogicalPointsToWindow(const Rect & input) const final;
  90. };