sdlWindow.h

Engine/source/windowManager/sdl/sdlWindow.h

More...

Classes:

class

Implementation of a window on SDL.

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef  _WINDOWMANAGER_SDL_WINDOW_
 25#define  _WINDOWMANAGER_SDL_WINDOW_
 26
 27#include "windowManager/platformWindowMgr.h"
 28#include "gfx/gfxTarget.h"
 29#include "gfx/gfxStructs.h"
 30#include "sim/actionMap.h"
 31
 32class PlatformWindowManagerSDL;
 33struct SDL_Window;
 34union SDL_Event;
 35
 36/// Implementation of a window on SDL.
 37class PlatformWindowSDL : public PlatformWindow
 38{
 39   friend class PlatformWindowManagerSDL;
 40
 41private:
 42
 43   /// @name Active window list
 44   ///
 45   /// Items used to track window instances.
 46   ///
 47   /// @{
 48
 49   /// Which manager created us?
 50   PlatformWindowManagerSDL *mOwningManager;
 51
 52   /// Which window comes next in list?
 53   PlatformWindowSDL *mNextWindow;
 54   
 55   /// @}
 56
 57   /// @name Window Information
 58   ///
 59   /// @{
 60
 61   /// Our SDL window.
 62   SDL_Window *mWindowHandle;
 63
 64   /// Our former Parent
 65   SDL_Window *mOldParent;   
 66
 67   /// The GFX device that we're tied to.
 68   GFXDevice *mDevice;
 69
 70   /// Reference to the render target allocated on this window.
 71   GFXWindowTargetRef mTarget;
 72
 73   /// Our current size/resolution/fullscreen status.
 74   GFXVideoMode mVideoMode;
 75
 76   /// Our position on the desktop.
 77   Point2I mPosition;
 78
 79   /// Is the mouse locked to this window?
 80   bool mMouseLocked;
 81
 82   /// Determines whether this window should lock the mouse when it has an opportunity
 83   bool mShouldLockMouse;
 84
 85   /// When set, we don't trigger device resets due to sizing events.
 86   bool mSuppressReset;
 87
 88   /// Menu associated with this window.  This is a passive property of the window and is not required to be used at all.
 89   void* mMenuHandle;
 90
 91   /// 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
 92   bool mClosing;
 93
 94   /// @}
 95
 96   void _processSDLEvent(SDL_Event &evt);
 97   void _triggerMouseLocationNotify(const SDL_Event& evt);
 98   void _triggerMouseButtonNotify(const SDL_Event& event);
 99   void _triggerMouseWheelNotify(const SDL_Event& event);
100   void _triggerKeyNotify(const SDL_Event& event);
101   void _triggerTextNotify(const SDL_Event& event);
102   void _updateMonitorFromMove(const SDL_Event& event);
103
104public:
105   PlatformWindowSDL();
106   ~PlatformWindowSDL();
107
108   virtual void* getSystemWindow(const WindowSystem system);
109
110   void* &getMenuHandle()
111   {
112      return mMenuHandle;
113   }
114
115   void setMenuHandle( void* menuHandle ) 
116   {
117      mMenuHandle = menuHandle;
118   }   
119
120   virtual GFXDevice *getGFXDevice();
121   virtual GFXWindowTarget *getGFXTarget();
122   
123   virtual void _setVideoMode(const GFXVideoMode &mode);
124   virtual const GFXVideoMode &getVideoMode();
125   virtual bool clearFullscreen();
126   virtual bool isFullscreen();
127   virtual void _setFullscreen(const bool fullscreen);
128   
129   virtual bool setCaption(const char *cap);
130   virtual const char *getCaption();
131   
132   // Window Client Area Extent
133   virtual void setClientExtent( const Point2I newExtent );
134   virtual const Point2I getClientExtent();
135  
136   // Window Bounds
137   virtual void setBounds(const RectI &newBounds);
138   virtual const RectI getBounds() const;
139
140   // Window Position
141   virtual void setPosition( const Point2I newPosition );
142   virtual const Point2I getPosition();
143   virtual void centerWindow();
144   virtual bool setSize(const Point2I &newSize);
145   
146   // Coordinate space conversion.
147   virtual Point2I clientToScreen( const Point2I& pos );
148   virtual Point2I screenToClient( const Point2I& pos );
149
150   virtual bool isOpen();
151   virtual bool isVisible();
152   virtual bool isFocused();
153   virtual bool isMinimized();
154   virtual bool isMaximized();
155
156   virtual void minimize();
157   virtual void maximize();
158   virtual void hide();
159   virtual void show();
160   virtual void close();
161   virtual void restore();
162   virtual void setFocus();
163
164   virtual void setMouseLocked(bool enable);
165   virtual bool isMouseLocked() const { return mMouseLocked; };
166   virtual bool shouldLockMouse() const { return mShouldLockMouse; };
167
168   /// Set if relevant keypress events should be translated into character input events.
169   virtual void setKeyboardTranslation(const bool enabled);
170
171   virtual WindowId getWindowId();
172
173   SDL_Window* getSDLWindow() const { return mWindowHandle; }
174
175   virtual PlatformWindow * getNextWindow() const
176   {
177      return mNextWindow;
178   }
179
180   /// Provide a simple GDI-based render for when the game is not rendering.
181   virtual void defaultRender();
182
183   /// Return the class name for the windows we create with this class.
184   static const UTF16 *getWindowClassName();
185
186   /// Return the class name for the curtain window class.
187   static const UTF16 *getCurtainWindowClassName();
188
189   /// Return the platform specific object needed to create or attach an
190   /// accelerated graohics drawing context on or to the window
191   virtual void* getPlatformDrawable() const { return mWindowHandle; }
192};
193#endif
194