SFML community forums

Help => General => Topic started by: ARandomFurry on May 04, 2011, 03:56:36 am

Title: sf::ConsoleWindow
Post 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?
Title: sf::ConsoleWindow
Post by: Walker on May 04, 2011, 04:52:59 am
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.
Title: sf::ConsoleWindow
Post by: ARandomFurry on May 04, 2011, 06:35:52 am
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
Title: sf::ConsoleWindow
Post by: Walker on May 04, 2011, 08:32:22 am
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 :)
Title: sf::ConsoleWindow
Post by: ARandomFurry on May 05, 2011, 05:54:55 am
I guess I'm lost on how to structure the loop for it really.
Title: sf::ConsoleWindow
Post by: Astrof on May 05, 2011, 07:36:56 am
What is this console for? Why don't you use a GUI for this (I think there's an SFML Gui addon somewhere here)?
Title: sf::ConsoleWindow
Post by: panithadrum on May 05, 2011, 09:41:57 am
Maybe you need something like this!
Code: [Select]
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();
}
Title: sf::ConsoleWindow
Post by: ARandomFurry on May 06, 2011, 12:49:11 am
Hmm,  but wouldn't it crash when the console is closed but the game window isn't?
Title: sf::ConsoleWindow
Post by: Laurent on May 06, 2011, 07:34:31 am
No, sf::RenderWindow's functions handle closed windows properly.
Title: sf::ConsoleWindow
Post by: ARandomFurry on May 07, 2011, 12:42:15 am
I mean if one window is closed but you still do stuff with it like events?
Title: sf::ConsoleWindow
Post by: OniLinkPlus on May 07, 2011, 01:50:02 am
Quote from: "Ignatus"
I mean if one window is closed but you still do stuff with it like events?

Quote from: "Laurent"
No, sf::RenderWindow's functions handle closed windows properly.
Title: sf::ConsoleWindow
Post by: Roswell_r on May 07, 2011, 02:03:46 am
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.
Title: sf::ConsoleWindow
Post by: ARandomFurry on May 08, 2011, 09:39:07 pm
Pretty much just a standard console with cin/cout/cerr