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

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