Tizen 2.1 base
[framework/uifw/ecore.git] / src / lib / ecore_x / xlib / ecore_x_region.c
1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif /* ifdef HAVE_CONFIG_H */
4
5 #include "ecore_x_private.h"
6
7 /*
8  * [x] XCreateRegion
9  * [ ] XPolygonRegion
10  * [x] XSetRegion
11  * [x] XDestroyRegion
12  *
13  * [x] XOffsetRegion
14  * [ ] XShrinkRegion
15  *
16  * [ ] XClipBox
17  * [x] XIntersectRegion
18  * [x] XUnionRegion
19  * [x] XUnionRectWithRegion
20  * [x] XSubtractRegion
21  * [ ] XXorRegion
22  *
23  * [x] XEmptyRegion
24  * [x] XEqualRegion
25  *
26  * [x] XPointInRegion
27  * [x] XRectInRegion
28  */
29
30 EAPI Ecore_X_XRegion *
31 ecore_x_xregion_new()
32 {
33    LOGFN(__FILE__, __LINE__, __FUNCTION__);
34    return (Ecore_X_XRegion *)XCreateRegion();
35 }
36
37 EAPI void
38 ecore_x_xregion_free(Ecore_X_XRegion *region)
39 {
40    LOGFN(__FILE__, __LINE__, __FUNCTION__);
41    if (!region)
42      return;
43
44    XDestroyRegion((Region)region);
45 }
46
47 EAPI Eina_Bool
48 ecore_x_xregion_set(Ecore_X_XRegion *region,
49                     Ecore_X_GC gc)
50 {
51    LOGFN(__FILE__, __LINE__, __FUNCTION__);
52    return XSetRegion(_ecore_x_disp, gc, (Region)region) ? EINA_TRUE : EINA_FALSE;
53 }
54
55 EAPI void
56 ecore_x_xregion_translate(Ecore_X_XRegion *region,
57                           int x,
58                           int y)
59 {
60    LOGFN(__FILE__, __LINE__, __FUNCTION__);
61    if (!region)
62      return;
63
64    /* return value not used */
65    XOffsetRegion((Region)region, x, y);
66 }
67
68 EAPI Eina_Bool
69 ecore_x_xregion_intersect(Ecore_X_XRegion *dst,
70                           Ecore_X_XRegion *r1,
71                           Ecore_X_XRegion *r2)
72 {
73    LOGFN(__FILE__, __LINE__, __FUNCTION__);
74    return XIntersectRegion((Region)r1, (Region)r2, (Region)dst) ? EINA_TRUE : EINA_FALSE;
75 }
76
77 EAPI Eina_Bool
78 ecore_x_xregion_union(Ecore_X_XRegion *dst,
79                       Ecore_X_XRegion *r1,
80                       Ecore_X_XRegion *r2)
81 {
82    LOGFN(__FILE__, __LINE__, __FUNCTION__);
83    return XUnionRegion((Region)r1, (Region)r2, (Region)dst) ? EINA_TRUE : EINA_FALSE;
84 }
85
86 EAPI Eina_Bool
87 ecore_x_xregion_union_rect(Ecore_X_XRegion *dst,
88                            Ecore_X_XRegion *src,
89                            Ecore_X_Rectangle *rect)
90 {
91    XRectangle xr;
92
93    LOGFN(__FILE__, __LINE__, __FUNCTION__);
94    xr.x = rect->x;
95    xr.y = rect->y;
96    xr.width = rect->width;
97    xr.height = rect->height;
98
99    return XUnionRectWithRegion(&xr, (Region)src, (Region)dst) ? EINA_TRUE : EINA_FALSE;
100 }
101
102 EAPI Eina_Bool
103 ecore_x_xregion_subtract(Ecore_X_XRegion *dst,
104                          Ecore_X_XRegion *rm,
105                          Ecore_X_XRegion *rs)
106 {
107    LOGFN(__FILE__, __LINE__, __FUNCTION__);
108    return XSubtractRegion((Region)rm, (Region)rs, (Region)dst) ? EINA_TRUE : EINA_FALSE;
109 }
110
111 EAPI Eina_Bool
112 ecore_x_xregion_is_empty(Ecore_X_XRegion *region)
113 {
114    if (!region)
115      return EINA_TRUE;
116
117    LOGFN(__FILE__, __LINE__, __FUNCTION__);
118    return XEmptyRegion((Region)region) ? EINA_TRUE : EINA_FALSE;
119 }
120
121 EAPI Eina_Bool
122 ecore_x_xregion_is_equal(Ecore_X_XRegion *r1,
123                          Ecore_X_XRegion *r2)
124 {
125    if (!r1 || !r2)
126      return EINA_FALSE;
127
128    LOGFN(__FILE__, __LINE__, __FUNCTION__);
129    return XEqualRegion((Region)r1, (Region)r1) ? EINA_TRUE : EINA_FALSE;
130 }
131
132 EAPI Eina_Bool
133 ecore_x_xregion_point_contain(Ecore_X_XRegion *region,
134                               int x,
135                               int y)
136 {
137    if (!region)
138      return EINA_FALSE;
139
140    LOGFN(__FILE__, __LINE__, __FUNCTION__);
141    return XPointInRegion((Region)region, x, y) ? EINA_TRUE : EINA_FALSE;
142 }
143
144 EAPI Eina_Bool
145 ecore_x_xregion_rect_contain(Ecore_X_XRegion *region,
146                              Ecore_X_Rectangle *rect)
147 {
148    if (!region || !rect)
149      return EINA_FALSE;
150
151    LOGFN(__FILE__, __LINE__, __FUNCTION__);
152    return XRectInRegion((Region)region,
153                         rect->x,
154                         rect->y,
155                         rect->width,
156                         rect->height) ? EINA_TRUE : EINA_FALSE;
157 }
158