-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowManager.cpp
More file actions
executable file
·86 lines (68 loc) · 1.71 KB
/
WindowManager.cpp
File metadata and controls
executable file
·86 lines (68 loc) · 1.71 KB
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
//
// Created by segalle on 03/11/2021.
//
#include "WindowManager.h"
WindowManager::WindowManager() :
x(WINDOW_WIDTH),
y(WINDOW_HEIGHT),
window(){
window.create(sf::VideoMode(x, y), "Save Saps");
window.setFramerateLimit(144);
createView();
}
WindowManager::WindowManager(int width, int height) :
x(width),
y(height),
window(){
if(width > 0 && height > 0) {
window.create(sf::VideoMode(width, height), "Save Saps");
}
else{
x = 1280;
y = 720;
window.create(sf::VideoMode(x, y), "Save Saps");
}
window.setFramerateLimit(144);
createView();
}
WindowManager::~WindowManager(){}
bool WindowManager::isOpen() {
return window.isOpen();
}
void WindowManager::draw(sf::Sprite* sprite) {
window.draw(*sprite);
}
bool WindowManager::isOnView(sf::Sprite* sprite){
float viewCenter = view.getCenter().x;
float halfExtents = view.getSize().x / 2.0f;
float viewMin = viewCenter - halfExtents;
float viewMax = viewCenter + halfExtents;
if ((sprite->getPosition().x + sprite->getGlobalBounds().width >= viewMin) && (sprite->getPosition().x <= viewMax)){
return true;
}
return false;
}
sf::View& WindowManager::getView() {
return view;
}
void WindowManager::createView() {
view.reset(sf::FloatRect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT));
}
void WindowManager::setView(const sf::View view){
window.setView(view);
}
void WindowManager::clear() {
window.clear();
}
void WindowManager::display() {
window.display();
}
void WindowManager::draw(sf::Text font){
window.draw(font);
}
void WindowManager::close() {
window.close();
}
bool WindowManager::pollEvent(sf::Event* event) {
return window.pollEvent(*event);
}