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

  1. /* Copyright T.Kobayashi */
  2.  
  3. /* 1991 08/17 H.Ogasawara  è┐ÄÜæ╬ë₧, âëâCâuâëâèë╗ */
  4. /* 1995 11/29 H.Ogasawara  debug */
  5.  
  6.  
  7.  
  8. #include    <stdio.h>
  9. #include    <wlib.h>
  10.  
  11.  
  12. #define        swap( a1, a2 )    { int _w ; _w = a2 ; a2 = a1 ; a1 = _w ; }
  13.  
  14. static int        Ydot= 12;
  15. static int        Xdot= 6;
  16. static unsigned char    **CharBuf;
  17. static WindowID        Cwp;
  18. static int        COLOR= 1;
  19.  
  20. #define        LEFTOFF        0    /* window left offset */
  21. /*#define        COLOR        1    /* reverse color */
  22.  
  23.  
  24. static    void
  25. DrawSetRegion( buf, x1, x2, y )
  26. DrawBuf    *buf;
  27. int    x1,
  28.     x2,
  29.     y;
  30. {
  31.     DrawSetLine( buf, LEFTOFF+x1*Xdot, y*Ydot, LEFTOFF+x2*Xdot-1,
  32.                 (y+1)*Ydot-1, COLOR|OptionXor, OptionFill );
  33. }
  34.  
  35. static void
  36. DrawRegion( x1, y1, x2, y2 )
  37. int        x1,
  38.         y1,
  39.         x2,
  40.         y2;
  41. {
  42.     DrawBuf    buf[90],
  43.         *bufp= buf;
  44.  
  45.     if( y1 > y2 ){
  46.         swap( y1, y2 );
  47.         swap( x1, x2 );
  48.     }
  49.     if( y1 < y2 ){
  50.         int    len= strlen( CharBuf[y1] ),
  51.             i;
  52.         if( x1 < len + 1 )
  53.             DrawSetRegion( bufp++, x1, len+1, y1 );
  54.         for( i= y1+1 ; i < y2 ; i++ ){
  55.             len = strlen( CharBuf[i] );
  56.             DrawSetRegion( bufp++, 0, len+ 1, i );
  57.         }
  58.         if( 0 < x2 )
  59.             DrawSetRegion( bufp++, 0, x2, y2 );
  60.     }else{
  61.         if( x1 > x2 )
  62.             DrawSetRegion( bufp++, x2, x1, y1 );
  63.         else if( x1 < x2 )
  64.             DrawSetRegion( bufp++, x1, x2, y1 );
  65.         else
  66.             return;
  67.     }
  68.     WindowDraw( Cwp, buf, bufp-buf );
  69. }
  70.  
  71. #if 0
  72. static int
  73. kpos( x, ptr )
  74. int        x;
  75. unsigned char    *ptr;
  76. {
  77.     int        kanji= FALSE;
  78.     unsigned char    *buf= ptr+x;
  79.     for(; *ptr && ptr< buf ; ptr++ )
  80.         kanji= ( !kanji && iskanji( *ptr ) );
  81.     return    kanji;
  82. }
  83. #endif
  84.  
  85. /*
  86. WindowID    wp;        ò`ëµé╖éΘâEâBâôâhâEé╠ ID
  87. EventInfo    *info;
  88. unsigned char    **cb;        âXâNâèü[âôâCâüü[âWé≡èiö[é╡é╜â|âCâôâ^
  89. int        ScrV;        ëµû╩é╠Åcò√îⁿé╠ò╢ÄÜÉö
  90. int        space_cut;    ìsûûé╠âXâyü[âXé≡âJâbâgé╖éΘ
  91. int        font;        âtâHâôâgâTâCâY
  92. */
  93.  
  94.  
  95. asm( "    .xdef    _SetClipBoardOffset
  96. _SetClipBoardOffset    equ    _ClipSetOperation
  97. " );
  98.  
  99. void
  100. ClipSetOperation( wp, info, cb, ScrV, xoff, yoff, space_cut, color, font )
  101. WindowID    wp;
  102. EventInfo    *info;
  103. unsigned char    **cb;
  104. int        ScrV,
  105.         space_cut;
  106. unsigned int    font;
  107. {
  108.     int        x1,
  109.             y1,
  110.             x2,
  111.             y2;
  112.  
  113.     CharBuf= cb;
  114.     Cwp= wp;
  115.     Ydot= font;
  116.     Xdot= font>>1;
  117.     COLOR= color;
  118.  
  119.     if( info->x < xoff || info->y < yoff )
  120.         return;
  121.  
  122.     info->x-= xoff;
  123.     info->y-= yoff;
  124.  
  125.     /* set start position y */
  126.     y2= y1= info->y/Ydot;
  127.     if( y1 < 0 || ScrV <= y1 )
  128.         return;
  129.  
  130.     /* set start position x */
  131.     {
  132.         int        len= strlen( CharBuf[y1] );
  133.         x1= (info->x /*-LEFTOFF*/)/Xdot;
  134.         if( x1 > len+1 )
  135.             x1= len+1;
  136.         if( KanjiTestPosition( CharBuf[y1], x1 ) )
  137.             x1--;
  138.         x2= x1;
  139.     }
  140.  
  141.     {
  142.         int        sx,
  143.                 sy,
  144.                 h,
  145.                 v,
  146.                 hx,
  147.                 hy;
  148.         WindowGetScreenPosition( wp, &sx, &sy );
  149.         WindowGetViewSize( wp, &h, &v );
  150.         WindowGetHome( wp, &hx, &hy );
  151.         sx += xoff /*LEFTOFF*/;
  152.         h -= xoff /*LEFTOFF*/;
  153.         sy += yoff;
  154.         v -= yoff;
  155.         while( info->LeftStat ){
  156.             int    x,
  157.                 y;
  158.             WindowGetEventInfo( info );
  159.             x= info->x -sx;    /* set local position */
  160.             y= info->y -sy;
  161.             if( 0 <= x && x < h && 0 <= y && y < v ){
  162.                 int    len;
  163.                 x= (x+hx)/Xdot;
  164.                 y= (y+hy)/Ydot;
  165.                 if( y >= ScrV )
  166.                     y= ScrV-1;
  167.                 len= strlen( CharBuf[y] );
  168.                 if( x < 0 )
  169.                     x= 0;
  170.                 if( x > len+1 )
  171.                     x= len+1;
  172.                 if( KanjiTestPosition( CharBuf[y], x ) )
  173.                     x--;
  174.                 if( y != y2 || x != x2 ){
  175.                     DrawRegion( x, y, x2, y2 );
  176.                     y2= y;
  177.                     x2= x;
  178.                 }
  179.             }
  180.         }
  181.     }
  182.     DrawRegion( x1, y1, x2, y2 );
  183.  
  184.     if( y1 > y2 ){
  185.         swap( y1, y2 );
  186.         swap( x1, x2 );
  187.     }
  188.  
  189.     WindowResetCommon( "Clip Board" );
  190.  
  191.     {
  192.         unsigned char    *cp, *bp,
  193.                 **ptr= CharBuf+y1,
  194.                 *p;
  195.         int        len= 0,
  196.                 i;
  197.         for( i= y1 ; i<= y2 ; i++ )
  198.             len+= strlen( CharBuf[i] )+1;
  199.         bp= cp= WindowGetCommon( "Clip Board", len );
  200.         if( y1 < y2 ){
  201.             unsigned char    *b= cp;
  202.             for( p= (*ptr++)+x1 ; *cp++= *p++ ;);
  203.             if( space_cut ){
  204.                 for( cp-=2 ; cp > b && *cp == ' ' ; cp-- );
  205.                 cp+= 2;
  206.             }
  207.             cp[-1]= '\r';
  208.             for( i= y2-y1-1 ; i-- ; cp[-1]= '\r' ){
  209.                 for( b= cp, p= *ptr++ ; *cp++= *p++ ;);
  210.                 if( space_cut ){
  211.                     for( cp-=2 ; cp > b && *cp == ' ' ; cp-- );
  212.                     cp+= 2;
  213.                 }
  214.             }
  215.             p= *ptr;
  216.             i= x2;
  217.         }else{
  218.             i= x2-x1;
  219.             p= *ptr +x1;
  220.             if( x1 > x2 ){
  221.                 i= -i;
  222.                 p= *ptr +x2;
  223.             }
  224.         }
  225.         for(; i-- ; *cp++= *p++ );
  226.         *cp= '\0';
  227.         if( cp > bp && !cp[-1] )
  228.             cp[-1]= '\r';
  229.     }
  230. }
  231.  
  232.