Fix:Core:Fixed osd plugin
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 27 Feb 2008 18:04:01 +0000 (18:04 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Wed, 27 Feb 2008 18:04:01 +0000 (18:04 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@917 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/src/attr.h
navit/src/attr_def.h
navit/src/callback.h
navit/src/graphics.c
navit/src/graphics.h
navit/src/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c
navit/src/navit.c
navit/src/osd/core/osd_core.c
navit/src/xpm/flag_wh_bk.xpm [new file with mode: 0644]

index d370dcb..55f1bbf 100644 (file)
@@ -39,6 +39,8 @@ struct attr {
                struct log *log;
                struct route *route;
                struct navigation *navigation;
+               struct coord *coord;
+               struct pcoord *pcoord;
        } u;
 };
 
index e96815f..017c925 100644 (file)
@@ -112,3 +112,8 @@ ATTR(callback)
 ATTR(route)
 ATTR(navigation)
 ATTR2(0x0008ffff,type_object_end)
+ATTR2(0x00090000,type_coord_begin)
+ATTR2(0x0009ffff,type_coord_end)
+ATTR2(0x000a0000,type_pcoord_begin)
+ATTR(destination)
+ATTR2(0x000affff,type_pcoord_end)
index 102f8e1..ebdaf04 100644 (file)
@@ -49,6 +49,14 @@ static inline struct callback *callback_new_1(void (*func)(void), void *p1)
        return callback_new(func, 1, p);
 }
 
+static inline struct callback *callback_new_attr_2(void (*func)(void), enum attr_type type, void *p1, void *p2)
+{
+       void *p[2];
+       p[0]=p1;
+       p[1]=p2;
+       return callback_new_attr(func, type, 2, p);
+}
+
 static inline struct callback *callback_new_2(void (*func)(void), void *p1, void *p2)
 {
        void *p[2];
index aeb474e..9d5926b 100644 (file)
@@ -191,6 +191,17 @@ graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct p
        this_->meth.draw_rectangle(this_->priv, gc->priv, p, w, h);
 }
 
+void
+graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct graphics_gc *gc2, struct graphics_font *font, char *text, struct point *p, int dx, int dy)
+{
+       this_->meth.draw_text(this_->priv, gc1->priv, gc2 ? gc2->priv : NULL, font->priv, text, p, dx, dy);
+}
+
+void
+graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img)
+{
+       this_->meth.draw_image(this_->priv, gc->priv, p, img->priv);
+}
 
 #include "attr.h"
 #include "popup.h"
@@ -413,7 +424,7 @@ xdisplay_draw_elements(struct graphics *gra, GHashTable *display_list, struct it
                                        if (gra->meth.draw_image_warp)
                                                gra->meth.draw_image_warp(gra->priv, gra->gc[0]->priv, di->pnt, di->count, di->label);
                                        else
-                                               dbg(0,"draw_image_warp not supported by graphics driver drawing '%s'\ņ", di->label);
+                                               dbg(0,"draw_image_warp not supported by graphics driver drawing '%s'\n", di->label);
                                        break;
                                default:
                                        printf("Unhandled element type %d\n", e->type);
index 1c975c9..9c33855 100644 (file)
@@ -96,8 +96,9 @@ struct graphics_font;
 struct graphics_gc;
 struct graphics_image;
 struct item;
-struct point;
 struct layout;
+struct point;
+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);
 void graphics_init(struct graphics *this_);
@@ -118,6 +119,8 @@ void graphics_draw_mode(struct graphics *this_, enum draw_mode_num mode);
 void graphics_draw_lines(struct graphics *this_, struct graphics_gc *gc, struct point *p, int count);
 void graphics_draw_circle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int r);
 void graphics_draw_rectangle(struct graphics *this_, struct graphics_gc *gc, struct point *p, int w, int h);
+void graphics_draw_text(struct graphics *this_, struct graphics_gc *gc1, struct graphics_gc *gc2, struct graphics_font *font, char *text, struct point *p, int dx, int dy);
+void graphics_draw_image(struct graphics *this_, struct graphics_gc *gc, struct point *p, struct graphics_image *img);
 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, struct layout *l);
index f4b987f..8ffc1c4 100644 (file)
@@ -577,17 +577,23 @@ overlay_draw(struct graphics_priv *parent, struct graphics_priv *overlay, int wi
                        p2[3]=127;
                }
        }
+       x=overlay->p.x;
+       if (x < 0)
+               x+=parent->width;
+       y=overlay->p.y;
+       if (y < 0)
+               y+=parent->height;
        if (window) {
                if (overlay->background_ready)
-                       gdk_draw_drawable(parent->drawable, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], overlay->background, 0, 0, overlay->p.x, overlay->p.y, overlay->width, overlay->height);
+                       gdk_draw_drawable(parent->drawable, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], overlay->background, 0, 0, x, y, overlay->width, overlay->height);
        }
        else {
-               gdk_draw_drawable(overlay->background, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], parent->drawable, overlay->p.x, overlay->p.y, 0, 0, overlay->width, overlay->height);
+               gdk_draw_drawable(overlay->background, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], parent->drawable, x, y, 0, 0, overlay->width, overlay->height);
                overlay->background_ready=1;
        }
-       gdk_draw_pixbuf(parent->drawable, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], pixbuf2, 0, 0, overlay->p.x, overlay->p.y, overlay->width, overlay->height, GDK_RGB_DITHER_NONE, 0, 0);
+       gdk_draw_pixbuf(parent->drawable, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], pixbuf2, 0, 0, x, y, overlay->width, overlay->height, GDK_RGB_DITHER_NONE, 0, 0);
        if (window)
-               gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], parent->drawable, overlay->p.x, overlay->p.y, overlay->p.x, overlay->p.y, overlay->width, overlay->height);
+               gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], parent->drawable, x, y, x, y, overlay->width, overlay->height);
 #if 0
        gdk_draw_drawable(gr->gra->drawable,
                         gr->gra->widget->style->fg_gc[GTK_WIDGET_STATE(gr->gra->widget)],
index 2c8ee22..8245e3c 100644 (file)
@@ -97,6 +97,8 @@ struct navit {
        int button_pressed,moved,popped;
        guint button_timeout, motion_timeout;
        struct log *textfile_debug_log;
+       struct pcoord destination;
+       int destination_valid;
 };
 
 struct gui *main_loop_gui;
@@ -583,7 +585,13 @@ navit_set_destination_from_bookmark(struct navit *this_, void *offset_p)
 void
 navit_set_destination(struct navit *this_, struct pcoord *c, char *description)
 {
+       if (c) {
+               this_->destination=*c;
+               this_->destination_valid=1;
+       } else
+               this_->destination_valid=0;
        navit_append_coord(this_, "destination.txt", c, "former_destination", description, this_->destinations, NULL, callback_cast(navit_set_destination_from_destination));
+       callback_list_call_attr_1(this_->attr_cbl, attr_destination, this_);
        if (this_->route) {
                route_set_destination(this_->route, c);
                if (this_->navigation)
@@ -689,8 +697,11 @@ navit_add_menu_destinations_from_file(struct navit *this_, char *file, struct me
                        offset=ftell(f);
                }
                fclose(f);
-               if (route && flag)
+               if (route && flag) {
+                       this_->destination=c;
+                       this_->destination_valid=1;
                        route_set_destination(route, &c);
+               }
        }
 }
 
@@ -1278,6 +1289,11 @@ navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr)
        case attr_layout:
                attr->u.str=g_strdup(this_->layout_current->name);
                break;
+       case attr_destination:
+               if (! this_->destination_valid)
+                       return 0;
+               attr->u.pcoord=&this_->destination;
+               break;
        default:
                return 0;
        }
index 02324e9..1590fc3 100644 (file)
@@ -1,6 +1,7 @@
 #include <math.h>
 #include <stdio.h>
 #include <glib.h>
+#include <string.h>
 #include "config.h"
 #include "item.h"
 #include "point.h"
@@ -66,14 +67,27 @@ handle(struct graphics *gr, struct graphics_gc *gc, struct point *p, int r, int
 }
 
 static void
-osd_compass_draw(struct compass *this, struct vehicle *v)
+format_distance(char *buffer, double distance)
+{
+       if (distance >= 100000)
+               sprintf(buffer,"%.0f km", distance/1000);
+       else if (distance >= 10000)
+               sprintf(buffer,"%.1f km", distance/1000);
+       else
+               sprintf(buffer,"%.2f km", distance/1000);
+}
+
+static void
+osd_compass_draw(struct compass *this, struct navit *nav, struct vehicle *v)
 {
        struct point p;
-       struct coord *pos, *dest;
-       double *vehicle_dir,dir,distance;
-       int dx,dy;
+       struct attr attr_dir, destination_attr, position_attr;
+       double dir;
        char buffer[16];
+       struct coord c1, c2;
+       enum projection pro;
 
+       dbg(0,"enter 0x%x 0x%x 0x%x\n", this, nav, v);
        graphics_draw_mode(this->gr, draw_mode_begin);
        p.x=0;
        p.y=0;
@@ -81,35 +95,21 @@ osd_compass_draw(struct compass *this, struct vehicle *v)
        p.x=30;
        p.y=30;
        graphics_draw_circle(this->gr, this->white, &p, 50);
-       if (v) {
-               vehicle_dir=vehicle_dir_get(v);
-               handle(this->gr, this->white, &p, 20, -*vehicle_dir);
-#if 0 /* FIXME */
-       dest=route_get_destination(co->route);
-       if (dest) {
-               pos=vehicle_pos_get(co->vehicle);       
-               dx=dest->x-pos->x;
-               dy=dest->y-pos->y;
-               dir=atan2(dx,dy)*180.0/M_PI;
-#if 0
-               printf("dx %d dy %d dir=%f vehicle_dir=%f\n", dx, dy, dir, *vehicle_dir);
-#endif
-               if (! co->flags->orient_north)
-                       dir-=*vehicle_dir;
-               handle(comp->gr, comp->green, &p, 20, dir);
+       if (v && vehicle_position_attr_get(v, attr_position_direction, &attr_dir)) {
+               handle(this->gr, this->white, &p, 20, -*attr_dir.u.numd);
+       }
+       dbg(0,"calling navit_get_attr\n");
+       if (navit_get_attr(nav, attr_destination, &destination_attr) && v && vehicle_position_attr_get(v, attr_position_coord_geo, &position_attr)) {
+               pro=destination_attr.u.pcoord->pro;
+               transform_from_geo(pro, position_attr.u.coord_geo, &c1);
+               c2.x=destination_attr.u.pcoord->x;
+               c2.y=destination_attr.u.pcoord->y;
+               dir=atan2(c2.x-c1.x,c2.y-c1.y)*180.0/M_PI;
+               handle(this->gr, this->green, &p, 20, dir);
+               format_distance(buffer, transform_distance(pro, &c1, &c2));
                p.x=8;
                p.y=72;
-               distance=transform_distance(pos, dest)/1000.0;
-               if (distance >= 100)
-                       sprintf(buffer,"%.0f km", distance);
-               else if (distance >= 10)
-                       sprintf(buffer,"%.1f km", distance);
-               else
-                       sprintf(buffer,"%.2f km", distance);
-
-               comp->gr->draw_text(comp->gr, comp->green, NULL, comp->font, buffer, &p, 0x10000, 0);
-       }
-#endif
+               graphics_draw_text(this->gr, this->green, NULL, this->font, buffer, &p, 0x10000, 0);
        }
        graphics_draw_mode(this->gr, draw_mode_end);
 }
@@ -117,7 +117,6 @@ osd_compass_draw(struct compass *this, struct vehicle *v)
 static void
 osd_compass_init(struct compass *this, struct navit *nav)
 {
-       struct point p;
        struct graphics *navit_gr;
        struct color c;
        navit_gr=navit_get_graphics(nav);
@@ -137,7 +136,10 @@ osd_compass_init(struct compass *this, struct navit *nav)
        graphics_gc_set_foreground(this->green, &c);
        graphics_gc_set_linewidth(this->green, 2);
 
-       osd_compass_draw(this, NULL);
+       this->font=graphics_font_new(this->gr, 200);
+       navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_draw), attr_position_coord_geo, this));
+
+       osd_compass_draw(this, nav, NULL);
 }
 
 static struct osd_priv *
@@ -153,7 +155,7 @@ osd_compass_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs
        attr=attr_search(attrs, NULL, attr_y);
        if (attr)
                this->p.y=attr->u.num;
-       navit_add_callback(nav, callback_new_attr_1(osd_compass_init, attr_navit, this));
+       navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_init), attr_navit, this));
        return (struct osd_priv *) this;
 }
 
diff --git a/navit/src/xpm/flag_wh_bk.xpm b/navit/src/xpm/flag_wh_bk.xpm
new file mode 100644 (file)
index 0000000..4564f8f
--- /dev/null
@@ -0,0 +1,28 @@
+/* XPM */
+static char *flag_bk_wh[]={
+"22 22 3 1 0 21",
+"      c None",
+"+     c #ffffff",
+"*     c #000000",
+"+++++++               ",
+"+***+++++++++         ",
+"+***+++***+++++++++   ",
+"+***+++***+++***+++   ",
+"++++******+++***+++   ",
+"++++***+++******+++   ",
+"++++***+++***+++**+   ",
+"+***++++++***+++**+   ",
+"+***+++***++++++**+   ",
+"+***+++***+++***+++   ",
+"++++******+++***+++   ",
+"++++***+++******+++   ",
+"++++++++++***+++**+   ",
+"+      +++++++++**+   ",
+"+            ++++++   ",
+"+                     ",
+"+                     ",
+"+                     ",
+"+                     ",
+"+                     ",
+"+                     ",
+"+                     "};