sdlWindowMgr.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _WINDOWMANAGER_SDL_WINDOWMANAGER_
  23. #define _WINDOWMANAGER_SDL_WINDOWMANAGER_
  24. #include "math/mMath.h"
  25. #include "gfx/gfxStructs.h"
  26. #include "windowManager/sdl/sdlWindow.h"
  27. #include "core/util/tVector.h"
  28. struct SDL_Window;
  29. class FileDialog; // TODO SDL REMOVE
  30. /// SDL2 implementation of the window manager interface.
  31. class PlatformWindowManagerSDL : public PlatformWindowManager
  32. {
  33. public:
  34. /// An enum that holds an event loop frame of the state of the
  35. /// keyboard for how the keyboard is interpreted inside of Torque.
  36. ///
  37. /// SDL has a concept of text editing events as well as raw input
  38. /// events. Because of this, SDL needs notified whenever it needs
  39. /// to fire text based events. SDL will continue firing raw input
  40. /// events as well during this time.
  41. ///
  42. /// The reason why this was created is because we needed time to
  43. /// transition between raw input to raw input + text based events.
  44. /// If we take a raw input and notify SDL we wanted text during the
  45. /// event loop, SDL will issue a text input event as well. This was
  46. /// causing issues with the console, where the console key would be
  47. /// appended to the console buffer upon opening it. We fix this by
  48. /// delaying the notification to SDL until the event loop is complete.
  49. enum class KeyboardInputState
  50. {
  51. NONE = 0, /// < No state change during this event loop cycle.
  52. TEXT_INPUT = 1, /// < We want to change to text based events & raw input.
  53. RAW_INPUT = 2 /// < We only want raw input.
  54. };
  55. protected:
  56. friend class PlatformWindowSDL;
  57. friend class FileDialog; // TODO SDL REMOVE
  58. virtual void _processCmdLineArgs(const S32 argc, const char **argv);
  59. /// Link the specified window into the window list.
  60. void linkWindow(PlatformWindowSDL *w);
  61. /// Remove specified window from the window list.
  62. void unlinkWindow(PlatformWindowSDL *w);
  63. /// Callback for the process list.
  64. void _process();
  65. /// List of allocated windows.
  66. PlatformWindowSDL *mWindowListHead;
  67. /// Parent window, used in window setup in web plugin scenarios.
  68. SDL_Window *mParentWindow;
  69. /// This is set as part of the canvas being shown, and flags that the windows should render as normal from now on.
  70. // Basically a flag that lets the window manager know that we've handled the splash screen, and to operate as normal.
  71. bool mDisplayWindow;
  72. /// set via command line -offscreen option, controls whether rendering/input
  73. // is intended for offscreen rendering
  74. bool mOffscreenRender;
  75. /// If a curtain window is present, then will be stored here.
  76. SDL_Window *mCurtainWindow;
  77. Map<U32, PlatformWindowSDL*> mWindowMap;
  78. SignalSlot<void()> mOnProcessSignalSlot;
  79. /// The input state that will change whenever SDL needs notified.
  80. /// After it is handled, it will return to state NONE.
  81. KeyboardInputState mInputState;
  82. public:
  83. PlatformWindowManagerSDL();
  84. ~PlatformWindowManagerSDL();
  85. virtual RectI getPrimaryDesktopArea();
  86. virtual S32 getDesktopBitDepth();
  87. virtual Point2I getDesktopResolution();
  88. virtual S32 findFirstMatchingMonitor(const char* name);
  89. virtual U32 getMonitorCount();
  90. virtual const char* getMonitorName(U32 index);
  91. virtual RectI getMonitorRect(U32 index);
  92. virtual RectI getMonitorUsableRect(U32 index);
  93. virtual U32 getMonitorModeCount(U32 monitorIndex);
  94. virtual const String getMonitorMode(U32 monitorIndex, U32 modeIndex);
  95. virtual const String getMonitorDesktopMode(U32 monitorIndex);
  96. virtual void getMonitorRegions(Vector<RectI> &regions);
  97. virtual PlatformWindow *createWindow(GFXDevice *device, const GFXVideoMode &mode);
  98. virtual void getWindows(VectorPtr<PlatformWindow*> &windows);
  99. virtual void setParentWindow(void* newParent);
  100. virtual void* getParentWindow();
  101. virtual PlatformWindow *getWindowById(WindowId id);
  102. virtual PlatformWindow *getFirstWindow();
  103. virtual PlatformWindow* getFocusedWindow();
  104. virtual void lowerCurtain();
  105. virtual void raiseCurtain();
  106. virtual void setDisplayWindow(bool set) { mDisplayWindow = set; }
  107. /// Stores the input state so that the event loop will fire a check if we need
  108. /// to change how keyboard input is being handled.
  109. /// @param state The state of the keyboard input, either being raw input or text
  110. /// based input.
  111. void updateSDLTextInputState(KeyboardInputState state);
  112. };
  113. #endif