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 - GameAddict

Pages: [1]
1
Graphics / Text Input - Handling press of backspace.
« on: June 15, 2012, 01:19:14 am »
I've been messing around with this for a while, and I'm having a bit of trouble getting this to work. I'm trying to write a simple text input system using sf::Text and sf::String, and nothing I've tried has gotten it to handle pressing backspace.

Here is my code:
#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>
using namespace std;

int main()
{
    sf::RenderWindow App(sf::VideoMode(800, 600), "SFML Text Input System");
    sf::String Text;
    string str;

    const sf::Input & Input = App.GetInput();

    while(App.IsOpened())
    {
        sf::Event Event;
        while(App.GetEvent(Event))
        {
            if (Event.Type == sf::Event::Closed) App.Close();
            if (Event.Type == sf::Event::TextEntered)
            {
                if (Event.Text.Unicode < 128)
                    str += static_cast<char>(Event.Text.Unicode);
            }
            Text.SetText(str);
        }

        App.Clear();
        App.Draw(Text);
        App.Display();
    }
}
 

Any help is greatly appreciated.  :)

Pages: [1]