home *** CD-ROM | disk | FTP | other *** search
/ PC Shareware 1999 March / PCShareware-3-99.iso / IMPLE / DJGPP.RAR / DJGPP2 / XLIB-SR0.ZIP / SRC / XLIBEMU / COPYAREA.C < prev    next >
C/C++ Source or Header  |  1994-01-14  |  4KB  |  149 lines

  1. /* $Id: copyarea.c 1.2 1994/01/15 02:12:35 ulrich Exp $ */
  2. /*
  3.  * copyarea.c
  4.  *
  5.  * X library function XCopyArea.
  6.  * GC Functions are only partly implemented.
  7.  */
  8. #include "Xlibemu.h"
  9. #ifdef DEBUG
  10. #include <stdio.h>
  11. #endif
  12.  
  13. extern int _GXfunctionToGrOPER[];
  14.  
  15. int
  16. XCopyArea(
  17.     Display*        dpy,
  18.     Drawable        src,
  19.     Drawable        dest,
  20.     GC            gc,
  21.     int            src_x,
  22.     int            src_y,
  23.     unsigned int    width,
  24.     unsigned int    height,
  25.     int            dest_x,
  26.     int            dest_y)
  27. {
  28.   int oper;
  29.   GrContext *src_mem, *dest_mem;
  30.  
  31.   oper = _GXfunctionToGrOPER[gc->values.function];
  32.  
  33.   switch (src->type) {
  34.   case 2:
  35.     src_mem = ((Window) src)->context;
  36.     break;
  37.   case 3:
  38.     src_mem = ((Pixmap) src)->context;
  39.     break;
  40.   default:
  41.     return 0;
  42.     break;
  43.   }
  44.   switch (dest->type) {
  45.   case 2:
  46.     dest_mem = ((Window) dest)->context;
  47.     {
  48.       int i, dest_x1, dest_y1;
  49.       XRectangle rect;
  50.       Region region;
  51.       BoxPtr pbox;
  52.       Window dest_w = (Window) dest;
  53.  
  54.       dest_x1 = dest_w->window_port.x1;
  55.       dest_y1 = dest_w->window_port.y1;
  56.  
  57.       rect.x = dest_x1 + dest_x;
  58.       rect.y = dest_y1 + dest_y;
  59.       rect.width = width;
  60.       rect.height = height;
  61.       region = XCreateRegion ();
  62.       XUnionRectWithRegion (&rect, region, region);
  63.       XIntersectRegion (dest_w->visible_region, region, region);
  64.       XOffsetRegion (region, -rect.x, -rect.y);
  65.  
  66.       pbox = region->rects;
  67.       for (i = region->numRects; --i >= 0; pbox++) {
  68.     GrBitBlt (dest_mem,
  69.           dest_x + pbox->x1,
  70.           dest_y + pbox->y1,
  71.           src_mem,
  72.           src_x + pbox->x1,
  73.           src_y + pbox->y1,
  74.           src_x + pbox->x2 - 1,
  75.           src_y + pbox->y2 - 1,
  76.           oper);
  77.       }
  78.       XDestroyRegion (region);
  79.  
  80.       if (src->type == 2 && gc->values.graphics_exposures == True) {
  81.     int dx, dy;
  82.     XEvent xe;
  83.     Window src_w = (Window) src;
  84.  
  85.     region = XCreateRegion ();
  86.     rect.x = src_w->window_port.x1 + src_x;
  87.     rect.y = src_w->window_port.y1 + src_y;
  88.     rect.width = width;
  89.     rect.height = height;
  90.     XUnionRectWithRegion (&rect, region, region);
  91.     XSubtractRegion (region, src_w->visible_region, region);
  92.  
  93.     /* move not available src region to dest window */
  94.  
  95.     dx = (dest_x1 + dest_x) - rect.x;
  96.     dy = (dest_y1 + dest_y) - rect.y;
  97.  
  98.     XOffsetRegion (region, dx, dy);
  99.     XIntersectRegion (dest_w->visible_region, region, region);
  100.  
  101.     pbox = region->rects;
  102.     for (i = region->numRects; --i >= 0; pbox++) {
  103.       xe.xgraphicsexpose.type = GraphicsExpose;
  104.       xe.xgraphicsexpose.send_event = False;
  105.       xe.xgraphicsexpose.display = dpy;
  106.       xe.xgraphicsexpose.drawable = dest;
  107.       xe.xgraphicsexpose.x = pbox->x1 - dest_x1;
  108.       xe.xgraphicsexpose.y = pbox->y1 - dest_y1;
  109.       xe.xgraphicsexpose.width = pbox->x2 - pbox->x1;
  110.       xe.xgraphicsexpose.height = pbox->y2 - pbox->y1;
  111. #if 0
  112.       fprintf (stderr, "GE src=%x dest=%x count=%d x1=%d y1=%d x2=%d y2=%d\n",
  113.            (int) src, (int) dest, i, b->x1, b->y1, b->x2, b->y2);
  114. #endif
  115.       xe.xgraphicsexpose.count = i;
  116.       xe.xgraphicsexpose.major_code = X_CopyArea;
  117.       xe.xgraphicsexpose.minor_code = 0;
  118.       _XEnq (dpy, &xe);
  119.     }
  120.     if (region->numRects == 0) {
  121.       xe.xnoexpose.type = NoExpose;
  122.       xe.xnoexpose.send_event = False;
  123.       xe.xnoexpose.display = dpy;
  124.       xe.xnoexpose.drawable = dest;
  125.       xe.xnoexpose.major_code = X_CopyArea;
  126.       xe.xnoexpose.minor_code = 0;
  127.       _XEnq (dpy, &xe);
  128.     }
  129.     XDestroyRegion (region);
  130.       }
  131.     }
  132.     break;
  133.   case 3:
  134.     dest_mem = ((Pixmap) dest)->context;
  135.     {
  136.       GrBitBlt (dest_mem,
  137.         dest_x, dest_y,
  138.         src_mem,
  139.         src_x, src_y, src_x + width - 1, src_y + height - 1,
  140.         oper);
  141.     }
  142.     break;
  143.   default:
  144.     return 0;
  145.     break;
  146.   }
  147.   return 1;
  148. }
  149.