-
Notifications
You must be signed in to change notification settings - Fork 0
/
InputBox.cpp
78 lines (67 loc) · 3.08 KB
/
InputBox.cpp
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
#include "InputBox.h"
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// All Initial Setting ---------------------------------------
// InputBox::InputBox(string msg, sf::Vector2f vec, sf::Color color){
// // box.setSize(vec);
// box.setOutlineThickness(5);
// box.setOutlineColor(color);
// box.setFillColor(sf::Color::Transparent);
// text.setFont(Fonts::getFont(Fonts::OPENSANS));
// text.setString(msg);
// text.setFillColor(color);
// text.setCharacterSize(vec.y/2);
// text.setPosition(box.getPosition().x + box.getLocalBounds().width/2 - text.getLocalBounds().width/2,
// box.getPosition().y + box.getLocalBounds().height/2 - text.getLocalBounds().height/1.5);
// }
// InputBox::InputBox(string msg): InputBox(msg, {500,100}, sf::Color::Transparent){}
InputBox::InputBox(){
box.setOutlineThickness(5);
box.setFillColor(sf::Color::Black);
box.setOutlineColor(sf::Color::White);
text.setFont(Fonts::getFont(Fonts::OPENSANS));
text.setFillColor(sf::Color::White);
}
void InputBox::SetText(string msg, int loc){
text.setString(msg);
// setPosition(getPosition().x, getPosition().y);
switch (loc)
{
case 1: text.setFont(Fonts::getFont(Fonts::BEATNEY));
break;
case 2: text.setFont(Fonts::getFont(Fonts::HARRYP));
break;
case 3: text.setFont(Fonts::getFont(Fonts::OPENSANS));
break;
case 4: text.setFont(Fonts::getFont(Fonts::PUMKIN));
break;
case 5: text.setFont(Fonts::getFont(Fonts::WINTER));
break;
default: cout << "Default" << endl;
text.setFont(Fonts::getFont(Fonts::OPENSANS));
break;
}
SetPosition(box.getPosition());
}
void InputBox::SetSize(int n){
text.setCharacterSize(n);
sf::Vector2f size = sf::Vector2f(text.getGlobalBounds().width+50.f,text.getGlobalBounds().height+30.f);
// box.setFillColor(sf::Color::Transparent);
box.setSize({250, size.y});
}
void InputBox::SetPosition(sf::Vector2f pos){
box.setPosition(pos.x, pos.y);
text.setPosition(pos.x + box.getLocalBounds().width/2.00 - text.getGlobalBounds().width/2.00,
pos.y + box.getGlobalBounds().height/2.00 - text.getGlobalBounds().height);
// cout << "BOX position: " << pos.x << ", " << pos.y << endl
// << "Text position: " << pos.x + box.getGlobalBounds().width/2.00 - text.getGlobalBounds().width/2.00 << ", " << pos.y + box.getGlobalBounds().height/2.00 - text.getGlobalBounds().height/1.00 << endl;
}
void InputBox::BoxSet(float width){
sf::Vector2f size = sf::Vector2f(text.getGlobalBounds().width+50.f,text.getGlobalBounds().height+30.f);
box.setSize({width, size.y});
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//AddEVentHandle Updata Window DRAW -------------------------------
void InputBox::draw(sf::RenderTarget& window, sf::RenderStates states) const{
window.draw(box);
window.draw(text);
}