home *** CD-ROM | disk | FTP | other *** search
/ Kyūkyoku!! X68000 Emulator / X68000Book.dat / mac / OLS / X68000 / Ko-Window / kow142s.lzh / wsrv / clip.c < prev    next >
C/C++ Source or Header  |  1995-11-22  |  1KB  |  70 lines

  1.  
  2. #include <stdio.h>
  3.  
  4. #define    CLIP
  5. #include "clip.h"
  6.  
  7. #define min( a, b ) (a) < (b) ? (a) : (b)
  8. #define max( a, b ) (a) > (b) ? (a) : (b)
  9.  
  10. void    ClipSet( cp, x, y, h, v )
  11. ClipClass    *cp ;
  12. int            x, y, h, v ;
  13. {
  14.     cp->clip.x1 = x ;
  15.     cp->clip.y1 = y ;
  16.     cp->clip.x2 = x + h - 1 ;
  17.     cp->clip.y2 = y + v - 1 ;
  18. }
  19.  
  20. void    ClipMove( cp, x, y )
  21. ClipClass    *cp ;
  22. int        x, y ;
  23. {
  24.     x -= cp->clip.x1 ;
  25.     y -= cp->clip.y1 ;
  26.     cp->clip.x1 += x ;
  27.     cp->clip.y1 += y ;
  28.     cp->clip.x2 += x ;
  29.     cp->clip.y2 += y ;
  30. }
  31.  
  32. int        ClipInner( cp, x, y )
  33. ClipClass    *cp ;
  34. int        x, y ;
  35. {
  36.     return( cp->clip.x1 <= x && x <= cp->clip.x2 && cp->clip.y1 <= y && y <= cp->clip.y2 );
  37. }
  38.  
  39. void    ClipGetSize( cp, xp, yp )
  40. ClipClass    *cp ;
  41. int            *xp, *yp ;
  42. {
  43.     *xp = cp->clip.x2 - cp->clip.x1 + 1 ;
  44.     *yp = cp->clip.y2 - cp->clip.y1 + 1 ;
  45. }
  46.  
  47. int        ClipOverlap( ret, v1, v2 )
  48. ClipClass    *ret, *v1, *v2 ;
  49. {
  50.     ret->clip.x1 = max( v1->clip.x1, v2->clip.x1 );
  51.     ret->clip.y1 = max( v1->clip.y1, v2->clip.y1 );
  52.     ret->clip.x2 = min( v1->clip.x2, v2->clip.x2 );
  53.     ret->clip.y2 = min( v1->clip.y2, v2->clip.y2 );
  54.  
  55.     /*    ârâàü[â|ü[âgé¬Ådé╚éτé╚éóé╞é½  */
  56.     if ( ret->clip.x1 > ret->clip.x2 || ret->clip.y1 > ret->clip.y2 )
  57.         return( FALSE );
  58.  
  59.     return( TRUE );
  60. }
  61.  
  62. int        ClipSetDraw( buf, clip, code, option )
  63. DrawBuf        *buf ;
  64. ClipClass    *clip ;
  65. int            code, option ;
  66. {
  67.     DrawSetLine( buf, clip->clip.x1, clip->clip.y1, clip->clip.x2, clip->clip.y2, code, option );
  68.     return( 1 );
  69. }
  70.