-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.cpp
More file actions
117 lines (97 loc) · 3.4 KB
/
button.cpp
File metadata and controls
117 lines (97 loc) · 3.4 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <vector>
#include <chrono>
#include <SFML/Graphics.hpp>
#include "button.h"
buttons::DebugButton::DebugButton(int height, int width, sf::Texture &texture) {
sprite.setTexture(texture);
sprite.setPosition((width * 32) - 304, 32 * (height + 0.5));
}
void buttons::DebugButton::DrawButton(sf::RenderWindow &window) {
window.draw(sprite);
}
void buttons::DebugButton::RevealAllMinesDebug(std::vector<std::vector<Tile>>& board, sf::Texture& texture) {
for (std::vector<Tile>& row : board) {
for (Tile& tile : row) {
if (tile.isMine) {
tile.state = "Revealed";
tile.topImage.setTexture(texture);
}
}
}
}
void buttons::DebugButton::HideAllMinesDebug(std::vector<std::vector<Tile>>& board, sf::Texture& texture) {
for (std::vector<Tile>& row : board) {
for (Tile& tile : row) {
if (tile.isMine) {
tile.state = "Hidden";
tile.topImage.setTexture(texture);
}
}
}
}
bool buttons::DebugButton::IsClicked(sf::RenderWindow& window) {
int x = sf::Mouse::getPosition(window).x;
int y = sf::Mouse::getPosition(window).y;
sf::FloatRect area = sprite.getGlobalBounds();
if (area.contains(x, y)) {
return true;
}
return false;
}
buttons::HappyButton::HappyButton(int height, int width, sf::Texture& texture) {
sprite.setTexture(texture);
sprite.setPosition(((width / 2) * 32) - 32, 32 * (height + 0.5));
}
void buttons::HappyButton::DrawButton(sf::RenderWindow& window) {
window.draw(sprite);
}
void buttons::HappyButton::ChangeState(sf::RenderWindow& window, sf::Texture& texture) {
sprite.setTexture(texture);
window.draw(sprite);
}
bool buttons::HappyButton::IsClicked(sf::RenderWindow& window) {
int x = sf::Mouse::getPosition(window).x;
int y = sf::Mouse::getPosition(window).y;
sf::FloatRect area = sprite.getGlobalBounds();
if (area.contains(x, y)) {
return true;
}
return false;
}
buttons::PauseButton::PauseButton(int height, int width, sf::Texture& texture) {
sprite.setTexture(texture);
sprite.setPosition((width * 32) - 240, 32 * (height + 0.5));
}
void buttons::PauseButton::DrawButton(sf::RenderWindow& window) {
window.draw(sprite);
}
void buttons::PauseButton::ChangeState(sf::RenderWindow& window, sf::Texture& texture) {
sprite.setTexture(texture);
window.draw(sprite);
}
bool buttons::PauseButton::IsClicked(sf::RenderWindow &window) {
int x = sf::Mouse::getPosition(window).x;
int y = sf::Mouse::getPosition(window).y;
sf::FloatRect area = sprite.getGlobalBounds();
if (area.contains(x, y)) {
return true;
}
return false;
}
buttons::LeaderBoardButton::LeaderBoardButton(int height, int width, sf::Texture& texture) {
sprite.setTexture(texture);
sprite.setPosition((width * 32) - 176, 32 * (height + 0.5));
}
void buttons::LeaderBoardButton::DrawButton(sf::RenderWindow& window) {
window.draw(sprite);
}
bool buttons::LeaderBoardButton::IsClicked(sf::RenderWindow &window) {
int x = sf::Mouse::getPosition(window).x;
int y = sf::Mouse::getPosition(window).y;
sf::FloatRect area = sprite.getGlobalBounds();
if (area.contains(x, y)) {
return true;
}
return false;
}