sdlWindow.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. /// @}
  70. void _processSDLEvent(SDL_Event &evt);
  71. void _triggerMouseLocationNotify(const SDL_Event& evt);
  72. void _triggerMouseButtonNotify(const SDL_Event& event);
  73. void _triggerMouseWheelNotify(const SDL_Event& event);
  74. void _triggerKeyNotify(const SDL_Event& event);
  75. void _triggerTextNotify(const SDL_Event& event);
  76. public:
  77. PlatformWindowSDL();
  78. ~PlatformWindowSDL();
  79. virtual void* getSystemWindow(const WindowSystem system);
  80. void* &getMenuHandle()
  81. {
  82. return mMenuHandle;
  83. }
  84. void setMenuHandle( void* menuHandle )
  85. {
  86. mMenuHandle = menuHandle;
  87. }
  88. virtual GFXDevice *getGFXDevice();
  89. virtual GFXWindowTarget *getGFXTarget();
  90. virtual void setVideoMode(const GFXVideoMode &mode);
  91. virtual const GFXVideoMode &getVideoMode();
  92. virtual bool clearFullscreen();
  93. virtual bool isFullscreen();
  94. virtual void _setFullscreen(const bool fullscreen);
  95. virtual bool setCaption(const char *cap);
  96. virtual const char *getCaption();
  97. // Window Client Area Extent
  98. virtual void setClientExtent( const Point2I newExtent );
  99. virtual const Point2I getClientExtent();
  100. // Window Bounds
  101. virtual void setBounds(const RectI &newBounds);
  102. virtual const RectI getBounds() const;
  103. // Window Position
  104. virtual void setPosition( const Point2I newPosition );
  105. virtual const Point2I getPosition();
  106. virtual void centerWindow();
  107. virtual bool setSize(const Point2I &newSize);
  108. // Coordinate space conversion.
  109. virtual Point2I clientToScreen( const Point2I& pos );
  110. virtual Point2I screenToClient( const Point2I& pos );
  111. virtual bool isOpen();
  112. virtual bool isVisible();
  113. virtual bool isFocused();
  114. virtual bool isMinimized();
  115. virtual bool isMaximized();
  116. virtual void minimize();
  117. virtual void maximize();
  118. virtual void hide();
  119. virtual void show();
  120. virtual void close();
  121. virtual void restore();
  122. virtual void setFocus();
  123. virtual void setMouseLocked(bool enable);
  124. virtual bool isMouseLocked() const { return mMouseLocked; };
  125. virtual bool shouldLockMouse() const { return mShouldLockMouse; };
  126. /// Set if relevant keypress events should be translated into character input events.
  127. virtual void setKeyboardTranslation(const bool enabled);
  128. virtual WindowId getWindowId();
  129. SDL_Window* getSDLWindow() const { return mWindowHandle; }
  130. virtual PlatformWindow * getNextWindow() const
  131. {
  132. return mNextWindow;
  133. }
  134. /// Provide a simple GDI-based render for when the game is not rendering.
  135. virtual void defaultRender();
  136. /// Return the class name for the windows we create with this class.
  137. static const UTF16 *getWindowClassName();
  138. /// Return the class name for the curtain window class.
  139. static const UTF16 *getCurtainWindowClassName();
  140. /// Return the platform specific object needed to create or attach an
  141. /// accelerated graohics drawing context on or to the window
  142. virtual void* getPlatformDrawable() const { return mWindowHandle; }
  143. };
  144. #endif