PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
window.h
1#pragma once
2
3#include "pixelbullet/core/event.h"
4
5#include "pixelbullet/input/input.h"
6#include "pixelbullet/window/window_chrome.h"
7#include "pixelbullet/window/window_config.h"
8
9#include <glm/glm.hpp>
10
11#include <cstdint>
12#include <functional>
13#include <memory>
14#include <optional>
15#include <string>
16#include <string_view>
17
18namespace pixelbullet
19{
20namespace window_internal
21{
22struct WindowAccess;
23struct WindowState;
24} // namespace window_internal
25
26class Filesystem;
27class VirtualPath;
28
29class Window final
30{
31public:
32 enum class WindowState
33 {
34 Normal,
35 Minimized,
36 Maximized
37 };
38
39 explicit Window(WindowConfig config);
40 ~Window();
41
43 void OnUpdate() noexcept;
44
46 void SetIcon(const Filesystem& filesystem, const VirtualPath& iconPath);
47
49 unsigned int GetWidth() const noexcept;
50 unsigned int GetHeight() const noexcept;
51 glm::ivec2 GetSize() const noexcept;
52 glm::ivec2 GetPosition() const noexcept;
53 glm::vec2 GetContentScale() const noexcept;
54 unsigned int GetFramebufferWidth() const noexcept;
55 unsigned int GetFramebufferHeight() const noexcept;
56 glm::ivec2 GetFramebufferSize() const noexcept;
57
59 void SetEventCallback(const std::function<void(pixelbullet::core::Event&)>& callback);
60 void SetFramebufferResizeCallback(const std::function<void(uint32_t)>& callback);
61
62 [[nodiscard]] const pixelbullet::input::InputState& GetInputState() const noexcept;
63
64 [[nodiscard]] bool IsKeyDown(pixelbullet::input::KeyCode key) const noexcept;
65
67 void Minimize() noexcept;
68
70 void Maximize() noexcept;
71
73 void Restore() noexcept;
74
76 void RequestClose() noexcept;
77
79 [[nodiscard]] bool SetClipboardText(std::string_view text);
80
82 [[nodiscard]] std::optional<std::string> GetClipboardText() const;
83
85 void ShowSystemMenuAt(const WindowPoint& client_point) noexcept;
86
88 [[nodiscard]] bool SupportsCustomChrome() const noexcept;
89
91 void SetCustomChromeLayout(const WindowChromeLayout& layout);
92
95
97 void SetCursorCaptured(bool captured) noexcept;
98
100 [[nodiscard]] bool IsCursorCaptured() const noexcept;
101
103 bool IsMinimized() const noexcept;
104
106 bool IsFocused() const noexcept;
107
109 bool IsMaximized() const noexcept;
110
112 WindowState GetWindowState() const noexcept;
113
114private:
115 void Init(const WindowConfig& config);
116 void Shutdown();
117
118 friend struct window_internal::WindowAccess;
119
120private:
121 std::unique_ptr<window_internal::WindowState> state_;
122};
123} // namespace pixelbullet
Definition filesystem.h:19
Definition virtual_path.h:10
WindowState GetWindowState() const noexcept
Returns the current window state.
Definition window.cc:188
void RequestClose() noexcept
Requests application shutdown through the normal window-close event path.
Definition window.cc:128
void Maximize() noexcept
Maximizes the window.
Definition window.cc:118
bool IsFocused() const noexcept
Returns whether the window currently has focus.
Definition window.cc:178
void ShowSystemMenuAt(const WindowPoint &client_point) noexcept
Shows the native window system menu anchored at the given client-space point.
Definition window.cc:143
std::optional< std::string > GetClipboardText() const
Returns the OS clipboard text for this window when available.
Definition window.cc:138
void SetCustomChromeLayout(const WindowChromeLayout &layout)
Stores draggable caption regions for custom chrome windows.
Definition window.cc:153
void SetEventCallback(const std::function< void(pixelbullet::core::Event &)> &callback)
Sets the callback that will be invoked when events occur.
Definition window.cc:88
bool SetClipboardText(std::string_view text)
Sets the OS clipboard text for this window.
Definition window.cc:133
void Restore() noexcept
Restores the window from a minimized or maximized state.
Definition window.cc:123
bool IsCursorCaptured() const noexcept
Returns whether the window is currently capturing the cursor.
Definition window.cc:168
void ClearCustomChromeLayout()
Clears the currently stored custom chrome layout.
Definition window.cc:158
void SetCursorCaptured(bool captured) noexcept
Captures the OS cursor for relative first-person input.
Definition window.cc:163
void SetIcon(const Filesystem &filesystem, const VirtualPath &iconPath)
Sets the window icon from an image file.
Definition window.cc:108
unsigned int GetWidth() const noexcept
Accessors for window size.
Definition window.cc:39
bool SupportsCustomChrome() const noexcept
Returns whether the current platform backend supports custom chrome.
Definition window.cc:148
bool IsMaximized() const noexcept
Returns whether the window is currently maximized.
Definition window.cc:183
void OnUpdate() noexcept
Polls for and processes events.
Definition window.cc:33
void Minimize() noexcept
Minimizes the window.
Definition window.cc:113
bool IsMinimized() const noexcept
Returns whether the window is currently minimized.
Definition window.cc:173
Definition event.h:108
Definition input.h:20
Definition window_chrome.h:34
Definition window_config.h:11
Definition window_chrome.h:28
Definition window_internal.h:111
Definition window_internal.h:37