summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2011-08-09 09:20:02 +0000
committerBoris Faure <billiob@gmail.com>2011-08-09 09:20:02 +0000
commitb8e9081c4aa6bb9b16cbad297ca71630167bcf19 (patch)
tree8c9b18b8726cb1a0a383071ab562ce22a07f29b5
add eenvader.fractal: an animated wallpaper
SVN revision: 62245
-rw-r--r--.gitignore35
-rw-r--r--AUTHORS1
-rw-r--r--COPYING32
-rw-r--r--ChangeLog0
-rw-r--r--Makefile.am6
-rw-r--r--NEWS0
-rwxr-xr-xautogen.sh17
-rw-r--r--configure.ac65
-rw-r--r--data/Makefile.am18
-rw-r--r--data/eenvaders.edc48
-rwxr-xr-xgen_invaders.py52
-rw-r--r--src/Makefile.am28
-rw-r--r--src/eenvaders.c106
-rw-r--r--src/eenvaders_edje_external.c192
-rw-r--r--src/eenvaders_evas_smart.c304
-rw-r--r--src/eenvaders_evas_smart.h8
16 files changed, 912 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6dc762d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,35 @@
1/INSTALL
2/Makefile
3/Makefile.in
4/aclocal.m4
5/autom4te.cache/
6/config.guess
7/config.h
8/config.h.in
9/config.log
10/config.status
11/config.sub
12/configure
13/depcomp
14/install-sh
15/libtool
16/ltmain.sh
17/m4/libtool.m4
18/m4/ltoptions.m4
19/m4/ltsugar.m4
20/m4/ltversion.m4
21/m4/lt~obsolete.m4
22/missing
23/src/.deps/
24/src/.libs/
25/src/Makefile
26/src/Makefile.in
27/src/eenvaders
28/src/*.lo
29/src/*.o
30/src/module.la
31/stamp-h1
32/compile
33/data/Makefile
34/data/Makefile.in
35/data/eenvaders.edj
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..1bba8ec
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1 @@
Boris Faure <billiob@gmail.com>
diff --git a/COPYING b/COPYING
new file mode 100644
index 0000000..9690c3f
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,32 @@
1
2Permission is hereby granted, free of charge, to any person obtaining a copy
3of this software and associated documentation files (the "Software"), to
4deal in the Software without restriction, including without limitation the
5rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6sell copies of the Software, and to permit persons to whom the Software is
7furnished to do so, subject to the following conditions:
8
9The above copyright notice and this permission notice shall be included in
10all copies of the Software and its Copyright notices. In addition publicly
11documented acknowledgment must be given that this software has been used if no
12source code of this software is made available publicly. Making the source
13available publicly means including the source for this software with the
14distribution, or a method to get this software via some reasonable mechanism
15(electronic transfer via a network or media) as well as making an offer to
16supply the source on request. This Copyright notice serves as an offer to
17supply the source on on request as well. Instead of this, supplying
18acknowledgments of use of this software in either Copyright notices, Manuals,
19Publicity and Marketing documents or any documentation provided with any
20product containing this software. This License does not apply to any software
21that links to the libraries provided by this software (statically or
22dynamically), but only to the software provided.
23
24Please see the COPYING-PLAIN for a plain-english explanation of this notice
25and its intent.
26
27THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
31IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/ChangeLog b/ChangeLog
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ChangeLog
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..215bf9f
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,6 @@
1AUTOMAKE_OPTIONS = 1.4 foreign
2MAINTAINERCLEANFILES = Makefile.in
3
4SUBDIRS = src data
5
6ACLOCAL_AMFLAGS = -I m4
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/NEWS
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..ae01364
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,17 @@
1#!/bin/sh
2
3rm -rf autom4te.cache
4rm -f aclocal.m4 ltmain.sh
5
6touch README
7
8echo "Running autopoint..." ; autopoint -f || :
9echo "Running aclocal..." ; aclocal -I m4 $ACLOCAL_FLAGS || exit 1
10echo "Running autoheader..." ; autoheader || exit 1
11echo "Running autoconf..." ; autoconf || exit 1
12echo "Running libtoolize..." ; (libtoolize --copy --automake || glibtoolize --automake) || exit 1
13echo "Running automake..." ; automake --add-missing --copy --gnu || exit 1
14
15if [ -z "$NOCONFIGURE" ]; then
16 ./configure "$@"
17fi
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..87d62fa
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,65 @@
1dnl Process this file with autoconf to produce a configure script.
2
3# get rid of that stupid cache mechanism
4rm -f config.cache
5
6AC_INIT(eenvaders, 0.1, billiob@efl.so)
7AC_PREREQ(2.52)
8AC_CONFIG_SRCDIR(configure.ac)
9AC_CANONICAL_BUILD
10AC_CANONICAL_HOST
11AC_ISC_POSIX
12
13AM_INIT_AUTOMAKE(1.6)
14AM_CONFIG_HEADER(config.h)
15m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
16
17AC_PROG_CC_C99
18AC_HEADER_STDC
19AC_C_CONST
20AM_PROG_CC_C_O
21
22define([AC_LIBTOOL_LANG_CXX_CONFIG], [:])dnl
23define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl
24AC_PROG_LIBTOOL
25
26PKG_CHECK_MODULES(ECORE_EVAS, [ecore-evas])
27PKG_CHECK_MODULES(ENLIGHTENMENT, [enlightenment])
28datadir_edj=$(pkg-config --variable=prefix enlightenment)/share/enlightenment/data/backgrounds
29
30PKG_CHECK_MODULES(EDJE, [edje >= 0.5.0])
31vmaj=$(pkg-config --variable=vmaj edje)
32MODULE_ARCH="$host_os-$host_cpu-$vmaj.0.0"
33AC_SUBST(MODULE_ARCH)
34AC_DEFINE_UNQUOTED(MODULE_ARCH, "$MODULE_ARCH", "Module architecture")
35
36# Find edje_cc
37AC_ARG_WITH(edje-cc,
38 AC_HELP_STRING([--with-edje-cc=PATH], [specify a specific path to edje_cc]),
39 [
40 v=$withval;
41 EDJE_CC=$v
42 ],[
43 EDJE_CC=$(pkg-config --variable=prefix edje)/bin/edje_cc
44 ]
45)
46AC_SUBST(EDJE_CC)
47AC_MSG_CHECKING([Which edje_cc to use])
48AC_MSG_RESULT(${EDJE_CC})
49
50datadir=$(pkg-config --variable=modules edje)/${PACKAGE}
51AC_ARG_ENABLE(homedir-install,
52 AS_HELP_STRING([--enable-homedir-install], [Install module in homedir]),
53 [
54 datadir="${HOME}/.edje/modules/${PACKAGE}";
55 datadir_edj="${HOME}/.e/e/backgrounds"
56 ]
57)
58AC_SUBST(datadir_edj)
59
60AC_OUTPUT([
61Makefile
62data/Makefile
63src/Makefile
64], [
65])
diff --git a/data/Makefile.am b/data/Makefile.am
new file mode 100644
index 0000000..ab7c7b4
--- /dev/null
+++ b/data/Makefile.am
@@ -0,0 +1,18 @@
1AUTOMAKE_OPTIONS = 1.4 foreign
2MAINTAINERCLEANFILES = Makefile.in
3
4EDJE_FLAGS = -v
5
6filesdir = @datadir_edj@
7files_DATA = eenvaders.edj
8
9EXTRA_DIST = eenvaders.edc
10
11eenvaders.edj: eenvaders.edc
12 $(EDJE_CC) $(EDJE_FLAGS) $< $@
13
14clean-local:
15 rm -rf eenvaders.edj *~
16
17uninstall:
18 rm -rf $(DESTDIR)@datadir_edj@/eenvaders.edj
diff --git a/data/eenvaders.edc b/data/eenvaders.edc
new file mode 100644
index 0000000..abc9c05
--- /dev/null
+++ b/data/eenvaders.edc
@@ -0,0 +1,48 @@
1externals {
2 external: "eenvaders";
3}
4
5collections {
6 group {
7 name: "e/desktop/background";
8
9 script {
10 public clock_cb(unused) {
11 emit("eenvaders:refresh", "☃");
12 timer(30, "clock_cb", 1);
13 }
14 }
15
16 parts {
17 part {
18 name: "bg";
19 type: RECT;
20 description {
21 state: "default" 0.0;
22 color: 0 43 54 255;
23 }
24 }
25 part {
26 name: "eenvaders";
27 type: EXTERNAL;
28 source: "eenvaders";
29
30 description {
31 state: "default" 0.0;
32 }
33 }
34 }
35
36 // Get everything started at load
37 programs {
38 program {
39 name: "init";
40 signal: "load";
41 source: "";
42 script {
43 clock_cb(0);
44 }
45 }
46 }
47 }
48}
diff --git a/gen_invaders.py b/gen_invaders.py
new file mode 100755
index 0000000..25528cc
--- /dev/null
+++ b/gen_invaders.py
@@ -0,0 +1,52 @@
1#!/usr/bin/python
2
3from PIL import Image
4
5WIDTH = 7
6HEIGHT = 7
7
8
9for i in range(1<<15):
10 img = Image.new("RGB", (WIDTH, HEIGHT), (255, 255, 255))
11 pix = img.load()
12 if (i & (1 << 0)):
13 pix[1, 1] = (0, 0, 0)
14 pix[5, 1] = (0, 0, 0)
15 if (i & (1 << 1)):
16 pix[2, 1] = (0, 0, 0)
17 pix[4, 1] = (0, 0, 0)
18 if (i & (1 << 2)):
19 pix[3, 1] = (0, 0, 0)
20 if (i & (1 << 3)):
21 pix[1, 2] = (0, 0, 0)
22 pix[5, 2] = (0, 0, 0)
23 if (i & (1 << 4)):
24 pix[2, 2] = (0, 0, 0)
25 pix[4, 2] = (0, 0, 0)
26 if (i & (1 << 5)):
27 pix[3, 2] = (0, 0, 0)
28 if (i & (1 << 6)):
29 pix[1, 3] = (0, 0, 0)
30 pix[5, 3] = (0, 0, 0)
31 if (i & (1 << 7)):
32 pix[2, 3] = (0, 0, 0)
33 pix[4, 3] = (0, 0, 0)
34 if (i & (1 << 8)):
35 pix[3, 3] = (0, 0, 0)
36 if (i & (1 << 9)):
37 pix[1, 4] = (0, 0, 0)
38 pix[5, 4] = (0, 0, 0)
39 if (i & (1 << 10)):
40 pix[2, 4] = (0, 0, 0)
41 pix[4, 4] = (0, 0, 0)
42 if (i & (1 << 11)):
43 pix[3, 4] = (0, 0, 0)
44 if (i & (1 << 12)):
45 pix[1, 5] = (0, 0, 0)
46 pix[5, 5] = (0, 0, 0)
47 if (i & (1 << 13)):
48 pix[2, 5] = (0, 0, 0)
49 pix[4, 5] = (0, 0, 0)
50 if (i & (1 << 14)):
51 pix[3, 5] = (0, 0, 0)
52 img.save("img/{0}.png".format(i))
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..5cd6e29
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,28 @@
1MAINTAINERCLEANFILES = Makefile.in
2INCLUDES = -I. \
3 -I$(top_srcdir) \
4 -I$(includedir) \
5 @EDJE_CFLAGS@
6
7
8pkgdir = $(datadir)/$(MODULE_ARCH)
9pkg_LTLIBRARIES = module.la
10module_la_SOURCES = \
11 eenvaders_evas_smart.c \
12 eenvaders_edje_external.c
13
14module_la_LIBADD = @EDJE_LIBS@
15module_la_LDFLAGS = -module -avoid-version
16module_la_DEPENDENCIES = $(top_builddir)/config.h
17
18bin_PROGRAMS = eenvaders
19
20eenvaders_SOURCES = \
21 eenvaders_evas_smart.c \
22 eenvaders.c
23eenvaders_CPPFLAGS = \
24 @ECORE_EVAS_CFLAGS@
25eenvaders_LDADD = @ECORE_EVAS_LIBS@
26
27clean-local:
28 rm -rf *~
diff --git a/src/eenvaders.c b/src/eenvaders.c
new file mode 100644
index 0000000..c14fa9d
--- /dev/null
+++ b/src/eenvaders.c
@@ -0,0 +1,106 @@
1#include <stdlib.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <unistd.h>
5#include <fcntl.h>
6#include <Evas.h>
7#include <Ecore.h>
8#include <Ecore_Evas.h>
9
10#include "eenvaders_evas_smart.h"
11
12#define BG 0xff002b36
13#define FG 0xff839496
14
15#define MIN(a,b) (((a)<(b))?(a):(b))
16
17static struct {
18 Ecore_Evas *ee;
19 Evas *evas;
20 Evas_Coord w, h;
21 Evas_Object *bg;
22 Evas_Object *eenvaders;
23} eenvaders_g;
24#define _G eenvaders_g
25
26static void
27resize_cb(Ecore_Evas *ee)
28{
29 int w, h;
30
31 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
32 evas_object_resize(_G.bg, w, h);
33 evas_object_resize(_G.eenvaders, w, h);
34}
35
36static Eina_Bool
37timer_cb(void *data)
38{
39 Evas_Object *o = (Evas_Object *)data;
40
41 evas_object_smart_callback_call(o, "refresh", NULL);
42
43 return EINA_TRUE;
44}
45
46int
47main(void)
48{
49 unsigned int seedval;
50 int fd;
51
52 if (!ecore_evas_init())
53 return -1;
54
55 _G.w = 600;
56 _G.h = 350;
57
58
59 /*open file */
60 if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
61 perror(NULL);
62 exit(1);
63 }
64 if (read(fd, &seedval, sizeof(seedval)) != sizeof(seedval)) {
65 perror(NULL);
66 close(fd);
67 exit(1);
68 }
69 close(fd);
70 srand(seedval);
71
72 _G.ee = ecore_evas_software_x11_new(
73 NULL, /* const char * disp_name */
74 0, /* Ecore_X_Window parent */
75 0, 0, _G.w, _G.h);
76
77 ecore_evas_title_set(_G.ee, "EEnavders.fractal");
78 ecore_evas_borderless_set(_G.ee, 0);
79 ecore_evas_show(_G.ee);
80 _G.evas = ecore_evas_get(_G.ee);
81
82 _G.bg = evas_object_rectangle_add(_G.evas);
83 evas_object_color_set(_G.bg,
84 (BG >> 16) & 0xff,
85 (BG >> 8) & 0xff,
86 BG & 0xff,
87 BG >> 24);
88 evas_object_move(_G.bg, 0, 0);
89 evas_object_resize(_G.bg, _G.w, _G.h);
90 evas_object_show(_G.bg);
91
92 _G.eenvaders = eenvaders_smart_new(_G.evas);
93 evas_object_resize(_G.eenvaders, _G.w, _G.h);
94 evas_object_show(_G.eenvaders);
95
96 ecore_timer_add(3, timer_cb, _G.eenvaders);
97
98 ecore_evas_callback_resize_set(_G.ee, &resize_cb);
99
100 ecore_main_loop_begin();
101
102 ecore_evas_shutdown();
103 ecore_shutdown();
104
105 return 0;
106}
diff --git a/src/eenvaders_edje_external.c b/src/eenvaders_edje_external.c
new file mode 100644
index 0000000..4108194
--- /dev/null
+++ b/src/eenvaders_edje_external.c
@@ -0,0 +1,192 @@
1#include <stdlib.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <unistd.h>
5#include <fcntl.h>
6#include <Evas.h>
7#include <Ecore.h>
8#include <Ecore_Evas.h>
9#include <Edje.h>
10
11#include "eenvaders_evas_smart.h"
12
13/* Prototypes -{{{-*/
14
15static Evas_Object *
16eenvaders_ext_add(void *data, Evas *evas, Evas_Object *parent,
17 const Eina_List *params, const char *part_name);
18static void
19eenvaders_ext_state_set(void *data, Evas_Object *obj,
20 const void *from_params,
21 const void *to_params, float pos);
22static void
23eenvaders_ext_signal_emit(void *data, Evas_Object *obj,
24 const char *emission, const char *source);
25static Eina_Bool
26eenvaders_ext_param_set(void *data, Evas_Object *obj,
27 const Edje_External_Param *param);
28static Eina_Bool
29eenvaders_ext_param_get(void *data, const Evas_Object *obj,
30 Edje_External_Param *param);
31static Evas_Object *
32eenvaders_ext_content_get(void *data, const Evas_Object *obj,
33 const char *content);
34static void*
35eenvaders_ext_params_parse(void *data, Evas_Object *obj,
36 const Eina_List *params);
37static void
38eenvaders_ext_params_free(void *params);
39static const char*
40eenvaders_ext_label_get(void *data);
41static const char*
42eenvaders_ext_description_get(void *data);
43static Evas_Object *
44eenvaders_ext_icon_add(void *data, Evas *e);
45static Evas_Object *
46eenvaders_ext_preview_add(void *data, Evas *e);
47static const char*
48eenvaders_ext_translate(void *data, const char *orig);
49
50/* }}} */
51/* Globals -{{{-*/
52
53static struct {
54 Edje_External_Type ext_type;
55} eenvaders_g = {
56 .ext_type = {
57 .abi_version = EDJE_EXTERNAL_TYPE_ABI_VERSION,
58 .module = "eenvaders",
59 .module_name = "eenvaders",
60 .add = eenvaders_ext_add,
61 .state_set = eenvaders_ext_state_set,
62 .signal_emit = eenvaders_ext_signal_emit,
63 .param_set = eenvaders_ext_param_set,
64 .param_get = eenvaders_ext_param_get,
65 .content_get = eenvaders_ext_content_get,
66 .params_parse = eenvaders_ext_params_parse,
67 .params_free = eenvaders_ext_params_free,
68 .label_get = eenvaders_ext_label_get,
69 .description_get = eenvaders_ext_description_get,
70 .icon_add = eenvaders_ext_icon_add,
71 .preview_add = eenvaders_ext_preview_add,
72 .translate = eenvaders_ext_translate,
73 },
74};
75#define _G eenvaders_g
76
77/* }}} */
78/* Edje External -{{{-*/
79
80static Evas_Object *
81eenvaders_ext_add(void *data, Evas *evas, Evas_Object *parent,
82 const Eina_List *params, const char *part_name)
83{
84 return eenvaders_smart_new(evas);
85}
86
87static void
88eenvaders_ext_state_set(void *data, Evas_Object *obj,
89 const void *from_params,
90 const void *to_params, float pos)
91{
92}
93
94static void
95eenvaders_ext_signal_emit(void *data, Evas_Object *obj,
96 const char *emission, const char *source)
97{
98 evas_object_smart_callback_call(obj, emission, NULL);
99}
100
101static Eina_Bool
102eenvaders_ext_param_set(void *data, Evas_Object *obj,
103 const Edje_External_Param *param)
104{
105 return EINA_TRUE;
106}
107
108static Eina_Bool
109eenvaders_ext_param_get(void *data, const Evas_Object *obj,
110 Edje_External_Param *param)
111{
112 return EINA_TRUE;
113}
114
115static Evas_Object *
116eenvaders_ext_content_get(void *data, const Evas_Object *obj,
117 const char *content)
118{
119 return NULL;
120}
121
122static void*
123eenvaders_ext_params_parse(void *data, Evas_Object *obj,
124 const Eina_List *params)
125{
126 return NULL;
127}
128
129static void
130eenvaders_ext_params_free(void *params)
131{
132}
133
134static const char*
135eenvaders_ext_label_get(void *data)
136{
137 return NULL;
138}
139
140static const char*
141eenvaders_ext_description_get(void *data)
142{
143 return NULL;
144}
145
146static Evas_Object *
147eenvaders_ext_icon_add(void *data, Evas *e)
148{
149 return NULL;
150}
151
152static Evas_Object *
153eenvaders_ext_preview_add(void *data, Evas *e)
154{
155 return NULL;
156}
157
158static const char*
159eenvaders_ext_translate(void *data, const char *orig)
160{
161 return NULL;
162}
163/* }}} */
164/* Init/Shutdown -{{{-*/
165
166Eina_Bool
167eenvaders_init(void)
168{
169 unsigned int seedval = time(NULL);
170 int fd;
171
172 if ((fd = open("/dev/random", O_RDONLY)) >= 0) {
173 read(fd, &seedval, sizeof(seedval));
174 close(fd);
175 }
176 srand(seedval);
177
178 edje_external_type_register("eenvaders", &_G.ext_type);
179
180 return EINA_TRUE;
181}
182
183void
184eenvaders_shutdown(void)
185{
186 edje_external_type_unregister("eenvaders");
187}
188
189EINA_MODULE_INIT(eenvaders_init);
190EINA_MODULE_SHUTDOWN(eenvaders_shutdown);
191
192/* }}} */
diff --git a/src/eenvaders_evas_smart.c b/src/eenvaders_evas_smart.c
new file mode 100644
index 0000000..935d4ae
--- /dev/null
+++ b/src/eenvaders_evas_smart.c
@@ -0,0 +1,304 @@
1#include <stdlib.h>
2
3#include "eenvaders_evas_smart.h"
4
5#define BG 0xff002b36
6#define FG 0xff839496
7
8#define MIN(a,b) (((a)<(b))?(a):(b))
9
10/* Prototypes -{{{-*/
11static Evas_Smart *_eenvaders_object_smart_get(void);
12static Evas_Object *eenvaders_object_new(Evas *evas);
13static void _eenvaders_object_del(Evas_Object *o);
14static void _eenvaders_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y);
15static void _eenvaders_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h);
16static void _eenvaders_object_show(Evas_Object *o);
17static void _eenvaders_object_hide(Evas_Object *o);
18static void _eenvaders_object_color_set(Evas_Object *o, int r, int g, int b, int a);
19static void _eenvaders_object_clip_set(Evas_Object *o, Evas_Object *clip);
20static void _eenvaders_object_clip_unset(Evas_Object *o);
21
22static void
23draw_eenvaders(Evas_Object *smart_obj,
24 int x, int y, int w, int h);
25/* }}} */
26/* Globals -{{{-*/
27
28static struct {
29 Evas_Smart_Class klass;
30} eenvaders_evas_smart_g = {
31 .klass = {
32 .name = "eenvaders_object",
33 .version = EVAS_SMART_CLASS_VERSION,
34 .add = NULL,
35 .del = _eenvaders_object_del,
36 .move = _eenvaders_object_move,
37 .resize = _eenvaders_object_resize,
38 .show = NULL,
39 .hide = NULL,
40 .color_set = NULL,
41 .clip_set = NULL,
42 .clip_unset = NULL,
43 .calculate = NULL,
44 .member_add = NULL,
45 .member_del = NULL,
46 .parent = NULL,
47 .callbacks = NULL,
48 .interfaces = NULL,
49 .data = NULL,
50 },
51#define _G eenvaders_evas_smart_g
52};
53
54/* }}} */
55/* Eenvaders functions -{{{-*/
56
57static void
58eenvaders_mouse_down(void *data,
59 Evas *evas,
60 Evas_Object *child,
61 void *event_info)
62{
63 Evas_Coord x, y, w, h;
64 Evas_Event_Mouse_Up *evt = event_info;
65 Evas_Object *parent = data;
66 void *mem;
67
68 x = evt->canvas.x;
69 y = evt->canvas.y;
70
71 mem = evas_object_data_del(child, "m");
72 if (!mem)
73 return;
74
75 free(mem);
76 evas_object_geometry_get(child, &x, &y, &w, &h);
77 evas_object_smart_member_del(child);
78 evas_object_del(child);
79 draw_eenvaders(parent, x+3, y+3, w-3, h-3);
80}
81
82static Evas_Object*
83new_eenvader(Evas *evas, Evas_Object *smart_obj)
84{
85 Evas_Object *o = NULL;
86 uint16_t u = rand();
87 int *mem = calloc(7 * 7, sizeof(int));
88
89 if (!mem) {
90 perror(NULL);
91 exit(1);
92 }
93
94 for (int i = 0; i < 15; i++) {
95 if (u & (1 << i)) {
96 mem[7 + 7*(i/3) + 1 + i%3] = FG;
97 mem[7 + 7*(i/3) + 5 - i%3] = FG;
98 }
99 }
100
101 o = evas_object_image_filled_add(evas);
102 evas_object_image_alpha_set(o, EINA_TRUE);
103 evas_object_image_fill_set(o, 0, 0, 7, 7);
104 evas_object_image_smooth_scale_set(o, EINA_FALSE);
105 evas_object_image_size_set (o, 7, 7);
106 evas_object_image_data_set(o, (void *) mem);
107 evas_object_data_set(o, "m", (void *) mem);
108
109 evas_object_event_callback_add(o,
110 EVAS_CALLBACK_MOUSE_DOWN,
111 eenvaders_mouse_down,
112 smart_obj);
113
114 return o;
115}
116
117static int
118square_ceil_7(int n)
119{
120 /* XXX: considering n >= 7 */
121 int r = 1;
122
123 n /= 7;
124
125 while (n >>= 1) {
126 r <<= 1;
127 }
128 return r * 7;
129}
130
131static void
132draw_eenvaders(Evas_Object *smart_obj,
133 int x, int y, int w, int h)
134{
135 Evas_Object *o;
136 int d;
137
138 if (w < 7 || h < 7)
139 return;
140
141 d = square_ceil_7(MIN(w,h));
142
143 o = new_eenvader(evas_object_evas_get(smart_obj), smart_obj);
144 evas_object_resize(o, d, d);
145 evas_object_smart_member_add(o, smart_obj);
146
147 switch(rand() & 3) {
148 case 0:
149 /* top-left */
150 evas_object_move(o, x, y);
151 evas_object_show(o);
152
153 draw_eenvaders(smart_obj, x+d, y, w-d, h); /* right */
154 draw_eenvaders(smart_obj, x, y+d, d, h-d); /* bottom */
155 break;
156 case 1:
157 /* top-right */
158 evas_object_move(o, x+w-d, y);
159 evas_object_show(o);
160
161 draw_eenvaders(smart_obj, x, y+d, w, h-d); /* bottom */
162 draw_eenvaders(smart_obj, x, y, w-d, d); /* left */
163 break;
164 case 2:
165 /* bottom-right */
166 evas_object_move(o, x+w-d, y+h-d);
167 evas_object_show(o);
168
169 draw_eenvaders(smart_obj, x, y, w-d, h); /* left */
170 draw_eenvaders(smart_obj, x+w-d, y, d, h-d); /* top */
171 break;
172 case 3:
173 /* bottom-left */
174 evas_object_move(o, x, y+h-d);
175 evas_object_show(o);
176
177 draw_eenvaders(smart_obj, x, y, w, h-d); /* top */
178 draw_eenvaders(smart_obj, x+d, y+h-d, w-d, d); /* right */
179 break;
180 }
181}
182
183/* }}} */
184/* Smart Object -{{{-*/
185
186Evas_Object *
187eenvaders_smart_new(Evas *e)
188{
189 return eenvaders_object_new(e);
190}
191
192static void
193eenvaders_on_refresh(void *data, Evas_Object *o, void *event_info)
194{
195 Evas_Coord x, y, w, h;
196 Evas_Object *child;
197 void *mem;
198 Eina_List *list;
199
200 list = evas_object_smart_members_get(o);
201 EINA_LIST_FREE(list, child) {
202 void *mem;
203
204 mem = evas_object_data_del(child, "m");
205 free(mem);
206 evas_object_event_callback_del(o, EVAS_CALLBACK_MOUSE_DOWN,
207 eenvaders_mouse_down);
208 evas_object_smart_member_del(child);
209 evas_object_del(child);
210 }
211
212 evas_object_geometry_get(o, &x, &y, &w, &h);
213 draw_eenvaders(o, x, y, w, h);
214}
215
216static Evas_Object *
217eenvaders_object_new(Evas *evas)
218{
219 Evas_Object *eenvaders_object;
220
221 eenvaders_object = evas_object_smart_add(evas,
222 _eenvaders_object_smart_get());
223 evas_object_smart_callback_add(eenvaders_object,
224 "refresh",
225 eenvaders_on_refresh,
226 NULL);
227
228 return eenvaders_object;
229}
230
231static Evas_Smart *
232_eenvaders_object_smart_get(void)
233{
234 static Evas_Smart *smart = NULL;
235
236 if (smart)
237 return smart;
238
239 smart = evas_smart_class_new(&_G.klass);
240 return smart;
241}
242
243static void
244_eenvaders_object_del(Evas_Object *o)
245{
246 Evas_Object *child;
247 void *mem;
248 Eina_List *list;
249
250 list = evas_object_smart_members_get(o);
251 EINA_LIST_FREE(list, child) {
252 void *mem;
253
254 evas_object_smart_member_del(child);
255 evas_object_del(child);
256 mem = evas_object_data_del(child, "m");
257 free(mem);
258
259 }
260}
261
262static void
263_eenvaders_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y)
264{
265 Evas_Coord orig_x, orig_y, dx, dy;
266 Eina_List *lst;
267 void *data;
268
269 evas_object_geometry_get(o, &orig_x, &orig_y, NULL, NULL);
270 dx = x - orig_x;
271 dy = y - orig_y;
272
273 lst = evas_object_smart_members_get(o);
274 EINA_LIST_FREE(lst, data) {
275 Evas_Object *child = data;
276
277 evas_object_geometry_get(child, &orig_x, &orig_y, NULL, NULL);
278 evas_object_move(child, orig_x + dx, orig_y + dy);
279 }
280}
281
282static void
283_eenvaders_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h)
284{
285 Evas_Coord x, y;
286 Evas_Object *child;
287 void *mem;
288 Eina_List *list;
289
290 list = evas_object_smart_members_get(o);
291 EINA_LIST_FREE(list, child) {
292 void *mem;
293
294 mem = evas_object_data_del(child, "m");
295 free(mem);
296 evas_object_smart_member_del(child);
297 evas_object_del(child);
298 }
299
300 evas_object_geometry_get(o, &x, &y, NULL, NULL);
301 draw_eenvaders(o, x, y, w, h);
302}
303
304/* }}} */
diff --git a/src/eenvaders_evas_smart.h b/src/eenvaders_evas_smart.h
new file mode 100644
index 0000000..65152f1
--- /dev/null
+++ b/src/eenvaders_evas_smart.h
@@ -0,0 +1,8 @@
1#ifndef EENVADERS_SMART_H
2#define EENVADERS_SMART_H
3#include <Evas.h>
4
5Evas_Object *eenvaders_smart_new(Evas *e);
6
7#endif
8