EchoesOfFate
A game for our COMP315 Project
 
Loading...
Searching...
No Matches
Textbox.h
Go to the documentation of this file.
1#pragma once
2#include <SFML/Graphics.hpp>
3#include <iostream>
4#include <sstream>
5
7#define DELETE_KEY 8
8#define ENTER_KEY 13
9#define ESCAPE_KEY 27
10
11using namespace sf;
12
13class Textbox{
14public:
15 Textbox() {};
16
17 Textbox(int size, Color color, bool sel);
18 void setFont(Font& font);
19 void setPosition(Vector2f pos);
20 void setLimit(bool ToF);
21 void setLimit(bool ToF, int lim);
22 void setSelected(bool sel);
23 std::string getText();
24 void drawTo(sf::RenderWindow& window);
25 void typedOn(sf::Event input);
26private:
27 Text textbox;
28 std:: ostringstream text;
29 bool isSelected;
30 bool hasLimit;
31 int limit;
32
33 void inputLogic(int charTyped) {
34 if (charTyped != DELETE_KEY && charTyped != ENTER_KEY && charTyped != ESCAPE_KEY) {
35 text << static_cast<char>(charTyped);
36 }
37 else if (charTyped == DELETE_KEY) {
38 if (text.str().length() > 0) {
39 deleteLastChar();
40 }
41 }
42
43 textbox.setString(text.str() + "_");
44
45 }
46
47 void deleteLastChar() {
48 std::string t = text.str();
49 std::string newT = "";
50 for (int i = 0; i < t.length() - 1; i++) {
51 newT += t[i];
52 }
55 text.str("");
56 text << newT;
57
58 textbox.setString(text.str());
59 }
60};
#define ESCAPE_KEY
Definition Textbox.h:9
#define DELETE_KEY
sepcial case for the key to have a proper function when typed instead of displaying a unicode value
Definition Textbox.h:7
#define ENTER_KEY
Definition Textbox.h:8
void setPosition(Vector2f pos)
set the font of the text
Definition Textbox.cpp:20
void setLimit(bool ToF)
set the position of the text box on the screen
Definition Textbox.cpp:24
Textbox()
Definition Textbox.h:15
void typedOn(sf::Event input)
draws the textbox to the window
Definition Textbox.cpp:51
std::string getText()
sets selected to true
Definition Textbox.cpp:43
void setFont(Font &font)
Definition Textbox.cpp:16
void setSelected(bool sel)
sets the text box with a specifiied limit
Definition Textbox.cpp:32
void drawTo(sf::RenderWindow &window)
grabs the text of the textbox
Definition Textbox.cpp:47