2
0

WindowHandler.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * WindowHandler.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/IWindowHandler.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_WINDOWED,
  24. // game runs in a fullscreen mode with resolution selected by player
  25. FULLSCREEN_TRUE
  26. };
  27. /// This class is responsible for management of game window and its main rendering surface
  28. class WindowHandler : public IWindowHandler
  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 getPreferredRenderingResolution() 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. void initializeRenderer();
  45. void initializeScreen();
  46. void updateFullscreenState();
  47. bool recreateWindow();
  48. void destroyScreen();
  49. void destroyWindow();
  50. void validateSettings();
  51. public:
  52. /// Creates and initializes screen, window and SDL state
  53. WindowHandler();
  54. /// Updates and potentially recreates target screen to match selected fullscreen status
  55. void onScreenResize() final;
  56. /// De-initializes and destroys screen, window and SDL state
  57. void close() final;
  58. /// Fills screen with black color, erasing any existing content
  59. void clearScreen() final;
  60. std::vector<Point> getSupportedResolutions() const final;
  61. std::vector<Point> getSupportedResolutions(int displayIndex) const;
  62. std::tuple<double, double> getSupportedScalingRange() const final;
  63. };