WindowHandler.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. enum class EWindowMode
  17. {
  18. // game runs in a window that covers part of the screen
  19. WINDOWED,
  20. // game runs in a 'window' that always covers entire screen and uses unmodified desktop resolution
  21. // The only mode that is available on mobile devices
  22. FULLSCREEN_WINDOWED,
  23. // game runs in a fullscreen mode with resolution selected by player
  24. FULLSCREEN_TRUE
  25. };
  26. /// This class is responsible for management of game window and its main rendering surface
  27. class WindowHandler
  28. {
  29. /// Dimensions of target surfaces/textures, this value is what game logic views as screen size
  30. Point getPreferredLogicalResolution() const;
  31. /// Dimensions of output window, if different from logicalResolution SDL will perform scaling
  32. /// This value is what player views as window size
  33. Point getPreferredRenderingResolution() const;
  34. EWindowMode getPreferredWindowMode() const;
  35. /// Returns index of display on which window should be created
  36. int getPreferredDisplayIndex() const;
  37. /// Returns index of rendering driver preferred by player or -1 if no preference
  38. int getPreferredRenderingDriver() const;
  39. /// Creates SDL window with specified parameters
  40. SDL_Window * createWindowImpl(Point dimensions, int flags, bool center);
  41. /// Creates SDL window using OS-specific settings & user-specific config
  42. SDL_Window * createWindow();
  43. void initializeRenderer();
  44. void initializeScreen();
  45. void updateFullscreenState();
  46. bool recreateWindow();
  47. void destroyScreen();
  48. void destroyWindow();
  49. void validateSettings();
  50. public:
  51. /// Creates and initializes screen, window and SDL state
  52. WindowHandler();
  53. /// Updates and potentially recreates target screen to match selected fullscreen status
  54. void onFullscreenChanged();
  55. /// De-initializes and destroys screen, window and SDL state
  56. void close();
  57. /// Fills screen with black color, erasing any existing content
  58. void clearScreen();
  59. };