diff options
author | seralph <seralph@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2009-10-14 12:05:48 +0000 |
---|---|---|
committer | seralph <seralph@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2009-10-14 12:05:48 +0000 |
commit | d5310034de132ebbc37e97969266e9732858a8dd (patch) | |
tree | f90804e754f65f2d06cebe78302339123dd3161d /navit | |
parent | 3dee96744c8684f9159bc0037c7861d686db75bd (diff) | |
download | navit-d5310034de132ebbc37e97969266e9732858a8dd.tar.gz |
Add:Core:Add the possibility to define cursors in layout
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@2667 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit')
-rw-r--r-- | navit/Makefile.am | 4 | ||||
-rw-r--r-- | navit/attr_def.h | 3 | ||||
-rw-r--r-- | navit/cursor.c | 198 | ||||
-rw-r--r-- | navit/cursor.h | 30 | ||||
-rw-r--r-- | navit/layout.c | 92 | ||||
-rw-r--r-- | navit/layout.h | 16 | ||||
-rw-r--r-- | navit/navit.c | 41 | ||||
-rw-r--r-- | navit/vehicle.c | 465 | ||||
-rw-r--r-- | navit/vehicle.h | 13 | ||||
-rw-r--r-- | navit/xmlconfig.c | 4 |
10 files changed, 491 insertions, 375 deletions
diff --git a/navit/Makefile.am b/navit/Makefile.am index abb3dc7ad..36d2257fa 100644 --- a/navit/Makefile.am +++ b/navit/Makefile.am @@ -29,12 +29,12 @@ pkgdata_DATA = navit.xml EXTRA_DIST = navit_shipped.xml navit.dtd -libnavit_la_SOURCES = announcement.c atom.c attr.c cache.c callback.c command.c compass.c coord.c country.c cursor.c data_window.c debug.c \ +libnavit_la_SOURCES = announcement.c atom.c attr.c cache.c callback.c command.c compass.c coord.c country.c data_window.c debug.c \ event.c event_glib.h file.c graphics.c gui.c item.c layout.c log.c main.c map.c \ linguistics.c mapset.c maptype.c menu.c messages.c navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \ profile.c projection.c roadprofile.c route.c search.c speech.c start_real.c transform.c track.c \ util.c vehicle.c vehicleprofile.c xmlconfig.c announcement.h atom.h attr.h attr_def.h cache.h callback.h color.h command.h compass.h coord.h country.h \ - cursor.h data.h data_window.h data_window_int.h debug.h destination.h draw_info.h endianess.h event.h \ + data.h data_window.h data_window_int.h debug.h destination.h draw_info.h endianess.h event.h \ file.h graphics.h gtkext.h gui.h item.h item_def.h keys.h log.h layer.h layout.h linguistics.h main.h map-share.h map.h\ map_data.h mapset.h maptype.h menu.h messages.h navigation.h navit.h osd.h \ param.h phrase.h plugin.h point.h plugin_def.h projection.h popup.h route.h profile.h roadprofile.h search.h speech.h start_real.h \ diff --git a/navit/attr_def.h b/navit/attr_def.h index 61ec3ce17..85592c135 100644 --- a/navit/attr_def.h +++ b/navit/attr_def.h @@ -1,6 +1,6 @@ /** * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team + * Copyright (C) 2005-2009 Navit Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License @@ -211,6 +211,7 @@ ATTR(navigation_long) ATTR(navigation_long_exact) ATTR(navigation_speech) ATTR(name) +ATTR(cursorname) ATTR(source) ATTR(description) ATTR(gc_type) diff --git a/navit/cursor.c b/navit/cursor.c deleted file mode 100644 index 9cbec92ab..000000000 --- a/navit/cursor.c +++ /dev/null @@ -1,198 +0,0 @@ -/** - * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <math.h> -#include <glib.h> -#include "debug.h" -#include "coord.h" -#include "transform.h" -#include "projection.h" -#include "point.h" -#include "graphics.h" -#include "vehicle.h" -#include "navit.h" -#include "callback.h" -#include "color.h" -#include "cursor.h" -#include "compass.h" -#include "item.h" -#include "layout.h" -#include "event.h" -/* #include "track.h" */ - - -struct cursor { - int w,h; - struct graphics *gra; - struct callback *animate_callback; - struct event_timeout *animate_timer; - struct point cursor_pnt; - struct graphics_gc *bg; - struct attr **attrs; - struct transformation *trans; - struct range *sequence_range; - int sequence; - int angle; - int speed; -}; - - - -static void -cursor_draw_do(struct cursor *this_, int lazy) -{ - if (!this_->attrs || !this_->gra) - return; - - struct point p; - int speed=this_->speed; - int angle=this_->angle; - int sequence=this_->sequence; - - transform_set_yaw(this_->trans, -this_->angle); - graphics_draw_mode(this_->gra, draw_mode_begin); - p.x=0; - p.y=0; - graphics_draw_rectangle(this_->gra, this_->bg, &p, this_->w, this_->h); - struct attr **attr=this_->attrs; - int match=0; - while (*attr) { - if ((*attr)->type == attr_itemgra) { - struct itemgra *itm=(*attr)->u.itemgra; - dbg(1,"speed %d-%d %d\n", itm->speed_range.min, itm->speed_range.max, speed); - if (speed >= itm->speed_range.min && speed <= itm->speed_range.max && - angle >= itm->angle_range.min && angle <= itm->angle_range.max && - sequence >= itm->sequence_range.min && sequence <= itm->sequence_range.max) { - graphics_draw_itemgra(this_->gra, itm, this_->trans); - } - if (sequence < itm->sequence_range.max) - match=1; - } - ++attr; - } - graphics_draw_drag(this_->gra, &this_->cursor_pnt); - graphics_draw_mode(this_->gra, lazy ? draw_mode_end_lazy : draw_mode_end); - if (this_->animate_callback) { - ++this_->sequence; - if (this_->sequence_range && this_->sequence_range->max < this_->sequence) - this_->sequence=this_->sequence_range->min; - if (! match && ! this_->sequence_range) - this_->sequence=0; - } -} - -void -cursor_draw(struct cursor *this_, struct graphics *gra, struct point *pnt, int lazy, int angle, int speed) -{ - if (angle < 0) - angle+=360; - dbg(1,"enter this=%p gra=%p pnt=%p lazy=%d dir=%d speed=%d\n", this_, gra, pnt, lazy, angle, speed); - dbg(1,"point %d,%d\n", pnt->x, pnt->y); - this_->cursor_pnt=*pnt; - this_->cursor_pnt.x-=this_->w/2; - this_->cursor_pnt.y-=this_->h/2; - this_->angle=angle; - this_->speed=speed; - if (!this_->gra) { - struct color c; - this_->gra=graphics_overlay_new(gra, &this_->cursor_pnt, this_->w, this_->h, 65535, 0); - if (this_->gra) { - this_->bg=graphics_gc_new(this_->gra); - c.r=0; c.g=0; c.b=0; c.a=0; - graphics_gc_set_foreground(this_->bg, &c); - graphics_background_gc(this_->gra, this_->bg); - } - } - cursor_draw_do(this_, lazy); -} - -int -cursor_add_attr(struct cursor *this_, struct attr *attr) -{ - int ret=1; - switch (attr->type) { - case attr_itemgra: - break; - default: - ret=0; - } - if (ret) - this_->attrs=attr_generic_add_attr(this_->attrs, attr); - return ret; -} - -struct cursor * -cursor_new(struct attr *parent, struct attr **attrs) -{ - struct cursor *this=g_new0(struct cursor,1); - struct attr *w,*h, *interval, *sequence_range; - struct pcoord center; - struct point scenter; - w=attr_search(attrs, NULL, attr_w); - h=attr_search(attrs, NULL, attr_h); - if (! w || ! h) - return NULL; - - this->w=w->u.num; - this->h=h->u.num; - this->trans=transform_new(); - center.pro=projection_screen; - center.x=0; - center.y=0; - transform_setup(this->trans, ¢er, 16, 0); - scenter.x=this->w/2; - scenter.y=this->h/2; - transform_set_screen_center(this->trans, &scenter); - interval=attr_search(attrs, NULL, attr_interval); - if (interval) { - this->animate_callback=callback_new_2(callback_cast(cursor_draw_do), this, 0); - this->animate_timer=event_add_timeout(interval->u.num, 1, this->animate_callback); - } - sequence_range=attr_search(attrs, NULL, attr_sequence_range); - if (sequence_range) { - struct range *r=g_new0(struct range,1); - r->min=sequence_range->u.range.min; - r->max=sequence_range->u.range.max; - this->sequence_range=r; - this->sequence=r->min; - } - else { - this->sequence_range=NULL; - } - dbg(2,"ret=%p\n", this); - return this; -} - -void -cursor_destroy(struct cursor *this_) -{ - if (this_->sequence_range) - g_free(this_->sequence_range); - if (this_->animate_callback) { - callback_destroy(this_->animate_callback); - event_remove_timeout(this_->animate_timer); - } - transform_destroy(this_->trans); - g_free(this_); -} diff --git a/navit/cursor.h b/navit/cursor.h deleted file mode 100644 index e618a003c..000000000 --- a/navit/cursor.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License - * version 2 as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef NAVIT_CURSOR_H -#define NAVIT_CURSOR_H - -/* prototypes */ -void cursor_draw(struct cursor *this_, struct graphics *gra, struct point *pnt, int lazy, int dir, int speed); -int cursor_add_attr(struct cursor *this_, struct attr *attr); -struct cursor *cursor_new(struct attr *parent, struct attr **attrs); -void cursor_destroy(struct cursor *this_); -/* end of prototypes */ - -#endif diff --git a/navit/layout.c b/navit/layout.c index a183fe8f4..230fa354a 100644 --- a/navit/layout.c +++ b/navit/layout.c @@ -1,6 +1,6 @@ /** * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team + * Copyright (C) 2005-2009 Navit Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -25,6 +25,7 @@ #include "coord.h" #include "debug.h" + struct layout * layout_new(struct attr *parent, struct attr **attrs) { struct layout *l; @@ -51,6 +52,9 @@ int layout_add_attr(struct layout *layout, struct attr *attr) { switch (attr->type) { + case attr_cursor: + layout->cursors = g_list_append(layout->cursors, attr->u.cursor); + return 1; case attr_layer: layout->layers = g_list_append(layout->layers, attr->u.layer); return 1; @@ -59,6 +63,92 @@ layout_add_attr(struct layout *layout, struct attr *attr) } } +/** + * Searchs the layout for a cursor with the given name. + * + * @param layout The layout + * @param name The name + * @returns A pointer to cursor with the given name or the name default or NULL. + * @author Ralph Sennhauser (10/2009) +*/ +struct cursor * +layout_get_cursor(struct layout *this_, char *name) +{ + GList *c; + struct cursor *d=NULL; + + c=g_list_first(this_->cursors); + while (c) { + if (! strcmp(((struct cursor *)c->data)->name, name)) + return c->data; + if (! strcmp(((struct cursor *)c->data)->name, "default")) + d=c->data; + c=g_list_next(c); + } + return d; +} + + + +struct cursor * +cursor_new(struct attr *parent, struct attr **attrs) +{ + struct attr *w, *h, *name, *interval, *sequence_range; + + w=attr_search(attrs, NULL, attr_w); + h=attr_search(attrs, NULL, attr_h); + if (! w || ! h) + return NULL; + + struct cursor *this=g_new0(struct cursor,1); + this->w=w->u.num; + this->h=h->u.num; + name=attr_search(attrs, NULL, attr_name); + if (name) + this->name=g_strdup(name->u.str); + else + this->name=g_strdup("default"); + interval=attr_search(attrs, NULL, attr_interval); + if (interval) + this->interval=interval->u.num; + sequence_range=attr_search(attrs, NULL, attr_sequence_range); + if (sequence_range) { + struct range *r=g_new0(struct range,1); + r->min=sequence_range->u.range.min; + r->max=sequence_range->u.range.max; + this->sequence_range=r; + } + else { + this->sequence_range=NULL; + } + dbg(2,"ret=%p\n", this); + return this; +} + +void +cursor_destroy(struct cursor *this_) +{ + if (this_->sequence_range) + g_free(this_->sequence_range); + if (this_->name) { + g_free(this_->name); + } + g_free(this_); +} + +int +cursor_add_attr(struct cursor *this_, struct attr *attr) +{ + switch (attr->type) { + case attr_itemgra: + this_->attrs=attr_generic_add_attr(this_->attrs, attr); + return 1; + default: + break; + } + return 0; +} + struct layer * layer_new(struct attr *parent, struct attr **attrs) diff --git a/navit/layout.h b/navit/layout.h index 887c7649b..1b2f1c09d 100644 --- a/navit/layout.h +++ b/navit/layout.h @@ -1,6 +1,6 @@ /** * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team + * Copyright (C) 2005-2009 Navit Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License @@ -63,11 +63,23 @@ struct itemgra { struct layer { char *name; int details; GList *itemgras; }; -struct layout { char *name; char *font; struct color color; GList *layers; int order_delta; }; +struct cursor { + struct attr **attrs; + struct range *sequence_range; + char *name; + int w,h; + int interval; +}; + +struct layout { char *name; char *font; struct color color; GList *layers; GList *cursors; int order_delta; }; /* prototypes */ struct layout *layout_new(struct attr *parent, struct attr **attrs); int layout_add_attr(struct layout *layout, struct attr *attr); +struct cursor *layout_get_cursor(struct layout *this_, char *name); +struct cursor *cursor_new(struct attr *parent, struct attr **attrs); +void cursor_destroy(struct cursor *this_); +int cursor_add_attr(struct cursor *this_, struct attr *attr); struct layer *layer_new(struct attr *parent, struct attr **attrs); int layer_add_attr(struct layer *layer, struct attr *attr); struct itemgra *itemgra_new(struct attr *parent, struct attr **attrs); diff --git a/navit/navit.c b/navit/navit.c index 05af24487..1decda785 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -1,6 +1,6 @@ /** * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team + * Copyright (C) 2005-2009 Navit Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -42,7 +42,6 @@ #include "param.h" #include "menu.h" #include "graphics.h" -#include "cursor.h" #include "popup.h" #include "data_window.h" #include "route.h" @@ -151,6 +150,7 @@ static void navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, st static int navit_add_vehicle(struct navit *this_, struct vehicle *v); static int navit_set_attr_do(struct navit *this_, struct attr *attr, int init); static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int *dir); +static void navit_set_cursors(struct navit *this_); static void navit_cmd_zoom_to_route(struct navit *this); static void navit_cmd_set_center_cursor(struct navit *this_); static void navit_cmd_announcer_toggle(struct navit *this_); @@ -1370,6 +1370,8 @@ navit_init(struct navit *this_) messagelist_init(this_->messages); + navit_set_cursors(this_); + dbg(2,"ready=%d\n",this_->ready); if (this_->ready == 3) navit_draw(this_); @@ -1481,6 +1483,33 @@ navit_set_center_coord_screen(struct navit *this_, struct coord *c, struct point navit_set_timeout(this_); } +/** + * Links all vehicles to a cursor depending on the current profile. + * + * @param this_ A navit instance + * @author Ralph Sennhauser (10/2009) + */ +static void +navit_set_cursors(struct navit *this_) +{ + struct attr name; + struct navit_vehicle *nv; + struct cursor *c; + GList *v; + + v=g_list_first(this_->vehicles); // GList of navit_vehicles + while (v) { + nv=v->data; + if (vehicle_get_attr(nv->vehicle, attr_cursorname, &name, NULL)) + c=layout_get_cursor(this_->layout_current, name.u.str); + else + c=layout_get_cursor(this_->layout_current, "default"); + vehicle_set_cursor(nv->vehicle, c); + v=g_list_next(v); + } + return; +} + static int navit_get_cursor_pnt(struct navit *this_, struct point *p, int *dir) { @@ -1605,6 +1634,7 @@ navit_set_attr_do(struct navit *this_, struct attr *attr, int init) if(this_->layout_current!=attr->u.layout) { this_->layout_current=attr->u.layout; graphics_font_destroy_all(this_->gra); + navit_set_cursors(this_); navit_draw(this_); attr_updated=1; } @@ -1992,21 +2022,16 @@ navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point * { struct point cursor_pnt; enum projection pro; - struct attr cursor; if (this_->blocked) return; - if (! vehicle_get_attr(nv->vehicle, attr_cursor, &cursor, NULL)) - return; - if (! cursor.u.cursor) - return; if (pnt) cursor_pnt=*pnt; else { pro=transform_get_projection(this_->trans); transform(this_->trans, pro, &nv->coord, &cursor_pnt, 1, 0, 0, NULL); } - cursor_draw(cursor.u.cursor, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans), nv->speed); + vehicle_draw(nv->vehicle, this_->gra, &cursor_pnt, pnt ? 0:1, nv->dir-transform_get_yaw(this_->trans), nv->speed); #if 0 if (pnt) pnt2=*pnt; diff --git a/navit/vehicle.c b/navit/vehicle.c index 1fae77579..fe8c282db 100644 --- a/navit/vehicle.c +++ b/navit/vehicle.c @@ -1,6 +1,6 @@ /** * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team + * Copyright (C) 2005-2009 Navit Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -26,20 +26,355 @@ #include "coord.h" #include "item.h" #include "log.h" -#include "callback.h" #include "plugin.h" -#include "vehicle.h" #include "transform.h" #include "util.h" +#include "event.h" +#include "coord.h" +#include "transform.h" +#include "projection.h" +#include "point.h" +#include "graphics.h" +#include "callback.h" +#include "color.h" +#include "layout.h" +#include "vehicle.h" struct vehicle { - struct vehicle_priv *priv; struct vehicle_methods meth; + struct vehicle_priv *priv; struct callback_list *cbl; struct log *nmea_log, *gpx_log; struct attr **attrs; + + // cursor + struct cursor *cursor; + struct callback *animate_callback; + struct event_timeout *animate_timer; + struct point cursor_pnt; + struct graphics *gra; + struct graphics_gc *bg; + struct transformation *trans; + int angle; + int speed; + int sequence; }; +static void vehicle_draw_do(struct vehicle *this_, int lazy); +static void vehicle_log_nmea(struct vehicle *this_, struct log *log); +static void vehicle_log_gpx(struct vehicle *this_, struct log *log); +static void vehicle_log_textfile(struct vehicle *this_, struct log *log); +static void vehicle_log_binfile(struct vehicle *this_, struct log *log); +static int vehicle_add_log(struct vehicle *this_, struct log *log); + + + +/** + * Creates a new vehicle + */ +struct vehicle * +vehicle_new(struct attr *parent, struct attr **attrs) +{ + struct vehicle *this_; + struct attr *source; + struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods * + meth, + struct callback_list * + cbl, + struct attr ** attrs); + char *type, *colon; + struct pcoord center; + + dbg(1, "enter\n"); + source = attr_search(attrs, NULL, attr_source); + if (!source) { + dbg(0, "no source\n"); + return NULL; + } + + type = g_strdup(source->u.str); + colon = strchr(type, ':'); + if (colon) + *colon = '\0'; + dbg(1, "source='%s' type='%s'\n", source->u.str, type); + + vehicletype_new = plugin_get_vehicle_type(type); + if (!vehicletype_new) { + dbg(0, "invalid type '%s'\n", type); + return NULL; + } + this_ = g_new0(struct vehicle, 1); + this_->cbl = callback_list_new(); + this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs); + if (!this_->priv) { + dbg(0, "vehicletype_new failed\n"); + callback_list_destroy(this_->cbl); + g_free(this_); + return NULL; + } + this_->attrs=attr_list_dup(attrs); + + this_->trans=transform_new(); + center.pro=projection_screen; + center.x=0; + center.y=0; + transform_setup(this_->trans, ¢er, 16, 0); + + dbg(1, "leave\n"); + return this_; +} + +/** + * Destroys a vehicle + * + * @param this_ The vehicle to destroy + */ +void +vehicle_destroy(struct vehicle *this_) +{ + if (this_->animate_callback) { + callback_destroy(this_->animate_callback); + event_remove_timeout(this_->animate_timer); + } + transform_destroy(this_->trans); + this_->meth.destroy(this_->priv); + callback_list_destroy(this_->cbl); + attr_list_free(this_->attrs); + g_free(this_); +} + +/** + * Creates an attribute iterator to be used with vehicles + */ +struct attr_iter * +vehicle_attr_iter_new(void) +{ + return (struct attr_iter *)g_new0(void *,1); +} + +/** + * Destroys a vehicle attribute iterator + * + * @param iter a vehicle attr_iter + */ +void +vehicle_attr_iter_destroy(struct attr_iter *iter) +{ + g_free(iter); +} + + + +/** + * Generic get function + * + * @param this_ A vehicle + * @param type The attribute type to look for + * @param attr A struct attr to store the attribute + * @param iter A vehicle attr_iter + */ +int +vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) +{ + int ret; + if (this_->meth.position_attr_get) { + ret=this_->meth.position_attr_get(this_->priv, type, attr); + if (ret) + return ret; + } + return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter); +} + +/** + * Generic set function + * + * @param this_ A vehicle + * @param attr + * @param attrs + */ +int +vehicle_set_attr(struct vehicle *this_, struct attr *attr, + struct attr **attrs) +{ + int ret=1; + if (this_->meth.set_attr) + ret=this_->meth.set_attr(this_->priv, attr, attrs); + if (ret == 1 && attr->type != attr_navit) + this_->attrs=attr_generic_set_attr(this_->attrs, attr); + return ret != 0; +} + +/** + * Generic add function + * + * @param this_ A vehicle + * @param attr A struct attr + */ +int +vehicle_add_attr(struct vehicle *this_, struct attr *attr) +{ + int ret=1; + switch (attr->type) { + case attr_callback: + callback_list_add(this_->cbl, attr->u.callback); + break; + case attr_log: + ret=vehicle_add_log(this_, attr->u.log); + break; + // currently supporting oldstyle cursor config. + case attr_cursor: + vehicle_set_cursor(this_, attr->u.cursor); + break; + default: + break; + } + if (ret) + this_->attrs=attr_generic_add_attr(this_->attrs, attr); + return ret; +} + +/** + * @brief Generic remove function. + * + * Used to remove a callback from the vehicle. + * @param this_ A vehicle + * @param attr + */ +int +vehicle_remove_attr(struct vehicle *this_, struct attr *attr) +{ + switch (attr->type) { + case attr_callback: + callback_list_remove(this_->cbl, attr->u.callback); + break; + default: + return 0; + } + return 1; +} + + + +/** + * Sets the cursor of a vehicle. + * + * @param this_ A vehicle + * @param cursor A cursor + * @author Ralph Sennhauser (10/2009) + */ +void +vehicle_set_cursor(struct vehicle *this_, struct cursor *cursor) +{ + if (!cursor) { // we require this for now. + return; + } + + if (this_->animate_callback) { + event_remove_timeout(this_->animate_timer); + this_->animate_timer=NULL; // dangling pointer! prevent double freeing. + callback_destroy(this_->animate_callback); + this_->animate_callback=NULL; // dangling pointer! prevent double freeing. + } + if (cursor->interval) { + this_->animate_callback=callback_new_2(callback_cast(vehicle_draw_do), this_, 0); + this_->animate_timer=event_add_timeout(cursor->interval, 1, this_->animate_callback); + } + + if (this_->gra) { + this_->cursor_pnt.x+=(this_->cursor->w - cursor->w)/2; + this_->cursor_pnt.y+=(this_->cursor->h - cursor->h)/2; + graphics_overlay_resize(this_->gra, &this_->cursor_pnt, cursor->w, cursor->h, 65535, 0); + } + + struct point sc; + sc.x=cursor->w/2; + sc.y=cursor->h/2; + transform_set_screen_center(this_->trans, &sc); + + this_->cursor=cursor; +} + +/** + * Draws a vehicle on top of a graphics. + * + * @param this_ The vehicle + * @param gra The graphics + * @param pnt Screen coordinates of the vehicle. + * @param lazy use lazy draw mode. + * @param angle The angle relative to the map. + * @param speed The speed of the vehicle. + */ +void +vehicle_draw(struct vehicle *this_, struct graphics *gra, struct point *pnt, int lazy, int angle, int speed) +{ + if (angle < 0) + angle+=360; + dbg(1,"enter this=%p gra=%p pnt=%p lazy=%d dir=%d speed=%d\n", this_, gra, pnt, lazy, angle, speed); + dbg(1,"point %d,%d\n", pnt->x, pnt->y); + this_->cursor_pnt=*pnt; + this_->cursor_pnt.x-=this_->cursor->w/2; + this_->cursor_pnt.y-=this_->cursor->h/2; + this_->angle=angle; + this_->speed=speed; + if (!this_->gra) { + struct color c; + this_->gra=graphics_overlay_new(gra, &this_->cursor_pnt, this_->cursor->w, this_->cursor->h, 65535, 0); + if (this_->gra) { + this_->bg=graphics_gc_new(this_->gra); + c.r=0; c.g=0; c.b=0; c.a=0; + graphics_gc_set_foreground(this_->bg, &c); + graphics_background_gc(this_->gra, this_->bg); + } + } + vehicle_draw_do(this_, lazy); +} + + + +static void +vehicle_draw_do(struct vehicle *this_, int lazy) +{ + if (!this_->cursor || !this_->cursor->attrs || !this_->gra) + return; + + struct point p; + struct cursor *cursor=this_->cursor; + int speed=this_->speed; + int angle=this_->angle; + int sequence=this_->sequence; + + transform_set_yaw(this_->trans, -this_->angle); + graphics_draw_mode(this_->gra, draw_mode_begin); + p.x=0; + p.y=0; + graphics_draw_rectangle(this_->gra, this_->bg, &p, cursor->w, cursor->h); + struct attr **attr=cursor->attrs; + int match=0; + while (*attr) { + if ((*attr)->type == attr_itemgra) { + struct itemgra *itm=(*attr)->u.itemgra; + dbg(1,"speed %d-%d %d\n", itm->speed_range.min, itm->speed_range.max, speed); + if (speed >= itm->speed_range.min && speed <= itm->speed_range.max && + angle >= itm->angle_range.min && angle <= itm->angle_range.max && + sequence >= itm->sequence_range.min && sequence <= itm->sequence_range.max) { + graphics_draw_itemgra(this_->gra, itm, this_->trans); + } + if (sequence < itm->sequence_range.max) + match=1; + } + ++attr; + } + graphics_draw_drag(this_->gra, &this_->cursor_pnt); + graphics_draw_mode(this_->gra, lazy ? draw_mode_end_lazy : draw_mode_end); + if (this_->animate_callback) { + ++this_->sequence; + if (cursor->sequence_range && cursor->sequence_range->max < this_->sequence) + this_->sequence=cursor->sequence_range->min; + if (! match && ! cursor->sequence_range) + this_->sequence=0; + } +} + static void vehicle_log_nmea(struct vehicle *this_, struct log *log) { @@ -197,125 +532,3 @@ vehicle_add_log(struct vehicle *this_, struct log *log) return 0; } -struct vehicle * -vehicle_new(struct attr *parent, struct attr **attrs) -{ - struct vehicle *this_; - struct attr *source; - struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods * - meth, - struct callback_list * - cbl, - struct attr ** attrs); - char *type, *colon; - - dbg(1, "enter\n"); - source = attr_search(attrs, NULL, attr_source); - if (!source) { - dbg(0, "no source\n"); - return NULL; - } - - type = g_strdup(source->u.str); - colon = strchr(type, ':'); - if (colon) - *colon = '\0'; - dbg(1, "source='%s' type='%s'\n", source->u.str, type); - - vehicletype_new = plugin_get_vehicle_type(type); - if (!vehicletype_new) { - dbg(0, "invalid type '%s'\n", type); - return NULL; - } - this_ = g_new0(struct vehicle, 1); - this_->cbl = callback_list_new(); - this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs); - if (!this_->priv) { - dbg(0, "vehicletype_new failed\n"); - callback_list_destroy(this_->cbl); - g_free(this_); - return NULL; - } - this_->attrs=attr_list_dup(attrs); - dbg(1, "leave\n"); - - return this_; -} - -struct attr_iter * -vehicle_attr_iter_new(void) -{ - return (struct attr_iter *)g_new0(void *,1); -} - -void -vehicle_attr_iter_destroy(struct attr_iter *iter) -{ - g_free(iter); -} - - -int -vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter) -{ - int ret; - if (this_->meth.position_attr_get) { - ret=this_->meth.position_attr_get(this_->priv, type, attr); - if (ret) - return ret; - } - return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter); -} - -int -vehicle_set_attr(struct vehicle *this_, struct attr *attr, - struct attr **attrs) -{ - int ret=1; - if (this_->meth.set_attr) - ret=this_->meth.set_attr(this_->priv, attr, attrs); - if (ret == 1 && attr->type != attr_navit) - this_->attrs=attr_generic_set_attr(this_->attrs, attr); - return ret != 0; -} - -int -vehicle_add_attr(struct vehicle *this_, struct attr *attr) -{ - int ret=1; - switch (attr->type) { - case attr_callback: - callback_list_add(this_->cbl, attr->u.callback); - break; - case attr_log: - ret=vehicle_add_log(this_, attr->u.log); - break; - default: - break; - } - if (ret) - this_->attrs=attr_generic_add_attr(this_->attrs, attr); - return ret; -} - -int -vehicle_remove_attr(struct vehicle *this_, struct attr *attr) -{ - switch (attr->type) { - case attr_callback: - callback_list_remove(this_->cbl, attr->u.callback); - break; - default: - return 0; - } - return 1; -} - -void -vehicle_destroy(struct vehicle *this_) -{ - this_->meth.destroy(this_->priv); - callback_list_destroy(this_->cbl); - attr_list_free(this_->attrs); - g_free(this_); -} diff --git a/navit/vehicle.h b/navit/vehicle.h index f9d65b3d5..9edd647cc 100644 --- a/navit/vehicle.h +++ b/navit/vehicle.h @@ -1,6 +1,6 @@ /** * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team + * Copyright (C) 2005-2009 Navit Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public License @@ -24,25 +24,28 @@ extern "C" { #endif +struct point; struct vehicle_priv; struct vehicle_methods { void (*destroy)(struct vehicle_priv *priv); int (*position_attr_get)(struct vehicle_priv *priv, enum attr_type type, struct attr *attr); int (*set_attr)(struct vehicle_priv *priv, struct attr *attr, struct attr **attrs); - }; - /* prototypes */ struct vehicle *vehicle_new(struct attr *parent, struct attr **attrs); +void vehicle_destroy(struct vehicle *this_); struct attr_iter *vehicle_attr_iter_new(void); +void vehicle_attr_iter_destroy(struct attr_iter *iter); + int vehicle_get_attr(struct vehicle *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter); int vehicle_set_attr(struct vehicle *this_, struct attr *attr, struct attr **attrs); int vehicle_add_attr(struct vehicle *this_, struct attr *attr); int vehicle_remove_attr(struct vehicle *this_, struct attr *attr); -void vehicle_destroy(struct vehicle *this_); -void vehicle_attr_iter_destroy(struct attr_iter *iter); + +void vehicle_set_cursor(struct vehicle *this_, struct cursor *cursor); +void vehicle_draw(struct vehicle *this_, struct graphics *gra, struct point *pnt, int lazy, int angle, int speed); /* end of prototypes */ #ifdef __cplusplus diff --git a/navit/xmlconfig.c b/navit/xmlconfig.c index 331cb6684..cbf8a8c42 100644 --- a/navit/xmlconfig.c +++ b/navit/xmlconfig.c @@ -1,6 +1,6 @@ /** * Navit, a modular navigation system. - * Copyright (C) 2005-2008 Navit Team + * Copyright (C) 2005-2009 Navit Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -44,7 +44,6 @@ #include "gui.h" #include "osd.h" #include "log.h" -#include "cursor.h" #include "announcement.h" #include "vehicleprofile.h" #include "roadprofile.h" @@ -303,6 +302,7 @@ struct element_func { { "graphics", "navit", NULL, attr_graphics}, { "gui", "navit", NULL, attr_gui}, { "layout", "navit", NULL, attr_layout}, + { "cursor", "layout", NULL, attr_cursor}, { "layer", "layout", NULL, attr_layer}, { "itemgra", "layer", NULL, attr_itemgra}, { "circle", "itemgra", NULL, attr_circle}, |