From 3cefadd098bb72a087406ecc09c1c04f1dca0ab5 Mon Sep 17 00:00:00 2001 From: Patrick Hornecker Date: Mon, 21 Dec 2009 16:07:36 +0100 Subject: file locations reorderd, map in gui...build problems on local machine --- friendfinder/e_smart_map.c | 486 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 486 insertions(+) create mode 100644 friendfinder/e_smart_map.c (limited to 'friendfinder/e_smart_map.c') diff --git a/friendfinder/e_smart_map.c b/friendfinder/e_smart_map.c new file mode 100644 index 0000000..dc32412 --- /dev/null +++ b/friendfinder/e_smart_map.c @@ -0,0 +1,486 @@ +#include +#include + +#include +#include +#include +#include + +#include "e_smart_map.h" +#include "e_smart_tile.h" + +#include "render/line.h" + +#include "map/smart_map_priv.h" + +#include "util/sqlite_helper.h" + +static Evas_Smart *get_smart(); +static void _map_object_add(Evas_Object *o); +static void _map_object_del(Evas_Object *o); +static void _map_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y); +static void _map_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h); +static void _map_object_show(Evas_Object *o); +static void _map_object_hide(Evas_Object *o); +static void _map_object_color_set(Evas_Object *o, int r, int g, int b, int a); +static void _map_object_clip_set(Evas_Object *o, Evas_Object *clip); +static void _map_object_clip_unset(Evas_Object *o); + +#define SMART_MAP_NAME "e_smart_map" + +void e_smart_map_set_info(Evas_Object *o, const char *info) +{ + struct smart_map *smart; + + smart = evas_object_smart_data_get(o); + if(smart->theme == NULL) + return; + + edje_object_part_text_set(smart->theme, "position", info); +} + +struct bubble +{ + struct overlay_object object; + Evas_Object *av; + Evas_Object *bb; +}; + +static struct bubble *create_text_bubble(struct smart_map *smart, char *info, char *text) +{ + struct bubble *bubble; + + bubble = (struct bubble*)malloc(sizeof(struct bubble)); + + bubble->object.obj = elm_box_add(smart->win); + evas_object_size_hint_weight_set(bubble->object.obj, 1.0, 1.0); + evas_object_size_hint_align_set(bubble->object.obj, 0.0, 0.0); + + bubble->av = elm_entry_add(smart->win); + elm_entry_entry_set(bubble->av, text); + elm_entry_line_wrap_set(bubble->av, 0); + evas_object_size_hint_weight_set(bubble->av, 1.0, 1.0); + // evas_object_smart_callback_add(av, "anchor,clicked", my_anchorblock_anchor, av); + + bubble->bb = elm_bubble_add(smart->win); + elm_bubble_info_set(bubble->bb, info); + evas_object_size_hint_min_set(bubble->bb, 150, 150); + evas_object_size_hint_max_set(bubble->bb, 300, 300); + evas_object_size_hint_weight_set(bubble->bb, 1.0, 1.0); + evas_object_size_hint_align_set(bubble->bb, 0.0, 0.0); + elm_bubble_content_set(bubble->bb, bubble->av); + evas_object_show(bubble->av); + elm_anchorblock_hover_end(bubble->av); + elm_box_pack_end(bubble->object.obj, bubble->bb); + + // evas_object_resize(bb, 100, 80); + // evas_object_move(bb, 120 - 15,160-23); + evas_object_show(bubble->bb); + bubble->object.ox = -14; + bubble->object.oy = -14; + bubble->object.sw = 480; + bubble->object.sh = 640; + fprintf(stderr, "FIXME: %s:%i\n", __FILE__, __LINE__); + return bubble; +} + +void e_smart_map_overlay_set_bubble(Evas_Object *o, char *overlay, char *info, char *text, double lat, double lon, int flags) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + + struct bubble *bb; + struct overlay_item *poi = malloc(sizeof(struct overlay_item)); + bb = create_text_bubble(smart, info, text); + + poi->obj = &bb->object; + poi->lat = lat; + poi->lon = lon; + poi->level_mask = flags; + + struct map_overlay *ov = overlay_find_by_name(smart, overlay); + if(ov == NULL) + e_smart_map_add_overlay(o, overlay); + + ov = overlay_find_by_name(smart, overlay); + if(ov == NULL) + return; + + overlay_add(smart, ov, poi); + overlay_change_level(smart, smart->current_level); + map_object_update(smart); +} + +void e_smart_map_overlay_hide(Evas_Object *o, char *overlay) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + + overlay_hide(smart, overlay); +} + +void e_smart_map_set_pos_px(Evas_Object *o, Evas_Coord x, Evas_Coord y) +{ + struct smart_map *smart; + + smart = evas_object_smart_data_get(o); + smart->ta.ox = x; + smart->ta.oy = y; + smart->ta.mode = POSITION_PX; + map_object_update(smart); +} + +void e_smart_map_set_pos(Evas_Object *o, double lat, double lon) +{ + struct smart_map *smart; + + smart = evas_object_smart_data_get(o); + smart->ta.lat = lat; + smart->ta.lon = lon; + smart->ta.mode = POSITION_WORLD; + smart->lat = lat; + smart->lon = lon; + map_object_update(smart); +} + +void e_smart_map_get_pos(Evas_Object *o, double *lat, double *lon) +{ + struct smart_map *smart; + + smart = evas_object_smart_data_get(o); + *lat = smart->lat; + *lon = smart->lon; +} + + +void e_smart_map_move(Evas_Object *o, Evas_Coord dx, Evas_Coord dy) +{ + struct smart_map *smart; + + smart = evas_object_smart_data_get(o); + smart->ta.ox += dx; + smart->ta.oy += dy; + smart->ta.mode = POSITION_PX; + map_object_update(smart); +} + +static inline void +_polyline_to_map(struct smart_map *smart, struct polyline *pl) +{ + int i; + int bx, by; + + if(smart->li == NULL) + return; + + for(i = 0; i < pl->count; i++) + { + if(i == 0) + { + + latlon_to_map(smart->li, + pl->points[i].lat, pl->points[i].lon, &bx, &by); + pl->points[i].x = bx; + pl->points[i].y = by; + } + else { + int x, y; + latlon_to_map(smart->li, + pl->points[i].lat, pl->points[i].lon, &x, &y); + pl->points[i].x = x; + pl->points[i].y = y; + + } + // point_dump(&pl->points[i]); + } +} + +int e_smart_map_add_path(Evas_Object *o, struct polyline *_pl) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + + Evas_Object *poly = e_smart_line_add(smart->evas); + _polyline_to_map(smart, _pl); + e_smart_line_set(poly, _pl); + evas_object_layer_set(poly, 0); + evas_object_pass_events_set(poly, 1); + evas_object_layer_set(smart->c.ctrl, 5); + evas_object_show(poly); + eina_array_push(smart->paths, poly); + map_object_update(smart); + return 0; +} + +int e_smart_map_add_overlay(Evas_Object *o, char *name) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + + struct map_overlay *ov = overlay_create(smart, name); + if(ov == NULL) + return -1; + + return eina_array_push(smart->overlays, ov); +} + +Evas_Object *e_smart_map_add(Evas_Object *win, const char *map_eet) +{ + Evas_Object *obj; + struct smart_map *smart; + Evas *e; + + e = evas_object_evas_get(win); + obj = evas_object_smart_add(e, get_smart()); + if(obj == NULL) + return NULL; + + smart = evas_object_smart_data_get(obj); + if(smart == NULL) + { + evas_object_del(obj); + return NULL; + } + smart->mi = map_info_read(map_eet); + if(smart->mi == NULL) + { + printf("map_info read failed\n"); + evas_object_del(obj); + return NULL; + } + + smart->evas = e; + smart->li = NULL; + smart->ta.tiles = NULL; + smart->ta.ox = 0; + smart->ta.oy = 0; + smart->ta.mode = POSITION_PX; + smart->drag = 0; + smart->theme = NULL; + smart->win = win; + smart->overlays = eina_array_new(4); + smart->paths = eina_array_new(4); + controls_init(smart); + _set_level(smart, 8); + return obj; +} + +int _set_level(struct smart_map *smart, int level) +{ + Eina_Array_Iterator iterator; + int i; + Evas_Object *path; + + smart->li = map_info_get_level(smart->mi, &level); + if(smart->li == NULL) + return -1; + + smart->current_level = level; + smart->ta.lat = smart->lat; + smart->ta.lon = smart->lon; + smart->ta.mode = POSITION_WORLD; + + EINA_ARRAY_ITER_NEXT(smart->paths, i, path, iterator) + { + struct polyline *_pl = e_smart_line_get(path); + if(_pl == NULL) + continue; + _polyline_to_map(smart, _pl); + e_smart_line_set(path, _pl); + evas_object_show(path); + } + + overlay_change_level(smart, level); + map_object_update(smart); + return 0; +} + +int e_smart_map_set_level(Evas_Object *o, int level) +{ + struct smart_map *smart; + + smart = evas_object_smart_data_get(o); + return _set_level(smart, level); +} + +static void +zoom_cb(void *data, Evas_Object *o, const char *emission, const char *source) +{ + double x, y; + int new_level; + struct smart_map *smart = (struct smart_map *)data; + int max_level = smart->mi->max_level; + int min_level = smart->mi->min_level; + + edje_object_part_drag_value_get(smart->theme, "zoom", &x, &y); + new_level = max_level - ((max_level - min_level) * y); + + smart->ta.lat = smart->lat; + smart->ta.lon = smart->lon; + smart->ta.mode = POSITION_WORLD; + + _set_level(smart, new_level); +} + +int e_smart_map_set_theme(Evas_Object *o, const char *theme, const char *group) +{ + Evas_Object *edje; + struct smart_map *smart; + + smart = evas_object_smart_data_get(o); + edje = edje_object_add(evas_object_evas_get(o)); + if(!edje_object_file_set(edje, theme, group)) + { + printf("failed loading %s/%s\n", theme, group); + return -1; + } + + // XXX: reset ? + smart->theme = edje; + + evas_object_smart_member_add(edje, o); + evas_object_move(edje, smart->x, smart->y); + evas_object_resize(edje, smart->w, smart->h); + evas_object_clip_set(edje, smart->clip); + evas_object_show(edje); + + edje_object_signal_callback_add(edje, "drag", "zoom", zoom_cb, smart); + edje_object_part_drag_value_set(edje, "zoom", 0.0, 0.5); + return 0; +} + +static void _map_object_add(Evas_Object *o) +{ + struct smart_map *smart; + + smart = calloc(1, sizeof(struct smart_map)); + if(smart == NULL) + return; + + smart->obj = o; + smart->x = 0; + smart->y = 0; + smart->w = 0; + smart->h = 0; + + smart->clip = evas_object_rectangle_add(evas_object_evas_get(o)); + evas_object_smart_member_add(smart->clip, o); + evas_object_color_set(smart->clip, 255, 255, 255, 255); + + evas_object_smart_data_set(o, smart); +} + +static void _map_object_del(Evas_Object *o) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + + // XXX + + free(smart); +} + +static void _map_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + if(!smart) + return; + + smart->x = x; + smart->y = y; + evas_object_move(smart->clip, x, y); + evas_object_move(smart->c.ctrl, x, y); + if(smart->theme) + evas_object_move(smart->theme, x, y); + map_object_update(smart); +} + +static void _map_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + if(!smart) + return; + smart->w = w; + smart->h = h; + smart->ta.w = w; + smart->ta.h = h; + evas_object_resize(smart->clip, w, h); + evas_object_resize(smart->c.ctrl, w, h); + if(smart->theme) + evas_object_resize(smart->theme, w, h); + map_object_update(smart); +} + +static void _map_object_show(Evas_Object *o) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + if(!smart) + return; + evas_object_show(smart->clip); +} + +static void _map_object_hide(Evas_Object *o) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + if(!smart) + return; + evas_object_hide(smart->clip); +} + +static void _map_object_color_set(Evas_Object *o, int r, int g, int b, int a) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + if(!smart) + return; + evas_object_color_set(smart->clip, r, g, b, a); +} + +static void _map_object_clip_set(Evas_Object *o, Evas_Object *clip) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + if(!smart) + return; + evas_object_clip_set(smart->clip, clip); +} + +static void _map_object_clip_unset(Evas_Object *o) +{ + struct smart_map *smart; + smart = evas_object_smart_data_get(o); + if(!smart) + return; + evas_object_clip_unset(smart->clip); +} + +static Evas_Smart *get_smart() +{ + static Evas_Smart *e_smart_map = NULL; + + if(e_smart_map != NULL) + return e_smart_map; + + e_smart_map = evas_smart_new(SMART_MAP_NAME, + _map_object_add, + _map_object_del, + NULL, + NULL, + NULL, + NULL, + NULL, + _map_object_move, + _map_object_resize, + _map_object_show, + _map_object_hide, + _map_object_color_set, + _map_object_clip_set, + _map_object_clip_unset, + NULL); + return e_smart_map; +} + -- cgit v1.2.3-55-g7522