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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Foz44

Pages: [1]
1
General / Re: basic text box
« on: February 17, 2020, 04:34:18 am »
Thank you very much for the advice - I'll give it a shot... 8)

2
General / Re: basic text box
« on: February 14, 2020, 10:58:14 pm »
Sorry - I'll try to give a better picture of what I'm after. I wanted to simulate the basic construct of the old msdos ui, where the user can type simple commands at the C:\ prompt, for example, and bring up various menus. At first I thought I found exactly what I needed with the example:

while (window.pollEvent(e)) {
     if (e.type == Event::KeyPressed) {             
         if (e.type == Event::TextEntered) {
              if (e.text.unicode < 128) {
                  input += static_cast<char>(e.text.unicode);

from my previous messages: I could use the 'input' variable to echo the characters back to the screen as the user typed them as well as add to input's position.y to bring the prompt down to the next line whenever Unicode 8 (return key) was detected, for example. the problem I'm having is that certain keys (the BackSpace key - Unicode 8, in my case) add unwanted characters to the 'input' string. What I need is to parse the string in such a way that only pure, printable char's are left. That way I could, among other things, use code such as:  if(input == "list") { MyClass.displayList(); }, or - as Laurent pointed out - use the more efficient string::pop_back() when the user presses BackSpace instead of 'substr()' that I have to use now...

3
General / Re:basic text box
« on: February 13, 2020, 09:45:50 pm »
Just when I thought it was safe to go back into the water...<i'm returning this to 'unsolved'>. I originally thought I was doing just that with the line "if(text.unicode < 128)", until I saw that the Unicode for the 'BackSpace' key is '8'. And nothing I've seen yet on the internet is very clear, so just how DO I filter out non-printable characters?

4
General / Re: basic text box
« on: February 08, 2020, 04:03:22 am »
OK, "input = input.supstr(0, input.size() - 2)" was the answer. (I had to make it "input.size() - "2" instead of "1" so that it would also remove the strange character that the BackSpace key itself made.) Thank you, Fx8akaoy, for the help.

For the benefit of anyone else not very familiar with C++ strings who may come across this thread, the internet says that std::string::pop_back() would do exactly what I needed. It did not work at all...

5
General / Re: basic text box
« on: February 07, 2020, 05:08:29 am »
I found most of what I needed in an old post - I can now save user input into a string and 'echo' each char to the screen at the location of a prompt like I want:

 while (window.pollEvent(e)) {
     if (e.type == Event::KeyPressed) {              
         if (e.type == Event::TextEntered) {
              if (e.text.unicode < 128) {
                  input += static_cast<char>(e.text.unicode);
                  output.setFillColor(Color::White);
                  output.setString(input);
              }
          }
      }
.
.
.
window.draw(prompt);
window.draw(output);

What I need now is a way to make the 'backspace' button work like it's supposed to. Will I have to manually pop a char off the end of the string for each "Keyboard::Backspace" detected, or does SFML have something for that?

6
General / [SOLVED]basic text box
« on: February 05, 2020, 06:03:40 am »
If I were relatively new to C++ and SFML and were looking for a way to incorporate into my game a text box for user input - something vaguely like a dos shell - would there be a tutorial or guide you might suggest?

Pages: [1]