1 /* ------------- rect.c --------------- */
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
)
11 if (DfWithin(o1
, t1
, t2
)) {
13 if (DfWithin(o2
, t1
, t2
))
18 else if (DfWithin(o2
, t1
, t2
)) {
20 if (DfWithin(o1
, t1
, t2
))
25 else if (DfWithin(t1
, o1
, o2
)) {
27 if (DfWithin(t2
, o1
, o2
))
32 else if (DfWithin(t2
, o1
, o2
)) {
34 if (DfWithin(t1
, o1
, o2
))
41 /* --- Return the rectangle produced by the overlap
42 of two other rectangles ---- */
43 DFRECT
DfSubRectangle(DFRECT r1
, DFRECT r2
)
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)
60 /* ------- return the client rectangle of a window ------ */
61 DFRECT
DfClientRect(void *wnd
)
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);
74 DfRectLeft(rc
) = DfGetClientLeft((DFWINDOW
)wnd
);
75 DfRectTop(rc
) = DfGetClientTop((DFWINDOW
)wnd
);
76 DfRectRight(rc
) = DfGetClientRight((DFWINDOW
)wnd
);
77 DfRectBottom(rc
) = DfGetClientBottom((DFWINDOW
)wnd
);
82 /* ----- return the rectangle relative to
83 its window's screen position -------- */
84 DFRECT
DfRelativeWindowRect(void *wnd
, DFRECT rc
)
86 DfRectLeft(rc
) -= DfGetLeft((DFWINDOW
)wnd
);
87 DfRectRight(rc
) -= DfGetLeft((DFWINDOW
)wnd
);
88 DfRectTop(rc
) -= DfGetTop((DFWINDOW
)wnd
);
89 DfRectBottom(rc
) -= DfGetTop((DFWINDOW
)wnd
);
93 /* ----- clip a rectangle to the parents of the window ----- */
94 DFRECT
DfClipRectangle(void *wnd
, DFRECT rc
)
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
);