1 /* 2 ----------------------------------------------------------------------------- 3 This source file is part of OGRE 4 (Object-oriented Graphics Rendering Engine) 5 For the latest info, see http://www.ogre3d.org/ 6 7 Copyright (c) 2000-2014 Torus Knot Software Ltd 8 9 Permission is hereby granted, free of charge, to any person obtaining a copy 10 of this software and associated documentation files (the "Software"), to deal 11 in the Software without restriction, including without limitation the rights 12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 copies of the Software, and to permit persons to whom the Software is 14 furnished to do so, subject to the following conditions: 15 16 The above copyright notice and this permission notice shall be included in 17 all copies or substantial portions of the Software. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 THE SOFTWARE. 26 ----------------------------------------------------------------------------- 27 */ 28 #ifndef __OgreWindowEventUtils_H__ 29 #define __OgreWindowEventUtils_H__ 30 31 #include "OgrePrerequisites.h" 32 #include "OgreBitesPrerequisites.h" 33 #include "OgrePlatform.h" 34 #include "OgreCommon.h" 35 #include "OgreHeaderPrefix.h" 36 37 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 38 # if !defined(WIN32_LEAN_AND_MEAN) 39 # define WIN32_LEAN_AND_MEAN 40 # endif 41 # if !defined(NOMINMAX) && defined(_MSC_VER) 42 # define NOMINMAX // required to stop windows.h messing up std::min 43 # endif 44 # include <windows.h> 45 #endif 46 47 /** \addtogroup Optional 48 * @{ 49 */ 50 /** \addtogroup Bites 51 * @{ 52 */ 53 namespace OgreBites 54 { 55 /** 56 Callback class used to send out window events to client app 57 */ 58 class _OgreBitesExport WindowEventListener 59 { 60 public: ~WindowEventListener()61 virtual ~WindowEventListener() {} 62 63 /** 64 @remarks 65 Window has moved position 66 @param rw 67 The RenderWindow which created this events 68 */ windowMoved(Ogre::RenderWindow * rw)69 virtual void windowMoved(Ogre::RenderWindow* rw) { (void)rw; } 70 71 /** 72 @remarks 73 Window has resized 74 @param rw 75 The RenderWindow which created this events 76 */ windowResized(Ogre::RenderWindow * rw)77 virtual void windowResized(Ogre::RenderWindow* rw) { (void)rw; } 78 79 /** 80 @remarks 81 Window is closing (Only triggered if user pressed the [X] button) 82 @param rw 83 The RenderWindow which created this events 84 @return True will close the window(default). 85 */ windowClosing(Ogre::RenderWindow * rw)86 virtual bool windowClosing(Ogre::RenderWindow* rw) { return true; } 87 88 /** 89 @remarks 90 Window has been closed (Only triggered if user pressed the [X] button) 91 @param rw 92 The RenderWindow which created this events 93 @note 94 The window has not actually close yet when this event triggers. It's only closed after 95 all windowClosed events are triggered. This allows apps to deinitialise properly if they 96 have services that needs the window to exist when deinitialising. 97 */ windowClosed(Ogre::RenderWindow * rw)98 virtual void windowClosed(Ogre::RenderWindow* rw) { (void)rw; } 99 100 /** 101 @remarks 102 Window has lost/gained focus 103 @param rw 104 The RenderWindow which created this events 105 */ windowFocusChange(Ogre::RenderWindow * rw)106 virtual void windowFocusChange(Ogre::RenderWindow* rw) { (void)rw; } 107 }; 108 109 /** 110 Utility class to handle Window Messages 111 112 This only provides a minimal implementation for moving/ resizing windows. 113 For input handling and proper platform integration rather use SDL2/ Qt/ whatever. 114 @see ApplicationContext 115 */ 116 class _OgreBitesExport WindowEventUtilities 117 { 118 public: 119 /** 120 Call this once per frame. This will update all registered RenderWindows. 121 */ 122 static void messagePump(); 123 124 /** 125 @remarks 126 Add a listener to listen to renderwindow events (multiple listener's per renderwindow is fine) 127 The same listener can listen to multiple windows, as the Window Pointer is sent along with 128 any messages. 129 @param window 130 The RenderWindow you are interested in monitoring 131 @param listener 132 Your callback listener 133 */ 134 static void addWindowEventListener( Ogre::RenderWindow* window, WindowEventListener* listener ); 135 136 /** 137 @remarks 138 Remove previously added listener 139 @param window 140 The RenderWindow you registered with 141 @param listener 142 The listener registered 143 */ 144 static void removeWindowEventListener( Ogre::RenderWindow* window, WindowEventListener* listener ); 145 146 /** 147 @remarks 148 Call upon creation of Ogre windows. You are free to add your 149 external windows here too if needed. 150 @param window 151 The RenderWindow to monitor 152 */ 153 static void _addRenderWindow(Ogre::RenderWindow* window); 154 155 /** 156 @remarks 157 Called upon deletion of previously registered windows. 158 @param window 159 The RenderWindow to remove from list 160 */ 161 static void _removeRenderWindow(Ogre::RenderWindow* window); 162 163 // backwards compatibility 164 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 165 //! Internal winProc (RenderWindow's use this when creating the Win32 Window) 166 static LRESULT CALLBACK _WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); 167 #endif 168 }; 169 } 170 /** @} */ 171 /** @} */ 172 173 namespace Ogre 174 { 175 // backwards compatibility 176 typedef OGRE_DEPRECATED OgreBites::WindowEventListener WindowEventListener; 177 typedef OGRE_DEPRECATED OgreBites::WindowEventUtilities WindowEventUtilities; 178 } 179 180 #include "OgreHeaderSuffix.h" 181 182 #endif 183