summaryrefslogtreecommitdiff
path: root/src/SFML/Window/Win32/WindowImplWin32.hpp
blob: 2b6b59d4694341a7f8f46b2b396f1c62895c02db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
//    you must not claim that you wrote the original software.
//    If you use this software in a product, an acknowledgment
//    in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
//    and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////

#ifndef SFML_WINDOWIMPLWIN32_HPP
#define SFML_WINDOWIMPLWIN32_HPP

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Event.hpp>
#include <SFML/Window/WindowImpl.hpp>
#include <windows.h>
#include <string>


namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// WindowImplWin32 is the Win32 implementation of WindowImpl
////////////////////////////////////////////////////////////
class WindowImplWin32 : public WindowImpl
{
public :

    ////////////////////////////////////////////////////////////
    /// Default constructor
    /// (creates a dummy window to provide a valid OpenGL context)
    ///
    ////////////////////////////////////////////////////////////
    WindowImplWin32();

    ////////////////////////////////////////////////////////////
    /// Construct the window implementation from an existing control
    ///
    /// \param Handle : Platform-specific handle of the control
    /// \param Params : Creation settings
    ///
    ////////////////////////////////////////////////////////////
    WindowImplWin32(WindowHandle Handle, WindowSettings& Params);

    ////////////////////////////////////////////////////////////
    /// Create the window implementation
    ///
    /// \param Mode :        Video mode to use
    /// \param Title :       Title of the window
    /// \param WindowStyle : Window style
    /// \param Params :      Creation settings
    ///
    ////////////////////////////////////////////////////////////
    WindowImplWin32(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, WindowSettings& Params);

    ////////////////////////////////////////////////////////////
    /// Destructor
    ///
    ////////////////////////////////////////////////////////////
    ~WindowImplWin32();

private :

    ////////////////////////////////////////////////////////////
    /// /see sfWindowImpl::ProcessEvents
    ///
    ////////////////////////////////////////////////////////////
    virtual void ProcessEvents();

    ////////////////////////////////////////////////////////////
    /// /see sfWindowImpl::Display
    ///
    ////////////////////////////////////////////////////////////
    virtual void Display();

    ////////////////////////////////////////////////////////////
    /// /see sfWindowImpl::MakeActive
    ///
    ////////////////////////////////////////////////////////////
    virtual void MakeActive(bool Active = true) const;

    ////////////////////////////////////////////////////////////
    /// /see sfWindowImpl::UseVerticalSync
    ///
    ////////////////////////////////////////////////////////////
    virtual void UseVerticalSync(bool Enabled);

    ////////////////////////////////////////////////////////////
    /// /see sfWindowImpl::ShowMouseCursor
    ///
    ////////////////////////////////////////////////////////////
    virtual void ShowMouseCursor(bool Show);

    ////////////////////////////////////////////////////////////
    /// /see sfWindowImpl::SetCursorPosition
    ///
    ////////////////////////////////////////////////////////////
    virtual void SetCursorPosition(unsigned int Left, unsigned int Top);

    ////////////////////////////////////////////////////////////
    /// /see sfWindowImpl::SetPosition
    ///
    ////////////////////////////////////////////////////////////
    virtual void SetPosition(int Left, int Top);

    ////////////////////////////////////////////////////////////
    /// /see sfWindowImpl::Show
    ///
    ////////////////////////////////////////////////////////////
    virtual void Show(bool State);

    ////////////////////////////////////////////////////////////
    /// /see sfWindowImpl::EnableKeyRepeat
    ///
    ////////////////////////////////////////////////////////////
    virtual void EnableKeyRepeat(bool Enabled);

    ////////////////////////////////////////////////////////////
    /// Register the window class
    ///
    ////////////////////////////////////////////////////////////
    void RegisterWindowClass();

    ////////////////////////////////////////////////////////////
    /// Switch to fullscreen mode
    ///
    /// \param Mode : video mode to switch to
    ///
    ////////////////////////////////////////////////////////////
    void SwitchToFullscreen(const VideoMode& Mode);

    ////////////////////////////////////////////////////////////
    /// Construct the context from graphics settings
    ///
    /// \param Mode :   Video mode
    /// \param Params : Creation settings
    ///
    ////////////////////////////////////////////////////////////
    void CreateContext(const VideoMode& Mode, WindowSettings& Params);

    ////////////////////////////////////////////////////////////
    /// Free all the graphical resources attached to the window
    ///
    ////////////////////////////////////////////////////////////
    void Cleanup();

    ////////////////////////////////////////////////////////////
    /// Process a Win32 event
    ///
    /// \param Message : Message to process
    /// \param WParam :  First parameter of the event
    /// \param LParam :  Second parameter of the event
    ///
    ////////////////////////////////////////////////////////////
    void ProcessEvent(UINT Message, WPARAM WParam, LPARAM LParam);

    ////////////////////////////////////////////////////////////
    /// Check the state of the shift keys on a key event,
    /// and return the corresponding SF key code
    ///
    /// \param KeyDown : True for a keydown event, false for a keyup event
    ///
    /// \return SFML key code corresponding to the shift key
    ///
    ////////////////////////////////////////////////////////////
    static Key::Code GetShiftState(bool KeyDown);

    ////////////////////////////////////////////////////////////
    /// Convert a Win32 virtual key code to a SFML key code
    ///
    /// \param VirtualKey : Virtual key code to convert
    /// \param Flags :      Additional flags
    ///
    /// \return SFML key code corresponding to VirtualKey
    ///
    ////////////////////////////////////////////////////////////
    static Key::Code VirtualKeyCodeToSF(WPARAM VirtualKey, LPARAM Flags);

    ////////////////////////////////////////////////////////////
    /// Check if the current version of the OS supports unicode
    /// messages and functions ; Windows 95/98/Me may not support
    /// it, whereas Windows NT/2000/XP/Vista will
    ///
    /// \return True if the OS supports unicode
    ///
    ////////////////////////////////////////////////////////////
    static bool HasUnicodeSupport();

    ////////////////////////////////////////////////////////////
    /// Function called whenever one of our windows receives a message
    ///
    /// \param Handle :  Win32 handle of the window
    /// \param Message : Message received
    /// \param WParam :  First parameter of the message
    /// \param LParam :  Second parameter of the message
    ///
    /// \return Something...
    ///
    ////////////////////////////////////////////////////////////
    static LRESULT CALLBACK GlobalOnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam);

    ////////////////////////////////////////////////////////////
    // Static member data
    ////////////////////////////////////////////////////////////
    static unsigned int     ourWindowCount;      ///< Number of windows that we own
    static const char*      ourClassNameA;       ///< Win32 window class name (ANSI version)
    static const wchar_t*   ourClassNameW;       ///< Win32 window class name (unicode version)
    static WindowImplWin32* ourFullscreenWindow; ///< Window currently in fullscreen

    ////////////////////////////////////////////////////////////
    // Member data
    ////////////////////////////////////////////////////////////
    HWND          myHandle;           ///< Win32 handle of the window
    long          myCallback;         ///< Stores the original event callback function of the control
    HCURSOR       myCursor;           ///< The system cursor to display into the window
    bool          myKeyRepeatEnabled; ///< Automatic key-repeat state for keydown events
    HDC           myDeviceContext;    ///< HDC associated to the window
    HGLRC         myGLContext;        ///< OpenGL rendering context associated to the HDC
};

} // namespace priv

} // namespace sf

#endif // SFML_WINDOWIMPLWIN32_HPP