I've got a program here that doesn't like to set sf::Text's sf::Strings from an std::vector<sf::String>. I've narrowed it down to this line:
lastLine.setString(lineVector[currentVectorPosition]);
And here's the full code:
#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;
bgColor.r = 0;
bgColor.g = 0;
bgColor.b = 203;
sf::RenderWindow rWnd(sf::VideoMode(800, 600), "OpenCMD [Version 2, Beta 1: Private Build]");
rWnd.setSize(sf::Vector2u(800, 600));
mainFont.loadFromFile("dos.ttf");
prefix.setCharacterSize(18);
prefix.setColor(sf::Color(255, 255, 255));
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::Return) {
lineVector.push_back(buf);
lineCounter += 1;
}
if(event.key.code == sf::Keyboard::Escape) {
rWnd.close();
}
}
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 {
i = 1; // Counter
currentVectorPosition = 0;
currentPrefixY = 0; // Set current text Y to 0
while(i <= lineCounter) { // while i s less than or equal to the number of lines
prefix.setPosition(0, currentPrefixY); // set the prefix x to 0, y to 0
lastLine.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, prefix.getPosition().y + prefix.getGlobalBounds().height);
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();
}
}
My question is: why is my sf::Text not able to set it's sf::String from an std::vector of sf::Strings?