-
Notifications
You must be signed in to change notification settings - Fork 0
/
Window.cpp
51 lines (41 loc) · 1.3 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
#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;
m_window.setFramerateLimit(60);
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);
}
void Window::Destroy(){
m_window.close();
}
void Window::BeginDraw(){ m_window.clear(sf::Color::Black); }
void Window::EndDraw(){ m_window.display(); }
bool Window::IsDone(){ return m_isDone; }
bool Window::IsFullscreen(){ return m_isFullscreen; }
void Window::Draw(sf::Drawable& l_drawable){
m_window.draw(l_drawable);
}
sf::Vector2u Window::GetWindowSize(){ return m_windowSize; }
void Window::ToggleFullscreen(){
m_isFullscreen = !m_isFullscreen;
Destroy();
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::F5){ ToggleFullscreen(); }
}
}