I am making input boxes in my game and I am having problems converting the unichar to char. How would I do this.
The reason I'm using unichar than keycode is because it's less handling needed for special characters.
Use a single ALLEGRO_USTR to store multiple unichars (there are plenty of functions for manipulating an ALLEGRO_USTR), and then use the various _ustr drawing functions to output to a bitmap.
Sorry but I really do not get any of that web page :S I use std::string to store my text. It's only converting from unichar to char I need.
Use an ALLEGRO_USTR instead of a std::string. You get free unicode support that way.
I've been trying and I don't get it. I get the unicode number all the time.
This will convert UTF32 (unichar) to UTF-8.
this will tell you how big your char buffer needs to be for the previous function.
I have it working by doing this:
Another noobie question in this simular matter.
How do I blank the buffer before using al_utf8_encode? as some special keys mess it up :/
the (somewhat) proper way:
case ALLEGRO_EVENT_KEY_CHAR: { char buf[5]; for(int i = 0; i < 5; ++i) buf[i] = NULL; al_utf8_encode( buf, this->event.keyboard.unichar ); printf( "%s", buf ); } break;
Because do not forget, utf-8 != to ascii, it has ascii + tons more so it needs up to 4 chars + NULL terminating which is why you need to use the function to get the size and to NULL size + 1.
ALLEGRO_USTR makes this easier, but I use std::string because my GUI API is backend independent.
Thanks Works a dream.
Definitely some bizarre code in this thread...
ALLEGRO_USTR *foo = al_ustr_new(""); al_ustr_append_chr(foo, unichar); printf("%s", al_cstr(foo)); // to convert to a C string al_draw_ustr(font, color, x,y, 0, foo);
Thanks, That one works better. I was just about to post this video showing an error I get when rendering buttons afterwards
Here is the video anyway
http://www.youtube.com/watch?v=M_A_Ty71JlY
This is my new case
You shouldn't create a new ustr on every key press. Have a single ustr for each text box. Append the new character to it, and draw it to the bitmap.
I don't know what your input class is doing, but this is very simple:
Use the various draw_ustr functions to output the text.
I have one event queue that handles everything since it's a simple game to re-create. The input field is a class and the data is stored in the input box due to needing them later on. It's a clone of Endless Online since the server was taken down by the owner. It's not been updated since 2007, the site was last updated 2009 so I'm creating the entire thing again since I used to play that daily Miss it to be honest. Anyway, I am making a clone of his MMORPG
The input field is a class and the data is stored in the input box due to needing them later on.
Yes, and if you make it an `ALLEGRO_USTR *` instead of a `char *`, you can do as Matthew says, and save the memory allocation and excess copying.
Yes, and if you make it an `ALLEGRO_USTR *` instead of a `char *`, you can do as Matthew says, and save the memory allocation and excess copying.
Yes, but I'm too used to std::string functions for appending text ect so it's copied to that. :/
I shall read more about ALLEGRO_USTR* for sure but for now I shall use std::string since I know it better