SFML community forums
Help => General => Topic started by: ARandomFurry on May 04, 2011, 03:56:36 am
-
Is it remotely possible to make a console window in an SFML window? More specifically sf::RenderWindow.
It would only need functions similar to std::cout, std::cin, std::getline.
It would mean that cin wouldn't 'freeze' the window like it does in the console.
I've been trying to make one, but it's just in my range of skills.
PS: Is this the right place for this topic?
-
It's most certainly possible. Simply drawing text and getting text input is not difficult at all - have a big string that shows the "history" and have one for input. You will probably want to parse commands and things so definitely keep your text as std::string and then make sf::String to draw with.
It's perhaps not an ideal solution if you want to make entirely text based things though - using the actual console is much easier with platform specific functions or something like curses.
If you're having trouble with handling and parsing strings, I'd recommend you head back to the console - it's easier to learn that stuff there.
-
But just setting it up is where im drawing a blank.
I'm pretty skilled with the actual console, just trying to implement my own isn't lining up thought wise
-
What part are you having trouble with, exactly?
You want to display all output in a scrolling text area, you want the user to be able to type in text input at any time. You'll need a function to output a line and a function to read in text from the "text box". I would just have a big string as I mentioned before. You can write a new line to the end of it simply enough, then you just need to delete the top line if it is at the maximum allowed size. Again, I'm giving answers but I'm not really sure what your specific question is :)
-
I guess I'm lost on how to structure the loop for it really.
-
What is this console for? Why don't you use a GUI for this (I think there's an SFML Gui addon somewhere here)?
-
Maybe you need something like this!
sf::RenderWindow gameWindow;
sf::RenderWindow consoleWindow;
gameWindow.create(...);
consoleWindow.create(...);
while(gameWindow.isOpened()) {
sf::Event event;
while(gameWindow.getEvent(event)) {
...
}
while(consoleWindow.getEvent(event)) {
...
}
gameWindow.clear();
...
gameWindow.display();
consoleWindow.clear();
...
consoleWindow.display();
}
-
Hmm, but wouldn't it crash when the console is closed but the game window isn't?
-
No, sf::RenderWindow's functions handle closed windows properly.
-
I mean if one window is closed but you still do stuff with it like events?
-
I mean if one window is closed but you still do stuff with it like events?
No, sf::RenderWindow's functions handle closed windows properly.
-
can you give a little more info as to what you want to do? do you only wish to use it like a standard console with cin/cout/cerr ?
or are you simply wanting a place to log information aesthetically? maybe a gui library would be more suitable for what you need and building a console window from that.
-
Pretty much just a standard console with cin/cout/cerr