#include <Elementary.h>
-#include "main.h"
-#include "log.h"
+#include <app.h>
+
#include "map.h"
+#include "log.h"
+#include "util.h"
+#include "conf.h"
-const char *const MAP_EDJE = "map.edj";
+#define WORLD_W 443
+#define WORLD_H 259
+#define ORIGIN_W 443
+#define ORIGIN_H 259
-Evas_Object *map_create(Evas_Object *parent)
+static Evas_Object *main_layout = NULL;
+static Evas_Object *map_layout = NULL;
+static city_data_s city[MAXIMUM_SELECTED_CITY] = {{{0, 0, 0, 0, 0, 0}, NULL},
+ {{0, 0, 0, 0, 0, 0}, NULL},
+ {{0, 0, 0, 0, 0, 0}, NULL},
+ {{0, 0, 0, 0, 0, 0}, NULL},
+ {{0, 0, 0, 0, 0, 0}, NULL}};
+
+
+static void
+map_geom_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ Evas_Coord x, y, w, h, x2, y2, w2, h2;
+ evas_object_geometry_get(obj, &x, &y, &w, &h);
+ double scale_w = (double) w / ORIGIN_W;
+ double scale_h = (double) h / ORIGIN_H;
+
+ int idx;
+ for (idx = 0; MAXIMUM_SELECTED_CITY > idx; idx++)
+ {
+ if (!city[idx].obj) continue;
+ evas_object_move(city[idx].obj,
+ (int)((double)city[idx].ci.x * scale_w) + x - (city[idx].w / 2),
+ (int)((double)city[idx].ci.y * scale_h) + y - (city[idx].h / 2));
+ }
+}
+
+static void
+map_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ int idx;
+ for (idx = 0; MAXIMUM_SELECTED_CITY > idx; idx++)
+ {
+ evas_object_del(city[idx].obj);
+ city[idx].obj = NULL;
+ }
+}
+
+Evas_Object *
+create_momentic_layout(Evas_Object *parent, const char *full_path)
+{
+ //Main Layout
+ main_layout = elm_layout_add(parent);
+ elm_layout_file_set(main_layout, full_path, "main");
+ evas_object_size_hint_weight_set(main_layout, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+
+ //Map
+ map_layout = elm_layout_add(main_layout);
+ elm_layout_file_set(map_layout, full_path, "map");
+ evas_object_event_callback_add(map_layout, EVAS_CALLBACK_RESIZE, map_geom_cb, NULL);
+ evas_object_event_callback_add(map_layout, EVAS_CALLBACK_MOVE, map_geom_cb, NULL);
+ evas_object_event_callback_add(map_layout, EVAS_CALLBACK_DEL, map_del_cb, NULL);
+ elm_object_part_content_set(main_layout, "map", map_layout);
+
+ return main_layout;
+}
+
+Eina_Bool
+add_city_to_map(int idx, city_s *ci)
{
- Evas_Object *map = NULL;
- Evas_Object *button = NULL;
char *path = NULL;
- char full_path[] = {0, };
+ char full_path[PATH_LEN] = {0, };
+
+ if (idx >= MAXIMUM_SELECTED_CITY) return EINA_FALSE;
+ if (0 > idx) return EINA_FALSE;
+ if (city[idx].obj) return EINA_FALSE;
- retv_if(!parent, NULL);
+ int i;
+ for (i = 0; i < MAXIMUM_SELECTED_CITY; i++)
+ {
+ if (city[i].ci.id == ci->id) return EINA_FALSE;
+ }
path = app_get_resource_path();
- retv_if(!path, NULL);
+ retv_if(!path, EINA_FALSE);
- snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, MAP_EDJE);
+ snprintf(full_path, sizeof(full_path), "%s/edje/city.edj", path);
free(path);
- map = elm_layout_add(parent);
- retv_if(!map, NULL);
- elm_layout_file_set(map, full_path, "main");
- evas_object_show(map);
+ Evas_Coord x, y, w, h, x2, y2, w2, h2;
+ evas_object_geometry_get(map_layout, &x, &y, &w, &h);
+ edje_object_part_geometry_get(elm_layout_edje_get(map_layout), "map", &x2, &y2, &w, &h);
+ double scale_w = (double) w / ORIGIN_W;
+ double scale_h = (double) h / ORIGIN_H;
+
+ char buf[256];
+ snprintf(buf, sizeof(buf), "city%d", idx);
+ city[idx].obj = elm_layout_add(map_layout);
+ elm_layout_file_set(city[idx].obj, full_path, buf);
+// evas_object_smart_member_add(city[idx].obj, map_layout);
+ evas_object_show(city[idx].obj);
+
+ Evas_Object *edje = elm_layout_edje_get(city[idx].obj);
+ city[idx].w = atoi(edje_object_data_get(edje, "width"));
+ city[idx].h = atoi(edje_object_data_get(edje, "height"));
+ memcpy(&city[idx].ci, ci, sizeof(city_s));
+
+ evas_object_resize(city[idx].obj, city[idx].w, city[idx].h);
- return map;
+ evas_object_move(city[idx].obj,
+ (int)((double)ci->x * scale_w) + x + x2 - (city[idx].w / 2),
+ (int)((double)ci->y * scale_h) + y + y2 - (city[idx].h / 2));
+
+ Elm_Transit *trans;
+
+ //Effect 1
+ trans = elm_transit_add();
+ elm_transit_object_add(trans, city[idx].obj);
+ elm_transit_effect_zoom_add(trans, 3.0, 1.0);
+ elm_transit_effect_color_add(trans, 0, 0, 0, 0, 255, 255, 255, 255);
+ elm_transit_tween_mode_set(trans, ELM_TRANSIT_TWEEN_MODE_DECELERATE);
+ elm_transit_duration_set(trans, 0.35);
+ elm_transit_go(trans);
+
+ //Effect 2
+ Evas_Object *effect =
+ (Evas_Object *) edje_object_part_object_get(edje, "effect");
+ evas_object_render_op_set(effect, EVAS_RENDER_ADD);
+ trans = elm_transit_add();
+ elm_transit_object_add(trans, effect);
+ elm_transit_effect_color_add(trans, 0, 0, 0, 0, 100, 100, 100, 100);
+ elm_transit_duration_set(trans, 1.25);
+ elm_transit_repeat_times_set(trans, -1);
+ elm_transit_auto_reverse_set(trans, EINA_TRUE);
+ elm_transit_go(trans);
+
+ return EINA_TRUE;
+}
+
+static void
+trans_del_cb(void *data, Elm_Transit *trans)
+{
+ int idx = (int) data;
+ evas_object_del(city[idx].obj);
+ city[idx].obj = NULL;
+}
+
+Eina_Bool
+remove_city_from_map(int idx)
+{
+ if (idx >= MAXIMUM_SELECTED_CITY) return EINA_FALSE;
+ if (0 > idx) return EINA_FALSE;
+ if (!city[idx].obj) return EINA_FALSE;
+
+ city[idx].ci.id = -1;
+ Elm_Transit *trans = elm_transit_add();
+ elm_transit_object_add(trans, city[idx].obj);
+ elm_transit_effect_zoom_add(trans, 1.0, 2.0);
+ elm_transit_effect_color_add(trans, 255, 255, 255, 255, 0, 0, 0, 0);
+ elm_transit_tween_mode_set(trans, ELM_TRANSIT_TWEEN_MODE_DECELERATE);
+ elm_transit_duration_set(trans, 0.35);
+ elm_transit_del_cb_set(trans, trans_del_cb, (void *)idx);
+ elm_transit_go(trans);
+
+ return EINA_TRUE;
+}
+
+void
+button_effect(Evas_Object *btn)
+{
+ Elm_Transit *trans = elm_transit_add();
+ elm_transit_object_add(trans, btn);
+ elm_transit_effect_zoom_add(trans, 1.0, 0.9);
+ elm_transit_duration_set(trans, 0.4);
+ elm_transit_event_enabled_set(trans, EINA_TRUE);
+ elm_transit_auto_reverse_set(trans, EINA_TRUE);
+ elm_transit_repeat_times_set(trans, -1);
+ elm_transit_go(trans);
}
-void map_destroy(Evas_Object *map)
+typedef struct part_info
{
- Evas_Object *button = NULL;
+ double p1, p2;
+
+} part_info_s;
+
+static void
+item_geom_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *rect1 = evas_object_data_get(obj, "part1");
+ Evas_Object *rect2 = evas_object_data_get(obj, "part2");
+
+ ret_if(!rect1);
+
+ Evas_Coord x, y, w, h, x2, y2, w2, h2;
+ double xx;
+ part_info_s *pi;
+
+ evas_object_geometry_get(obj, &x, &y, &w, &h);
+ edje_object_part_geometry_get(elm_layout_edje_get(obj), "graph", &x2, &y2, &w2, &h2);
+
+ pi = evas_object_data_get(rect1, "part_info");
+ if (!pi) return;
+
+ xx = (double)(x + x2) + (((double)w2) * pi->p1);
+ evas_object_move(rect1, (int) xx, (y + y2));
+ evas_object_resize(rect1, (int) (((double)w2) * (pi->p2 - pi->p1)), h2);
+
+ if (!rect2) return;
+
+ pi = evas_object_data_get(rect2, "part_info");
+ ret_if(!pi);
+
+ xx = (double)(x + x2) + (((double)w2) * pi->p1);
+ evas_object_move(rect2, (int) xx, (y + y2));
+ evas_object_resize(rect2, (int) (((double)w2) * (pi->p2 - pi->p1)), h2);
+}
+
+static void
+item_del_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
+{
+ Evas_Object *rect1 = evas_object_data_get(obj, "part1");
+ Evas_Object *rect2 = evas_object_data_get(obj, "part2");
+ part_info_s *p1 = evas_object_data_get(rect1, "p1");
+ part_info_s *p2 = evas_object_data_get(rect1, "p2");
+ free(p1);
+ free(p2);
+ evas_object_del(rect1);
+ evas_object_del(rect2);
+}
+
+Eina_Bool
+set_time_range(Evas_Object *item, int idx, double p1, double p2, double p3, double p4)
+{
+ retv_if(!item, EINA_FALSE);
+ retv_if(idx < 0 || idx >= 6, EINA_FALSE); /* FIXME */
+
+ if (0.0f != p1)
+ p1 /= 24.0f;
+
+ if (0.0f != p2)
+ p2 /= 24.0f;
+
+ if (0.0f != p3)
+ p3 /= 24.0f;
+ if (0.0f != p4)
+ p4 /= 24.0f;
+
+ evas_object_event_callback_del(item, EVAS_CALLBACK_MOVE, item_geom_cb);
+ evas_object_event_callback_del(item, EVAS_CALLBACK_RESIZE, item_geom_cb);
+ evas_object_event_callback_del(item, EVAS_CALLBACK_DEL, item_del_cb);
+ evas_object_event_callback_add(item, EVAS_CALLBACK_MOVE, item_geom_cb, NULL);
+ evas_object_event_callback_add(item, EVAS_CALLBACK_RESIZE, item_geom_cb, NULL);
+ evas_object_event_callback_add(item, EVAS_CALLBACK_DEL, item_del_cb, NULL);
+
+ Evas_Object *rect;
+ rect = evas_object_data_get(item, "part1");
+ evas_object_del(rect);
+ rect = evas_object_data_get(item, "part2");
+ evas_object_del(rect);
+
+ Evas_Coord x, y, w, h, x2, y2, w2, h2;
+
+ double xx;
+ part_info_s *pi;
+
+ //Part 1
+
+ rect = evas_object_rectangle_add(evas_object_evas_get(item));
+ evas_object_smart_member_add(rect, item);
+ switch (idx)
+ {
+ case 0:
+ evas_object_color_set(rect, 239, 81, 39, 255);
+ break;
+ case 1:
+ evas_object_color_set(rect, 63, 170, 150, 255);
+ break;
+ case 2:
+ evas_object_color_set(rect, 34, 138, 255, 255);
+ break;
+ case 3:
+ evas_object_color_set(rect, 255, 47, 213, 255);
+ break;
+ case 4:
+ evas_object_color_set(rect, 248, 176, 67, 255);
+ break;
+ case 5:
+ evas_object_color_set(rect, 255, 200, 0, 255);
+ break;
+ }
+ evas_object_geometry_get(item, &x, &y, &w, &h);
+ edje_object_part_geometry_get(elm_layout_edje_get(item), "graph", &x2, &y2, &w2, &h2);
+
+ xx = x + x2 + (w2 * p1);
+ evas_object_show(rect);
+
+ evas_object_data_set(item, "part1", rect);
+
+ pi = calloc(1, sizeof(part_info_s));
+ if (pi)
+ {
+ pi->p1 = p1;
+ pi->p2 = p2;
+ evas_object_data_set(rect, "part_info", pi);
+ }
+
+ //Part 2
+ if ((p3 == 0 && p4 == 0)) return EINA_TRUE;
+
+ rect = evas_object_rectangle_add(evas_object_evas_get(item));
+ evas_object_smart_member_add(rect, item);
+
+ switch (idx)
+ {
+ case 0:
+ evas_object_color_set(rect, 239, 81, 39, 255);
+ break;
+ case 1:
+ evas_object_color_set(rect, 63, 170, 150, 255);
+ break;
+ case 2:
+ evas_object_color_set(rect, 34, 138, 255, 255);
+ break;
+ case 3:
+ evas_object_color_set(rect, 255, 47, 213, 255);
+ break;
+ case 4:
+ evas_object_color_set(rect, 248, 176, 67, 255);
+ break;
+ case 5:
+ evas_object_color_set(rect, 255, 200, 0, 255);
+ break;
+ }
+ evas_object_geometry_get(item, &x, &y, &w, &h);
+ edje_object_part_geometry_get(elm_layout_edje_get(item), "graph", &x2, &y2, &w2, &h2);
+ xx = x + x2 + (w2 * p1);
+ evas_object_show(rect);
+
+ evas_object_data_set(item, "part2", rect);
+
+ pi = calloc(1, sizeof(part_info_s));
+ if (pi)
+ {
+ pi->p1 = p3;
+ pi->p2 = p4;
+ evas_object_data_set(rect, "part_info", pi);
+ }
+
+ return EINA_TRUE;
+}
+
+
+Eina_Bool
+set_marker(Evas_Object *item, int idx)
+{
+ if (idx < 0 || idx >= MAXIMUM_SELECTED_CITY) return EINA_FALSE;
+ if (!item) return EINA_FALSE;
+
+ char *path = NULL;
+ char full_path[PATH_LEN] = {0, };
+ path = app_get_resource_path();
+ retv_if(!path, EINA_FALSE);
+
+ snprintf(full_path, sizeof(full_path), "%s/edje/item2.edj", path);
+ free(path);
+
+ Evas_Object *img = elm_image_add(item);
+ retv_if(!img, EINA_FALSE);
- ret_if(!map);
+ switch (idx)
+ {
+ case 0:
+ elm_image_file_set(img, full_path, "my_status");
+ break;
+ case 1:
+ elm_image_file_set(img, full_path, "location_mint");
+ break;
+ case 2:
+ elm_image_file_set(img, full_path, "location_blue");
+ break;
+ case 3:
+ elm_image_file_set(img, full_path, "location_pink");
+ break;
+ case 4:
+ elm_image_file_set(img, full_path, "location_orange");
+ break;
+ }
+ elm_object_part_content_set(item, "mark", img);
- evas_object_del(map);
+ return EINA_TRUE;
}