-
Notifications
You must be signed in to change notification settings - Fork 0
/
Window.cpp
78 lines (67 loc) · 2.17 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
75
76
77
78
#include "Window.hpp"
Window::Window()
:_window(sf::VideoMode(_windowSize.first, _windowSize.second), "NeuralNetworks")
{
_window.setFramerateLimit(60);
}
void Window::clear()
{
_window.clear();
}
void Window::display()
{
_window.display();
}
void Window::setFrameRate(unsigned int frameRate)
{
_window.setFramerateLimit(frameRate);
}
void Window::drawBox(const Box& box, std::pair<int, int> position, bool dragged)
{
sf::RectangleShape boxBorder(sf::Vector2f(box.getSize(), box.getSize()));
boxBorder.setPosition(sf::Vector2f(position.first, position.second));
boxBorder.setFillColor(dragged ? sf::Color(36, 37, 38) : sf::Color::Black);
boxBorder.setOutlineThickness(2);
boxBorder.setOutlineColor(sf::Color::White);
sf::CircleShape hero(box.getHeroSize());
hero.setFillColor(sf::Color::Blue);
hero.setOrigin(box.getHeroSize(), box.getHeroSize());
hero.setPosition(box.getHeroPos().first + position.first, box.getHeroPos().second + position.second);
sf::CircleShape food(box.getFoodSize());
food.setFillColor(sf::Color::Green);
food.setOrigin(box.getFoodSize(), box.getFoodSize());
food.setPosition(box.getFoodPos().first + position.first, box.getFoodPos().second + position.second);
_window.draw(boxBorder);
_window.draw(food);
_window.draw(hero);
}
Window::Event Window::pollEvent()
{
sf::Event event;
while (_window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
return Event::Close;
if (event.type == sf::Event::KeyPressed)
{
if(event.key.code == sf::Keyboard::P)
return Event::ClickPauseButton;
if(event.key.code == sf::Keyboard::N)
return Event::ClickNextButton;
if(event.key.code == sf::Keyboard::S)
return Event::ClickSaveButton;
if(event.key.code == sf::Keyboard::L)
return Event::ClickLoadButton;
}
}
return Event::None;
}
std::pair<int, int> Window::getMousePosition()
{
sf::Mouse mouse;
return std::make_pair(mouse.getPosition(_window).x, mouse.getPosition(_window).y);
}
void Window::close()
{
_window.close();
}