Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::ConsoleWindow  (Read 4435 times)

0 Members and 1 Guest are viewing this topic.

ARandomFurry

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
sf::ConsoleWindow
« 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?

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
sf::ConsoleWindow
« Reply #1 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.

ARandomFurry

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
sf::ConsoleWindow
« Reply #2 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

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
sf::ConsoleWindow
« Reply #3 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 :)

ARandomFurry

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
sf::ConsoleWindow
« Reply #4 on: May 05, 2011, 05:54:55 am »
I guess I'm lost on how to structure the loop for it really.

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
sf::ConsoleWindow
« Reply #5 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)?

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
sf::ConsoleWindow
« Reply #6 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();
}

ARandomFurry

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
sf::ConsoleWindow
« Reply #7 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
sf::ConsoleWindow
« Reply #8 on: May 06, 2011, 07:34:31 am »
No, sf::RenderWindow's functions handle closed windows properly.
Laurent Gomila - SFML developer

ARandomFurry

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
sf::ConsoleWindow
« Reply #9 on: May 07, 2011, 12:42:15 am »
I mean if one window is closed but you still do stuff with it like events?

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
sf::ConsoleWindow
« Reply #10 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.
I use the latest build of SFML2

Roswell_r

  • Newbie
  • *
  • Posts: 12
    • View Profile
sf::ConsoleWindow
« Reply #11 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.

ARandomFurry

  • Newbie
  • *
  • Posts: 10
    • View Profile
    • Email
sf::ConsoleWindow
« Reply #12 on: May 08, 2011, 09:39:07 pm »
Pretty much just a standard console with cin/cout/cerr