PageRenderTime 75ms CodeModel.GetById 39ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 25#ifndef SFML_WINDOWIMPLWIN32_HPP
 26#define SFML_WINDOWIMPLWIN32_HPP
 27
 28////////////////////////////////////////////////////////////
 29// Headers
 30////////////////////////////////////////////////////////////
 31#include <SFML/Window/Event.hpp>
 32#include <SFML/Window/WindowImpl.hpp>
 33#include <windows.h>
 34#include <string>
 35
 36
 37namespace sf
 38{
 39namespace priv
 40{
 41////////////////////////////////////////////////////////////
 42/// \brief Windows implementation of WindowImpl
 43///
 44////////////////////////////////////////////////////////////
 45class WindowImplWin32 : public WindowImpl
 46{
 47public :
 48
 49    ////////////////////////////////////////////////////////////
 50    /// \brief Construct the window implementation from an existing control
 51    ///
 52    /// \param handle Platform-specific handle of the control
 53    ///
 54    ////////////////////////////////////////////////////////////
 55    WindowImplWin32(WindowHandle handle);
 56
 57    ////////////////////////////////////////////////////////////
 58    /// \brief Create the window implementation
 59    ///
 60    /// \param mode  Video mode to use
 61    /// \param title Title of the window
 62    /// \param style Window style
 63    ///
 64    ////////////////////////////////////////////////////////////
 65    WindowImplWin32(VideoMode mode, const std::string& title, unsigned long style);
 66
 67    ////////////////////////////////////////////////////////////
 68    /// \brief Destructor
 69    ///
 70    ////////////////////////////////////////////////////////////
 71    ~WindowImplWin32();
 72
 73private :
 74
 75    ////////////////////////////////////////////////////////////
 76    /// \brief Get the OS-specific handle of the window
 77    ///
 78    /// \return Handle of the window
 79    ///
 80    ////////////////////////////////////////////////////////////
 81    virtual WindowHandle GetSystemHandle() const;
 82
 83    ////////////////////////////////////////////////////////////
 84    /// \brief Process incoming events from the operating system
 85    ///
 86    /// \param block Use true to block the thread until an event arrives
 87    ///
 88    ////////////////////////////////////////////////////////////
 89    virtual void ProcessEvents(bool block);
 90
 91    ////////////////////////////////////////////////////////////
 92    /// \brief Show or hide the mouse cursor
 93    ///
 94    /// \param show True to show, false to hide
 95    ///
 96    ////////////////////////////////////////////////////////////
 97    virtual void ShowMouseCursor(bool show);
 98
 99    ////////////////////////////////////////////////////////////
100    /// \brief Change the position of the mouse cursor
101    ///
102    /// \param x Left coordinate of the cursor, relative to the window
103    /// \param y Top coordinate of the cursor, relative to the window
104    ///
105    ////////////////////////////////////////////////////////////
106    virtual void SetCursorPosition(unsigned int x, unsigned int y);
107
108    ////////////////////////////////////////////////////////////
109    /// \brief Change the position of the window on screen
110    ///
111    /// \param x Left position
112    /// \param y Top position
113    ///
114    ////////////////////////////////////////////////////////////
115    virtual void SetPosition(int x, int y);
116
117    ////////////////////////////////////////////////////////////
118    /// \brief Change the size of the rendering region of the window
119    ///
120    /// \param width  New width
121    /// \param height New height
122    ///
123    ////////////////////////////////////////////////////////////
124    virtual void SetSize(unsigned int width, unsigned int height);
125
126    ////////////////////////////////////////////////////////////
127    /// \brief Change the title of the window
128    ///
129    /// \param title New title
130    ///
131    ////////////////////////////////////////////////////////////
132    virtual void SetTitle(const std::string& title);
133
134    ////////////////////////////////////////////////////////////
135    /// \brief Show or hide the window
136    ///
137    /// \param show True to show, false to hide
138    ///
139    ////////////////////////////////////////////////////////////
140    virtual void Show(bool show);
141
142    ////////////////////////////////////////////////////////////
143    /// \brief Enable or disable automatic key-repeat
144    ///
145    /// \param enabled True to enable, false to disable
146    ///
147    ////////////////////////////////////////////////////////////
148    virtual void EnableKeyRepeat(bool enabled);
149
150    ////////////////////////////////////////////////////////////
151    /// \brief Change the window's icon
152    ///
153    /// \param width  Icon's width, in pixels
154    /// \param height Icon's height, in pixels
155    /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits
156    ///
157    ////////////////////////////////////////////////////////////
158    virtual void SetIcon(unsigned int width, unsigned int height, const Uint8* pixels);
159
160    ////////////////////////////////////////////////////////////
161    /// Register the window class
162    ///
163    ////////////////////////////////////////////////////////////
164    void RegisterWindowClass();
165
166    ////////////////////////////////////////////////////////////
167    /// \brief Switch to fullscreen mode
168    ///
169    /// \param mode Video mode to switch to
170    ///
171    ////////////////////////////////////////////////////////////
172    void SwitchToFullscreen(const VideoMode& mode);
173
174    ////////////////////////////////////////////////////////////
175    /// \brief Free all the graphical resources attached to the window
176    ///
177    ////////////////////////////////////////////////////////////
178    void Cleanup();
179
180    ////////////////////////////////////////////////////////////
181    /// \brief Process a Win32 event
182    ///
183    /// \param message Message to process
184    /// \param wParam  First parameter of the event
185    /// \param lParam  Second parameter of the event
186    ///
187    ////////////////////////////////////////////////////////////
188    void ProcessEvent(UINT message, WPARAM wParam, LPARAM lParam);
189
190    ////////////////////////////////////////////////////////////
191    /// \brief Convert a Win32 virtual key code to a SFML key code
192    ///
193    /// \param key   Virtual key code to convert
194    /// \param flags Additional flags
195    ///
196    /// \return SFML key code corresponding to the key
197    ///
198    ////////////////////////////////////////////////////////////
199    static Key::Code VirtualKeyCodeToSF(WPARAM key, LPARAM flags);
200
201    ////////////////////////////////////////////////////////////
202    /// \brief Check if the current version of the OS supports
203    ///        unicode messages and functions ; Windows 95/98/Me
204    ///        may not support it, whereas Windows NT/2000/XP/Vista
205    ///        will
206    ///
207    /// \return True if the OS supports unicode
208    ///
209    ////////////////////////////////////////////////////////////
210    static bool HasUnicodeSupport();
211
212    ////////////////////////////////////////////////////////////
213    /// \brief Function called whenever one of our windows receives a message
214    ///
215    /// \param handle  Win32 handle of the window
216    /// \param message Message received
217    /// \param wParam  First parameter of the message
218    /// \param lParam  Second parameter of the message
219    ///
220    /// \return True to discard the event after it has been processed
221    ///
222    ////////////////////////////////////////////////////////////
223    static LRESULT CALLBACK GlobalOnEvent(HWND handle, UINT message, WPARAM wParam, LPARAM lParam);
224
225    ////////////////////////////////////////////////////////////
226    // Member data
227    ////////////////////////////////////////////////////////////
228    HWND    myHandle;           ///< Win32 handle of the window
229    long    myCallback;         ///< Stores the original event callback function of the control
230    HCURSOR myCursor;           ///< The system cursor to display into the window
231    HICON   myIcon;             ///< Custom icon assigned to the window
232    bool    myKeyRepeatEnabled; ///< Automatic key-repeat state for keydown events
233    bool    myIsCursorIn;       ///< Is the mouse cursor in the window's area ?
234};
235
236} // namespace priv
237
238} // namespace sf
239
240#endif // SFML_WINDOWIMPLWIN32_HPP