-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.cpp
More file actions
63 lines (50 loc) · 1.66 KB
/
Interface.cpp
File metadata and controls
63 lines (50 loc) · 1.66 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
#include "Interface.h"
Interface::Interface(const std::string& texturePath,
const std::string& aimedTexturePath,
const sf::Vector2f& pos,
const sf::Vector2f& size)
{
if (!texture.loadFromFile(texturePath)) {
std::cerr << "texture from " << texturePath <<" has not loaded!\n";
}
if (!aimedTexturePath.empty()) {
aimedTexture.loadFromFile(aimedTexturePath);
}
sprite.setTexture(texture);
sprite.setPosition(pos);
// ìàñøòàáèðîâàíèå òåêñòóðû ïîä óêàçàííûé ðàçìåð
sf::Vector2u texSize = texture.getSize();
sprite.setScale(size.x / texSize.x, size.y / texSize.y);
// äëÿ íàâåä¸ííîé âåðñèè
if (aimedTexture.getSize().x > 0) {
aimedSprite.setTexture(aimedTexture);
aimedSprite.setPosition(pos);
aimedSprite.setScale(size.x / aimedTexture.getSize().x, size.y / aimedTexture.getSize().y);
}
position = pos;
}
void Interface::Draw(sf::RenderWindow& window) {
if (isAimed && aimedTexture.getSize().x > 0)
window.draw(aimedSprite);
else
window.draw(sprite);
}
void Interface::SetAimed(bool aimed) {
isAimed = aimed;
}
void Interface::SetPosition(const sf::Vector2f& pos) {
position = pos;
sprite.setPosition(pos);
aimedSprite.setPosition(pos);
}
inline void Interface::Press() { isPressed = true; }
inline void Interface::UnPress() { isPressed = false; }
sf::FloatRect Interface::getGlobalBounds() const {
return (isAimed && aimedTexture.getSize().x > 0)
? aimedSprite.getGlobalBounds()
: sprite.getGlobalBounds();
}
sf::RenderWindow& operator<<(sf::RenderWindow& window, Interface& button) {
button.Draw(window);
return window;
}