Message-ID: <3A4A3486.1745FBE4@gtcom.net> From: Krogg X-Mailer: Mozilla 4.73 [en] (Win95; U) X-Accept-Language: en,en-US,en-GB,ja,af MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Trouble with text while in graphic mode References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 117 Date: Wed, 27 Dec 2000 13:27:18 -0500 NNTP-Posting-Host: 12.16.179.196 X-Trace: eagle.america.net 977941653 12.16.179.196 (Wed, 27 Dec 2000 13:27:33 EST) NNTP-Posting-Date: Wed, 27 Dec 2000 13:27:33 EST Organization: 24hoursupport.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Da Pickle wrote: > > Hi there, > > I am making a game and want the player to be able to name their character. I > want to be able to do this while in graphic mode. > I can ask for the input no problem using the textout() function, but how do > I let the player see what they are typing? If I use scanf they don't get to > see what they are typing while they type it. > > Do I have to use gui routines? Setup dialog boxes and all that? Please help. > > Thanks most likely yes,I needed the same kind of thing once so i have allready done some of the work for you.This is a stripped down version of the text dialog from the allegro library.It can be used all by itself... //You need a data structure to hold the data: typedef struct //for editing text { char *s; // the data. int d1; // the size of the data. int d2; // pointer to cursor location in the data. } EDITTEXT; //then you declare an instance of the data: EDITTEXT MY_NAME; char players_name="SUPER MAN___"; //Initialize the instance: MY_FILE_EDIT.s =&players_name; MY_FILE_EDIT.d1=12; MY_FILE_EDIT.d2=1; //loop till done entering data; int x; while( ) { x=0;if(keypressed()){x=readkey();}//If there is a keypressed then get it; edit_text(&MY_NAME,x); //send presses key to the editor drawscreen(); //draw the screen again to reflect changes //just to illustrate that you WILL have to //draw the text on the screen yourself.and //you allready know how to use textout()... } //and fianlly the editing function it self... int edit_text(EDITTEXT *d, int c) { int l,p; char *s; s=d->s; l=strlen(s); if (d->d2 > l){d->d2 = l;} if ((c >> 8) == KEY_LEFT){if (d->d2 > 0){d->d2--;}} else if ((c >> 8) == KEY_RIGHT){if (d->d2 < l){d->d2++;}} else if ((c >> 8) == KEY_HOME){d->d2 = 0;} else if ((c >> 8) == KEY_END) {d->d2 = l;} else if ((c >> 8) == KEY_DEL) { if (d->d2 < l) { for (p=d->d2; s[p]; p++){s[p] = s[p+1];} } } else if ((c >> 8) == KEY_BACKSPACE) { if (d->d2 > 0) { d->d2--; for (p=d->d2; s[p]; p++){s[p] = s[p+1];} } } else { c &= 0xFF; if ((c >= 32) && (c <= 126)) { if (l < d->d1) { while (l >= d->d2) { s[l+1] = s[l]; l--; } s[d->d2] = c; d->d2++; } } } return c; } Thank you to the original author of the code that i stripped this out of........ -- |"""""<`.THE PRINCE ,'>"""""""""""""""""""""""""""""""""""| | `.`/""""""\,',' my sig is too big, | |SEE HIS ( / \ \' SEE HIS but its really cool. | | FACE \/<> <>\/ SMILE | | / W \ Visit my ascii art site: | | ,'\_|||||_/`. http://www.gtcom.net/~krogg/ascii/ | | ,',' ||| `.`. krogg DOT no DOT to DOT spam AT gtcom DOT net | |____<,' TIME TO DIE `.>____Remove no.to.spam to reply____|