merge r5815-5828,5832-5859 from trunk
[mikachu/openbox.git] / openbox / geom.h
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    geom.h for the Openbox window manager
4    Copyright (c) 2006        Mikael Magnusson
5    Copyright (c) 2003-2007   Dana Jansens
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #ifndef __geom_h
21 #define __geom_h
22
23 typedef struct _Point {
24     int x;
25     int y;
26 } Point;
27
28 #define POINT_SET(pt, nx, ny) (pt).x = (nx), (pt).y = (ny)
29
30 typedef struct _Size {
31     int width;
32     int height;
33 } Size;
34
35 #define SIZE_SET(sz, w, h) (sz).width = (w), (sz).height = (h)
36
37 typedef struct _Rect {
38     int x;
39     int y;
40     int width;
41     int height;
42 } Rect;
43
44 #define RECT_LEFT(r) ((r).x)
45 #define RECT_TOP(r) ((r).y)
46 #define RECT_RIGHT(r) ((r).x + (r).width - 1)
47 #define RECT_BOTTOM(r) ((r).y + (r).height - 1)
48
49 #define RECT_SET_POINT(r, nx, ny) \
50     (r).x = (nx), (r).y = (ny)
51 #define RECT_SET_SIZE(r, w, h) \
52     (r).width = (w), (r).height = (h)
53 #define RECT_SET(r, nx, ny, w, h) \
54     (r).x = (nx), (r).y = (ny), (r).width = (w), (r).height = (h)
55
56 #define RECT_EQUAL(r1, r2) ((r1).x == (r2).x && (r1).y == (r2).y && \
57                             (r1).width == (r2).width && \
58                             (r1).height == (r2).height)
59
60 #define RECT_CONTAINS(r, px, py) \
61     ((px) >= (r).x && (px) < (r).x + (r).width && \
62      (py) >= (r).y && (py) < (r).y + (r).height)
63 #define RECT_CONTAINS_RECT(r, o) \
64     ((o).x >= (r).x && (o).x + (o).width <= (r).x + (r).width && \
65      (o).y >= (r).y && (o).y + (o).height <= (r).y + (r).height)
66
67 /* Returns true if Rect r and o intersect */
68 #define RECT_INTERSECTS_RECT(r, o) \
69     ((o).x < (r).x + (r).width && (o).x + (o).width > (r).x && \
70      (o).y < (r).y + (r).height && (o).y + (o).height > (r).y)
71
72 /* Sets Rect r to be the intersection of Rect a and b. */
73 #define RECT_SET_INTERSECTION(r, a, b) \
74     ((r).x = MAX((a).x, (b).x), \
75      (r).y = MAX((a).y, (b).y), \
76      (r).width = MIN((a).x + (a).width - 1, \
77                      (b).x + (b).width - 1) - (r).x + 1, \
78      (r).height = MIN((a).y + (a).height - 1, \
79                       (b).y + (b).height - 1) - (r).y + 1)
80
81 typedef struct _Strut {
82     int left;
83     int top;
84     int right;
85     int bottom;
86 } Strut;
87
88 typedef struct _StrutPartial {
89     int left;
90     int top;
91     int right;
92     int bottom;
93
94     int left_start,   left_end;
95     int top_start,    top_end;
96     int right_start,  right_end;
97     int bottom_start, bottom_end;
98 } StrutPartial;
99
100 #define STRUT_SET(s, l, t, r, b) \
101     (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b)
102
103 #define STRUT_PARTIAL_SET(s, l, t, r, b, ls, le, ts, te, rs, re, bs, be) \
104     (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b), \
105     (s).left_start = (ls), (s).left_end = (le), \
106     (s).top_start = (ts), (s).top_end = (te), \
107     (s).right_start = (rs), (s).right_end = (re), \
108     (s).bottom_start = (bs), (s).bottom_end = (be)
109
110 #define STRUT_ADD(s1, s2) \
111     (s1).left = MAX((s1).left, (s2).left), \
112     (s1).right = MAX((s1).right, (s2).right), \
113     (s1).top = MAX((s1).top, (s2).top), \
114     (s1).bottom = MAX((s1).bottom, (s2).bottom)
115
116 #define STRUT_EXISTS(s1) \
117     ((s1).left || (s1).top || (s1).right || (s1).bottom)
118
119 #define STRUT_EQUAL(s1, s2) \
120     ((s1).left == (s2).left && \
121      (s1).top == (s2).top && \
122      (s1).right == (s2).right && \
123      (s1).bottom == (s2).bottom)
124
125 #define PARTIAL_STRUT_EQUAL(s1, s2) \
126     ((s1).left == (s2).left && \
127      (s1).top == (s2).top && \
128      (s1).right == (s2).right && \
129      (s1).bottom == (s2).bottom && \
130      (s1).left_start == (s2).left_start && \
131      (s1).left_end == (s2).left_end && \
132      (s1).top_start == (s2).top_start && \
133      (s1).top_end == (s2).top_end && \
134      (s1).right_start == (s2).right_start && \
135      (s1).right_end == (s2).right_end && \
136      (s1).bottom_start == (s2).bottom_start && \
137      (s1).bottom_end == (s2).bottom_end)
138
139 #endif