-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNullWindow.cpp
More file actions
144 lines (120 loc) · 2.44 KB
/
Copy pathNullWindow.cpp
File metadata and controls
144 lines (120 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
*
* @file NullWindow.cpp
* @author Gaspard Kirira
*
* Copyright 2026, Gaspard Kirira.
* All rights reserved.
* https://github.com/vixcpp/game
*
* Use of this source code is governed by a MIT license
* that can be found in the LICENSE file.
*
* Vix.cpp
*
*/
#include <vix/game/NullWindow.hpp>
#include <utility>
#include <vix/game/GameError.hpp>
namespace vix::game
{
GameBoolResult NullWindow::open(
const WindowConfig &config)
{
auto valid = config.validate();
if (!valid)
{
return valid.error();
}
title_ = config.title;
width_ = config.width;
height_ = config.height;
open_ = true;
close_requested_ = false;
events_.clear();
return true;
}
void NullWindow::close() noexcept
{
open_ = false;
close_requested_ = true;
}
std::vector<WindowEvent> NullWindow::poll_events()
{
std::vector<WindowEvent> out;
out.swap(events_);
return out;
}
void NullWindow::present()
{
}
bool NullWindow::open() const noexcept
{
return open_;
}
bool NullWindow::close_requested() const noexcept
{
return close_requested_;
}
const std::string &NullWindow::title() const noexcept
{
return title_;
}
void NullWindow::set_title(std::string value)
{
title_ = std::move(value);
}
std::uint32_t NullWindow::width() const noexcept
{
return width_;
}
std::uint32_t NullWindow::height() const noexcept
{
return height_;
}
void NullWindow::resize(
std::uint32_t width,
std::uint32_t height)
{
if (width == 0 || height == 0)
{
return;
}
width_ = width;
height_ = height;
events_.push_back(WindowEvent::resized(width_, height_));
}
const char *NullWindow::backend_name() const noexcept
{
return "null";
}
void *NullWindow::native_handle() noexcept
{
return nullptr;
}
const void *NullWindow::native_handle() const noexcept
{
return nullptr;
}
void NullWindow::push_event(WindowEvent event)
{
events_.push_back(event);
if (event.is_close_request())
{
close_requested_ = true;
}
if (event.type == WindowEventType::Resized)
{
if (event.width > 0 && event.height > 0)
{
width_ = event.width;
height_ = event.height;
}
}
}
void NullWindow::request_close()
{
close_requested_ = true;
events_.push_back(WindowEvent::close_requested());
}
} // namespace vix::game