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 (within(o1
, t1
, t2
)) {
13 if (within(o2
, t1
, t2
))
18 else if (within(o2
, t1
, t2
)) {
20 if (within(o1
, t1
, t2
))
25 else if (within(t1
, o1
, o2
)) {
27 if (within(t2
, o1
, o2
))
32 else if (within(t2
, o1
, o2
)) {
34 if (within(t1
, o1
, o2
))
41 /* --- Return the rectangle produced by the overlap
42 of two other rectangles ---- */
43 DFRECT
subRectangle(DFRECT r1
, DFRECT r2
)
46 subVector((int *) &RectLeft(r
), (int *) &RectRight(r
),
47 RectLeft(r1
), RectRight(r1
),
48 RectLeft(r2
), RectRight(r2
));
49 subVector((int *) &RectTop(r
), (int *) &RectBottom(r
),
50 RectTop(r1
), RectBottom(r1
),
51 RectTop(r2
), RectBottom(r2
));
52 if (RectRight(r
) == -1 || RectTop(r
) == -1)
60 /* ------- return the client rectangle of a window ------ */
61 DFRECT
ClientRect(void *wnd
)
67 RectLeft(rc
) = 1; // GetClientLeft((DFWINDOW)wnd);
68 RectTop(rc
) = 2; // GetClientTop((DFWINDOW)wnd);
69 RectRight(rc
) = DfGetScreenWidth () - 2; // GetClientRight((DFWINDOW)wnd);
70 RectBottom(rc
) = DfGetScreenHeight () - 2; // GetClientBottom((DFWINDOW)wnd);
74 RectLeft(rc
) = GetClientLeft((DFWINDOW
)wnd
);
75 RectTop(rc
) = GetClientTop((DFWINDOW
)wnd
);
76 RectRight(rc
) = GetClientRight((DFWINDOW
)wnd
);
77 RectBottom(rc
) = GetClientBottom((DFWINDOW
)wnd
);
82 /* ----- return the rectangle relative to
83 its window's screen position -------- */
84 DFRECT
RelativeWindowRect(void *wnd
, DFRECT rc
)
86 RectLeft(rc
) -= GetLeft((DFWINDOW
)wnd
);
87 RectRight(rc
) -= GetLeft((DFWINDOW
)wnd
);
88 RectTop(rc
) -= GetTop((DFWINDOW
)wnd
);
89 RectBottom(rc
) -= GetTop((DFWINDOW
)wnd
);
93 /* ----- clip a rectangle to the parents of the window ----- */
94 DFRECT
ClipRectangle(void *wnd
, DFRECT rc
)
97 RectLeft(sr
) = RectTop(sr
) = 0;
98 RectRight(sr
) = DfGetScreenWidth()-1;
99 RectBottom(sr
) = DfGetScreenHeight()-1;
100 if (!TestAttribute((DFWINDOW
)wnd
, NOCLIP
))
101 while ((wnd
= GetParent((DFWINDOW
)wnd
)) != NULL
)
102 rc
= subRectangle(rc
, ClientRect(wnd
));
103 return subRectangle(rc
, sr
);