home *** CD-ROM | disk | FTP | other *** search
/ Kyūkyoku!! X68000 Emulator / X68000Book.dat / mac / OLS / X68000 / Ko-Window / kow142s.lzh / parts / textmap.c < prev    next >
C/C++ Source or Header  |  1990-07-14  |  2KB  |  110 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include "wlib.h"
  5. #include "parts.h"
  6.  
  7. /*
  8.     proto -s textmap.c > temp
  9. */
  10. static    int        TextMapExec( WindowID, EventInfo* );
  11.  
  12. typedef    struct    {
  13.         int        colums, lines ;
  14.         int        attr, font ;
  15.         char    *buf ;
  16.     }
  17.         TextMap ;
  18.  
  19. WindowID    TextMapOpen( x, y, colums, lines, parent, attr, font )
  20. int            x, y, colums, lines ;
  21. WindowID    parent ;
  22. int            attr, font ;
  23. {
  24.     WindowID    wp ;
  25.     TextMap        *p ;
  26.     int            i, len ;
  27.  
  28.     wp = WindowOpen( x, y, colums * font / 2, lines * font, parent, TextMapExec );
  29.     p = malloc( sizeof( TextMap ) );
  30.     if ( p == NULL )
  31.         return( NULL );
  32.     p->buf = malloc( lines * ( colums + 1 ) );
  33.     if ( p->buf == NULL )
  34.     {
  35.         free( p );
  36.         return( NULL );
  37.     }
  38.     len = colums + 1 ;
  39.     for( i = 0 ; i < lines ; ++i )
  40.     {
  41.         memset( p->buf + i * len, ' ', colums );
  42.         p->buf[ i * len + colums ] = '\0' ;
  43.     }
  44.  
  45.     p->colums = colums ;
  46.     p->lines = lines ;
  47.     p->attr = attr ;
  48.     p->font = font ;
  49.     WindowSetClientData( wp, 0, p );
  50.     return( wp );
  51. }
  52.  
  53. void    TextMapClose( wp )
  54. WindowID    wp ;
  55. {
  56.     TextMap        *p ;
  57.  
  58.     p = WindowGetClientPointer( wp );
  59.     free( p->buf );
  60.     free( p );
  61. }
  62.  
  63. static    int        TextMapExec( wp, info )
  64. WindowID    wp ;
  65. EventInfo    *info ;
  66. {
  67.     int            i, j, n, len ;
  68.     DrawBuf        buf[10], *bufp ;
  69.     TextMap        *p ;
  70.  
  71.     p = WindowGetClientPointer( wp );
  72.     switch( info->option )
  73.     {
  74.         case EventRedraw :
  75.             DrawSetClear( buf, 1 );
  76.             WindowDraw( wp, buf, 1 );
  77.             i = info->y / p->font ;
  78.             n = ( info->y + info->v ) / p->font + 1 ;
  79.             if ( n >= p->lines )
  80.                 n = p->lines - 1 ;
  81.             len = p->colums + 1 ;
  82.             while( i <= n )
  83.             {
  84.                 bufp = buf ;
  85.                 for( j = 0 ; j < 10 ; ++j )
  86.                 {
  87.                     DrawSetSymbol( bufp++, 0, i * p->font, p->buf + i*len, p->attr, p->font );
  88.                     if ( ++i > n )
  89.                         break ;
  90.                 }
  91.                 WindowDraw( wp, buf, bufp-buf );
  92.             }
  93.             break ;
  94.     }
  95.     return( TRUE );
  96. }
  97.  
  98. void    TextMapPutString( wp, x, y, str )
  99. WindowID    wp ;
  100. int            x, y ;
  101. char        *str ;
  102. {
  103.     TextMap        *p ;
  104.     int            len ;
  105.  
  106.     p = WindowGetClientPointer( wp );
  107.     len = p->colums + 1 ;
  108.     memcpy( p->buf + y*len + x, str, strlen( str ) );
  109. }
  110.