-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputBox.cpp
More file actions
82 lines (63 loc) · 2 KB
/
InputBox.cpp
File metadata and controls
82 lines (63 loc) · 2 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
//
// Created by Kristal Hong on 11/16/23.
//
#include "InputBox.h"
InputBox::InputBox()
: selectedItem(nullptr) {
// Initialize other properties of the input box as needed
shape.setOutlineColor(sf::Color::Black);
shape.setOutlineThickness(2.0f);
shape.setFillColor(sf::Color::Transparent);
shape.setSize({100, 50});
buttonText.setFont(Fonts::getFont(OPEN_SANS));
buttonText.setCharacterSize(24);
buttonText.setFillColor(sf::Color::Black);
}
void InputBox::setSelectedItem(Item* item) {
if (item != nullptr) {
selectedItem = item;
const sf::Text& itemText = selectedItem->getText();
setText(itemText.getString());
}
}
void InputBox::draw(sf::RenderTarget& window, sf::RenderStates states) const {
window.draw(shape, states);
window.draw(buttonText, states);
}
sf::FloatRect InputBox::getGlobalBounds() const {
return shape.getGlobalBounds();
}
Item *InputBox::getSelectedItem() {
return selectedItem;
}
void InputBox::addEventHandler(sf::RenderWindow &window, sf::Event event) {
if(MouseEvents::isClicked(shape, window)) {
// std::cout << "Being clicked";
isClicked = true;
} else {
isClicked = false;
}
}
void InputBox::setText(const std::string& text) {
buttonText.setString(text);
sf::FloatRect textBounds = buttonText.getLocalBounds();
buttonText.setOrigin(textBounds.left + textBounds.width / 2.0f, textBounds.top + textBounds.height / 2.0f);
Position::centerText(shape, buttonText);
}
std::string InputBox::getText() const {
return buttonText.getString();
}
void InputBox::setSize(sf::Vector2f position) {
shape.setSize(position);
Position::centerText(shape, buttonText);
}
void InputBox::setPosition(sf::Vector2f position) {
shape.setPosition({position.x, position.y});
Position::centerText(shape, buttonText);
}
sf::Vector2f InputBox::getPosition() const {
return shape.getPosition();
}
sf::Vector2f InputBox::getSize() const {
return shape.getSize();
}