home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / progjour / 1991 / 04 / v_move.c < prev    next >
C/C++ Source or Header  |  1991-05-03  |  1KB  |  49 lines

  1. /*    v_move.c- Move Viewport */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <tools/viewport.h>
  7.  
  8. int v_move( viewport *v, unsigned row, unsigned col )
  9. {
  10.     /* Move the viewport to indicated absolute row and column. The
  11.      * viewport must be closed or hidden to move it. If the viewport
  12.      * is open and active, it's deactivated, moved, then reopened.
  13.      * You may not move the viewport past the edge of the screen.
  14.      * Return true if the viewport ended up where specified, false if
  15.      * it bumped up against the side of the screen.
  16.      */
  17.  
  18.     int              rval       = 1 ;   /* return value */
  19.     int              was_active = !v->inactive;
  20.     struct text_info info;
  21.  
  22.     if( v->magic != VMAGIC )
  23.         return 0;
  24.  
  25.     gettextinfo( &info );
  26.  
  27.     if( row+v->nrows > info.screenheight  )     /* Truncate row and col */
  28.     {                                           /* so that the viewport */
  29.         row = info.screenheight - v->nrows ;    /* stays on the screen. */
  30.         rval = 0;
  31.     }
  32.     if( col+v->ncols > info.screenwidth )
  33.     {
  34.         col = info.screenwidth - v->ncols ;
  35.         rval = 0;
  36.     }
  37.  
  38.     if( was_active )
  39.         v_deactivate( v, 1 );
  40.  
  41.     v->row = row;
  42.     v->col = col;
  43.  
  44.     if( was_active )
  45.         v_open( v );
  46.  
  47.     return rval;
  48. }
  49.