-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalert_screen.cpp
More file actions
77 lines (64 loc) · 2.04 KB
/
alert_screen.cpp
File metadata and controls
77 lines (64 loc) · 2.04 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
#include "head.h"
using namespace std;
#define alert_x 600
#define alert_y 200
void alert_screen(string alert, int number_of_button, const string button_string[], void (*func[])(sf::RenderWindow&) )
{
//Texture load
sf::Texture button_back;
button_back.loadFromFile("data/button0.png");
//Mozemy maksymalnie wypisac 4 przyciski wiec dodatkowe nie zostana narysowane
if (number_of_button > 4)
number_of_button = 4;
//Komunikat
sf::Text sfml_alert(alert, font, 30);
sfml_alert.setColor(sf::Color::Green);
sf::FloatRect alert_size = sfml_alert.getLocalBounds();
sfml_alert.setPosition((alert_x - alert_size.width) / 2, 30);
sf::RenderWindow okno(sf::VideoMode(alert_x, alert_y), "Alert", sf::Style::None);
//Przyciski
vector <button*> buttons;
float _space = (alert_x - (number_of_button * 100.f)) / (number_of_button + 1);
float space = _space;
for (int i = 0; i < number_of_button; i++)
{
buttons.push_back(new button(sf::Vector2f(100.f, 30.f), sf::Vector2f(space, 100.f), button_string[i], font, 30, sf::Color::White, button_back));
space += 100 + _space;
}
cout << endl;
//Static step object
sf::Clock clock;
sf::Time timeSinceLastUpdate = sf::Time::Zero;
sf::Time TimePerFrame = sf::seconds(1.f / 60.f);
while (okno.isOpen())
{
timeSinceLastUpdate += clock.restart();
sf::Event event;
while (timeSinceLastUpdate > TimePerFrame)
{
while (okno.pollEvent(event))
{
if (event.type == sf::Event::Closed)
okno.close();
if (event.type == sf::Event::KeyPressed && sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Escape))
okno.close();
if (event.type == sf::Event::MouseButtonPressed && sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
for (int i = 0; i < number_of_button; i++)
{
if (buttons.at(i)->mouse_over_button(okno))
{
func[i](okno);
}
}
}
} //while event
timeSinceLastUpdate -= TimePerFrame;
}
okno.clear(sf::Color(182, 0, 0));
okno.draw(sfml_alert);
for (int i = 0; i < number_of_button; i++)
okno.draw(*buttons.at(i));
okno.display();
}
}