-
Notifications
You must be signed in to change notification settings - Fork 2
/
sfml_window_manager.cpp
89 lines (79 loc) · 2.65 KB
/
sfml_window_manager.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "sfml_window_manager.h"
#include "sfml_resources.h"
#include <cassert>
sfml_window_manager *sfml_window_manager::m_instance = nullptr; //!OCLINT static accepted singleton
#if(SFML_VERSION_MINOR > 3)
sfml_window_manager::sfml_window_manager()
: m_window(sf::VideoMode(
static_cast<unsigned int>(sf::VideoMode::getDesktopMode().width - 200),
static_cast<unsigned int>(sf::VideoMode::getDesktopMode().height - 200)),
"Nature Zen", static_cast<unsigned int>(get_video_mode())),
m_state{ game_state::playing }
{
m_window.setPosition(sf::Vector2i(100, 50));
m_screen_center = sf::Vector2i(m_window.getSize().x / 2,
m_window.getSize().y / 2);
m_window.setFramerateLimit(300);
sf::Image ico = sfml_resources::get().get_zen_ind().copyToImage();
sf::Vector2u is = ico.getSize();
m_window.setIcon(is.x, is.y, ico.getPixelsPtr());
}
#else
sfml_window_manager::sfml_window_manager()
: m_window(sf::VideoMode(
static_cast<unsigned int>(1000),
static_cast<unsigned int>(1000)),
"Nature Zen")
{
// Set up window, start location to the center
m_window.setPosition(sf::Vector2i(0, 0));
m_screen_center = sf::Vector2i(m_window.getSize().x / 2,
m_window.getSize().y / 2);
}
#endif
sfml_window_manager &sfml_window_manager::get() {
if (!m_instance) {
m_instance = new sfml_window_manager();
}
assert(m_instance);
return *m_instance;
}
void sfml_window_manager::update() {
if (m_window.getSize().y < 568) {
m_window.setSize(sf::Vector2u(m_window.getSize().x,568));
m_window.setPosition(m_window_pos);
}
if (m_window.getSize().x < 852) {
m_window.setSize(sf::Vector2u(852,m_window.getSize().y));
m_window.setPosition(m_window_pos);
}
m_screen_center = sf::Vector2i(m_window.getView().getSize().x / 2,
m_window.getView().getSize().y / 2);
}
void sfml_window_manager::process() {
m_window_pos = m_window.getPosition();
}
void sfml_window_manager::set_state(game_state s) {
m_state = s;
sf::Vector2f size = m_window.getView().getSize();
m_old_view = m_window.getDefaultView();
m_old_view.setSize(size);
sfml_window_manager::get().get_window().setView(m_old_view);
}
int get_video_mode() {
#ifndef NDEBUG
return sf::Style::Default;
#else
return sf::Style::Fullscreen;
#endif
}
bool active(game_state s) {
return sfml_window_manager::get().get_state() == s &&
sfml_window_manager::get().get_window().isOpen();
}
/*
void test_sfml_window_manager() //!OCLINT tests may be long
{
sfml_window_manager &window_manager = sfml_window_manager::get();
}
*/