Add:Core:Add the possibility to define cursors in layout
authorseralph <seralph@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 14 Oct 2009 12:05:48 +0000 (12:05 +0000)
committerseralph <seralph@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 14 Oct 2009 12:05:48 +0000 (12:05 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@2667 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/Makefile.am
navit/attr_def.h
navit/cursor.c [deleted file]
navit/cursor.h [deleted file]
navit/layout.c
navit/layout.h
navit/navit.c
navit/vehicle.c
navit/vehicle.h
navit/xmlconfig.c

index abb3dc7..36d2257 100644 (file)
@@ -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 \
index 61ec3ce..85592c1 100644 (file)
@@ -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 (file)
index 9cbec92..0000000
+++ /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, &center, 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 (file)
index e618a00..0000000
+++ /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
index a183fe8..230fa35 100644 (file)
@@ -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)
index 887c764..1b2f1c0 100644 (file)
@@ -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);
index 05af244..1decda7 100644 (file)
@@ -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;
index 1fae775..fe8c282 100644 (file)
@@ -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
 #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, &center, 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_);
-}
index f9d65b3..9edd647 100644 (file)
@@ -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
 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
index 331cb66..cbf8a8c 100644 (file)
@@ -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},