-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTyping.cpp
More file actions
94 lines (60 loc) · 1.75 KB
/
Typing.cpp
File metadata and controls
94 lines (60 loc) · 1.75 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
//
// Created by Kristal Hong on 11/1/23.
//
#include "Typing.h"
Typing::Typing()
{
//
}
Typing::Typing(Fonts &font, const sf::Vector2f &position)
: multiText(font, position) {
}
void Typing::addEventHandler(sf::RenderWindow &window, sf::Event event) {
char inputChar = static_cast<char>(event.text.unicode);
std::string inputAsString = std::to_string(event.text.unicode);
if (event.type == sf::Event::TextEntered) {
if (inputChar >= 32) {
sf::Color charColor;
if (colorCoder.isOperator(inputChar)) {
charColor = sf::Color::Green;
} else if (colorCoder.isNumber(inputChar)) {
charColor = sf::Color::Red;
} else {
charColor = sf::Color::Black; // Default color
}
multiText.push(inputChar);
multiText.back().setFillColor(charColor);
colorCoder.color(multiText);
isTyping = true;
}
if (inputChar == 10) {
multiText.push(inputChar);
}
if (inputChar == 8) {
multiText.pop();
}
}
}
void Typing::update() {
multiText.updateCursorBlink();
if (multiText.empty()) {
multiText.setCursorPosition({60, 535});
}
}
void Typing::draw(sf::RenderTarget &target, sf::RenderStates states) const {
target.draw(multiText, states);
}
bool Typing::isOperator(char c) {
// std::cout << colorCoder.isOperator(c);
return colorCoder.isOperator(c);
}
bool Typing::isNumber(char c) {
// std::cout << colorCoder.isNumber(c);
return colorCoder.isNumber(c);
}
MultiText &Typing::getMultiText() {
return multiText;
}
void Typing::setFont(const fontEnum &font) {
multiText.updateFont(font);
}