Window/Window.hpp
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//
24
25#ifndef SFML_WINDOW_HPP
26#define SFML_WINDOW_HPP
27
29// Headers
31#include <SFML/Window/Event.hpp>
32#include <SFML/Window/Input.hpp>
33#include <SFML/Window/VideoMode.hpp>
34#include <SFML/Window/WindowHandle.hpp>
35#include <SFML/Window/WindowListener.hpp>
36#include <SFML/Window/WindowSettings.hpp>
37#include <SFML/Window/WindowStyle.hpp>
38#include <SFML/System/Clock.hpp>
39#include <SFML/System/NonCopyable.hpp>
40#include <queue>
41#include <string>
42
43
44namespace sf
45{
46namespace priv
47{
48 class WindowImpl;
49}
50
55class SFML_API Window : public WindowListener, NonCopyable
56{
57public :
58
63 Window();
64
74 Window(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());
75
83 Window(WindowHandle Handle, const WindowSettings& Params = WindowSettings());
84
89 virtual ~Window();
90
100 void Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());
101
109 void Create(WindowHandle Handle, const WindowSettings& Params = WindowSettings());
110
117 void Close();
118
127 bool IsOpened() const;
128
135 unsigned int GetWidth() const;
136
143 unsigned int GetHeight() const;
144
151 const WindowSettings& GetSettings() const;
152
161 bool GetEvent(Event& EventReceived);
162
169 void UseVerticalSync(bool Enabled);
170
177 void ShowMouseCursor(bool Show);
178
186 void SetCursorPosition(unsigned int Left, unsigned int Top);
187
196 void SetPosition(int Left, int Top);
197
205 void SetSize(unsigned int Width, unsigned int Height);
206
213 void Show(bool State);
214
222 void EnableKeyRepeat(bool Enabled);
223
232 void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels);
233
243 bool SetActive(bool Active = true) const;
244
249 void Display();
250
257 const Input& GetInput() const;
258
265 void SetFramerateLimit(unsigned int Limit);
266
273 float GetFrameTime() const;
274
282 void SetJoystickThreshold(float Threshold);
283
284private :
285
290 virtual void OnCreate();
291
298 virtual void OnEvent(const Event& EventReceived);
299
306 void Initialize(priv::WindowImpl* Impl);
307
309 // Member data
311 priv::WindowImpl* myWindow;
312 std::queue<Event> myEvents;
313 Input myInput;
314 Clock myClock;
315 WindowSettings mySettings;
316 float myLastFrameTime;
317 bool myIsExternal;
318 unsigned int myFramerateLimit;
319 int mySetCursorPosX;
320 int mySetCursorPosY;
321};
322
323} // namespace sf
324
325
326#endif // SFML_WINDOW_HPP
Clock is an utility class for manipulating time.
Definition Clock.hpp:40
Event defines a system event and its parameters.
Definition Event.hpp:198
Input handles real-time input from keyboard and mouse.
Definition Input.hpp:45
VideoMode defines a video mode (width, height, bpp, frequency) and provides static functions for gett...
Definition VideoMode.hpp:43
Base class for classes that want to receive events from a window (for internal use only).
const Input & GetInput() const
Get the input manager of the window.
Definition Window.cpp:376
unsigned int GetWidth() const
Get the width of the rendering region of the window.
Definition Window.cpp:191
void SetCursorPosition(unsigned int Left, unsigned int Top)
Change the position of the mouse cursor.
Definition Window.cpp:260
void SetIcon(unsigned int Width, unsigned int Height, const Uint8 *Pixels)
Change the window's icon.
Definition Window.cpp:327
void SetPosition(int Left, int Top)
Change the position of the window on screen.
Definition Window.cpp:276
void EnableKeyRepeat(bool Enabled)
Enable or disable automatic key-repeat.
Definition Window.cpp:317
float GetFrameTime() const
Get time elapsed since last frame.
Definition Window.cpp:394
Window()
Default constructor.
Definition Window.cpp:49
void SetFramerateLimit(unsigned int Limit)
Limit the framerate to a maximum fixed frequency.
Definition Window.cpp:385
void ShowMouseCursor(bool Show)
Show or hide the mouse cursor.
Definition Window.cpp:250
bool GetEvent(Event &EventReceived)
Get the event on top of events stack, if any, and pop it.
Definition Window.cpp:218
void Show(bool State)
Show or hide the window.
Definition Window.cpp:303
bool SetActive(bool Active=true) const
Activate of deactivate the window as the current target for rendering.
Definition Window.cpp:338
void Create(VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings())
Create (or recreate) the window.
Definition Window.cpp:104
void Close()
Close (destroy) the window.
Definition Window.cpp:165
unsigned int GetHeight() const
Get the height of the rendering region of the window.
Definition Window.cpp:200
void UseVerticalSync(bool Enabled)
Enable / disable vertical synchronization.
Definition Window.cpp:240
void SetJoystickThreshold(float Threshold)
Change the joystick threshold, ie.
Definition Window.cpp:404
void SetSize(unsigned int Width, unsigned int Height)
Change the size of the rendering region of the window.
Definition Window.cpp:293
bool IsOpened() const
Tell whether or not the window is opened (ie.
Definition Window.cpp:182
void Display()
Display the window on screen.
Definition Window.cpp:353
const WindowSettings & GetSettings() const
Get the creation settings of the window.
Definition Window.cpp:209
@ Resize
Titlebar + resizable border + maximize button.
@ Close
Titlebar + close button.
NonCopyable()
The default constructor won't be generated, so provide it.
Structure defining the creation settings of windows.