summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsongwon0.lee <songwon0.lee@samsung.com>2013-10-04 11:19:33 +0900
committersongwon0.lee <songwon0.lee@samsung.com>2013-10-04 11:19:33 +0900
commitbc9472bbbd7aa35eb3b82cdac90b382aade99bb5 (patch)
tree2358435cacd61c500319fff54ad168450f2595f6
parent4e555151bfccb44eb3e00e8004adf663a06af335 (diff)
initialize
-rw-r--r--Makefile.am4
-rwxr-xr-xautogen.sh8
-rw-r--r--configure.ac19
-rw-r--r--data/Makefile.am3
-rw-r--r--data/edc/Makefile.am11
-rw-r--r--data/edc/cell_button.edc99
-rw-r--r--data/edc/layout.edc24
-rw-r--r--data/image/bear.pngbin0 -> 7117 bytes
-rw-r--r--data/image/default.pngbin0 -> 4878 bytes
-rw-r--r--data/image/fish.pngbin0 -> 5525 bytes
-rw-r--r--data/image/frog.pngbin0 -> 5267 bytes
-rw-r--r--data/image/kitty.pngbin0 -> 6262 bytes
-rw-r--r--data/image/lion.pngbin0 -> 7265 bytes
-rw-r--r--data/image/monkey.pngbin0 -> 6150 bytes
-rw-r--r--data/image/pig.pngbin0 -> 5187 bytes
-rw-r--r--data/image/rabbit.pngbin0 -> 6655 bytes
-rw-r--r--src/Makefile.am8
-rw-r--r--src/cell.c131
-rw-r--r--src/cell.h23
-rw-r--r--src/cell_manager.c377
-rw-r--r--src/main.c54
21 files changed, 761 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..0480cd3
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1,4 @@
1MAINTAINERCLEANFILES = Makefile.in Makefile
2ACLOCAL_AMFLAGS = -I m4
3SUBDIRS = data src
4
diff --git a/autogen.sh b/autogen.sh
new file mode 100755
index 0000000..5377014
--- /dev/null
+++ b/autogen.sh
@@ -0,0 +1,8 @@
1*#!/bin/sh
2
3echo "Running aclocal..." ; aclocal $ACLOCAL_FLAGS || exit 1
4echo "Running autoheader..." ; autoheader || exit 1
5echo "Running autoconf..." ; autoconf || exit 1
6echo "Running automake..." ; automake --add-missing --copy --gnu || exit 1
7./configure "$@"
8
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..d57ed13
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,19 @@
1 AC_INIT(e-jeweld, 0.0.0, songwon0.lee@samsung.com)
2 AC_PREREQ(2.52)
3 AC_CONFIG_SRCDIR([src/main.c])
4 AC_CONFIG_HEADERS([config.h])
5
6 AM_INIT_AUTOMAKE([foreign])
7
8 AC_PROG_CC
9
10 PKG_CHECK_MODULES([ELEMENTARY], elementary)
11 AC_DEFINE_UNQUOTED([DESKTOP],[${DESKTOP}],["Desktop build is enabled"])
12 AC_CONFIG_FILES([Makefile
13 data/Makefile
14 data/edc/Makefile
15 src/Makefile
16 ])
17 AC_OUTPUT
18
19
diff --git a/data/Makefile.am b/data/Makefile.am
new file mode 100644
index 0000000..885effa
--- /dev/null
+++ b/data/Makefile.am
@@ -0,0 +1,3 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3SUBDIRS = edc
diff --git a/data/edc/Makefile.am b/data/edc/Makefile.am
new file mode 100644
index 0000000..832707d
--- /dev/null
+++ b/data/edc/Makefile.am
@@ -0,0 +1,11 @@
1EDJE_FLAGS = \
2-id ../image
3TARGET = cell_button.edj
4clean:
5 rm -rf *.edj
6all: $(TARGET)
7$(TARGET):
8 rm -rf *.edj
9 edje_cc layout.edc $(EDJE_FLAGS)
10 edje_cc cell_button.edc $(EDJE_FLAGS)
11
diff --git a/data/edc/cell_button.edc b/data/edc/cell_button.edc
new file mode 100644
index 0000000..ad043bb
--- /dev/null
+++ b/data/edc/cell_button.edc
@@ -0,0 +1,99 @@
1#define STATE_PROGRAM(type_idx) \
2program {\
3 name: "set_type_"type_idx;\
4 signal: "cell_type,"type_idx;\
5 action: STATE_SET type_idx 0.0;\
6 target: "cell_image";\
7}\
8
9collections {
10group { name: "elm/button/base/simple_button";
11 images {
12 image: "default.png" COMP;
13 }
14 parts {
15 part { name: "click_rect";
16 type: RECT;
17 description { state: "default" 0.0;
18 color: 255 255 255 0;
19 }
20 }
21 part { name: "cell_image";
22 type: IMAGE;
23 description { state: "default" 0.0;
24 align: 0.5 0.5;
25 image.normal: "default.png";
26 }
27 description { state: "0" 0.0; inherit: "default"; }
28 description { state: "1" 0.0; inherit: "default"; }
29 description { state: "2" 0.0; inherit: "default"; }
30 description { state: "3" 0.0; inherit: "default"; }
31 description { state: "4" 0.0; inherit: "default"; }
32 description { state: "5" 0.0; inherit: "default"; }
33 description { state: "6" 0.0; inherit: "default"; }
34 description { state: "7" 0.0; inherit: "default"; }
35 }
36 }
37 programs {
38 program { name: "button_click";
39 signal: "mouse,down,1";
40 source: "click_rect";
41 action: SIGNAL_EMIT "elm,action,press" "";
42 }
43 program { name: "focus_on";
44 signal: "elm,action,focus";
45 source: "elm";
46 action: SIGNAL_EMIT "elm,action,press" "";
47 }
48 program { name: "button_unclick";
49 signal: "mouse,up,1";
50 source: "click_rect";
51 action: SIGNAL_EMIT "elm,action,unpress" "";
52 }
53 program { name: "focus_out";
54 signal: "elm,action,unfocus";
55 source: "elm";
56 action: SIGNAL_EMIT "elm,action,unpress" "";
57 }
58 program { name: "button_unclick3";
59 signal: "mouse,clicked,1";
60 source: "click_rect";
61 action: SIGNAL_EMIT "elm,action,click" "";
62 }
63 STATE_PROGRAM(0);
64 STATE_PROGRAM(1);
65 STATE_PROGRAM(2);
66 STATE_PROGRAM(3);
67 STATE_PROGRAM(4);
68 STATE_PROGRAM(5);
69 STATE_PROGRAM(6);
70 STATE_PROGRAM(7);
71 }
72}
73
74group { name: "elm/button/base/animal_button";
75 inherit: "elm/button/base/simple_button";
76 images {
77 image: "rabbit.png" COMP;
78 image: "bear.png" COMP;
79 image: "fish.png" COMP;
80 image: "frog.png" COMP;
81 image: "kitty.png" COMP;
82 image: "lion.png" COMP;
83 image: "monkey.png" COMP;
84 image: "pig.png" COMP;
85 }
86 parts {
87 part { name: "cell_image"; type: IMAGE;
88 description { state: "0" 0.0; image.normal: "rabbit.png"; }
89 description { state: "1" 0.0; image.normal: "bear.png"; }
90 description { state: "2" 0.0; image.normal: "fish.png"; }
91 description { state: "3" 0.0; image.normal: "frog.png"; }
92 description { state: "4" 0.0; image.normal: "kitty.png"; }
93 description { state: "5" 0.0; image.normal: "lion.png"; }
94 description { state: "6" 0.0; image.normal: "monkey.png"; }
95 description { state: "7" 0.0; image.normal: "pig.png"; }
96 }
97 }
98}
99}
diff --git a/data/edc/layout.edc b/data/edc/layout.edc
new file mode 100644
index 0000000..d5450f6
--- /dev/null
+++ b/data/edc/layout.edc
@@ -0,0 +1,24 @@
1collections {
2group { name: "layout";
3 min: 400 500;
4 parts{
5 part{ name : "top_menu_bar"; type: SWALLOW;
6 description { state : "default" 0.0;
7 rel1.relative : 0.0 0.0;
8 rel2.relative : 1.0 0.2;
9 }
10 }
11 part{ name : "content_swallow"; type:SWALLOW;
12 description {state : "default" 0.0;
13 rel1.relative : 0.0 0.2;
14 rel2.relative: 1.0 0.8;
15 }
16 }
17 part { name : "bottom_menu_bar"; type: SWALLOW;
18 description{state : "default" 0.0;
19 rel1.relative : 0.0 0.8;
20 rel2.relative : 1.0 1.0;
21 }
22 }
23 }
24} }
diff --git a/data/image/bear.png b/data/image/bear.png
new file mode 100644
index 0000000..f57eb54
--- /dev/null
+++ b/data/image/bear.png
Binary files differ
diff --git a/data/image/default.png b/data/image/default.png
new file mode 100644
index 0000000..dfb71b7
--- /dev/null
+++ b/data/image/default.png
Binary files differ
diff --git a/data/image/fish.png b/data/image/fish.png
new file mode 100644
index 0000000..f0f784b
--- /dev/null
+++ b/data/image/fish.png
Binary files differ
diff --git a/data/image/frog.png b/data/image/frog.png
new file mode 100644
index 0000000..42b035b
--- /dev/null
+++ b/data/image/frog.png
Binary files differ
diff --git a/data/image/kitty.png b/data/image/kitty.png
new file mode 100644
index 0000000..1848e41
--- /dev/null
+++ b/data/image/kitty.png
Binary files differ
diff --git a/data/image/lion.png b/data/image/lion.png
new file mode 100644
index 0000000..74e712e
--- /dev/null
+++ b/data/image/lion.png
Binary files differ
diff --git a/data/image/monkey.png b/data/image/monkey.png
new file mode 100644
index 0000000..e2563a4
--- /dev/null
+++ b/data/image/monkey.png
Binary files differ
diff --git a/data/image/pig.png b/data/image/pig.png
new file mode 100644
index 0000000..0e46cd9
--- /dev/null
+++ b/data/image/pig.png
Binary files differ
diff --git a/data/image/rabbit.png b/data/image/rabbit.png
new file mode 100644
index 0000000..3d916ab
--- /dev/null
+++ b/data/image/rabbit.png
Binary files differ
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..e0b3794
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,8 @@
1MAINTAINERCLEANFILES = Makefile.in Makefile
2
3bin_PROGRAMS = e_jeweled
4e_jeweled_SOURCES = main.c cell.h cell.c cell_manager.c
5e_jeweled_LDADD = @ELEMENTARY_LIBS@
6e_jeweled_CFLAGS = @ELEMENTARY_CFLAGS@
7
8
diff --git a/src/cell.c b/src/cell.c
new file mode 100644
index 0000000..363574d
--- /dev/null
+++ b/src/cell.c
@@ -0,0 +1,131 @@
1#include "cell.h"
2
3#define TYPE_MAX 8
4
5static void
6transit_del_cb(void *data, Elm_Transit *transit)
7{
8 Cell_Info *info= data;
9 Elm_Transit* trans = elm_transit_add();
10 elm_transit_object_add(trans, info->obj);
11 elm_transit_effect_translation_add(trans, 0, 0,
12 (info->pos_x - info->target_x) *SIZE,
13 (info->pos_y - info->target_y) * SIZE);
14 elm_transit_duration_set(trans, TRANSIT_TIME);
15 elm_transit_objects_final_state_keep_set(trans, EINA_TRUE);
16 elm_transit_go(trans);
17}
18
19void
20cell_down_move(Cell_Info* info, Elm_Transit_Del_Cb move_end_cb)
21{
22 if (info)
23 {
24 Elm_Transit* trans = elm_transit_add();
25 elm_transit_object_add(trans, info->obj);
26 elm_transit_effect_translation_add(trans, 0, 0,
27 (info->target_x - info->pos_x) *SIZE,
28 (info->target_y - info->pos_y) * SIZE);
29 elm_transit_duration_set(trans, 0.2);
30 elm_transit_objects_final_state_keep_set(trans, EINA_TRUE);
31 elm_transit_go(trans);
32
33 elm_transit_del_cb_set(trans, move_end_cb, info);
34 evas_object_show(info->obj);
35 }
36}
37
38void
39cell_target_back_move(Cell_Info *info)
40{
41 Elm_Transit* trans = elm_transit_add();
42 elm_transit_object_add(trans, info->obj);
43 if (info->pos_y < 0)
44 {
45 info->pos_y = (info->target_y * -1) - 1;
46 evas_object_move(info->obj,
47 info->pos_x * SIZE,
48 info->pos_y * SIZE + START_POS_Y);
49 }
50 elm_transit_effect_translation_add(trans, 0, 0,
51 (info->target_x - info->pos_x) * SIZE,
52 (info->target_y - info->pos_y) * SIZE);
53 elm_transit_duration_set(trans, 0.15);
54 elm_transit_objects_final_state_keep_set(trans, EINA_TRUE);
55 elm_transit_go(trans);
56
57 elm_transit_del_cb_set(trans, transit_del_cb, info);
58}
59
60void
61cell_target_match_move(Cell_Info *info, Elm_Transit_Del_Cb match_cb, void* data)
62{
63 Elm_Transit* trans = elm_transit_add();
64 elm_transit_object_add(trans, info->obj);
65 elm_transit_effect_translation_add(trans, 0, 0,
66 (info->target_x - info->pos_x) *SIZE, (info->target_y - info->pos_y) * SIZE);
67 elm_transit_duration_set(trans, 0.15);
68 elm_transit_objects_final_state_keep_set(trans, EINA_TRUE);
69 elm_transit_go(trans);
70
71 info->pos_x = info->target_x;
72 info->pos_y = info->target_y;
73 if (data)
74 {
75 Eina_List* list = data;
76 list = eina_list_append(list, info);
77 elm_transit_del_cb_set(trans, match_cb, list);
78 }
79}
80
81void
82cell_type_reset(Cell_Info *info)
83{
84 int random = rand() % TYPE_MAX;
85 info->type = random;
86
87 char buf[15];
88 sprintf(buf, "cell_type,%d", info->type);
89 elm_object_signal_emit(info->obj, buf, "");
90 info->triple_match = EINA_FALSE;
91}
92
93void
94cell_standby_set(Cell_Info *info, int x)
95{
96 info->pos_x = x;
97 info->pos_y = -1;
98 evas_object_move(info->obj, x * SIZE, -SIZE + START_POS_Y);
99 cell_type_reset(info);
100}
101
102void
103cell_explosion(Cell_Info *info)
104{
105 evas_object_hide(info->obj);
106}
107
108Cell_Info *
109cell_add(Evas_Object *parent, int r, int c)
110{
111 Cell_Info *info = (Cell_Info *)malloc(sizeof(Cell_Info));
112 info->obj = elm_button_add(parent);
113 elm_object_style_set(info->obj, "animal_button");
114 evas_object_resize(info->obj, SIZE, SIZE);
115 evas_object_show(info->obj);
116
117 cell_type_reset(info);
118
119 info->target_x = info->pos_x = r;
120 info->target_y = info->pos_y = c;
121
122 evas_object_move(info->obj, r * SIZE, c * SIZE + START_POS_Y);
123
124 return info;
125}
126
127void
128cell_remove(Cell_Info *info)
129{
130 free(info);
131}
diff --git a/src/cell.h b/src/cell.h
new file mode 100644
index 0000000..5515f3a
--- /dev/null
+++ b/src/cell.h
@@ -0,0 +1,23 @@
1#include <Elementary.h>
2
3#define SIZE 50
4#define CELL_WIDTH 8
5#define CELL_HEIGHT 8
6#define START_POS_Y 100
7#define TRANSIT_TIME 0.3
8
9typedef struct _Cell_Info{
10 int type;
11 int pos_x, pos_y;
12 int target_x, target_y;
13 Evas_Object* obj;
14 Eina_Bool triple_match;
15}Cell_Info;
16
17void cell_down_move(Cell_Info* info, Elm_Transit_Del_Cb move_end_cb);
18void cell_target_back_move(Cell_Info *info);
19void cell_target_match_move(Cell_Info *info, Elm_Transit_Del_Cb match_cb, void* data);
20void cell_explosion(Cell_Info *info);
21void cell_standby_set(Cell_Info *info, int x);
22void cell_type_reset(Cell_Info *info);
23Cell_Info *cell_add(Evas_Object *parent, int r, int c);
diff --git a/src/cell_manager.c b/src/cell_manager.c
new file mode 100644
index 0000000..fae3e52
--- /dev/null
+++ b/src/cell_manager.c
@@ -0,0 +1,377 @@
1#include "cell.h"
2
3#define move_dir_x_get(dir) dir % 2
4#define move_dir_y_get(dir) dir / 2
5
6typedef enum
7{
8 NONE = 0,
9 LEFT = -1, // x = -1 % 2 = -1, y = -1 / 2 = 0
10 RIGHT = 1, // x = 1 % 2 = 1, y = 1 / 2 = 0
11 UP = -2, // x = -2 % 2 = 0, y = -2 / 2 = -1
12 DOWN = 2 // x = 2 % 2 = 0, y = 2 / 2 = 1;
13}MOVE_DIR;
14
15static int move_cell_count = 0;
16static int mouse_move_x, mouse_move_y;
17static Cell_Info* selected_cell;
18static Cell_Info* cell_list[CELL_WIDTH][CELL_HEIGHT];
19
20static void _cell_chain_explosion(Eina_List* list);
21
22static MOVE_DIR
23_mouse_direction(int x, int y)
24{
25 //move magnitude
26 int mg = x * x + y * y;
27
28 MOVE_DIR dir = NONE;
29
30 if (mg > 100)
31 {
32 if (abs(x) > abs(y))
33 {
34 if (x < 0) dir = LEFT;
35 else dir = RIGHT;
36 }
37 else
38 {
39 if (y < 0) dir = UP;
40 else dir = DOWN;
41 }
42 }
43 return dir;
44}
45
46static int
47_cell_list_sort_cb(const void *d1, const void *d2)
48{
49 const Cell_Info *info1 = d1;
50 const Cell_Info *info2 = d2;
51
52 if (info1->pos_x > info2->pos_x)
53 return 1;
54
55 if (info1->pos_x == info2->pos_x)
56 {
57 if (info1->pos_y > info2->pos_y)
58 return -1;
59 else return 1;
60 }
61 else
62 {
63 return -1;
64 }
65}
66
67static Cell_Info *
68_cell_info_get_by_index(int x, int y)
69{
70 if ( x < 0 || x >= CELL_WIDTH || y < 0 || y >= CELL_HEIGHT)
71 return NULL;
72 else
73 return cell_list[x][y];
74}
75
76static Cell_Info *
77_cell_info_get_by_dir(Cell_Info *info, MOVE_DIR dir)
78{
79 int x = info->pos_x + move_dir_x_get(dir);
80 int y = info->pos_y + move_dir_y_get(dir);
81
82 return _cell_info_get_by_index(x, y);
83}
84
85static Cell_Info *
86_cell_target_by_dir(Cell_Info *info, MOVE_DIR dir)
87{
88 Cell_Info *swap = _cell_info_get_by_dir(info, dir);
89
90 if (swap)
91 {
92 swap->target_x = info->pos_x;
93 swap->target_y = info->pos_y;
94 info->target_x = swap->pos_x;
95 info->target_y = swap->pos_y;
96
97 cell_list[swap->pos_x][swap->pos_y] = info;
98 cell_list[info->pos_x][info->pos_y] = swap;
99 }
100 return swap;
101}
102
103static Eina_Bool
104_cell_near_match_check(Cell_Info *info)
105{
106 Cell_Info *l_cell = _cell_info_get_by_dir(info, LEFT);
107 Cell_Info *u_cell = _cell_info_get_by_dir(info, UP);
108 Eina_Bool check = EINA_FALSE;
109
110 if (l_cell && l_cell->type == info->type)
111 check = EINA_TRUE;
112 if (u_cell && u_cell->type == info->type)
113 check = EINA_TRUE;
114 return check;
115}
116
117static Eina_List *
118_cell_chain_check_by_dir(Cell_Info *info, MOVE_DIR dir)
119{
120 Cell_Info *cell = _cell_info_get_by_index(info->target_x + move_dir_x_get(dir),
121 info->target_y + move_dir_y_get(dir));
122
123 Eina_List* list = NULL;
124 if (cell && (cell->type == info->type))
125 {
126 list = eina_list_append(list, cell);
127 do
128 {
129 Cell_Info* next = _cell_info_get_by_dir(cell, dir);
130
131 if (next && next->type == cell->type)
132 {
133 list = eina_list_append(list, next);
134 cell = next;
135 }
136 else
137 cell = NULL;
138 }
139 while (cell);
140 }
141
142 return list;
143}
144
145static Eina_List *
146_cell_chain_get(Cell_Info* info)
147{
148 int left, right, up, down;
149 Eina_List* h_list = eina_list_merge(_cell_chain_check_by_dir(info, LEFT),
150 _cell_chain_check_by_dir(info, RIGHT));
151
152 Eina_List* v_list = eina_list_merge(_cell_chain_check_by_dir(info, UP),
153 _cell_chain_check_by_dir(info, DOWN));
154 Eina_List* total_list = NULL;
155
156 if (eina_list_count(h_list) >= 2)
157 total_list = eina_list_merge(total_list, h_list);
158
159 if (eina_list_count(v_list) >= 2)
160 total_list = eina_list_merge(total_list, v_list);
161
162 return total_list;
163}
164
165static void
166_cell_target_back_set(Cell_Info *info1, Cell_Info *info2)
167{
168 cell_list[info1->pos_x][info1->pos_y] = info1;
169 cell_list[info2->pos_x][info2->pos_y] = info2;
170}
171
172static Cell_Info *
173_cell_align_get(int x, int y, Eina_List* list)
174{
175 Cell_Info *info = NULL;
176 int i;
177 for (i = y ; i >= 0 ; --i)
178 {
179 info = cell_list[x][i];
180 if (info)
181 {
182 cell_list[x][i] = NULL;
183 break;
184 }
185 }
186
187 if (!info)
188 {
189 info = eina_list_nth(list, eina_list_count(list)-1);
190 list = eina_list_remove(list, info);
191 cell_standby_set(info, x);
192 }
193
194 return info;
195}
196
197static void
198_cell_all_check()
199{
200 int i, j;
201
202 for ( i = 0 ; i < CELL_WIDTH ; i++)
203 {
204 for ( j = CELL_HEIGHT -1 ; j >= 0 ; --j)
205 {
206 if(!cell_list[i][j]->triple_match)
207 {
208 Eina_List *selected_cell_list = NULL;
209
210 selected_cell_list = _cell_chain_get(cell_list[i][j]);
211
212 if(selected_cell_list)
213 {
214 printf("combo!!!\n");
215 _cell_chain_explosion(selected_cell_list);
216 return;
217 }
218 }
219
220 }
221 }
222}
223
224static void
225_cell_down_move_end_cb(void* data, Elm_Transit* transit)
226{
227 Cell_Info *info= data;
228 info->pos_x = info->target_x;
229 info->pos_y = info->target_y;
230
231 info->triple_match = EINA_FALSE;
232 move_cell_count--;
233 if (move_cell_count <= 0)
234 {
235 _cell_all_check();
236 }
237}
238
239static void
240_cell_line_down(int x, Eina_List* list)
241{
242 int y = CELL_HEIGHT - 1;
243 for ( ; y >= 0 ; --y)
244 {
245 if (cell_list[x][y] == NULL)
246 {
247 cell_list[x][y] = _cell_align_get(x, y, list);
248 if (cell_list[x][y])
249 {
250 move_cell_count++;
251 cell_list[x][y]->target_x = x;
252 cell_list[x][y]->target_y = y;
253 cell_down_move(cell_list[x][y], _cell_down_move_end_cb);
254 }
255 }
256 }
257
258}
259
260 static void
261_cell_chain_explosion(Eina_List* list)
262{
263 Eina_List *l;
264 Cell_Info *info;
265
266 list = eina_list_sort(list, eina_list_count(list),_cell_list_sort_cb);
267 EINA_LIST_FOREACH(list, l, info)
268 {
269 info->triple_match = EINA_TRUE;
270 cell_explosion(info);
271 cell_list[info->pos_x][info->pos_y] = NULL;
272 }
273
274 int i = 0 ;
275 for ( ; i < CELL_WIDTH ; i++)
276 _cell_line_down(i,list);
277}
278
279static void
280_cell_chain_explosion_cb(void* data, Elm_Transit* transit)
281{
282 _cell_chain_explosion(data);
283}
284
285static void
286_cell_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
287{
288 selected_cell = data;
289 mouse_move_x = mouse_move_y = 0;
290}
291
292static void
293_cell_mouse_move_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
294{
295 if(!selected_cell) return;
296
297 Evas_Event_Mouse_Move *ev = event_info;
298 if (ev->buttons != 1) return;
299
300 mouse_move_x += ev->cur.canvas.x - ev->prev.canvas.x;
301 mouse_move_y += ev->cur.canvas.y - ev->prev.canvas.y;
302
303 int x = 0, y = 0 ;
304
305 MOVE_DIR dir = _mouse_direction(mouse_move_x, mouse_move_y);
306 if (dir == NONE) return; //mouse move distance is not enough to determine the direction of move cell
307
308 Cell_Info* target_cell = _cell_target_by_dir(selected_cell, dir);
309 if (target_cell)
310 {
311 Eina_List *selected_cell_list = NULL, *target_cell_list = NULL;
312
313 if (target_cell->type != selected_cell->type)
314 {
315 selected_cell_list = _cell_chain_get(selected_cell);
316 target_cell_list = _cell_chain_get(target_cell);
317 }
318
319 if (!selected_cell_list && !target_cell_list)
320 {
321 _cell_target_back_set(selected_cell, target_cell);
322 cell_target_back_move(selected_cell);
323 cell_target_back_move(target_cell);
324 }
325 else
326 {
327 cell_target_match_move(selected_cell,
328 _cell_chain_explosion_cb,
329 selected_cell_list);
330 cell_target_match_move(target_cell,
331 _cell_chain_explosion_cb,
332 target_cell_list);
333 }
334 selected_cell = NULL;
335 }
336}
337
338void
339cell_table_init(Evas_Object *parent)
340{
341 Cell_Info *cell_info;
342 int i = 0, j = 0;
343
344 for (j = 0 ; j < CELL_HEIGHT ; ++j)
345 {
346 for (i = 0 ; i < CELL_WIDTH ; ++i)
347 {
348 cell_info = cell_add(parent, i, j);
349 while (_cell_chain_get(cell_info))
350 cell_type_reset(cell_info);
351
352 evas_object_event_callback_add(cell_info->obj,
353 EVAS_CALLBACK_MOUSE_DOWN,
354 _cell_mouse_down_cb,
355 cell_info);
356 evas_object_event_callback_add(cell_info->obj,
357 EVAS_CALLBACK_MOUSE_MOVE,
358 _cell_mouse_move_cb,
359 cell_info);
360 cell_list[i][j] = cell_info;
361 }
362 }
363}
364
365void
366cell_table_remove()
367{
368 int i, j;
369
370 for (j = 0 ; j < CELL_HEIGHT ; ++j)
371 {
372 for (i = 0 ; i < CELL_WIDTH ; ++i)
373 {
374 cell_remove(cell_list[i][j]);
375 }
376 }
377}
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..7ad925c
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,54 @@
1#include <Elementary.h>
2
3#include "cell.h"
4
5EAPI_MAIN int
6elm_main(int argc, char **argv)
7{
8 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
9 elm_theme_extension_add(NULL, "./data/edc/cell_button.edj");
10
11 Evas_Object *win = elm_win_util_standard_add("e-jeweled", "e-jeweled");
12 elm_win_autodel_set(win, EINA_TRUE);
13 evas_object_resize(win, 400, 600);
14 evas_object_show(win);
15
16 Evas_Object *layout = elm_layout_add(win);
17 elm_layout_file_set(layout,"./data/edc/layout.edj", "layout");
18 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
19 elm_win_resize_object_add(win, layout);
20 evas_object_show(layout);
21
22 Evas_Object* box = elm_box_add(win);
23 elm_box_horizontal_set(box, EINA_TRUE);
24 elm_object_part_content_set(layout, "top_menu_bar", box);
25 evas_object_show(box);
26
27 Evas_Object* btn = elm_button_add(win);
28 elm_object_text_set(btn, "SCORE");
29 evas_object_show(btn);
30 elm_box_pack_end(box, btn);
31
32 btn = elm_button_add(win);
33 elm_object_text_set(btn, "SHAKE");
34 evas_object_show(btn);
35 elm_box_pack_end(box, btn);
36
37 box = elm_box_add(win);
38 elm_object_part_content_set(layout, "bottom_menu_bar", box);
39 evas_object_show(box);
40
41 Evas_Object *pb = elm_progressbar_add(win);
42 elm_box_pack_end(box, pb);
43 evas_object_show(pb);
44
45 cell_table_init(win);
46
47 elm_run();
48 elm_shutdown();
49
50 cell_table_remove();
51
52 return 0;
53}
54ELM_MAIN()