OgreWindowEventUtilities.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. Copyright (c) 2000-2011 Torus Knot Software Ltd
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  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 FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. -----------------------------------------------------------------------------
  23. */
  24. #ifndef __OgreWindowEventUtils_H__
  25. #define __OgreWindowEventUtils_H__
  26. #include "OgrePrerequisites.h"
  27. #include "OgrePlatform.h"
  28. #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
  29. # define WIN32_LEAN_AND_MEAN
  30. # if !defined(NOMINMAX) && defined(_MSC_VER)
  31. # define NOMINMAX // required to stop windows.h messing up std::min
  32. # endif
  33. # include <windows.h>
  34. #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE && !defined(__LP64__)
  35. # include <Carbon/Carbon.h>
  36. #endif
  37. namespace Ogre
  38. {
  39. /** \addtogroup Core
  40. * @{
  41. */
  42. /** \addtogroup RenderSystem
  43. * @{
  44. */
  45. /**
  46. @Remarks
  47. Callback class used to send out window events to client app
  48. */
  49. class _OgreExport WindowEventListener
  50. {
  51. public:
  52. virtual ~WindowEventListener() {}
  53. /**
  54. @Remarks
  55. Window has moved position
  56. @param rw
  57. The RenderWindow which created this events
  58. */
  59. virtual void windowMoved(RenderWindow* rw)
  60. { (void)rw; }
  61. /**
  62. @Remarks
  63. Window has resized
  64. @param rw
  65. The RenderWindow which created this events
  66. */
  67. virtual void windowResized(RenderWindow* rw)
  68. { (void)rw; }
  69. /**
  70. @Remarks
  71. Window is closing (Only triggered if user pressed the [X] button)
  72. @param rw
  73. The RenderWindow which created this events
  74. @return True will close the window(default).
  75. */
  76. virtual bool windowClosing(RenderWindow* rw)
  77. { (void)rw; return true; }
  78. /**
  79. @Remarks
  80. Window has been closed (Only triggered if user pressed the [X] button)
  81. @param rw
  82. The RenderWindow which created this events
  83. @note
  84. The window has not actually close yet when this event triggers. It's only closed after
  85. all windowClosed events are triggered. This allows apps to deinitialise properly if they
  86. have services that needs the window to exist when deinitialising.
  87. */
  88. virtual void windowClosed(RenderWindow* rw)
  89. { (void)rw; }
  90. /**
  91. @Remarks
  92. Window has lost/gained focus
  93. @param rw
  94. The RenderWindow which created this events
  95. */
  96. virtual void windowFocusChange(RenderWindow* rw)
  97. { (void)rw; }
  98. };
  99. /**
  100. @Remarks
  101. Utility class to handle Window Events/Pumping/Messages
  102. */
  103. class _OgreExport WindowEventUtilities
  104. {
  105. public:
  106. /**
  107. @Remarks
  108. Call this once per frame if not using Root:startRendering(). This will update all registered
  109. RenderWindows (If using external Windows, you can optionally register those yourself)
  110. */
  111. static void messagePump();
  112. /**
  113. @Remarks
  114. Add a listener to listen to renderwindow events (multiple listener's per renderwindow is fine)
  115. The same listener can listen to multiple windows, as the Window Pointer is sent along with
  116. any messages.
  117. @param window
  118. The RenderWindow you are interested in monitoring
  119. @param listner
  120. Your callback listener
  121. */
  122. static void addWindowEventListener( RenderWindow* window, WindowEventListener* listener );
  123. /**
  124. @Remarks
  125. Remove previously added listener
  126. @param window
  127. The RenderWindow you registered with
  128. @param listner
  129. The listener registered
  130. */
  131. static void removeWindowEventListener( RenderWindow* window, WindowEventListener* listener );
  132. /**
  133. @Remarks
  134. Called by RenderWindows upon creation for Ogre generated windows. You are free to add your
  135. external windows here too if needed.
  136. @param window
  137. The RenderWindow to monitor
  138. */
  139. static void _addRenderWindow(RenderWindow* window);
  140. /**
  141. @Remarks
  142. Called by RenderWindows upon creation for Ogre generated windows. You are free to add your
  143. external windows here too if needed.
  144. @param window
  145. The RenderWindow to remove from list
  146. */
  147. static void _removeRenderWindow(RenderWindow* window);
  148. #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
  149. //! Internal winProc (RenderWindow's use this when creating the Win32 Window)
  150. static LRESULT CALLBACK _WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  151. #elif OGRE_PLATFORM == OGRE_PLATFORM_APPLE && !defined __OBJC__ && !defined(__LP64__)
  152. //! Internal UPP Window Handler (RenderWindow's use this when creating the OS X Carbon Window
  153. static OSStatus _CarbonWindowHandler(EventHandlerCallRef nextHandler, EventRef event, void* wnd);
  154. #endif
  155. //These are public only so GLXProc can access them without adding Xlib headers header
  156. typedef multimap<RenderWindow*, WindowEventListener*>::type WindowEventListeners;
  157. static WindowEventListeners _msListeners;
  158. typedef vector<RenderWindow*>::type Windows;
  159. static Windows _msWindows;
  160. };
  161. /** @} */
  162. /** @} */
  163. }
  164. #endif