-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.cpp
65 lines (55 loc) · 1.49 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
#include "Window.h"
GameWindow::GameWindow(sf::VideoMode mode, const sf::String& title, sf::Uint32 style)
: m_title(title)
{
m_windowedSize = { mode.width, mode.height };
m_isFullscreen = style == sf::Style::Fullscreen;
create(mode, title, style);
setFramerateLimit(70);
setKeyRepeatEnabled(false);
}
void GameWindow::toggleFullscreen()
{
if (m_isFullscreen) {
create(sf::VideoMode(getWindowedSize().x, getWindowedSize().y), m_title, sf::Style::Default);
}
else {
create(sf::VideoMode::getDesktopMode(), m_title, sf::Style::Fullscreen);
}
setView(sf::View({ 0.f, 0.f, (float)getSize().x, (float)getSize().y }));
m_isFullscreen = !m_isFullscreen;
}
void GameWindow::updateWindowedSize()
{
if (!m_isFullscreen)
{
m_windowedSize = getSize();
}
setView(sf::View({ 0.f, 0.f, (float)getSize().x, (float)getSize().y }));
}
void GameWindow::setTitle(const sf::String& title)
{
sf::Window::setTitle(title);
m_title = title;
}
void GameWindow::setSize(const sf::Vector2u& size)
{
sf::Window::setSize(size);
updateWindowedSize();
}
bool GameWindow::isFullscreen() const
{
return m_isFullscreen;
}
sf::Vector2u GameWindow::getWindowedSize() const
{
return m_windowedSize;
}
sf::Vector2f GameWindow::getScale() const
{
return { getSize().x / (float)sf::VideoMode::getDesktopMode().width, getSize().y / (float)sf::VideoMode::getDesktopMode().height };
}
sf::String GameWindow::getTitle() const
{
return m_title;
}