-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColorButton.h
More file actions
60 lines (51 loc) · 1.67 KB
/
ColorButton.h
File metadata and controls
60 lines (51 loc) · 1.67 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
#pragma once
#include <SFML/Graphics.hpp>
class ColorButton {
public:
ColorButton(const sf::Vector2f& position, const sf::Color& color, float size = 28.f)
: m_size(size) {
m_rect.setSize({ size, size });
m_rect.setFillColor(color);
m_rect.setPosition(position);
m_bg.setSize({ size + 8.f, size + 8.f });
m_bg.setOrigin(4.f, 4.f); // ðàìêà âîêðóã êâàäðàòà
m_bg.setPosition(position);
m_bg.setFillColor(sf::Color(0, 0, 0, 0));
m_bg.setOutlineThickness(0.f);
}
void setPosition(const sf::Vector2f& p) {
m_rect.setPosition(p);
m_bg.setPosition(p);
}
bool isClicked(const sf::Vector2f& mousePos) const {
return m_rect.getGlobalBounds().contains(mousePos);
}
void setHovered(bool h) { m_hovered = h; }
void setSelected(bool s) { m_selected = s; }
sf::Color getColor() const { return m_rect.getFillColor(); }
void draw(sf::RenderWindow& window) const {
// ôîí-ðàìêà äëÿ õîâåðà/àêòèâíîãî
auto bg = m_bg;
if (m_selected) {
bg.setOutlineThickness(3.f);
bg.setOutlineColor(sf::Color(30, 144, 255)); // dodger blue
}
else if (m_hovered) {
bg.setOutlineThickness(2.f);
bg.setOutlineColor(sf::Color(120, 120, 120));
}
else {
bg.setOutlineThickness(1.f);
bg.setOutlineColor(sf::Color(60, 60, 60));
}
window.draw(bg);
// ñàì öâåò
window.draw(m_rect);
}
private:
float m_size;
mutable sf::RectangleShape m_rect;
mutable sf::RectangleShape m_bg;
bool m_hovered = false;
bool m_selected = false;
};