home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Tcl-Tk 8.0 / Pre-installed version / tk8.0 / win / tkWinRegion.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-15  |  3.7 KB  |  180 lines  |  [TEXT/CWIE]

  1. /* 
  2.  * tkWinRegion.c --
  3.  *
  4.  *    Tk Region emulation code.
  5.  *
  6.  * Copyright (c) 1995 Sun Microsystems, Inc.
  7.  *
  8.  * See the file "license.terms" for information on usage and redistribution
  9.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10.  *
  11.  * SCCS: @(#) tkWinRegion.c 1.7 96/05/03 11:05:54
  12.  */
  13.  
  14. #include "tkWinInt.h"
  15.  
  16.  
  17. /*
  18.  *----------------------------------------------------------------------
  19.  *
  20.  * TkCreateRegion --
  21.  *
  22.  *    Construct an empty region.
  23.  *
  24.  * Results:
  25.  *    Returns a new region handle.
  26.  *
  27.  * Side effects:
  28.  *    None.
  29.  *
  30.  *----------------------------------------------------------------------
  31.  */
  32.  
  33. TkRegion
  34. TkCreateRegion()
  35. {
  36.     RECT rect;
  37.     memset(&rect, 0, sizeof(RECT));
  38.     return (TkRegion) CreateRectRgnIndirect(&rect);
  39. }
  40.  
  41. /*
  42.  *----------------------------------------------------------------------
  43.  *
  44.  * TkDestroyRegion --
  45.  *
  46.  *    Destroy the specified region.
  47.  *
  48.  * Results:
  49.  *    None.
  50.  *
  51.  * Side effects:
  52.  *    Frees the storage associated with the specified region.
  53.  *
  54.  *----------------------------------------------------------------------
  55.  */
  56.  
  57. void
  58. TkDestroyRegion(r)
  59.     TkRegion r;
  60. {
  61.     DeleteObject((HRGN) r);
  62. }
  63.  
  64. /*
  65.  *----------------------------------------------------------------------
  66.  *
  67.  * TkClipBox --
  68.  *
  69.  *    Computes the bounding box of a region.
  70.  *
  71.  * Results:
  72.  *    Sets rect_return to the bounding box of the region.
  73.  *
  74.  * Side effects:
  75.  *    None.
  76.  *
  77.  *----------------------------------------------------------------------
  78.  */
  79.  
  80. void
  81. TkClipBox(r, rect_return)
  82.     TkRegion r;
  83.     XRectangle* rect_return;
  84. {
  85.     RECT rect;
  86.     GetRgnBox((HRGN)r, &rect);
  87.     rect_return->x = (short) rect.left;
  88.     rect_return->y = (short) rect.top;
  89.     rect_return->width = (short) (rect.right - rect.left);
  90.     rect_return->height = (short) (rect.bottom - rect.top);
  91. }
  92.  
  93. /*
  94.  *----------------------------------------------------------------------
  95.  *
  96.  * TkIntersectRegion --
  97.  *
  98.  *    Compute the intersection of two regions.
  99.  *
  100.  * Results:
  101.  *    Returns the result in the dr_return region.
  102.  *
  103.  * Side effects:
  104.  *    None.
  105.  *
  106.  *----------------------------------------------------------------------
  107.  */
  108.  
  109. void
  110. TkIntersectRegion(sra, srb, dr_return)
  111.     TkRegion sra;
  112.     TkRegion srb;
  113.     TkRegion dr_return;
  114. {
  115.     CombineRgn((HRGN) dr_return, (HRGN) sra, (HRGN) srb, RGN_AND);
  116. }
  117.  
  118. /*
  119.  *----------------------------------------------------------------------
  120.  *
  121.  * TkUnionRectWithRegion --
  122.  *
  123.  *    Create the union of a source region and a rectangle.
  124.  *
  125.  * Results:
  126.  *    Returns the result in the dr_return region.
  127.  *
  128.  * Side effects:
  129.  *    None.
  130.  *
  131.  *----------------------------------------------------------------------
  132.  */
  133.  
  134. void
  135. TkUnionRectWithRegion(rectangle, src_region, dest_region_return)
  136.     XRectangle* rectangle;
  137.     TkRegion src_region;
  138.     TkRegion dest_region_return;
  139. {
  140.     HRGN rectRgn = CreateRectRgn(rectangle->x, rectangle->y,
  141.         rectangle->x + rectangle->width, rectangle->y + rectangle->height);
  142.     CombineRgn((HRGN) dest_region_return, (HRGN) src_region,
  143.         (HRGN) rectRgn, RGN_OR);
  144.     DeleteObject(rectRgn);
  145. }
  146.  
  147. /*
  148.  *----------------------------------------------------------------------
  149.  *
  150.  * TkRectInRegion --
  151.  *
  152.  *    Test whether a given rectangle overlaps with a region.
  153.  *
  154.  * Results:
  155.  *    Returns RectanglePart or RectangleOut.  Note that this is
  156.  *    not a complete implementation since it doesn't test for
  157.  *    RectangleIn.
  158.  *
  159.  * Side effects:
  160.  *    None.
  161.  *
  162.  *----------------------------------------------------------------------
  163.  */
  164.  
  165. int
  166. TkRectInRegion(r, x, y, width, height)
  167.     TkRegion r;
  168.     int x;
  169.     int y;
  170.     unsigned int width;
  171.     unsigned int height;
  172. {
  173.     RECT rect;
  174.     rect.top = y;
  175.     rect.left = x;
  176.     rect.bottom = y+height;
  177.     rect.right = x+width;
  178.     return RectInRegion((HRGN)r, &rect) ? RectanglePart : RectangleOut;
  179. }
  180.