| Author |
Message |
< beginners ~ Text Input: Creating words by entering and showing on screen |
|
tekne
|
Posted: Tue Nov 10, 2009 10:48 pm |
|
|
| Joined: Tue Nov 10, 2009 6:06 pmPosts: 11 |
Hi all, I'm extremely new to oF and have very little coding experience through Processing (super beginner code-wise). I've looked everywhere for several days now and I can't even seem to find any proper reference so if someone can please help guide me, I'd be most grateful. I'm currently using some code kindly posted online here: http://gussiefinknottle.wordpress.com/c ... rameworks/and mashing it up with the soundPlayerExample. Now that I've got that working, how do I: Code so that I can type out a word on the keyboard, press enter, then have the word appear on the screen?
Or alternatively, show the word being typed out in real time onscreen and press enter so that it saves somewhere on the screen.All the examples I've found only show strings already written out in the body of the code. The soundPlayer example shows how the letter can be highlighted, but doesn't give a clue on how it can stay. I hope this makes sense to someone. Thank you thank you thank you!!
|
|
Top
|
|
|
tekne
|
Posted: Wed Nov 11, 2009 3:53 am |
|
|
| Joined: Tue Nov 10, 2009 6:06 pmPosts: 11 |
Just to clarify a bit:
I simply want to type words and have them displayed on screen.
I'd like to combine a keypressed and draw function together if possible - or find an alternative.
So something like:
void testApp::keyPressed (int key){ if (key == 'a'){ theFont.drawString("a");
and then something to string them together like:
string str =""'' str += char(letter); theFont.drawString(str, 100, 250);
Please pardon the examples. The point is that I'm not familiar with code/c++/openframeworks language well enough yet.
Thanks again.
|
|
Top
|
|
|
marek
|
Posted: Wed Nov 11, 2009 11:40 am |
|
|
| Joined: Wed Feb 04, 2009 11:13 amPosts: 56 |
you'd want to define a string in testApp.h class testApp { public: ....
string str; };
then in testApp::setup() { you want to initialize it as an empty string: str = "";
then in keyPressed() you add a character to it. (also you want to take into account the backspace key)
void testApp::keyPressed(int key) { if(key==8 && str.size()>0) { // backspace str = str.substr(0, str.size()-1); // delete one character } else { str.append (1, (char)key ); } }
then in testApp::draw(), just draw the string
theFont.drawString(str, 100, 250);
you don't want to do any drawing outside of the draw() method.
I think that's it.
|
|
Top
|
|
|
tekne
|
Posted: Fri Nov 13, 2009 4:43 am |
|
|
| Joined: Tue Nov 10, 2009 6:06 pmPosts: 11 |
Sweet! Just tried it and it works! Thank you so much for your help! One hurdle jumped, some more to go. Thanks again!
|
|
Top
|
|
|
|
All times are UTC
Users browsing this forum: Google [Bot] and 1 guest
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|