sdlWindowMgr.h
Engine/source/windowManager/sdl/sdlWindowMgr.h
Classes:
class
SDL2 implementation of the window manager interface.
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_WINDOWMANAGER_ 25#define _WINDOWMANAGER_SDL_WINDOWMANAGER_ 26 27#include "math/mMath.h" 28#include "gfx/gfxStructs.h" 29#include "windowManager/sdl/sdlWindow.h" 30#include "core/util/tVector.h" 31 32struct SDL_Window; 33class FileDialog; // TODO SDL REMOVE 34 35/// SDL2 implementation of the window manager interface. 36class PlatformWindowManagerSDL : public PlatformWindowManager 37{ 38public: 39 /// An enum that holds an event loop frame of the state of the 40 /// keyboard for how the keyboard is interpreted inside of Torque. 41 /// 42 /// SDL has a concept of text editing events as well as raw input 43 /// events. Because of this, SDL needs notified whenever it needs 44 /// to fire text based events. SDL will continue firing raw input 45 /// events as well during this time. 46 /// 47 /// The reason why this was created is because we needed time to 48 /// transition between raw input to raw input + text based events. 49 /// If we take a raw input and notify SDL we wanted text during the 50 /// event loop, SDL will issue a text input event as well. This was 51 /// causing issues with the console, where the console key would be 52 /// appended to the console buffer upon opening it. We fix this by 53 /// delaying the notification to SDL until the event loop is complete. 54 enum class KeyboardInputState 55 { 56 NONE = 0, /// < No state change during this event loop cycle. 57 TEXT_INPUT = 1, /// < We want to change to text based events & raw input. 58 RAW_INPUT = 2 /// < We only want raw input. 59 }; 60 61protected: 62 friend class PlatformWindowSDL; 63 friend class FileDialog; // TODO SDL REMOVE 64 65 virtual void _processCmdLineArgs(const S32 argc, const char **argv); 66 67 /// Link the specified window into the window list. 68 void linkWindow(PlatformWindowSDL *w); 69 70 /// Remove specified window from the window list. 71 void unlinkWindow(PlatformWindowSDL *w); 72 73 /// Callback for the process list. 74 void _process(); 75 76 /// List of allocated windows. 77 PlatformWindowSDL *mWindowListHead; 78 79 /// Parent window, used in window setup in web plugin scenarios. 80 SDL_Window *mParentWindow; 81 82 /// This is set as part of the canvas being shown, and flags that the windows should render as normal from now on. 83 // Basically a flag that lets the window manager know that we've handled the splash screen, and to operate as normal. 84 bool mDisplayWindow; 85 86 /// set via command line -offscreen option, controls whether rendering/input 87 // is intended for offscreen rendering 88 bool mOffscreenRender; 89 90 /// If a curtain window is present, then will be stored here. 91 SDL_Window *mCurtainWindow; 92 93 Map<U32, PlatformWindowSDL*> mWindowMap; 94 95 SignalSlot<void()> mOnProcessSignalSlot; 96 97 /// The input state that will change whenever SDL needs notified. 98 /// After it is handled, it will return to state NONE. 99 KeyboardInputState mInputState; 100 101public: 102 PlatformWindowManagerSDL(); 103 ~PlatformWindowManagerSDL(); 104 105 virtual RectI getPrimaryDesktopArea(); 106 virtual S32 getDesktopBitDepth(); 107 virtual Point2I getDesktopResolution(); 108 109 virtual S32 findFirstMatchingMonitor(const char* name); 110 virtual U32 getMonitorCount(); 111 virtual const char* getMonitorName(U32 index); 112 virtual RectI getMonitorRect(U32 index); 113 virtual RectI getMonitorUsableRect(U32 index); 114 virtual U32 getMonitorModeCount(U32 monitorIndex); 115 virtual const String getMonitorMode(U32 monitorIndex, U32 modeIndex); 116 virtual const String getMonitorDesktopMode(U32 monitorIndex); 117 118 virtual void getMonitorRegions(Vector<RectI> ®ions); 119 virtual PlatformWindow *createWindow(GFXDevice *device, const GFXVideoMode &mode); 120 virtual void getWindows(VectorPtr<PlatformWindow*> &windows); 121 122 virtual void setParentWindow(void* newParent); 123 virtual void* getParentWindow(); 124 125 virtual PlatformWindow *getWindowById(WindowId id); 126 virtual PlatformWindow *getFirstWindow(); 127 virtual PlatformWindow* getFocusedWindow(); 128 129 virtual void lowerCurtain(); 130 virtual void raiseCurtain(); 131 132 virtual void setDisplayWindow(bool set) { mDisplayWindow = set; } 133 134 /// Stores the input state so that the event loop will fire a check if we need 135 /// to change how keyboard input is being handled. 136 /// @param state The state of the keyboard input, either being raw input or text 137 /// based input. 138 void updateSDLTextInputState(KeyboardInputState state); 139}; 140 141#endif 142