CmWindowEventUtilities.h 5.8 KB

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