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
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... Ts>
330 void handleEvents(Ts&&... 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
445 void setMouseCursorVisible(bool visible);
446
458 void setMouseCursorGrabbed(bool grabbed);
459
476 void setMouseCursor(const Cursor& cursor);
477
490 void setKeyRepeatEnabled(bool enabled);
491
503 void setJoystickThreshold(float threshold);
504
519 void requestFocus();
520
532 [[nodiscard]] bool hasFocus() const;
533
546 [[nodiscard]] WindowHandle getNativeHandle() const;
547
558 [[nodiscard]] bool createVulkanSurface(const VkInstance& instance,
559 VkSurfaceKHR& surface,
560 const VkAllocationCallbacks* allocator = nullptr);
561
562protected:
571 virtual void onCreate();
572
580 virtual void onResize();
581
582private:
583 friend class Window;
584
597 void filterEvent(const Event& event);
598
603 void initialize();
604
606 // Member data
608 std::unique_ptr<priv::WindowImpl> m_impl;
609 Vector2u m_size;
610};
611
612} // namespace sf
613
614#include <SFML/Window/WindowBase.inl>
615
struct VkInstance_T * VkInstance
Definition Vulkan.hpp:35
std::uint64_t VkSurfaceKHR
Definition Vulkan.hpp:47
#define SFML_WINDOW_API
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 (size, bpp)
Definition VideoMode.hpp:44
Window that serves as a base for other windows.
WindowBase()
Default constructor.
WindowBase(VideoMode mode, const String &title, State state)
Construct a new window.
WindowBase(const WindowBase &)=delete
Deleted copy constructor.
virtual ~WindowBase()
Destructor.
WindowBase(WindowHandle handle)
Construct the window from an existing control.
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.
WindowBase & operator=(const WindowBase &)=delete
Deleted copy assignment.
Window that serves as a target for OpenGL rendering.
State
Enumeration of the window states.
"platform-specific" WindowHandle
Low-level window handle type, specific to each platform.