home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / vifs / ggets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-29  |  1.1 KB  |  64 lines

  1. /*
  2.  *    ggets.c  -- get a string in graphic mode with echo
  3.  *
  4.  *    8 oct  1988  Olle
  5.  */
  6.  
  7. #include <graphics.h>
  8. #include <ctype.h>
  9. #include <conio.h>
  10.  
  11. void ggets( register char *buf )
  12. {
  13. char c[2];
  14. int n;
  15. int chw, chh;
  16. struct fillsettingstype fis;
  17.  
  18. /* get a string in graphic mode with echo */
  19. /* assume TOP_TEXT & LEFT_TEXT justification */
  20.  
  21. /* get character size for erase */
  22. chw = textwidth( "A" );
  23. chh = textheight( "A" );
  24.  
  25. /* get fill settings */
  26. getfillsettings( &fis );
  27.  
  28. /* setup for character erase */
  29. setfillstyle( SOLID_FILL, getbkcolor() );
  30.  
  31. c[1] = '\0';
  32.  
  33. for ( n = 0;;)
  34.     {
  35.     c[0] = *buf++ = getch();
  36.  
  37.     if (isprint( c[0] ))
  38.         {
  39.         outtext( c );
  40.         ++n;
  41.         }
  42.     else if (c[0] == '\b' && n > 0)
  43.         {
  44.         buf -= 2; --n;
  45.         /* erasing is a bit elaborate */
  46.         moverel( -chw, 0 );
  47.  
  48.         /* fill with the background color */
  49.         bar( getx(), gety(), getx() + chw - 1, gety() + chh - 1 );
  50.         }
  51.     else if (c[0] == '\b')
  52.         --buf;
  53.     else if (c[0] == '\r' || c[0] == '\n')
  54.         {
  55.         *--buf = '\0';
  56.         break;
  57.         }
  58.     }
  59.  
  60. /* restore fill settings */
  61. setfillstyle( fis.pattern, fis.color );
  62. }
  63.  
  64.