SFML 3.0.1
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-2025 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
30#include <SFML/Window/Export.hpp>
31
32#include <SFML/Window/Vulkan.hpp>
33#include <SFML/Window/WindowEnums.hpp>
34#include <SFML/Window/WindowHandle.hpp>
35
36#include <SFML/System/Time.hpp>
37#include <SFML/System/Vector2.hpp>
38
39#include <memory>
40#include <optional>
41
42#include <cstdint>
43
44
45 namespace sf
46{
47 class Cursor;
48 class String;
49 class VideoMode;
50
51 namespace priv
52{
53 class WindowImpl;
54}
55
56 class Event;
57
62 class SFML_WINDOW_API WindowBase
63{
64 public:
72 WindowBase();
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
137 WindowBase(WindowBase&&) noexcept;
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
172 virtual void create(VideoMode mode, const String& title, State state);
173
180 virtual void create(WindowHandle handle);
181
192 virtual void close();
193
204 [[nodiscard]] bool isOpen() const;
205
226 [[nodiscard]] std::optional<Event> pollEvent();
227
252 [[nodiscard]] std::optional<Event> waitEvent(Time timeout = Time::Zero);
253
329 template <typename... Handlers>
330 void handleEvents(Handlers&&... handlers);
331
340 [[nodiscard]] Vector2i getPosition() const;
341
354 void setPosition(Vector2i position);
355
367 [[nodiscard]] Vector2u getSize() const;
368
377 void setSize(Vector2u size);
378
387 void setMinimumSize(const std::optional<Vector2u>& minimumSize);
388
397 void setMaximumSize(const std::optional<Vector2u>& maximumSize);
398
407 void setTitle(const String& title);
408
425 void setIcon(Vector2u size, const std::uint8_t* pixels);
426
435 void setVisible(bool visible);
436
448 void setMouseCursorVisible(bool visible);
449
461 void setMouseCursorGrabbed(bool grabbed);
462
479 void setMouseCursor(const Cursor& cursor);
480
493 void setKeyRepeatEnabled(bool enabled);
494
506 void setJoystickThreshold(float threshold);
507
522 void requestFocus();
523
535 [[nodiscard]] bool hasFocus() const;
536
549 [[nodiscard]] WindowHandle getNativeHandle() const;
550
561 [[nodiscard]] bool createVulkanSurface(const VkInstance& instance,
562 VkSurfaceKHR& surface,
563 const VkAllocationCallbacks* allocator = nullptr);
564
565protected:
574 virtual void onCreate();
575
583 virtual void onResize();
584
585private:
586 friend class Window;
587
600 void filterEvent(const Event& event);
601
606 void initialize();
607
609 // Member data
611 std::unique_ptr<priv::WindowImpl> m_impl;
612 Vector2u m_size;
613};
614
615} // namespace sf
616
617#include <SFML/Window/WindowBase.inl>
618
Time.hpp
Vector2.hpp
Vulkan.hpp
VkInstance
struct VkInstance_T * VkInstance
Definition Vulkan.hpp:35
VkSurfaceKHR
std::uint64_t VkSurfaceKHR
Definition Vulkan.hpp:47
WindowEnums.hpp
WindowHandle.hpp
Export.hpp
SFML_WINDOW_API
#define SFML_WINDOW_API
Definition Window/Export.hpp:42
sf::Cursor
Cursor defines the appearance of a system cursor.
Definition Cursor.hpp:51
sf::Event
Defines a system event and its parameters.
Definition Event.hpp:48
sf::String
Utility string class that automatically handles conversions between types and encodings.
Definition String.hpp:89
sf::Time
Represents a time value.
Definition Time.hpp:42
sf::VideoMode
VideoMode defines a video mode (size, bpp)
Definition VideoMode.hpp:44
sf::WindowBase::setMouseCursorGrabbed
void setMouseCursorGrabbed(bool grabbed)
Grab or release the mouse cursor.
sf::WindowBase::setMouseCursor
void setMouseCursor(const Cursor &cursor)
Set the displayed cursor to a native system cursor.
sf::WindowBase::setIcon
void setIcon(Vector2u size, const std::uint8_t *pixels)
Change the window's icon.
sf::WindowBase::WindowBase
WindowBase()
Default constructor.
sf::WindowBase::handleEvents
void handleEvents(Handlers &&... handlers)
Handle all pending events.
sf::WindowBase::createVulkanSurface
bool createVulkanSurface(const VkInstance &instance, VkSurfaceKHR &surface, const VkAllocationCallbacks *allocator=nullptr)
Create a Vulkan rendering surface.
sf::WindowBase::getSize
Vector2u getSize() const
Get the size of the rendering region of the window.
sf::WindowBase::onCreate
virtual void onCreate()
Function called after the window has been created.
sf::WindowBase::requestFocus
void requestFocus()
Request the current window to be made the active foreground window.
sf::WindowBase::WindowBase
WindowBase(VideoMode mode, const String &title, State state)
Construct a new window.
sf::WindowBase::WindowBase
WindowBase(const WindowBase &)=delete
Deleted copy constructor.
sf::WindowBase::Window
friend class Window
Definition WindowBase.hpp:586
sf::WindowBase::setVisible
void setVisible(bool visible)
Show or hide the window.
sf::WindowBase::getPosition
Vector2i getPosition() const
Get the position of the window.
sf::WindowBase::pollEvent
std::optional< Event > pollEvent()
Pop the next event from the front of the FIFO event queue, if any, and return it.
sf::WindowBase::create
virtual void create(VideoMode mode, const String &title, std::uint32_t style=Style::Default, State state=State::Windowed)
Create (or recreate) the window.
sf::WindowBase::setMaximumSize
void setMaximumSize(const std::optional< Vector2u > &maximumSize)
Set the maximum window rendering region size.
sf::WindowBase::setPosition
void setPosition(Vector2i position)
Change the position of the window on screen.
sf::WindowBase::setMinimumSize
void setMinimumSize(const std::optional< Vector2u > &minimumSize)
Set the minimum window rendering region size.
sf::WindowBase::~WindowBase
virtual ~WindowBase()
Destructor.
sf::WindowBase::onResize
virtual void onResize()
Function called after the window has been resized.
sf::WindowBase::close
virtual void close()
Close the window and destroy all the attached resources.
sf::WindowBase::isOpen
bool isOpen() const
Tell whether or not the window is open.
sf::WindowBase::WindowBase
WindowBase(WindowHandle handle)
Construct the window from an existing control.
sf::WindowBase::waitEvent
std::optional< Event > waitEvent(Time timeout=Time::Zero)
Wait for an event and return it.
sf::WindowBase::setSize
void setSize(Vector2u size)
Change the size of the rendering region of the window.
sf::WindowBase::setTitle
void setTitle(const String &title)
Change the title of the window.
sf::WindowBase::setJoystickThreshold
void setJoystickThreshold(float threshold)
Change the joystick threshold.
sf::WindowBase::hasFocus
bool hasFocus() const
Check whether the window has the input focus.
sf::WindowBase::WindowBase
WindowBase(VideoMode mode, const String &title, std::uint32_t style=Style::Default, State state=State::Windowed)
Construct a new window.
sf::WindowBase::WindowBase
WindowBase(WindowBase &&) noexcept
Move constructor.
sf::WindowBase::getNativeHandle
WindowHandle getNativeHandle() const
Get the OS-specific handle of the window.
sf::WindowBase::setMouseCursorVisible
void setMouseCursorVisible(bool visible)
Show or hide the mouse cursor.
sf::WindowBase::operator=
WindowBase & operator=(const WindowBase &)=delete
Deleted copy assignment.
sf::WindowBase::setKeyRepeatEnabled
void setKeyRepeatEnabled(bool enabled)
Enable or disable automatic key-repeat.
sf::State
State
Enumeration of the window states.
Definition WindowEnums.hpp:55
sf::WindowHandle
"platform-specific" WindowHandle
Low-level window handle type, specific to each platform.
Definition WindowHandle.hpp:68
sf::State::Windowed
@ Windowed
Floating window.
Definition WindowEnums.hpp:56
sf::Style::Default
@ Default
Default window style.
Definition WindowEnums.hpp:44
sf::Style
Definition WindowEnums.hpp:31
sf
Definition AudioResource.hpp:36
sf::StencilUpdateOperation::Zero
@ Zero
If the stencil test passes, the value in the stencil buffer is set to zero.
Definition StencilMode.hpp:63
sf::Vector2u
Vector2< unsigned int > Vector2u
Definition Vector2.hpp:209
sf::Vector2i
Vector2< int > Vector2i
Definition Vector2.hpp:208