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

  1. /*    v_scroll.c */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <tools/viewport.h>
  7.  
  8. int v_scroll_region( viewport *v, int up, int to_left,
  9.                     int left, int top, int right, int bottom )
  10. {
  11.       /* Move the text in the viewport "to_left" lines to the left and up
  12.        * "up" lines. Go right if "to_left" is negative, down if "up" is
  13.        * negative. Cursor position is not changed. Newly opened space
  14.        * is filled with blanks. This function may not be used to clear
  15.        * the viewport--false is returned (and no movement occurs along
  16.        * that axis) if the requested movement is >= the viewpoint
  17.        * dimension. Use v_clear() to clear a viewport.
  18.        *
  19.        * The scrolled region is bounded by by the window-relative left and right
  20.        * columms, and top and bottom rows. You can use 0,0,100,100 for these
  21.        * last four arguments if you want to scroll the whole window because
  22.        * v_scroll_region truncates the box size down to the viewport size
  23.        * if necessary.
  24.        */
  25.  
  26.     int this_many, from, to, ncols, nrows;
  27.     int value = 1;                /* return value */
  28.  
  29.     if( v->magic != VMAGIC )
  30.     return 0;
  31.     if( v->inactive )
  32.     v_open( v );
  33.  
  34.     left  = v->col + left;        /* figure out the cooridinates  */
  35.     top   = v->row + top;        /* of the upper left corner,    */
  36.     ncols = right-left +1;        /* and the size of the affected */
  37.     nrows = bottom-top +1;        /* region.            */
  38.  
  39.     if( (left >= v->ncols) || (top >= v->nrows) ) /* bounding box is outside */
  40.     return 0;                  /* window entirely.         */
  41.  
  42.     if( left + ncols > v->ncols )    /* if the bounding box is outside  */
  43.     {                    /* of the window, truncate it down */
  44.     ncols = v->ncols - left ;    /* to fit.               */
  45.     value = 0;
  46.     }
  47.     if( top  + nrows > v->nrows )
  48.     {
  49.         nrows = v->nrows - top ;
  50.     value = 0;
  51.     }
  52.  
  53.     /* Do horizontal motion first, then vertical. */
  54.  
  55.     if( to_left )
  56.     {
  57.     this_many = ncols - abs(to_left) ;
  58.     from      = (to_left > 0) ? (left + to_left):(left        );
  59.     to      = (to_left > 0) ? (left          ):(left - to_left);
  60.  
  61.     if( this_many < 0 )
  62.         value = 0;
  63.     else if( this_many > 0 )
  64.         movetext( from+1, top+1, from+this_many, top+nrows,
  65.                             to +1, top +1 );
  66.  
  67.     _v_fill_scr( VINIT_CHAR | (v->bcolor << 4 | v->fcolor) << 8,
  68.                top, to_left > 0 ? left + this_many : left,
  69.                    nrows, ncols - this_many );
  70.     }
  71.     if( up )
  72.     {
  73.     this_many = nrows - abs( up ) ;
  74.     from      = (up > 0) ? (top +  up) : (top      );
  75.     to      = (up > 0) ? (top      ) : (top -  up);
  76.  
  77.     if( this_many < 0 )
  78.         value = 0;
  79.     else if( this_many > 0 )
  80.         movetext( left+1, from+1, left+ncols, from+this_many,
  81.                             left+1, to+1 );
  82.  
  83.     _v_fill_scr( VINIT_CHAR | (v->bcolor << 4 | v->fcolor) << 8,
  84.             up > 0 ? top + this_many : top , left,
  85.                     nrows - this_many, ncols );
  86.     }
  87.     return value;
  88. }
  89.  
  90.