www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/12/27/13:36:41

Message-ID: <3A4A3486.1745FBE4@gtcom.net>
From: Krogg <krogg DOT no DOT to DOT spam AT gtcom DOT net>
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: <Pwo26.57825$Z9 DOT 3562044 AT news1 DOT rdc1 DOT mb DOT home DOT com>
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( <we are still wanting input> )
 {
  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____|

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019