sdlWindow.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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_WINDOW_
  23. #define _WINDOWMANAGER_SDL_WINDOW_
  24. #include "windowManager/platformWindowMgr.h"
  25. #include "gfx/gfxTarget.h"
  26. #include "gfx/gfxStructs.h"
  27. #include "sim/actionMap.h"
  28. class PlatformWindowManagerSDL;
  29. struct SDL_Window;
  30. union SDL_Event;
  31. /// Implementation of a window on SDL.
  32. class PlatformWindowSDL : public PlatformWindow
  33. {
  34. friend class PlatformWindowManagerSDL;
  35. private:
  36. /// @name Active window list
  37. ///
  38. /// Items used to track window instances.
  39. ///
  40. /// @{
  41. /// Which manager created us?
  42. PlatformWindowManagerSDL *mOwningManager;
  43. /// Which window comes next in list?
  44. PlatformWindowSDL *mNextWindow;
  45. /// @}
  46. /// @name Window Information
  47. ///
  48. /// @{
  49. /// Our SDL window.
  50. SDL_Window *mWindowHandle;
  51. /// Our former Parent
  52. SDL_Window *mOldParent;
  53. /// The GFX device that we're tied to.
  54. GFXDevice *mDevice;
  55. /// Reference to the render target allocated on this window.
  56. GFXWindowTargetRef mTarget;
  57. /// Our current size/resolution/fullscreen status.
  58. GFXVideoMode mVideoMode;
  59. /// Our position on the desktop.
  60. Point2I mPosition;
  61. /// Is the mouse locked to this window?
  62. bool mMouseLocked;
  63. /// Determines whether this window should lock the mouse when it has an opportunity
  64. bool mShouldLockMouse;
  65. /// When set, we don't trigger device resets due to sizing events.
  66. bool mSuppressReset;
  67. /// Menu associated with this window. This is a passive property of the window and is not required to be used at all.
  68. void* mMenuHandle;
  69. /// Indicates if the window is being closed. This allows us to safely ignore other events like focus being gained or losed after cleanup has begun
  70. bool mClosing;
  71. /// @}
  72. void _processSDLEvent(SDL_Event &evt);
  73. void _triggerMouseLocationNotify(const SDL_Event& evt);
  74. void _triggerMouseButtonNotify(const SDL_Event& event);
  75. void _triggerMouseWheelNotify(const SDL_Event& event);
  76. void _triggerKeyNotify(const SDL_Event& event);
  77. void _triggerTextNotify(const SDL_Event& event);
  78. void _updateMonitorFromMove(const SDL_Event& event);
  79. public:
  80. PlatformWindowSDL();
  81. ~PlatformWindowSDL();
  82. void* getSystemWindow(const WindowSystem system) override;
  83. void* &getMenuHandle()
  84. {
  85. return mMenuHandle;
  86. }
  87. void setMenuHandle( void* menuHandle )
  88. {
  89. mMenuHandle = menuHandle;
  90. }
  91. GFXDevice *getGFXDevice() override;
  92. GFXWindowTarget *getGFXTarget() override;
  93. void _setVideoMode(const GFXVideoMode &mode) override;
  94. const GFXVideoMode &getVideoMode() override;
  95. bool clearFullscreen() override;
  96. bool isFullscreen() override;
  97. void _setFullscreen(const bool fullscreen) override;
  98. bool setCaption(const char *cap) override;
  99. const char *getCaption() override;
  100. // Window Client Area Extent
  101. void setClientExtent( const Point2I newExtent ) override;
  102. const Point2I getClientExtent() override;
  103. // Window Bounds
  104. void setBounds(const RectI &newBounds) override;
  105. const RectI getBounds() const override;
  106. // Window Position
  107. void setPosition( const Point2I newPosition ) override;
  108. const Point2I getPosition() override;
  109. void centerWindow() override;
  110. bool setSize(const Point2I &newSize) override;
  111. // Coordinate space conversion.
  112. Point2I clientToScreen( const Point2I& pos ) override;
  113. Point2I screenToClient( const Point2I& pos ) override;
  114. bool isOpen() override;
  115. bool isVisible() override;
  116. bool isFocused() override;
  117. bool isMinimized() override;
  118. bool isMaximized() override;
  119. void minimize() override;
  120. void maximize() override;
  121. void hide() override;
  122. void show() override;
  123. void close() override;
  124. void restore() override;
  125. void setFocus() override;
  126. void setMouseLocked(bool enable) override;
  127. bool isMouseLocked() const override { return mMouseLocked; };
  128. bool shouldLockMouse() const override { return mShouldLockMouse; };
  129. /// Set if relevant keypress events should be translated into character input events.
  130. void setKeyboardTranslation(const bool enabled) override;
  131. WindowId getWindowId() override;
  132. SDL_Window* getSDLWindow() const { return mWindowHandle; }
  133. PlatformWindow * getNextWindow() const override
  134. {
  135. return mNextWindow;
  136. }
  137. /// Provide a simple GDI-based render for when the game is not rendering.
  138. virtual void defaultRender();
  139. /// Return the class name for the windows we create with this class.
  140. static const UTF16 *getWindowClassName();
  141. /// Return the class name for the curtain window class.
  142. static const UTF16 *getCurtainWindowClassName();
  143. /// Return the platform specific object needed to create or attach an
  144. /// accelerated graohics drawing context on or to the window
  145. void* getPlatformDrawable() const override { return mWindowHandle; }
  146. };
  147. #endif