28 #include <SFML/Window/Window.hpp>
29 #include <SFML/Window/Context.hpp>
30 #include <SFML/Window/WindowImpl.hpp>
31 #include <SFML/System/Sleep.hpp>
51 myLastFrameTime (0.f),
54 mySetCursorPosX (0xFFFF),
55 mySetCursorPosY (0xFFFF)
66 myLastFrameTime (0.f),
69 mySetCursorPosX (0xFFFF),
70 mySetCursorPosY (0xFFFF)
72 Create(Mode, Title, WindowStyle, Params);
81 myLastFrameTime (0.f),
84 mySetCursorPosX (0xFFFF),
85 mySetCursorPosY (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);
387 myFramerateLimit = Limit;
396 return myLastFrameTime;
407 myWindow->SetJoystickThreshold(Threshold);
414 void Window::OnCreate()
423 void 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);
442 void Window::Initialize(priv::WindowImpl* Window)
446 myWindow->Initialize();
449 while (!myEvents.empty())
453 myWindow->AddListener(
this);
454 myWindow->AddListener(&myInput);
464 myLastFrameTime = 0.f;
Titlebar + resizable border + maximize button.
void EnableKeyRepeat(bool Enabled)
Enable or disable automatic key-repeat.
Title bar + fixed border.
Window()
Default constructor.
Structure defining the creation settings of windows.
unsigned int GetWidth() const
Get the width of the rendering region of the window.
virtual ~Window()
Destructor.
bool IsValid() const
Tell whether or not the video mode is supported.
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...
float GetFrameTime() const
Get time elapsed since last frame.
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.
bool IsOpened() const
Tell whether or not the window is opened (ie.
static Context & GetGlobal()
Get the global context.
VideoMode defines a video mode (width, height, bpp, frequency) and provides static functions for gett...
void UseVerticalSync(bool Enabled)
Enable / disable vertical synchronization.
Fullscreen mode (this flag and all others are mutually exclusive)
bool GetEvent(Event &EventReceived)
Get the event on top of events stack, if any, and pop it.
bool SetActive(bool Active=true) const
Activate of deactivate the window as the current target for rendering.
void SetFramerateLimit(unsigned int Limit)
Limit the framerate to a maximum fixed frequency.
float GetElapsedTime() const
Get the time elapsed since last reset.
void Close()
Close (destroy) the window.
unsigned int GetHeight() const
Get the height of the rendering region of the window.
void Display()
Display the window on screen.
const WindowSettings & GetSettings() const
Get the creation settings of the window.
void SetSize(unsigned int Width, unsigned int Height)
Change the size of the rendering region of the window.
Window is a rendering window ; it can create a new window or connect to an existing one...
void Reset()
Restart the timer.
void SetActive(bool Active)
Activate or deactivate the context.
void SetCursorPosition(unsigned int Left, unsigned int Top)
Change the position of the mouse cursor.
void Show(bool State)
Show or hide the window.
void SetJoystickThreshold(float Threshold)
Change the joystick threshold, ie.
void ShowMouseCursor(bool Show)
Show or hide the mouse cursor.
void Create(VideoMode Mode, const std::string &Title, unsigned long WindowStyle=Style::Resize|Style::Close, const WindowSettings &Params=WindowSettings())
Create (or recreate) the window.
Event defines a system event and its parameters.
const Input & GetInput() const
Get the input manager of the window.