-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextInput.cpp
More file actions
148 lines (82 loc) · 2.58 KB
/
TextInput.cpp
File metadata and controls
148 lines (82 loc) · 2.58 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
// Created by Kristal Hong on 11/1/23.
//
#include "TextInput.h"
TextInput::TextInput()
{
label.setFont(Fonts::getFont(OPEN_SANS));
label.setString("Comments:");
label.setCharacterSize(22);
label.setFillColor(sf::Color::Black);
label.setPosition({40, 485});
inputBox.setSize({650, 190});
inputBox.setPosition({30, 520});
inputBox.setFillColor(sf::Color::Transparent);
inputBox.setOutlineColor(sf::Color::Black);
inputBox.setOutlineThickness(2.0f);
enableState(HIDDEN);
}
void TextInput::setLabel(const sf::Text &labelText) {
label = labelText;
}
void TextInput::setLabelSize(int size) {
fontSize = size;
}
void TextInput::setLabelMargin(const sf::FloatRect &margin) {
// text.setPosition({margin.left, margin.top});
}
void TextInput::setPosition(const sf::Vector2f &position) {
}
void TextInput::setTextColor(const sf::Color& color) {
textColor = color;
}
void TextInput::addEventHandler(sf::RenderWindow &window, sf::Event event) {
if (MouseEvents::isClicked(inputBox, window)) {
active = true;
typing.getMultiText().disableState(HIDDEN);
typing.getMultiText().setCursorStatus();
} else if(MouseEvents::mouseClicked(window, event)) {
active = false;
typing.getMultiText().enableState(HIDDEN);
}
if (active) {
if (sf::Event::TextEntered == event.type){
HistoryNode hn;
hn.snapshot = getSnapshot();
hn.component = this;
History::pushHistory(hn);
}
typing.addEventHandler(window, event);
}
}
void TextInput::update() {
if (!active) {
typing.getMultiText().setCursorStatus();
} else {
typing.update();
}
}
void TextInput::draw(sf::RenderTarget& target, sf::RenderStates states) const {
if (!checkState(HIDDEN)) {
target.draw(label, states);
target.draw(typing, states);
target.draw(inputBox, states);
}
}
TextInput::TextInput(Fonts &font, const sf::Vector2f &position, const sf::Vector2f &size)
: inputBox(size), typing(font, position) {
inputBox.setPosition(position);
inputBox.setFillColor(sf::Color::Black);
inputBox.setOutlineColor(sf::Color::Black);
inputBox.setOutlineThickness(1.0f);
}
Snapshot TextInput::getSnapshot() {
Snapshot snapshot (typing.getMultiText().getString());
return snapshot;
}
void TextInput::applySnapshot(const Snapshot& snapshot) {
typing.getMultiText().setString(snapshot.getText());
}
void TextInput::setFont(const fontEnum &font) {
typing.setFont(font);
}