Hi, I'm making a console window with SFML and I've reached my first uncertainty: new line characters.
I want a new line character to create a new line. There seems to be no function in sf::Text to do this automatically.
So, with efficiency in mind, should I create a loop for each sub-string delineated by new line characters and call RenderWindow::Draw on each sub-string? or is there a better way.
https://github.com/FRex/LuaConsole/blob/master/src/LuaConsole/LuaSFMLConsoleView.cpp
^^This guy doesn't even use sf::Text. He creates his own vertex thingies using the glyphs from the font.
What is the recommended approach here?
Edit:
Here is what I have now(it functions but seems wasteful):
{
float lineSpacing = sessionText.getCharacterSize() + sessionText.getLineSpacing();
int i{ 0 };
for (std::string const & substring : model.get_sessionString())
{
sf::Transform t;
t.translate(0.f, lineSpacing * i);
sessionText.setString(substring);
AppWindow::instance().getAppWindow().draw(sessionText, t);
i++;
}
}
This is great thanks. I want to program my own because I need the practice. I'll definitely follow the Selba Tutorials.
Right now I am struggling to think how should I handle input into my window.
I currently am using a singleton for my AppWindow and I when I handle the sf events I set std::bitsets for each key press.
In my console.update I check the bitsets like this:
AppWindow::instance().get_IsKeyPressed().any()
I don't want to couple my console to my AppWindow singleton class so this sucks.
@FRex : I see that your ConsoleInput takes an sf::event. How and where do you pass the event to the function?
https://github.com/FRex/LuaConsole/blob/master/src/LuaConsole/LuaSFMLConsoleInput.cpp
auto const keybits = AppWindow::instance().get_IsKeyPressed();
if (keybits.none())
{
return;
}
if (keybits[sf::Keyboard::Key::BackSpace])
{
std::cout << "backspace\n";
}
if (keybits[sf::Keyboard::Key::Delete])
{
std::cout << "delete\n";
}
if (keybits[sf::Keyboard::Key::Enter])
{
m_model.add_to_session(m_model.get_promptLine());
m_model.reset_promptLine();
}
I also have this nasty stuff.