Fixing a small bug for hide mouse. Save the current surface under the mouse. But...
[reactos.git] / rosapps / dflat32 / rect.c
1 /* ------------- rect.c --------------- */
2
3 #include "dflat.h"
4
5 /* --- Produce the vector end points produced by the overlap
6 of two other vectors --- */
7 static void subVector(int *v1, int *v2,
8 int t1, int t2, int o1, int o2)
9 {
10 *v1 = *v2 = -1;
11 if (DfWithin(o1, t1, t2)) {
12 *v1 = o1;
13 if (DfWithin(o2, t1, t2))
14 *v2 = o2;
15 else
16 *v2 = t2;
17 }
18 else if (DfWithin(o2, t1, t2)) {
19 *v2 = o2;
20 if (DfWithin(o1, t1, t2))
21 *v1 = o1;
22 else
23 *v1 = t1;
24 }
25 else if (DfWithin(t1, o1, o2)) {
26 *v1 = t1;
27 if (DfWithin(t2, o1, o2))
28 *v2 = t2;
29 else
30 *v2 = o2;
31 }
32 else if (DfWithin(t2, o1, o2)) {
33 *v2 = t2;
34 if (DfWithin(t1, o1, o2))
35 *v1 = t1;
36 else
37 *v1 = o1;
38 }
39 }
40
41 /* --- Return the rectangle produced by the overlap
42 of two other rectangles ---- */
43 DFRECT DfSubRectangle(DFRECT r1, DFRECT r2)
44 {
45 DFRECT r = {0,0,0,0};
46 subVector((int *) &DfRectLeft(r), (int *) &DfRectRight(r),
47 DfRectLeft(r1), DfRectRight(r1),
48 DfRectLeft(r2), DfRectRight(r2));
49 subVector((int *) &DfRectTop(r), (int *) &DfRectBottom(r),
50 DfRectTop(r1), DfRectBottom(r1),
51 DfRectTop(r2), DfRectBottom(r2));
52 if (DfRectRight(r) == -1 || DfRectTop(r) == -1)
53 DfRectRight(r) =
54 DfRectLeft(r) =
55 DfRectTop(r) =
56 DfRectBottom(r) = 0;
57 return r;
58 }
59
60 /* ------- return the client rectangle of a window ------ */
61 DFRECT DfClientRect(void *wnd)
62 {
63 DFRECT rc;
64
65 if (wnd == NULL)
66 {
67 DfRectLeft(rc) = 1; // DfGetClientLeft((DFWINDOW)wnd);
68 DfRectTop(rc) = 2; // DfGetClientTop((DFWINDOW)wnd);
69 DfRectRight(rc) = DfGetScreenWidth () - 2; // DfGetClientRight((DFWINDOW)wnd);
70 DfRectBottom(rc) = DfGetScreenHeight () - 2; // DfGetClientBottom((DFWINDOW)wnd);
71 return rc;
72 }
73
74 DfRectLeft(rc) = DfGetClientLeft((DFWINDOW)wnd);
75 DfRectTop(rc) = DfGetClientTop((DFWINDOW)wnd);
76 DfRectRight(rc) = DfGetClientRight((DFWINDOW)wnd);
77 DfRectBottom(rc) = DfGetClientBottom((DFWINDOW)wnd);
78
79 return rc;
80 }
81
82 /* ----- return the rectangle relative to
83 its window's screen position -------- */
84 DFRECT DfRelativeWindowRect(void *wnd, DFRECT rc)
85 {
86 DfRectLeft(rc) -= DfGetLeft((DFWINDOW)wnd);
87 DfRectRight(rc) -= DfGetLeft((DFWINDOW)wnd);
88 DfRectTop(rc) -= DfGetTop((DFWINDOW)wnd);
89 DfRectBottom(rc) -= DfGetTop((DFWINDOW)wnd);
90 return rc;
91 }
92
93 /* ----- clip a rectangle to the parents of the window ----- */
94 DFRECT DfClipRectangle(void *wnd, DFRECT rc)
95 {
96 DFRECT sr;
97 DfRectLeft(sr) = DfRectTop(sr) = 0;
98 DfRectRight(sr) = DfGetScreenWidth()-1;
99 DfRectBottom(sr) = DfGetScreenHeight()-1;
100 if (!DfTestAttribute((DFWINDOW)wnd, DF_NOCLIP))
101 while ((wnd = DfGetParent((DFWINDOW)wnd)) != NULL)
102 rc = DfSubRectangle(rc, DfClientRect(wnd));
103 return DfSubRectangle(rc, sr);
104 }
105
106 /* EOF */