SFML
Simple and Fast Multimedia Library
Loading...
Searching...
No Matches
WindowBase.hpp
Go to the documentation of this file.
1
2//
3// SFML - Simple and Fast Multimedia Library
4// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
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#pragma once
26
28// Headers
31
35
36#include <SFML/System/Time.hpp>
38
39#include <memory>
40#include <optional>
41
42#include <cstdint>
43
44
45namespace sf
46{
47class Cursor;
48class String;
49class VideoMode;
50
51namespace priv
52{
53class WindowImpl;
54}
55
56class Event;
57
63{
64public:
73
90 WindowBase(VideoMode mode, const String& title, std::uint32_t style = Style::Default, State state = State::Windowed);
91
103 WindowBase(VideoMode mode, const String& title, State state);
104
111 explicit WindowBase(WindowHandle handle);
112
119 virtual ~WindowBase();
120
125 WindowBase(const WindowBase&) = delete;
126
131 WindowBase& operator=(const WindowBase&) = delete;
132
138
143 WindowBase& operator=(WindowBase&&) noexcept;
144
158 virtual void create(VideoMode mode, const String& title, std::uint32_t style = Style::Default, State state = State::Windowed);
159
166 virtual void create(WindowHandle handle);
167
178 virtual void close();
179
190 [[nodiscard]] bool isOpen() const;
191
212 [[nodiscard]] std::optional<Event> pollEvent();
213
238 [[nodiscard]] std::optional<Event> waitEvent(Time timeout = Time::Zero);
239
315 template <typename... Ts>
316 void handleEvents(Ts&&... handlers);
317
326 [[nodiscard]] Vector2i getPosition() const;
327
340 void setPosition(Vector2i position);
341
353 [[nodiscard]] Vector2u getSize() const;
354
363 void setSize(Vector2u size);
364
373 void setMinimumSize(const std::optional<Vector2u>& minimumSize);
374
383 void setMaximumSize(const std::optional<Vector2u>& maximumSize);
384
393 void setTitle(const String& title);
394
411 void setIcon(Vector2u size, const std::uint8_t* pixels);
412
421 void setVisible(bool visible);
422
431 void setMouseCursorVisible(bool visible);
432
444 void setMouseCursorGrabbed(bool grabbed);
445
463 void setMouseCursor(const Cursor& cursor);
464
477 void setKeyRepeatEnabled(bool enabled);
478
490 void setJoystickThreshold(float threshold);
491
507
519 [[nodiscard]] bool hasFocus() const;
520
533 [[nodiscard]] WindowHandle getNativeHandle() const;
534
545 [[nodiscard]] bool createVulkanSurface(const VkInstance& instance,
546 VkSurfaceKHR& surface,
547 const VkAllocationCallbacks* allocator = nullptr);
548
549protected:
558 virtual void onCreate();
559
567 virtual void onResize();
568
569private:
570 friend class Window;
571
584 void filterEvent(const Event& event);
585
590 void initialize();
591
593 // Member data
595 std::unique_ptr<priv::WindowImpl> m_impl;
596 Vector2u m_size;
597};
598
599} // namespace sf
600
601#include <SFML/Window/WindowBase.inl>
602
struct VkInstance_T * VkInstance
Definition Vulkan.hpp:35
std::uint64_t VkSurfaceKHR
Definition Vulkan.hpp:47
#define SFML_WINDOW_API
Definition Export.hpp:42
Cursor defines the appearance of a system cursor.
Definition Cursor.hpp:51
Defines a system event and its parameters.
Definition Event.hpp:47
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:89
Represents a time value.
Definition Time.hpp:42
VideoMode defines a video mode (width, height, bpp).
Definition VideoMode.hpp:44
void setMouseCursorGrabbed(bool grabbed)
Grab or release the mouse cursor.
void setMouseCursor(const Cursor &cursor)
Set the displayed cursor to a native system cursor.
void setIcon(Vector2u size, const std::uint8_t *pixels)
Change the window's icon.
WindowBase()
Default constructor.
bool createVulkanSurface(const VkInstance &instance, VkSurfaceKHR &surface, const VkAllocationCallbacks *allocator=nullptr)
Create a Vulkan rendering surface.
Vector2u getSize() const
Get the size of the rendering region of the window.
virtual void onCreate()
Function called after the window has been created.
void requestFocus()
Request the current window to be made the active foreground window.
WindowBase(VideoMode mode, const String &title, State state)
Construct a new window.
WindowBase(const WindowBase &)=delete
Deleted copy constructor.
friend class Window
Definition WindowBase.hpp:570
void setVisible(bool visible)
Show or hide the window.
Vector2i getPosition() const
Get the position of the window.
std::optional< Event > pollEvent()
Pop the next event from the front of the FIFO event queue, if any, and return it.
virtual void create(VideoMode mode, const String &title, std::uint32_t style=Style::Default, State state=State::Windowed)
Create (or recreate) the window.
void setMaximumSize(const std::optional< Vector2u > &maximumSize)
Set the maximum window rendering region size.
void setPosition(Vector2i position)
Change the position of the window on screen.
void setMinimumSize(const std::optional< Vector2u > &minimumSize)
Set the minimum window rendering region size.
virtual ~WindowBase()
Destructor.
virtual void onResize()
Function called after the window has been resized.
virtual void close()
Close the window and destroy all the attached resources.
bool isOpen() const
Tell whether or not the window is open.
WindowBase(WindowHandle handle)
Construct the window from an existing control.
std::optional< Event > waitEvent(Time timeout=Time::Zero)
Wait for an event and return it.
void setSize(Vector2u size)
Change the size of the rendering region of the window.
void setTitle(const String &title)
Change the title of the window.
void setJoystickThreshold(float threshold)
Change the joystick threshold.
void handleEvents(Ts &&... handlers)
Handle all pending events.
bool hasFocus() const
Check whether the window has the input focus.
WindowBase(VideoMode mode, const String &title, std::uint32_t style=Style::Default, State state=State::Windowed)
Construct a new window.
WindowBase(WindowBase &&) noexcept
Move constructor.
WindowHandle getNativeHandle() const
Get the OS-specific handle of the window.
void setMouseCursorVisible(bool visible)
Show or hide the mouse cursor.
WindowBase & operator=(const WindowBase &)=delete
Deleted copy assignment.
void setKeyRepeatEnabled(bool enabled)
Enable or disable automatic key-repeat.
Definition WindowEnums.hpp:31
@ Default
Default window style.
Definition WindowEnums.hpp:44
Definition Glsl.hpp:39
Definition BlendMode.hpp:34
State
Enumeration of the window states.
Definition WindowEnums.hpp:55
@ Windowed
Floating window.
Definition WindowEnums.hpp:56
Vector2< unsigned int > Vector2u
Definition Vector2.hpp:225
Vector2< int > Vector2i
Definition Vector2.hpp:224