28#include <SFML/Window/Window.hpp>
29#include <SFML/Window/Context.hpp>
30#include <SFML/Window/WindowImpl.hpp>
31#include <SFML/System/Sleep.hpp>
54mySetCursorPosX (0xFFFF),
55mySetCursorPosY (0xFFFF)
69mySetCursorPosX (0xFFFF),
70mySetCursorPosY (0xFFFF)
72 Create(Mode, Title, WindowStyle, Params);
84mySetCursorPosX (0xFFFF),
85mySetCursorPosY (0xFFFF)
113 if (FullscreenWindow)
115 std::cerr <<
"Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl;
116 WindowStyle &=
~Style::Fullscreen;
123 std::cerr <<
"The requested video mode is not available, switching to a valid mode" << std::endl;
128 FullscreenWindow =
this;
140 Initialize(priv::WindowImpl::New(Mode, Title, WindowStyle, mySettings));
156 Initialize(priv::WindowImpl::New(Handle, mySettings));
172 if (
this == FullscreenWindow)
173 FullscreenWindow = NULL;
184 return myWindow != NULL;
193 return myWindow ? myWindow->GetWidth() : 0;
202 return myWindow ? myWindow->GetHeight() : 0;
221 if (myWindow && myEvents.empty())
222 myWindow->DoEvents();
225 if (!myEvents.empty())
227 EventReceived = myEvents.front();
243 myWindow->UseVerticalSync(Enabled);
253 myWindow->ShowMouseCursor(
Show);
265 mySetCursorPosX = Left;
266 mySetCursorPosY = Top;
268 myWindow->SetCursorPosition(Left, Top);
281 myWindow->SetPosition(Left, Top);
285 std::cerr <<
"Warning : trying to change the position of an external SFML window, which is not allowed" << std::endl;
296 myWindow->SetSize(Width, Height);
308 myWindow->Show(State);
320 myWindow->EnableKeyRepeat(Enabled);
330 myWindow->SetIcon(Width, Height, Pixels);
342 myWindow->SetActive(Active);
356 if (myFramerateLimit > 0)
358 float RemainingTime = 1.f / myFramerateLimit - myClock.GetElapsedTime();
359 if (RemainingTime > 0)
360 Sleep(RemainingTime);
364 myLastFrameTime = myClock.GetElapsedTime();
387 myFramerateLimit = Limit;
396 return myLastFrameTime;
407 myWindow->SetJoystickThreshold(Threshold);
414void Window::OnCreate()
423void Window::OnEvent(
const Event& EventReceived)
426 if ((EventReceived.Type == Event::MouseMoved) &&
427 (EventReceived.MouseMove.X == mySetCursorPosX) &&
428 (EventReceived.MouseMove.Y == mySetCursorPosY))
430 mySetCursorPosX = 0xFFFF;
431 mySetCursorPosY = 0xFFFF;
435 myEvents.push(EventReceived);
442void Window::Initialize(priv::WindowImpl*
Window)
446 myWindow->Initialize();
449 while (!myEvents.empty())
453 myWindow->AddListener(
this);
454 myWindow->AddListener(&myInput);
464 myLastFrameTime = 0.f;
static Context & GetGlobal()
Get the global context.
void SetActive(bool Active)
Activate or deactivate the context.
Event defines a system event and its parameters.
VideoMode defines a video mode (width, height, bpp, frequency) and provides static functions for gett...
static VideoMode GetMode(std::size_t Index)
Get a valid video mode Index must be in range [0, GetModesCount()[ Modes are sorted from best to wors...
Window is a rendering window ; it can create a new window or connect to an existing one.
const Input & GetInput() const
Get the input manager of the window.
unsigned int GetWidth() const
Get the width of the rendering region of the window.
void SetCursorPosition(unsigned int Left, unsigned int Top)
Change the position of the mouse cursor.
void SetIcon(unsigned int Width, unsigned int Height, const Uint8 *Pixels)
Change the window's icon.
void SetPosition(int Left, int Top)
Change the position of the window on screen.
void EnableKeyRepeat(bool Enabled)
Enable or disable automatic key-repeat.
float GetFrameTime() const
Get time elapsed since last frame.
Window()
Default constructor.
void SetFramerateLimit(unsigned int Limit)
Limit the framerate to a maximum fixed frequency.
void ShowMouseCursor(bool Show)
Show or hide the mouse cursor.
bool GetEvent(Event &EventReceived)
Get the event on top of events stack, if any, and pop it.
virtual ~Window()
Destructor.
void Show(bool State)
Show or hide the window.
bool SetActive(bool Active=true) const
Activate of deactivate the window as the current target for rendering.
void Create(VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings())
Create (or recreate) the window.
void Close()
Close (destroy) the window.
unsigned int GetHeight() const
Get the height of the rendering region of the window.
void UseVerticalSync(bool Enabled)
Enable / disable vertical synchronization.
void SetJoystickThreshold(float Threshold)
Change the joystick threshold, ie.
void SetSize(unsigned int Width, unsigned int Height)
Change the size of the rendering region of the window.
bool IsOpened() const
Tell whether or not the window is opened (ie.
void Display()
Display the window on screen.
const WindowSettings & GetSettings() const
Get the creation settings of the window.
Enumeration of window creation styles.
@ Fullscreen
Fullscreen mode (this flag and all others are mutually exclusive).
@ Titlebar
Title bar + fixed border.
@ Resize
Titlebar + resizable border + maximize button.
@ Close
Titlebar + close button.
Structure defining the creation settings of windows.