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