-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cpp
74 lines (56 loc) · 1.08 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
71
72
73
74
#include "Window.h"
Window::Window(const std::string& title, uint width, uint height)
: bDone_(false)
{
Setup(title, sf::Vector2u(width, height));
}
Window::~Window()
{
Destroy();
}
void Window::Setup(const std::string& title, const sf::Vector2u& size)
{
title_ = title;
size_ = size;
renderWindow.setTitle(title_);
renderWindow.setSize(size_);
renderWindow.setFramerateLimit(60);
Create();
}
void Window::Update()
{
sf::Event event;
while (renderWindow.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
bDone_ = true;
}
if ((event.type == sf::Event::KeyPressed) &&
(event.key.code == sf::Keyboard::Escape))
{
bDone_ = true;
}
}
}
void Window::BeginDraw()
{
renderWindow.clear(sf::Color::White);
}
void Window::EndDraw()
{
renderWindow.display();
}
void Window::Draw(const sf::Drawable& drawable)
{
renderWindow.draw(drawable);
}
void Window::Create()
{
auto style = (m_isFullscreen ? sf::Style::Fullscreen : sf::Style::Default);
renderWindow.create({size_.x, size_.y, 32}, title_, style);
}
void Window::Destroy()
{
renderWindow.close();
}