sdlWindow.h
Engine/source/windowManager/sdl/sdlWindow.h
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 /// @} 92 93 void _processSDLEvent(SDL_Event &evt); 94 void _triggerMouseLocationNotify(const SDL_Event& evt); 95 void _triggerMouseButtonNotify(const SDL_Event& event); 96 void _triggerMouseWheelNotify(const SDL_Event& event); 97 void _triggerKeyNotify(const SDL_Event& event); 98 void _triggerTextNotify(const SDL_Event& event); 99 100public: 101 PlatformWindowSDL(); 102 ~PlatformWindowSDL(); 103 104 virtual void* getSystemWindow(const WindowSystem system); 105 106 void* &getMenuHandle() 107 { 108 return mMenuHandle; 109 } 110 111 void setMenuHandle( void* menuHandle ) 112 { 113 mMenuHandle = menuHandle; 114 } 115 116 virtual GFXDevice *getGFXDevice(); 117 virtual GFXWindowTarget *getGFXTarget(); 118 119 virtual void setVideoMode(const GFXVideoMode &mode); 120 virtual const GFXVideoMode &getVideoMode(); 121 virtual bool clearFullscreen(); 122 virtual bool isFullscreen(); 123 virtual void _setFullscreen(const bool fullscreen); 124 125 virtual bool setCaption(const char *cap); 126 virtual const char *getCaption(); 127 128 // Window Client Area Extent 129 virtual void setClientExtent( const Point2I newExtent ); 130 virtual const Point2I getClientExtent(); 131 132 // Window Bounds 133 virtual void setBounds(const RectI &newBounds); 134 virtual const RectI getBounds() const; 135 136 // Window Position 137 virtual void setPosition( const Point2I newPosition ); 138 virtual const Point2I getPosition(); 139 virtual void centerWindow(); 140 virtual bool setSize(const Point2I &newSize); 141 142 // Coordinate space conversion. 143 virtual Point2I clientToScreen( const Point2I& pos ); 144 virtual Point2I screenToClient( const Point2I& pos ); 145 146 virtual bool isOpen(); 147 virtual bool isVisible(); 148 virtual bool isFocused(); 149 virtual bool isMinimized(); 150 virtual bool isMaximized(); 151 152 virtual void minimize(); 153 virtual void maximize(); 154 virtual void hide(); 155 virtual void show(); 156 virtual void close(); 157 virtual void restore(); 158 virtual void setFocus(); 159 160 virtual void setMouseLocked(bool enable); 161 virtual bool isMouseLocked() const { return mMouseLocked; }; 162 virtual bool shouldLockMouse() const { return mShouldLockMouse; }; 163 164 /// Set if relevant keypress events should be translated into character input events. 165 virtual void setKeyboardTranslation(const bool enabled); 166 167 virtual WindowId getWindowId(); 168 169 SDL_Window* getSDLWindow() const { return mWindowHandle; } 170 171 virtual PlatformWindow * getNextWindow() const 172 { 173 return mNextWindow; 174 } 175 176 /// Provide a simple GDI-based render for when the game is not rendering. 177 virtual void defaultRender(); 178 179 /// Return the class name for the windows we create with this class. 180 static const UTF16 *getWindowClassName(); 181 182 /// Return the class name for the curtain window class. 183 static const UTF16 *getCurtainWindowClassName(); 184 185 /// Return the platform specific object needed to create or attach an 186 /// accelerated graohics drawing context on or to the window 187 virtual void* getPlatformDrawable() const { return mWindowHandle; } 188}; 189#endif 190
