]> Dogcows Code - chaz/openbox/blob - openbox/geom.h
comment typo
[chaz/openbox] / 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 #include <glib.h>
24
25 typedef struct _GravityCoord {
26 int pos;
27 gboolean center;
28 gboolean opposite;
29 } GravityCoord;
30
31 typedef struct _GravityPoint {
32 GravityCoord x;
33 GravityCoord y;
34 } GravityPoint;
35
36 #define GRAVITY_COORD_SET(c, p, cen, opp) \
37 (c).pos = (p), (c).center = (cen), (c).opposite = (opp)
38
39
40 typedef struct _Point {
41 int x;
42 int y;
43 } Point;
44
45 #define POINT_SET(pt, nx, ny) (pt).x = (nx), (pt).y = (ny)
46 #define POINT_EQUAL(p1, p2) ((p1).x == (p2).x && (p1).y == (p2).y)
47
48 typedef struct _Size {
49 int width;
50 int height;
51 } Size;
52
53 #define SIZE_SET(sz, w, h) (sz).width = (w), (sz).height = (h)
54
55 typedef struct _Rect {
56 int x;
57 int y;
58 int width;
59 int height;
60 } Rect;
61
62 #define RECT_LEFT(r) ((r).x)
63 #define RECT_TOP(r) ((r).y)
64 #define RECT_RIGHT(r) ((r).x + (r).width - 1)
65 #define RECT_BOTTOM(r) ((r).y + (r).height - 1)
66
67 #define RECT_SET_POINT(r, nx, ny) \
68 (r).x = (nx), (r).y = (ny)
69 #define RECT_SET_SIZE(r, w, h) \
70 (r).width = (w), (r).height = (h)
71 #define RECT_SET(r, nx, ny, w, h) \
72 (r).x = (nx), (r).y = (ny), (r).width = (w), (r).height = (h)
73
74 #define RECT_EQUAL(r1, r2) ((r1).x == (r2).x && (r1).y == (r2).y && \
75 (r1).width == (r2).width && \
76 (r1).height == (r2).height)
77 #define RECT_EQUAL_DIMS(r, x, y, w, h) \
78 ((r).x == (x) && (r).y == (y) && (r).width == (w) && (r).height == (h))
79
80 #define RECT_TO_DIMS(r, x, y, w, h) \
81 (x) = (r).x, (y) = (r).y, (w) = (r).width, (h) = (r).height
82
83 #define RECT_CONTAINS(r, px, py) \
84 ((px) >= (r).x && (px) < (r).x + (r).width && \
85 (py) >= (r).y && (py) < (r).y + (r).height)
86 #define RECT_CONTAINS_RECT(r, o) \
87 ((o).x >= (r).x && (o).x + (o).width <= (r).x + (r).width && \
88 (o).y >= (r).y && (o).y + (o).height <= (r).y + (r).height)
89
90 /* Returns true if Rect r and o intersect */
91 #define RECT_INTERSECTS_RECT(r, o) \
92 ((o).x < (r).x + (r).width && (o).x + (o).width > (r).x && \
93 (o).y < (r).y + (r).height && (o).y + (o).height > (r).y)
94
95 /* Sets Rect r to be the intersection of Rect a and b. */
96 #define RECT_SET_INTERSECTION(r, a, b) \
97 ((r).x = MAX((a).x, (b).x), \
98 (r).y = MAX((a).y, (b).y), \
99 (r).width = MIN((a).x + (a).width - 1, \
100 (b).x + (b).width - 1) - (r).x + 1, \
101 (r).height = MIN((a).y + (a).height - 1, \
102 (b).y + (b).height - 1) - (r).y + 1)
103
104 typedef struct _Strut {
105 int left;
106 int top;
107 int right;
108 int bottom;
109 } Strut;
110
111 typedef struct _StrutPartial {
112 int left;
113 int top;
114 int right;
115 int bottom;
116
117 int left_start, left_end;
118 int top_start, top_end;
119 int right_start, right_end;
120 int bottom_start, bottom_end;
121 } StrutPartial;
122
123 #define STRUT_SET(s, l, t, r, b) \
124 (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b)
125
126 #define STRUT_PARTIAL_SET(s, l, t, r, b, ls, le, ts, te, rs, re, bs, be) \
127 (s).left = (l), (s).top = (t), (s).right = (r), (s).bottom = (b), \
128 (s).left_start = (ls), (s).left_end = (le), \
129 (s).top_start = (ts), (s).top_end = (te), \
130 (s).right_start = (rs), (s).right_end = (re), \
131 (s).bottom_start = (bs), (s).bottom_end = (be)
132
133 #define STRUT_ADD(s1, s2) \
134 (s1).left = MAX((s1).left, (s2).left), \
135 (s1).right = MAX((s1).right, (s2).right), \
136 (s1).top = MAX((s1).top, (s2).top), \
137 (s1).bottom = MAX((s1).bottom, (s2).bottom)
138
139 #define STRUT_EXISTS(s1) \
140 ((s1).left || (s1).top || (s1).right || (s1).bottom)
141
142 #define STRUT_EQUAL(s1, s2) \
143 ((s1).left == (s2).left && \
144 (s1).top == (s2).top && \
145 (s1).right == (s2).right && \
146 (s1).bottom == (s2).bottom)
147
148 #define PARTIAL_STRUT_EQUAL(s1, s2) \
149 ((s1).left == (s2).left && \
150 (s1).top == (s2).top && \
151 (s1).right == (s2).right && \
152 (s1).bottom == (s2).bottom && \
153 (s1).left_start == (s2).left_start && \
154 (s1).left_end == (s2).left_end && \
155 (s1).top_start == (s2).top_start && \
156 (s1).top_end == (s2).top_end && \
157 (s1).right_start == (s2).right_start && \
158 (s1).right_end == (s2).right_end && \
159 (s1).bottom_start == (s2).bottom_start && \
160 (s1).bottom_end == (s2).bottom_end)
161
162 #define RANGES_INTERSECT(r1x, r1w, r2x, r2w) \
163 (r1x < r2x + r2w && r1x + r1w > r2x)
164
165 #endif
This page took 0.050608 seconds and 4 git commands to generate.