home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / x / xibm.zip / ibm8514 / brcTile.c < prev    next >
C/C++ Source or Header  |  1991-09-20  |  6KB  |  204 lines

  1. /*
  2.  * $Id: brcTile.c,v 1.1 1991/09/20 19:10:24 mtranle Exp $
  3.  *
  4.  * Copyright IBM Corporation 1987,1990
  5.  *
  6.  * All Rights Reserved
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that 
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of IBM not be
  13.  * used in advertising or publicity pertaining to distribution of the
  14.  * software without specific, written prior permission.
  15.  *
  16.  * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  17.  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  18.  * IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  19.  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20.  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  21.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  22.  * SOFTWARE.
  23.  *
  24. */
  25. /*
  26.  * PRPQ 5799-PFF (C) COPYRIGHT IBM CORPORATION 1987,1990
  27.  * LICENSED MATERIALS - PROPERTY OF IBM
  28.  * REFER TO COPYRIGHT INSTRUCTIONS FORM NUMBER G120-2083
  29.  */
  30. /*
  31.  *  Hardware interface routines for IBM 8514/A adapter for
  32.  *  X.11 server(s) on IBM equipment.
  33.  *
  34.  */
  35.  
  36. /* Tile an area with a pixmap image.
  37.  *
  38.  */
  39. #include "X.h"
  40. #include "misc.h"
  41. #include "gcstruct.h"
  42. #include "pixmapstr.h"
  43.  
  44. #include "OScompiler.h"
  45.  
  46. #include "x8514.h"
  47.  
  48. #include "ibmTrace.h"
  49.  
  50. extern int ibm8514cursorSemaphore ;
  51.  
  52. void
  53. ibm8514RotateTile( w, h, dx, dy )
  54.      int w, h, dx, dy ;
  55. {
  56.     int rx, ry ;
  57.  
  58.     /*THIS IS COMPLETELY OFFSCREEN, SO DISABLE CURSORCHECKING */
  59.     ibm8514cursorSemaphore++ ;
  60.  
  61.     rx = w - dx ;
  62.     ry = h - dy ;
  63.  
  64.     /* DO BOTTOM RIGHT */
  65.     /* You definitely want to do this, even if dx==dy==0.
  66.        This is to force *something* into the RotatedTile location */
  67.     ibm8514Bitblt( GXcopy, ibm8514ALLPLANES, ibm8514ALLPLANES,
  68.           TILE_X + dx, TILE_Y + dy,
  69.           ROTTILE_X, ROTTILE_Y,
  70.           rx, ry ) ;
  71.  
  72.     /* DO TOP RIGHT */
  73.     if (dy)
  74.     ibm8514Bitblt( GXcopy, ibm8514ALLPLANES, ibm8514ALLPLANES,
  75.               TILE_X + dx, TILE_Y,
  76.               ROTTILE_X, ROTTILE_Y + ry,
  77.               rx, dy ) ;
  78.  
  79.     /* DO BOTTOM LEFT */
  80.     if (dx)
  81.     {
  82.     ibm8514Bitblt( GXcopy, ibm8514ALLPLANES, ibm8514ALLPLANES,
  83.               TILE_X , TILE_Y+dy,
  84.               ROTTILE_X+rx, ROTTILE_Y,
  85.               dx, ry ) ;
  86.  
  87.     /* DO TOP LEFT */
  88.     if (dy)
  89.         ibm8514Bitblt( GXcopy,  ibm8514ALLPLANES, ibm8514ALLPLANES,
  90.               TILE_X , TILE_Y,
  91.               ROTTILE_X+rx, ROTTILE_Y+ry,
  92.               dx, dy ) ;
  93.     }
  94.  
  95.     /* set things back the way you found them */
  96.     ibm8514cursorSemaphore-- ;
  97.  
  98.     return ;
  99. }
  100.  
  101. void
  102. ibm8514TileRect( pTile, merge, planes, x, y, w, h, xSrc, ySrc )
  103.      PixmapPtr     pTile ;
  104.      int     merge ;
  105.      unsigned long int planes ;
  106.      int     x, y, w, h, xSrc, ySrc ;
  107. {
  108.     int htarget, tlx, tly ;
  109.     int maxhite, maxwid ;
  110.     int CursorIsSaved ;
  111.     int tmp_w, tw, th, hoffset, voffset ;
  112.  
  113.     TRACE( ( "ibm8514TileRect(pTile=x%x,merge=x%x,planes=x%02x,x=%d,y=%d,w=%d,h=%d,xSrc=%d,ySrc=%d\n",
  114.         pTile, merge, planes, x, y, w, h, xSrc, ySrc ) ) ;
  115.  
  116.     x = MAX(0,x) ;
  117.     y = MAX(0,y) ;
  118.     w = MIN(_8514_SCREENWIDTH-x,w) ;
  119.     h = MIN(_8514_SCREENHEIGHT-y,h) ;
  120.  
  121.     if ( (w <= 0) || (h <= 0) )
  122.     return ;
  123.  
  124.     /* trap the trivial cases.  Use ppcrep if you can.  Fall thru to do the
  125.      * hard cases if you have to.
  126.      */
  127.  
  128.     switch ( merge )
  129.     {
  130.       case GXset :
  131.       case GXclear :
  132.       case GXinvert :
  133.     ibm8514DrawRectangle( ibm8514ALLPLANES, merge, planes,
  134.                  x, y, w, h ) ;
  135.       case GXnoop:
  136.     return ;
  137.       case GXcopy :
  138.       case GXcopyInverted :
  139.     ppcTileRect( pTile, merge, planes, x, y, w, h, xSrc, ySrc ) ;
  140.     return ;
  141.     default :
  142.     tlx = pTile->drawable.width ;
  143.     tly = pTile->drawable.height ;
  144.     if ( ( tlx > MAXTILESIZE ) || ( tly > MAXTILESIZE ) )
  145.     {
  146.         ppcTileRect( pTile, merge, planes,
  147.             x, y, w, h, xSrc, ySrc ) ;
  148.         return ;
  149.     }
  150.     break ;
  151.     }
  152.  
  153.     CursorIsSaved =
  154.     !ibm8514cursorSemaphore && ibm8514CheckCursor( x, y, w, h ) ;
  155.     ibm8514cursorSemaphore++ ;
  156.  
  157.     /* ALAS, ALACK, we are going to have to actually draw the silly thing N
  158.        times.  I won't bother rotating it, I'll just draw to the origin points
  159.        clipped to the desired box.  It's not clear when this is a win.
  160.        */
  161.     ibm8514DrawColorImage( TILE_X, TILE_Y, tlx, tly,
  162.               pTile->devPrivate.ptr,
  163.               pTile->devKind,
  164.               GXcopy, ibm8514ALLPLANES ) ;
  165.  
  166.     /*expand the tile to largest available size */
  167.     maxwid = MIN( MAXTILESIZE, w ) ;
  168.     while ( tlx << 1 <= maxwid )
  169.     {
  170.     ibm8514Bitblt( GXcopy, ibm8514ALLPLANES, ibm8514ALLPLANES,
  171.               TILE_X, TILE_Y, tlx + TILE_X, TILE_Y, tlx, tly ) ;
  172.     tlx <<= 1 ;
  173.     }
  174.     maxhite = MIN( MAXTILESIZE, h ) ;
  175.     while ( tly << 1 <= maxhite )
  176.     {
  177.     ibm8514Bitblt( GXcopy, ibm8514ALLPLANES, ibm8514ALLPLANES,
  178.               TILE_X, TILE_Y, TILE_X, TILE_Y + tly, tlx, tly ) ;
  179.     tly <<= 1 ;
  180.     }
  181.  
  182.     if ( ( hoffset = ( x - xSrc ) % tlx ) < 0 )
  183.     hoffset += tlx ;
  184.     if ( ( voffset = ( y - ySrc ) % tly ) < 0 )
  185.     voffset += tly ;
  186.  
  187.     ibm8514RotateTile( tlx, tly, hoffset, voffset ) ;
  188.  
  189.     for ( ; h ; h -= th, y += th )
  190.     {
  191.     th = MIN( h, tly ) ;
  192.     for ( htarget = x, tmp_w = w ; tmp_w ; tmp_w -= tw, htarget += tlx )
  193.         ibm8514Bitblt( merge, ibm8514ALLPLANES, planes,
  194.               ROTTILE_X, ROTTILE_Y,
  195.               htarget, y,
  196.               tw = MIN( tmp_w, tlx ), th ) ;
  197.     }
  198.  
  199.     if ( !--ibm8514cursorSemaphore && CursorIsSaved )
  200.     ibm8514ReplaceCursor() ;
  201.  
  202.     return ;
  203. }
  204.