-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cpp
70 lines (60 loc) · 1.52 KB
/
Window.cpp
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
#include "Window.h"
Window::Window() { Setup("Window", sf::Vector2u(640, 480)); }
Window::Window(const std::string &title, const sf::Vector2u &size) { Setup(title, size); }
Window::~Window() { Destroy(); }
void Window::Setup(const std::string title, const sf::Vector2u &size)
{
m_windowTitle = title;
m_windowSize = size;
m_isFullscreen = false;
m_isDone = false;
Create();
}
void Window::Create()
{
auto style = (m_isFullscreen ? sf::Style::Fullscreen
: sf::Style::Default);
m_window.create({m_windowSize.x, m_windowSize.y, 32},
m_windowTitle, style);
m_window.setFramerateLimit(60);
}
void Window::Destroy()
{
m_window.close();
m_isDone = true;
}
void Window::BeginDraw() { m_window.clear(sf::Color::White); }
void Window::EndDraw() { m_window.display(); }
bool Window::IsDone() { return m_isDone; }
bool Window::IsFullscreen() { return m_isFullscreen; }
sf::RenderWindow *Window::GetRenderWindow() { return &m_window; }
sf::Vector2u Window::GetWindowSize() { return m_windowSize; }
void Window::ToggleFullscreen()
{
m_isFullscreen = !m_isFullscreen;
m_window.close();
Create();
}
void Window::Update()
{
sf::Event event;
while (m_window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
m_isDone = true;
}
else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape)
{
m_isDone = true;
}
else if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::F5)
{
ToggleFullscreen();
}
}
}
bool Window::Active()
{
return m_window.hasFocus();
}