/extlibs/SFML/src/SFML/Window/Win32/WindowImplWin32.hpp

https://bitbucket.org/hugoruscitti/pilascpp · C++ Header · 240 lines · 44 code · 29 blank · 167 comment · 0 complexity · 5402519c583738f9bdea07b30b22e93b MD5 · raw file

  1. ////////////////////////////////////////////////////////////
  2. //
  3. // SFML - Simple and Fast Multimedia Library
  4. // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
  5. //
  6. // This software is provided 'as-is', without any express or implied warranty.
  7. // In no event will the authors be held liable for any damages arising from the use of this software.
  8. //
  9. // Permission is granted to anyone to use this software for any purpose,
  10. // including commercial applications, and to alter it and redistribute it freely,
  11. // subject to the following restrictions:
  12. //
  13. // 1. The origin of this software must not be misrepresented;
  14. // you must not claim that you wrote the original software.
  15. // If you use this software in a product, an acknowledgment
  16. // in the product documentation would be appreciated but is not required.
  17. //
  18. // 2. Altered source versions must be plainly marked as such,
  19. // and must not be misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source distribution.
  22. //
  23. ////////////////////////////////////////////////////////////
  24. #ifndef SFML_WINDOWIMPLWIN32_HPP
  25. #define SFML_WINDOWIMPLWIN32_HPP
  26. ////////////////////////////////////////////////////////////
  27. // Headers
  28. ////////////////////////////////////////////////////////////
  29. #include <SFML/Window/Event.hpp>
  30. #include <SFML/Window/WindowImpl.hpp>
  31. #include <windows.h>
  32. #include <string>
  33. namespace sf
  34. {
  35. namespace priv
  36. {
  37. ////////////////////////////////////////////////////////////
  38. /// \brief Windows implementation of WindowImpl
  39. ///
  40. ////////////////////////////////////////////////////////////
  41. class WindowImplWin32 : public WindowImpl
  42. {
  43. public :
  44. ////////////////////////////////////////////////////////////
  45. /// \brief Construct the window implementation from an existing control
  46. ///
  47. /// \param handle Platform-specific handle of the control
  48. ///
  49. ////////////////////////////////////////////////////////////
  50. WindowImplWin32(WindowHandle handle);
  51. ////////////////////////////////////////////////////////////
  52. /// \brief Create the window implementation
  53. ///
  54. /// \param mode Video mode to use
  55. /// \param title Title of the window
  56. /// \param style Window style
  57. ///
  58. ////////////////////////////////////////////////////////////
  59. WindowImplWin32(VideoMode mode, const std::string& title, unsigned long style);
  60. ////////////////////////////////////////////////////////////
  61. /// \brief Destructor
  62. ///
  63. ////////////////////////////////////////////////////////////
  64. ~WindowImplWin32();
  65. private :
  66. ////////////////////////////////////////////////////////////
  67. /// \brief Get the OS-specific handle of the window
  68. ///
  69. /// \return Handle of the window
  70. ///
  71. ////////////////////////////////////////////////////////////
  72. virtual WindowHandle GetSystemHandle() const;
  73. ////////////////////////////////////////////////////////////
  74. /// \brief Process incoming events from the operating system
  75. ///
  76. /// \param block Use true to block the thread until an event arrives
  77. ///
  78. ////////////////////////////////////////////////////////////
  79. virtual void ProcessEvents(bool block);
  80. ////////////////////////////////////////////////////////////
  81. /// \brief Show or hide the mouse cursor
  82. ///
  83. /// \param show True to show, false to hide
  84. ///
  85. ////////////////////////////////////////////////////////////
  86. virtual void ShowMouseCursor(bool show);
  87. ////////////////////////////////////////////////////////////
  88. /// \brief Change the position of the mouse cursor
  89. ///
  90. /// \param x Left coordinate of the cursor, relative to the window
  91. /// \param y Top coordinate of the cursor, relative to the window
  92. ///
  93. ////////////////////////////////////////////////////////////
  94. virtual void SetCursorPosition(unsigned int x, unsigned int y);
  95. ////////////////////////////////////////////////////////////
  96. /// \brief Change the position of the window on screen
  97. ///
  98. /// \param x Left position
  99. /// \param y Top position
  100. ///
  101. ////////////////////////////////////////////////////////////
  102. virtual void SetPosition(int x, int y);
  103. ////////////////////////////////////////////////////////////
  104. /// \brief Change the size of the rendering region of the window
  105. ///
  106. /// \param width New width
  107. /// \param height New height
  108. ///
  109. ////////////////////////////////////////////////////////////
  110. virtual void SetSize(unsigned int width, unsigned int height);
  111. ////////////////////////////////////////////////////////////
  112. /// \brief Change the title of the window
  113. ///
  114. /// \param title New title
  115. ///
  116. ////////////////////////////////////////////////////////////
  117. virtual void SetTitle(const std::string& title);
  118. ////////////////////////////////////////////////////////////
  119. /// \brief Show or hide the window
  120. ///
  121. /// \param show True to show, false to hide
  122. ///
  123. ////////////////////////////////////////////////////////////
  124. virtual void Show(bool show);
  125. ////////////////////////////////////////////////////////////
  126. /// \brief Enable or disable automatic key-repeat
  127. ///
  128. /// \param enabled True to enable, false to disable
  129. ///
  130. ////////////////////////////////////////////////////////////
  131. virtual void EnableKeyRepeat(bool enabled);
  132. ////////////////////////////////////////////////////////////
  133. /// \brief Change the window's icon
  134. ///
  135. /// \param width Icon's width, in pixels
  136. /// \param height Icon's height, in pixels
  137. /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
  138. ///
  139. ////////////////////////////////////////////////////////////
  140. virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels);
  141. ////////////////////////////////////////////////////////////
  142. /// Register the window class
  143. ///
  144. ////////////////////////////////////////////////////////////
  145. void RegisterWindowClass();
  146. ////////////////////////////////////////////////////////////
  147. /// \brief Switch to fullscreen mode
  148. ///
  149. /// \param mode Video mode to switch to
  150. ///
  151. ////////////////////////////////////////////////////////////
  152. void SwitchToFullscreen(const VideoMode& mode);
  153. ////////////////////////////////////////////////////////////
  154. /// \brief Free all the graphical resources attached to the window
  155. ///
  156. ////////////////////////////////////////////////////////////
  157. void Cleanup();
  158. ////////////////////////////////////////////////////////////
  159. /// \brief Process a Win32 event
  160. ///
  161. /// \param message Message to process
  162. /// \param wParam First parameter of the event
  163. /// \param lParam Second parameter of the event
  164. ///
  165. ////////////////////////////////////////////////////////////
  166. void ProcessEvent(UINT message, WPARAM wParam, LPARAM lParam);
  167. ////////////////////////////////////////////////////////////
  168. /// \brief Convert a Win32 virtual key code to a SFML key code
  169. ///
  170. /// \param key Virtual key code to convert
  171. /// \param flags Additional flags
  172. ///
  173. /// \return SFML key code corresponding to the key
  174. ///
  175. ////////////////////////////////////////////////////////////
  176. static Key::Code VirtualKeyCodeToSF(WPARAM key, LPARAM flags);
  177. ////////////////////////////////////////////////////////////
  178. /// \brief Check if the current version of the OS supports
  179. /// unicode messages and functions ; Windows 95/98/Me
  180. /// may not support it, whereas Windows NT/2000/XP/Vista
  181. /// will
  182. ///
  183. /// \return True if the OS supports unicode
  184. ///
  185. ////////////////////////////////////////////////////////////
  186. static bool HasUnicodeSupport();
  187. ////////////////////////////////////////////////////////////
  188. /// \brief Function called whenever one of our windows receives a message
  189. ///
  190. /// \param handle Win32 handle of the window
  191. /// \param message Message received
  192. /// \param wParam First parameter of the message
  193. /// \param lParam Second parameter of the message
  194. ///
  195. /// \return True to discard the event after it has been processed
  196. ///
  197. ////////////////////////////////////////////////////////////
  198. static LRESULT CALLBACK GlobalOnEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam);
  199. ////////////////////////////////////////////////////////////
  200. // Member data
  201. ////////////////////////////////////////////////////////////
  202. HWND myHandle; ///< Win32 handle of the window
  203. long myCallback; ///< Stores the original event callback function of the control
  204. HCURSOR myCursor; ///< The system cursor to display into the window
  205. HICON myIcon; ///< Custom icon assigned to the window
  206. bool myKeyRepeatEnabled; ///< Automatic key-repeat state for keydown events
  207. bool myIsCursorIn; ///< Is the mouse cursor in the window's area ?
  208. };
  209. } // namespace priv
  210. } // namespace sf
  211. #endif // SFML_WINDOWIMPLWIN32_HPP