summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiin.moon <jiin.moon@samsung.com>2015-05-15 23:09:41 +0900
committerChunEon Park <hermet@hermet.pe.kr>2015-05-15 23:09:42 +0900
commite707aa3efb0b4a0b7d6169755075a9943793e4f5 (patch)
treedb6a5a78a5ec1c67cf58cbbc0045e21b56fe74c7
parent76004dfbec84664e253babc5bf576398a5901395 (diff)
elementary: Create new widget for image masking
Summary: For now, if apply image mask to smart obejct, masking does not work except to implement in edc file. @feature Reviewers: Jaehyun_Cho, Jaehyun, jpeg, raster, cedric, Hermet Subscribers: raster, jpeg, cedric Projects: #elementary Differential Revision: https://phab.enlightenment.org/D2055
-rw-r--r--src/lib/Elementary.h.in1
-rw-r--r--src/lib/Makefile.am6
-rw-r--r--src/lib/elm_clipper.c225
-rw-r--r--src/lib/elm_clipper.eo78
-rw-r--r--src/lib/elm_clipper.h41
-rw-r--r--src/lib/elm_clipper_eo.h11
-rw-r--r--src/lib/elm_clipper_legacy.h12
-rw-r--r--src/lib/elm_widget_clipper.h66
8 files changed, 440 insertions, 0 deletions
diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in
index cd17bbfd3..87d904595 100644
--- a/src/lib/Elementary.h.in
+++ b/src/lib/Elementary.h.in
@@ -195,6 +195,7 @@ EAPI extern Elm_Version *elm_version;
195#include <elm_cache.h> 195#include <elm_cache.h>
196#include <elm_calendar.h> 196#include <elm_calendar.h>
197#include <elm_check.h> 197#include <elm_check.h>
198#include <elm_clipper.h>
198#include <elm_clock.h> 199#include <elm_clock.h>
199#include <elm_cnp.h> 200#include <elm_cnp.h>
200#include <elm_colorselector.h> 201#include <elm_colorselector.h>
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index 859b0ef4e..a488e76ab 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -48,6 +48,7 @@ elm_widget_bubble.h \
48elm_widget_button.h \ 48elm_widget_button.h \
49elm_widget_calendar.h \ 49elm_widget_calendar.h \
50elm_widget_check.h \ 50elm_widget_check.h \
51elm_widget_clipper.h \
51elm_widget_clock.h \ 52elm_widget_clock.h \
52elm_widget_colorselector.h \ 53elm_widget_colorselector.h \
53elm_widget_conform.h \ 54elm_widget_conform.h \
@@ -177,6 +178,9 @@ elm_calendar_common.h \
177elm_check.h \ 178elm_check.h \
178elm_check_eo.h \ 179elm_check_eo.h \
179elm_check_legacy.h \ 180elm_check_legacy.h \
181elm_clipper.h \
182elm_clipper_eo.h \
183elm_clipper_legacy.h \
180elm_clock.h \ 184elm_clock.h \
181elm_clock_eo.h \ 185elm_clock_eo.h \
182elm_clock_legacy.h \ 186elm_clock_legacy.h \
@@ -424,6 +428,7 @@ elm_bubble.c \
424elm_button.c \ 428elm_button.c \
425elm_calendar.c \ 429elm_calendar.c \
426elm_check.c \ 430elm_check.c \
431elm_clipper.c \
427elm_clock.c \ 432elm_clock.c \
428elm_cnp.c \ 433elm_cnp.c \
429elm_colorselector.c \ 434elm_colorselector.c \
@@ -545,6 +550,7 @@ elm_bubble.eo \
545elm_button.eo \ 550elm_button.eo \
546elm_calendar.eo \ 551elm_calendar.eo \
547elm_check.eo \ 552elm_check.eo \
553elm_clipper.eo \
548elm_clock.eo \ 554elm_clock.eo \
549elm_colorselector.eo \ 555elm_colorselector.eo \
550elm_conformant.eo \ 556elm_conformant.eo \
diff --git a/src/lib/elm_clipper.c b/src/lib/elm_clipper.c
new file mode 100644
index 000000000..374f9bf57
--- /dev/null
+++ b/src/lib/elm_clipper.c
@@ -0,0 +1,225 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4
5#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
6
7#include <Elementary.h>
8
9#include "elm_priv.h"
10#include "elm_widget_clipper.h"
11#include "elm_widget_container.h"
12
13#define MY_CLASS ELM_CLIPPER_CLASS
14
15#define MY_CLASS_NAME "Elm_Clipper"
16#define MY_CLASS_NAME_LEGACY "elm_clipper"
17
18static void
19_calc_region(Eo *obj)
20{
21 int x, y, w, h;
22 int calx1, caly1, calx2, caly2;
23
24 ELM_CLIPPER_DATA_GET(obj, sd);
25 evas_object_geometry_get(sd->content, &x, &y, &w, &h);
26
27 calx1 = (int)(w * sd->region_x1 + x);
28 caly1 = (int)(h * sd->region_y1 + y);
29
30 if (sd->region_x2 < sd->region_x1) calx2 = 0;
31 else calx2 = (int)(w * (sd->region_x2 - sd->region_x1));
32 if (sd->region_y2 < sd->region_y1) caly2 = 0;
33 else caly2 = (int)(h * (sd->region_y2 - sd->region_y1));
34
35 evas_object_move(sd->clipper, calx1, caly1);
36 evas_object_resize(sd->clipper, calx2, caly2);
37}
38
39EOLIAN static void
40_elm_clipper_clip_set(Eo *obj, Elm_Clipper_Data *sd, Evas_Object *clip)
41{
42 if (sd->clipper != clip)
43 {
44 if (sd->clipper)
45 {
46 elm_widget_sub_object_del(obj, sd->clipper);
47 if (sd->content) evas_object_clip_unset(sd->content);
48 sd->clipper = NULL;
49 }
50 if (clip)
51 {
52 elm_widget_sub_object_add(obj, clip);
53 evas_object_smart_member_add(clip, obj);
54 _calc_region(obj);
55 if (sd->content) evas_object_clip_set(sd->content, clip);
56 sd->clipper = clip;
57 }
58 }
59}
60
61EOLIAN static Evas_Object *
62_elm_clipper_clip_get(Eo *obj EINA_UNUSED, Elm_Clipper_Data *sd)
63{
64 return sd->clipper;
65}
66
67EOLIAN static void
68_elm_clipper_region_set(Eo *obj, Elm_Clipper_Data *sd, double x1, double y1, double x2, double y2)
69{
70 if (x2 < x1 || y2 < y1)
71 ERR("Clipper region x2/y2 should be greater than or equal to x1/y1!\n");
72
73 if (sd->region_x1 != x1 || sd->region_y1 != y1 ||
74 sd->region_x2 != x2 || sd->region_y2 != y2)
75 {
76 sd->region_x1 = x1;
77 sd->region_y1 = y1;
78 sd->region_x2 = x2;
79 sd->region_y2 = y2;
80 _calc_region(obj);
81 }
82}
83
84EOLIAN static void
85_elm_clipper_region_get(Eo *obj EINA_UNUSED, Elm_Clipper_Data *sd, double *x1, double *y1, double *x2, double *y2)
86{
87 if (x1) *x1 = sd->region_x1;
88 if (y1) *y1 = sd->region_y1;
89 if (x2) *x2 = sd->region_x2;
90 if (y2) *y2 = sd->region_y2;
91}
92
93EOLIAN static Eina_Bool
94_elm_clipper_elm_widget_sub_object_del(Eo *obj, Elm_Clipper_Data *sd, Evas_Object *sobj)
95{
96 Eina_Bool int_ret = EINA_FALSE;
97 eo_do_super(obj, MY_CLASS, int_ret = elm_obj_widget_sub_object_del(sobj));
98 if (!int_ret) return EINA_FALSE;
99 if (sobj == sd->content) evas_object_data_del(sobj, "_elm_leaveme");
100 evas_object_smart_member_del(sobj);
101 return EINA_TRUE;
102}
103
104EOLIAN static void
105_elm_clipper_evas_object_smart_resize(Eo *obj, Elm_Clipper_Data *sd EINA_UNUSED, Evas_Coord w, Evas_Coord h)
106{
107 eo_do_super(obj, MY_CLASS, evas_obj_smart_resize(w, h));
108 if(sd->content) evas_object_resize(sd->content, w, h);
109 _calc_region(obj);
110}
111
112EOLIAN static void
113_elm_clipper_evas_object_smart_move(Eo *obj, Elm_Clipper_Data *sd EINA_UNUSED, Evas_Coord x, Evas_Coord y)
114{
115 eo_do_super(obj, MY_CLASS, evas_obj_smart_move(x, y));
116 evas_object_move(sd->content, x, y);
117 _calc_region(obj);
118}
119
120EOLIAN static void
121_elm_clipper_evas_object_smart_show(Eo *obj, Elm_Clipper_Data *sd)
122{
123 eo_do_super(obj, MY_CLASS, evas_obj_smart_show());
124 if(sd->content) evas_object_show(sd->content);
125 if(sd->clipper) evas_object_show(sd->clipper);
126
127}
128
129EOLIAN static void
130_elm_clipper_evas_object_smart_hide(Eo *obj, Elm_Clipper_Data *sd)
131{
132 eo_do_super(obj, MY_CLASS, evas_obj_smart_hide());
133 if(sd->content) evas_object_hide(sd->content);
134 if(sd->clipper) evas_object_hide(sd->clipper);
135}
136
137EOLIAN static Eina_Bool
138_elm_clipper_elm_container_content_set(Eo *obj, Elm_Clipper_Data *sd, const char *part, Evas_Object *content)
139{
140 if (part && strcmp(part, "default")) return EINA_FALSE;
141 if (sd->content != content)
142 {
143 if (sd->content)
144 {
145 elm_widget_sub_object_del(obj, sd->content);
146 sd->content = NULL;
147 }
148 if (content)
149 {
150 elm_widget_sub_object_add(content,obj);
151 evas_object_data_set(content, "_elm_leaveme", (void *)1);
152 evas_object_smart_member_add(content, obj);
153 _calc_region(obj);
154 if (sd->clipper) evas_object_clip_set(content, sd->clipper);
155 sd->content = content;
156 }
157 }
158 return EINA_TRUE;
159}
160
161EOLIAN static Evas_Object*
162_elm_clipper_elm_container_content_get(Eo *obj EINA_UNUSED, Elm_Clipper_Data *sd, const char *part)
163{
164 if (part && strcmp(part, "default")) return NULL;
165 return sd->content;
166}
167
168EOLIAN static Evas_Object*
169_elm_clipper_elm_container_content_unset(Eo *obj, Elm_Clipper_Data *sd, const char *part)
170{
171 Evas_Object *content;
172 if (part && strcmp(part, "default")) return NULL;
173 content = sd->content;
174 elm_widget_sub_object_del(obj, sd->content);
175 sd->content = NULL;
176 return content;
177}
178
179EOLIAN static void
180_elm_clipper_evas_object_smart_add(Eo *obj, Elm_Clipper_Data *priv)
181{
182 eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
183 elm_widget_sub_object_parent_add(obj);
184 elm_widget_can_focus_set(obj, EINA_FALSE);
185 priv->content = NULL;
186 priv->clipper = NULL;
187 priv->region_x1 = 0;
188 priv->region_y1 = 0;
189 priv->region_x2 = 1;
190 priv->region_y2 = 1;
191}
192
193EOLIAN static void
194_elm_clipper_evas_object_smart_del(Eo *obj, Elm_Clipper_Data *sd)
195{
196 eo_do_super(obj, MY_CLASS, evas_obj_smart_del());
197 ELM_SAFE_FREE(sd->content, evas_object_del);
198 ELM_SAFE_FREE(sd->clipper, evas_object_del);
199 sd->content = NULL;
200 sd->clipper = NULL;
201}
202
203
204EAPI Evas_Object *
205elm_clipper_add(Evas_Object *parent)
206{
207 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
208 Evas_Object *obj = eo_add(MY_CLASS, parent);
209 return obj;
210}
211
212EOLIAN static void
213_elm_clipper_eo_base_constructor(Eo *obj, Elm_Clipper_Data *sd EINA_UNUSED)
214{
215 eo_do_super(obj, MY_CLASS, eo_constructor());
216 eo_do(obj, evas_obj_type_set(MY_CLASS_NAME_LEGACY));
217}
218
219static void
220_elm_clipper_class_constructor(Eo_Class *klass)
221{
222 evas_smart_legacy_type_register(MY_CLASS_NAME_LEGACY, klass);
223}
224
225#include "elm_clipper.eo.c"
diff --git a/src/lib/elm_clipper.eo b/src/lib/elm_clipper.eo
new file mode 100644
index 000000000..fa31eb2ae
--- /dev/null
+++ b/src/lib/elm_clipper.eo
@@ -0,0 +1,78 @@
1class Elm.Clipper (Elm.Container)
2{
3 eo_prefix: elm_obj_clipper;
4 methods {
5 @property clip {
6 set {
7 /*@
8 @brief Set the clip object of the clipper
9
10 Sets the clip object for clipping
11
12 @note
13 Allow setting only an Evas_Object_Rectangle and an Evas_Object_Image as clip on 1.14
14
15 @since 1.15
16
17 @ingroup Clipper */
18 }
19 get {
20 /*@
21 @brief Get the mask object of the clipper
22
23 @see elm_clipper_mask_set()
24
25 @since 1.15
26
27 @ingroup Clipper */
28 }
29 values {
30 Evas_Object *mask;
31 }
32 }
33 @property region {
34 set {
35 /*@
36 @brief Set the region of the clipper
37
38 Sets the position and the size of the clipper on clipper object
39
40 @note The value should be normalized. (0 ~ 1)
41
42 @since 1.15
43
44 @ingroup Clipper */
45 }
46 get {
47 /*@
48 @brief Get the region of the clipper
49
50 @see elm_clipper_region_align_set()
51
52 @since 1.15
53
54 @ingroup Clipper */
55 }
56 values {
57 double x1; /*@ left edge of the clipper on elm_clipper widget */
58 double y1; /*@ top edge of the clipper on elm_clipper widget */
59 double x2; /*@ right edge of the clipper on elm_clipper widget */
60 double y2; /*@ bottom edge of the clipper on elm_clipper widget */
61 }
62 }
63 }
64 implements {
65 class.constructor;
66 Eo.Base.constructor;
67 Evas.Object_Smart.hide;
68 Evas.Object_Smart.show;
69 Evas.Object_Smart.move;
70 Evas.Object_Smart.add;
71 Evas.Object_Smart.del;
72 Evas.Object_Smart.resize;
73 Elm.Widget.sub_object_del;
74 Elm.Container.content_get;
75 Elm.Container.content_set;
76 Elm.Container.content_unset;
77 }
78}
diff --git a/src/lib/elm_clipper.h b/src/lib/elm_clipper.h
new file mode 100644
index 000000000..2ae4dd58f
--- /dev/null
+++ b/src/lib/elm_clipper.h
@@ -0,0 +1,41 @@
1/**
2 * @defgroup Clipper Clipper
3 * @ingroup Elementary
4 *
5 * This widget display a clipped object.
6 * For this widget, need a clipper object and a content object.
7 * The content would be clipped out by the clipper.
8 * If clipper is not set, you would see the content without cuts
9 *
10 * The Evas_Object_Rectangle and the Evas_Object_Image object can be a clipper.
11 * A content can have only a clipper even if user set some objects as the clipper.
12 *
13 * This widget can display a clipped object into many shapes according to the clipper.
14 * The shape of the clipped object be decided by pixel's transparency of the clipper object.
15 * If you want to cut out the content into a circle,
16 * the clipper's pixel should have non-zero as alpha value into the circle.
17 * In case of outside of the circle, should have zero as alpha value.
18 *
19 * This widget inherits from @ref elm-container-class,
20 * So you can use are:
21 *
22 * @li @ref elm_object_part_content_set
23 * @li @ref elm_object_part_content_get
24 * @li @ref elm_object_part_content_unset
25 *
26 * Default content parts of the clipper widget that you can use are:
27 * @li @c "default" - The content to be clipped off
28 *
29 * @{
30 */
31
32#ifdef EFL_EO_API_SUPPORT
33#include <elm_clipper_eo.h>
34#endif
35#ifndef EFL_NOLEGACY_API_SUPPORT
36#include <elm_clipper_legacy.h>
37#endif
38
39/**
40 * @}
41 */
diff --git a/src/lib/elm_clipper_eo.h b/src/lib/elm_clipper_eo.h
new file mode 100644
index 000000000..3b9a71cc0
--- /dev/null
+++ b/src/lib/elm_clipper_eo.h
@@ -0,0 +1,11 @@
1/**
2 * @ingroup Clipper
3 *
4 * @{
5 */
6
7#include "elm_clipper.eo.h"
8
9/**
10 * @}
11 */
diff --git a/src/lib/elm_clipper_legacy.h b/src/lib/elm_clipper_legacy.h
new file mode 100644
index 000000000..09725739f
--- /dev/null
+++ b/src/lib/elm_clipper_legacy.h
@@ -0,0 +1,12 @@
1/**
2 * @brief Add a new clipper object to the parent
3 *
4 * @param parent The parent object
5 * @return The new object or NULL if it cannot be created
6 * @since 1.14
7 *
8 * @ingroup Clipper
9 */
10EAPI Evas_Object *elm_clipper_add(Evas_Object *parent);
11
12#include "elm_clipper.eo.legacy.h"
diff --git a/src/lib/elm_widget_clipper.h b/src/lib/elm_widget_clipper.h
new file mode 100644
index 000000000..08bb5e8d2
--- /dev/null
+++ b/src/lib/elm_widget_clipper.h
@@ -0,0 +1,66 @@
1#ifndef ELM_WIDGET_CLIPPER_H
2#define ELM_WIDGET_CLIPPER_H
3
4#include "Elementary.h"
5
6/* DO NOT USE THIS HEADER UNLESS YOU ARE PREPARED FOR BREAKING OF YOUR
7 * CODE. THIS IS ELEMENTARY'S INTERNAL WIDGET API (for now) AND IS NOT
8 * FINAL. CALL elm_widget_api_check(ELM_INTERNAL_API_VERSION) TO CHECK
9 * IT AT RUNTIME.
10 */
11
12/**
13 * @addtogroup Widget
14 * @{
15 *
16 * @section elm-clipper-class The Elementary Clipper Class
17 *
18 * Elementary, besides having the @ref Clipper widget, exposes its
19 * foundation -- the Elementary Clipper Class -- in order to create other
20 * widgets which are a clipper object with some more logic on top.
21 */
22
23
24/**
25 * Base widget smart data extended with clipper instance data.
26 */
27typedef struct _Elm_Clipper_Data Elm_Clipper_Data;
28struct _Elm_Clipper_Data
29{
30 Evas_Object *content, *clipper;
31 float region_x1;
32 float region_y1;
33 float region_x2;
34 float region_y2;
35};
36
37/**
38 * @}
39 */
40
41#define ELM_CLIPPER_DATA_GET(o, sd) \
42 Elm_Clipper_Data * sd = eo_data_scope_get(o, ELM_CLIPPER_CLASS)
43
44#define ELM_CLIPPER_DATA_GET_OR_RETURN(o, ptr) \
45 ELM_CLIPPER_DATA_GET(o, ptr); \
46 if (EINA_UNLIKELY(!ptr)) \
47 { \
48 CRI("No widget data for object %p (%s)", \
49 o, evas_object_type_get(o)); \
50 return; \
51 }
52
53#define ELM_CLIPPER_DATA_GET_OR_RETURN_VAL(o, ptr, val) \
54 ELM_CLIPPER_DATA_GET(o, ptr); \
55 if (EINA_UNLIKELY(!ptr)) \
56 { \
57 CRI("No widget data for object %p (%s)", \
58 o, evas_object_type_get(o)); \
59 return val; \
60 }
61
62#define ELM_CLIPPER_CHECK(obj) \
63 if (EINA_UNLIKELY(!eo_isa((obj), ELM_CLIPPER_CLASS))) \
64 return
65
66#endif