sdlWindow.h 5.9 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. virtual void* getSystemWindow(const WindowSystem system);
  83. void* &getMenuHandle()
  84. {
  85. return mMenuHandle;
  86. }
  87. void setMenuHandle( void* menuHandle )
  88. {
  89. mMenuHandle = menuHandle;
  90. }
  91. virtual GFXDevice *getGFXDevice();
  92. virtual GFXWindowTarget *getGFXTarget();
  93. virtual void _setVideoMode(const GFXVideoMode &mode);
  94. virtual const GFXVideoMode &getVideoMode();
  95. virtual bool clearFullscreen();
  96. virtual bool isFullscreen();
  97. virtual void _setFullscreen(const bool fullscreen);
  98. virtual bool setCaption(const char *cap);
  99. virtual const char *getCaption();
  100. // Window Client Area Extent
  101. virtual void setClientExtent( const Point2I newExtent );
  102. virtual const Point2I getClientExtent();
  103. // Window Bounds
  104. virtual void setBounds(const RectI &newBounds);
  105. virtual const RectI getBounds() const;
  106. // Window Position
  107. virtual void setPosition( const Point2I newPosition );
  108. virtual const Point2I getPosition();
  109. virtual void centerWindow();
  110. virtual bool setSize(const Point2I &newSize);
  111. // Coordinate space conversion.
  112. virtual Point2I clientToScreen( const Point2I& pos );
  113. virtual Point2I screenToClient( const Point2I& pos );
  114. virtual bool isOpen();
  115. virtual bool isVisible();
  116. virtual bool isFocused();
  117. virtual bool isMinimized();
  118. virtual bool isMaximized();
  119. virtual void minimize();
  120. virtual void maximize();
  121. virtual void hide();
  122. virtual void show();
  123. virtual void close();
  124. virtual void restore();
  125. virtual void setFocus();
  126. virtual void setMouseLocked(bool enable);
  127. virtual bool isMouseLocked() const { return mMouseLocked; };
  128. virtual bool shouldLockMouse() const { return mShouldLockMouse; };
  129. /// Set if relevant keypress events should be translated into character input events.
  130. virtual void setKeyboardTranslation(const bool enabled);
  131. virtual WindowId getWindowId();
  132. SDL_Window* getSDLWindow() const { return mWindowHandle; }
  133. virtual PlatformWindow * getNextWindow() const
  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. virtual void* getPlatformDrawable() const { return mWindowHandle; }
  146. };
  147. #endif