sdlWindowMgr.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. #include "core/volume.h"
  29. struct SDL_Window;
  30. class FileDialog; // TODO SDL REMOVE
  31. /// SDL2 implementation of the window manager interface.
  32. class PlatformWindowManagerSDL : public PlatformWindowManager
  33. {
  34. public:
  35. /// An enum that holds an event loop frame of the state of the
  36. /// keyboard for how the keyboard is interpreted inside of Torque.
  37. ///
  38. /// SDL has a concept of text editing events as well as raw input
  39. /// events. Because of this, SDL needs notified whenever it needs
  40. /// to fire text based events. SDL will continue firing raw input
  41. /// events as well during this time.
  42. ///
  43. /// The reason why this was created is because we needed time to
  44. /// transition between raw input to raw input + text based events.
  45. /// If we take a raw input and notify SDL we wanted text during the
  46. /// event loop, SDL will issue a text input event as well. This was
  47. /// causing issues with the console, where the console key would be
  48. /// appended to the console buffer upon opening it. We fix this by
  49. /// delaying the notification to SDL until the event loop is complete.
  50. enum class KeyboardInputState
  51. {
  52. NONE = 0, /// < No state change during this event loop cycle.
  53. TEXT_INPUT = 1, /// < We want to change to text based events & raw input.
  54. RAW_INPUT = 2 /// < We only want raw input.
  55. };
  56. #ifdef TORQUE_SECURE_VFS
  57. struct DragAndDropFSInfo
  58. {
  59. String mRootName;
  60. Torque::FS::FileSystemRef mDragAndDropFS;
  61. DragAndDropFSInfo();
  62. DragAndDropFSInfo(String rootName, Torque::FS::FileSystemRef fileSystem);
  63. ~DragAndDropFSInfo();
  64. };
  65. #endif
  66. protected:
  67. friend class PlatformWindowSDL;
  68. friend class FileDialog; // TODO SDL REMOVE
  69. virtual void _processCmdLineArgs(const S32 argc, const char **argv);
  70. /// Link the specified window into the window list.
  71. void linkWindow(PlatformWindowSDL *w);
  72. /// Remove specified window from the window list.
  73. void unlinkWindow(PlatformWindowSDL *w);
  74. /// Callback for the process list.
  75. void _process();
  76. /// List of allocated windows.
  77. PlatformWindowSDL *mWindowListHead;
  78. /// Parent window, used in window setup in web plugin scenarios.
  79. SDL_Window *mParentWindow;
  80. /// This is set as part of the canvas being shown, and flags that the windows should render as normal from now on.
  81. // Basically a flag that lets the window manager know that we've handled the splash screen, and to operate as normal.
  82. bool mDisplayWindow;
  83. /// set via command line -offscreen option, controls whether rendering/input
  84. // is intended for offscreen rendering
  85. bool mOffscreenRender;
  86. /// If a curtain window is present, then will be stored here.
  87. SDL_Window *mCurtainWindow;
  88. Map<U32, PlatformWindowSDL*> mWindowMap;
  89. SignalSlot<void()> mOnProcessSignalSlot;
  90. /// The input state that will change whenever SDL needs notified.
  91. /// After it is handled, it will return to state NONE.
  92. KeyboardInputState mInputState;
  93. #ifdef TORQUE_SECURE_VFS
  94. /// Used to check if a root is already used when generating root names.
  95. HashMap<String, DragAndDropFSInfo> mActiveDragAndDropByRoot;
  96. /// Used to keep track of what mounts are handling a given path.
  97. HashMap<Torque::Path, DragAndDropFSInfo> mActiveDragAndDropFSByPath;
  98. #endif
  99. public:
  100. PlatformWindowManagerSDL();
  101. ~PlatformWindowManagerSDL();
  102. virtual RectI getPrimaryDesktopArea();
  103. virtual S32 getDesktopBitDepth();
  104. virtual Point2I getDesktopResolution();
  105. virtual S32 findFirstMatchingMonitor(const char* name);
  106. virtual U32 getMonitorCount();
  107. virtual const char* getMonitorName(U32 index);
  108. virtual RectI getMonitorRect(U32 index);
  109. virtual RectI getMonitorUsableRect(U32 index);
  110. virtual U32 getMonitorModeCount(U32 monitorIndex);
  111. virtual const String getMonitorMode(U32 monitorIndex, U32 modeIndex);
  112. virtual const String getMonitorDesktopMode(U32 monitorIndex);
  113. virtual void getMonitorRegions(Vector<RectI> &regions);
  114. virtual PlatformWindow *createWindow(GFXDevice *device, const GFXVideoMode &mode);
  115. virtual void getWindows(VectorPtr<PlatformWindow*> &windows);
  116. virtual void setParentWindow(void* newParent);
  117. virtual void* getParentWindow();
  118. virtual PlatformWindow *getWindowById(WindowId id);
  119. virtual PlatformWindow *getFirstWindow();
  120. virtual PlatformWindow* getFocusedWindow();
  121. virtual void lowerCurtain();
  122. virtual void raiseCurtain();
  123. virtual void setDisplayWindow(bool set) { mDisplayWindow = set; }
  124. /// Stores the input state so that the event loop will fire a check if we need
  125. /// to change how keyboard input is being handled.
  126. /// @param state The state of the keyboard input, either being raw input or text
  127. /// based input.
  128. void updateSDLTextInputState(KeyboardInputState state);
  129. };
  130. #endif