Sign in to follow this  
Strumluff

Input with SDL

Recommended Posts

Hi, I've only started using SDL early this week. I've got myself a nice user interface set up for my program and have reached a point that I can't quite work out. I'm programming in C++, my user interface is a Sudoku grid which can be navigated using the keyboard. What I want is for when the enter key is pressed a dialog box or something printed to the screen will come up asking a question with a way for the user to input a value. The user will enter an integer value which I simply want to be stored in a variable. For now I am making do using the console in the background behind the SDL window using iostream commands: if (CurrentEvent.key.keysym.sym == SDLK_RETURN){ cout << "Enter value for square" << endl; cin >> InValue; } I hope someone can help me here or point me in the right direction, don't attack me though I'm new! Thanks, any help appreciated.

Share this post


Link to post
Share on other sites
I have a tutorial on how to get string input here.

To adapt it to your sitaution, restrict the valid input to numbers only. Then add a function to the class that retrieves the string as an int using atoi()

Share this post


Link to post
Share on other sites
Thats great Foo,
I'm utterly grateful for the assistance, now to sit down and make sense of the tutorial :D

Anyway much appreciated, that looks suited to do the job, theres just one thing, that your tutorial handles an input on a keypress.
In my situation navigation is done using the arrows, then the enter key must be hit, then a question can be phrased before an integer is required from the user, then it needs to be displayed to the screen at a set of coordinates of a surface as well as used in another class.

I shall take the time to look through your tutorial and think of how I can link this up, thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this