2 /* Copyright (C) 2001 Dominik Vogt */
3 /* This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ** This file supplies routines for fvwm internal rectangle handling.
23 /* ---------------------------- included header files ---------------------- */
29 /* ---------------------------- local definitions -------------------------- */
31 /* ---------------------------- local macros ------------------------------- */
33 /* ---------------------------- imports ------------------------------------ */
35 /* ---------------------------- exported variables (globals) --------------- */
37 /* ---------------------------- local types -------------------------------- */
39 /* ---------------------------- forward declarations ----------------------- */
41 /* ---------------------------- local variables ---------------------------- */
43 /* ---------------------------- local functions ---------------------------- */
45 static int fvwmrect_do_intervals_intersect(
46 int x1
, int width1
, int x2
, int width2
)
48 return !(x1
+ width1
<= x2
|| x2
+ width2
<= x1
);
51 /* ---------------------------- interface functions ------------------------ */
53 /* Returns 1 if the given rectangles intersect and 0 otherwise */
54 int fvwmrect_do_rectangles_intersect(rectangle
*r
, rectangle
*s
)
56 if (r
->x
+ r
->width
<= s
->x
)
60 if (s
->x
+ s
->width
<= r
->x
)
64 if (r
->y
+ r
->height
<= s
->y
)
68 if (s
->y
+ s
->height
<= r
->y
)
76 /* Subtracts the values in s2_ from the ones in s1_g and stores the result in
78 void fvwmrect_subtract_rectangles(
79 rectangle
*rdiff
, rectangle
*r1
, rectangle
*r2
)
81 rdiff
->x
= r1
->x
- r2
->x
;
82 rdiff
->y
= r1
->y
- r2
->y
;
83 rdiff
->width
= r1
->width
- r2
->width
;
84 rdiff
->height
= r1
->height
- r2
->height
;
89 /* Returns 1 is the rectangles are identical and 0 if not */
90 int fvwmrect_rectangles_equal(
91 rectangle
*r1
, rectangle
*r2
)
97 if (r1
== NULL
|| r2
== NULL
)
101 if (r1
->x
!= r2
->x
|| r1
->y
!= r2
->y
|| r1
->width
!= r2
->width
||
102 r1
->height
!= r2
->height
)
110 int fvwmrect_move_into_rectangle(rectangle
*move_rec
, rectangle
*target_rec
)
114 if (!fvwmrect_do_intervals_intersect(
115 move_rec
->x
, move_rec
->width
, target_rec
->x
,
118 move_rec
->x
= move_rec
->x
% (int)target_rec
->width
;
121 move_rec
->x
+= target_rec
->width
;
123 move_rec
->x
+= target_rec
->x
;
126 if (!fvwmrect_do_intervals_intersect(
127 move_rec
->y
, move_rec
->height
, target_rec
->y
,
130 move_rec
->y
= move_rec
->y
% (int)target_rec
->height
;
133 move_rec
->y
+= target_rec
->height
;
135 move_rec
->y
+= target_rec
->y
;
142 int fvwmrect_intersect_xrectangles(
143 XRectangle
*r1
, XRectangle
*r2
)
145 int x1
= max(r1
->x
, r2
->x
);
146 int y1
= max(r1
->y
, r2
->y
);
147 int x2
= min(r1
->x
+ r1
->width
, r2
->x
+ r2
->width
);
148 int y2
= min(r1
->y
+ r1
->height
, r2
->y
+ r2
->height
);
153 r1
->height
= y2
- y1
;
155 if (x2
> x1
&& y2
> y1
)