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
|
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <vector>
int main() {
/* Set Variables */
sf::Color bgColor;
sf::Font mainFont;
sf::String pre = "System!>";
sf::Text prefix;
sf::String buf;
sf::Text buffer;
sf::String lastStr;
sf::Text lastLine;
std::vector<sf::String> lineVector;
int lineCounter = 1;
int currentVectorPosition = 0;
int currentPrefixY = 0;
int i = 0;
int x = 0;
bgColor.r = 0;
bgColor.g = 0;
bgColor.b = 203;
sf::RenderWindow rWnd(sf::VideoMode(800, 600), "SFML Window");
rWnd.setSize(sf::Vector2u(800, 600));
mainFont.loadFromFile("dos.ttf");
prefix.setCharacterSize(18);
prefix.setColor(sf::Color(255, 255, 255));
prefix.setString(pre);
prefix.setFont(mainFont);
prefix.setPosition(0, currentPrefixY);
prefix.setStyle(sf::Text::Regular);
buffer.setCharacterSize(18);
buffer.setColor(sf::Color(255, 255, 255));
buffer.setFont(mainFont);
buffer.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, 0);
buffer.setString(buf);
buffer.setStyle(sf::Text::Regular);
lastLine.setCharacterSize(18);
lastLine.setColor(sf::Color(255, 255, 255));
lastLine.setFont(mainFont);
lastLine.setPosition(0, 0);
lastLine.setString(lastStr);
lastLine.setStyle(sf::Text::Regular);
while(rWnd.isOpen()) {
rWnd.clear(bgColor);
sf::Event event;
while(rWnd.pollEvent(event)) {
if(event.type == sf::Event::Closed) {
rWnd.close();
}
if(event.type == sf::Event::KeyPressed) {
if(event.key.code == sf::Keyboard::Escape) {
rWnd.close();
}
if(event.key.code == sf::Keyboard::Return) {
lineVector.push_back(buf);
buf.clear();
lineCounter += 1;
}
}
if(event.type == sf::Event::TextEntered) {
if(event.text.unicode == '\b') {
if(!buf.isEmpty()) {
buf.erase(buf.getSize() - 1, 1);
}
} else {
buf.insert(buf.getSize(), event.text.unicode);
}
}
}
/* Somewhere between here */
if(lineCounter == 1) {
prefix.setPosition(0, 0);
buffer.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, 0);
} else {
x = 0;
i = 1;
currentVectorPosition = 0;
currentPrefixY = 0;
while(i < lineCounter) {
prefix.setPosition(0, currentPrefixY);
lastLine.setPosition(prefix.getGlobalBounds().width + 1, prefix.getPosition().y);
x++;
lastLine.setString(lineVector[currentVectorPosition]);
rWnd.draw(prefix);
rWnd.draw(lastLine);
currentPrefixY = prefix.getPosition().y + prefix.getGlobalBounds().height;
i += 1;
currentVectorPosition += 1;
}
prefix.setPosition(0, currentPrefixY);
buffer.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, prefix.getPosition().y/* + prefix.getGlobalBounds().height*/);
}
buffer.setString(buf);
rWnd.draw(prefix);
rWnd.draw(buffer);
rWnd.display();
}
}
|