From 56a3aade0f5cfaab09ad5d243d06bc0e00084a73 Mon Sep 17 00:00:00 2001 From: martin-s Date: Fri, 16 Nov 2007 09:27:40 +0000 Subject: [PATCH] Made support for slippy map git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@561 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/src/graphics.c | 19 +++++++++- navit/src/graphics.h | 3 +- navit/src/navit.c | 103 +++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 111 insertions(+), 14 deletions(-) diff --git a/navit/src/graphics.c b/navit/src/graphics.c index 3793552..113efde 100644 --- a/navit/src/graphics.c +++ b/navit/src/graphics.c @@ -544,6 +544,24 @@ graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, if (route) route_draw(route, trans, displaylist); xdisplay_draw(displaylist->dl, gra, layouts, order); + gra->meth.draw_mode(gra->priv, draw_mode_end); +} + +void +graphics_displaylist_move(struct displaylist *displaylist, int dx, int dy) +{ + struct displaylist_handle *dlh; + struct displayitem *di; + int i; + + dlh=graphics_displaylist_open(displaylist); + while ((di=graphics_displaylist_next(dlh))) { + for (i = 0 ; i < di->count ; i++) { + di->pnt[i].x+=dx; + di->pnt[i].y+=dy; + } + } + graphics_displaylist_close(dlh); } @@ -574,7 +592,6 @@ graphics_draw(struct graphics *gra, struct displaylist *displaylist, GList *maps profile(1,"xdisplay_draw"); profile(0,"end"); - gra->meth.draw_mode(gra->priv, draw_mode_end); #if 0 for (i = 0 ; i < data_window_type_end; i++) { data_window_end(co->data_window[i]); diff --git a/navit/src/graphics.h b/navit/src/graphics.h index 7e3eeec..a657e61 100644 --- a/navit/src/graphics.h +++ b/navit/src/graphics.h @@ -99,7 +99,7 @@ struct point; struct route; struct transformation; struct graphics *graphics_new(const char *type, struct attr **attrs); -struct graphics * graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h); +struct graphics *graphics_overlay_new(struct graphics *parent, struct point *p, int w, int h); void graphics_init(struct graphics *this_); void *graphics_get_data(struct graphics *this_, char *type); void graphics_register_resize_callback(struct graphics *this_, void (*callback)(void *data, int w, int h), void *data); @@ -119,6 +119,7 @@ void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, str void display_add(struct displaylist *displaylist, struct item *item, int count, struct point *pnt, char *label); int graphics_ready(struct graphics *this_); void graphics_displaylist_draw(struct graphics *gra, struct displaylist *displaylist, struct transformation *trans, GList *layouts, struct route *route); +void graphics_displaylist_move(struct displaylist *displaylist, int dx, int dy); void graphics_draw(struct graphics *gra, struct displaylist *displaylist, GList *mapsets, struct transformation *trans, GList *layouts, struct route *route); struct displaylist_handle *graphics_displaylist_open(struct displaylist *displaylist); struct displayitem *graphics_displaylist_next(struct displaylist_handle *dlh); diff --git a/navit/src/navit.c b/navit/src/navit.c index a2dc1d9..b62b306 100644 --- a/navit/src/navit.c +++ b/navit/src/navit.c @@ -83,6 +83,9 @@ struct navit { struct menu *bookmarks; GHashTable *bookmarks_hash; struct menu *destinations; + struct point pressed, last, current; + int button_pressed,moved; + guint button_timeout, motion_timeout; }; struct gui *main_loop_gui; @@ -146,25 +149,100 @@ navit_resize(void *data, int w, int h) navit_draw(this_); } +static gboolean +navit_popup(void *data) +{ + struct navit *this_=data; + popup(this_, 1, &this_->pressed); + this_->button_timeout=0; + return FALSE; +} + static void navit_button(void *data, int pressed, int button, struct point *p) { struct navit *this_=data; - if (pressed && button == 1) { - int border=16; - if (! transform_within_border(this_->trans, p, border)) { + int border=16; + + if (pressed) { + this_->pressed=*p; + this_->last=*p; + if (button == 1) { + this_->button_pressed=1; + this_->moved=0; + this_->button_timeout=g_timeout_add(500, navit_popup, data); + } + if (button == 2) navit_set_center_screen(this_, p); - } else + if (button == 3) popup(this_, button, p); + if (button == 4) + navit_zoom_in(this_, 2); + if (button == 5) + navit_zoom_out(this_, 2); + } else { + this_->button_pressed=0; + if (this_->button_timeout) { + g_source_remove(this_->button_timeout); + this_->button_timeout=0; + if (! this_->moved && ! transform_within_border(this_->trans, p, border)) + navit_set_center_screen(this_, p); + + } + if (this_->motion_timeout) { + g_source_remove(this_->motion_timeout); + this_->motion_timeout=0; + } + if (this_->moved) { + struct point p; + transform_get_size(this_->trans, &p.x, &p.y); + p.x/=2; + p.y/=2; + p.x-=this_->last.x-this_->pressed.x; + p.y-=this_->last.y-this_->pressed.y; + navit_set_center_screen(this_, &p); + } + } +} + + +static gboolean +navit_motion_timeout(void *data) +{ + struct navit *this_=data; + int dx, dy; + + dx=(this_->current.x-this_->last.x); + dy=(this_->current.y-this_->last.y); + if (dx || dy) { + this_->last=this_->current; + graphics_displaylist_move(this_->displaylist, dx, dy); + graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layouts, this_->route); + this_->moved=1; + } + this_->motion_timeout=0; + return FALSE; +} + +static void +navit_motion(void *data, struct point *p) +{ + struct navit *this_=data; + int dx, dy; + + if (this_->button_pressed) { + dx=(p->x-this_->pressed.x); + dy=(p->y-this_->pressed.y); + if (dx < -4 || dx > 4 || dy < -4 || dy > 4) { + if (this_->button_timeout) { + g_source_remove(this_->button_timeout); + this_->button_timeout=0; + } + this_->current=*p; + if (! this_->motion_timeout) + this_->motion_timeout=g_timeout_add(100, navit_motion_timeout, data); + } } - if (pressed && button == 2) - navit_set_center_screen(this_, p); - if (pressed && button == 3) - popup(this_, button, p); - if (pressed && button == 4) - navit_zoom_in(this_, 2); - if (pressed && button == 5) - navit_zoom_out(this_, 2); } void @@ -238,6 +316,7 @@ navit_set_graphics(struct navit *this_, struct graphics *gra, char *type) this_->gra_type=g_strdup(type); graphics_register_resize_callback(this_->gra, navit_resize, this_); graphics_register_button_callback(this_->gra, navit_button, this_); + graphics_register_motion_callback(this_->gra, navit_motion, this_); } struct graphics * -- 2.7.4