Add:Core:Support for FRA FRA NLS Setting
[navit-package] / navit / navit.c
index 5e9ab6e..eb92e8b 100644 (file)
@@ -136,6 +136,8 @@ struct navit {
        int pitch;
        int follow_cursor;
        int prevTs;
+       int graphics_flags;
+       int zoom_min, zoom_max;
 };
 
 struct gui *main_loop_gui;
@@ -198,7 +200,7 @@ navit_draw_async(struct navit *this_, int async)
                navit_vehicle_draw(this_, nv, NULL);
                l=g_list_next(l);
        }
-       graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL);
+       graphics_draw(this_->gra, this_->displaylist, this_->mapsets->data, this_->trans, this_->layout_current, async, NULL, this_->graphics_flags|1);
 }
 
 void
@@ -219,7 +221,7 @@ void
 navit_draw_displaylist(struct navit *this_)
 {
        if (this_->ready == 3)
-               graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, 1);
+               graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, this_->graphics_flags|1);
 }
 
 static void
@@ -246,6 +248,7 @@ void
 navit_handle_resize(struct navit *this_, int w, int h)
 {
        struct map_selection sel;
+       int callback=(this_->ready == 1);
        this_->ready |= 2;
        if (this_->w != w || this_->h != h) {
                memset(&sel, 0, sizeof(sel));
@@ -259,6 +262,8 @@ navit_handle_resize(struct navit *this_, int w, int h)
        }
        if (this_->ready == 3)
                navit_draw(this_);
+       if (callback)
+               callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
 }
 
 static void
@@ -315,14 +320,16 @@ update_transformation(struct transformation *tr, struct point *old, struct point
        int yaw;
        double angleo,anglen;
 
-       transform_reverse(tr, old, &co);
+       if (!transform_reverse(tr, old, &co))
+               return;
        if (rot) {
                angleo=atan2(old->y-rot->y, old->x-rot->x)*180/M_PI;
                anglen=atan2(new->y-rot->y, new->x-rot->x)*180/M_PI;
                yaw=transform_get_yaw(tr)+angleo-anglen;
                transform_set_yaw(tr, yaw % 360);
        }
-       transform_reverse(tr, new, &cn);
+       if (!transform_reverse(tr, new, &cn))
+               return;
        cp=transform_get_center(tr);
        c.x=cp->x+co.x-cn.x;
        c.y=cp->y+co.y-cn.y;
@@ -344,6 +351,7 @@ navit_handle_button(struct navit *this_, int pressed, int button, struct point *
 {
        int border=16;
 
+       dbg(1,"enter %d %d (ignore %d)\n",pressed,button,this_->ignore_button);
        callback_list_call_attr_4(this_->attr_cbl, attr_button, this_, GINT_TO_POINTER(pressed), GINT_TO_POINTER(button), p);
        if (this_->ignore_button) {
                this_->ignore_button=0;
@@ -410,6 +418,7 @@ static void
 navit_button(void *data, int pressed, int button, struct point *p)
 {
        struct navit *this=data;
+       dbg(1,"enter %d %d ignore %d\n",pressed,button,this->ignore_graphics_events);
        if (!this->ignore_graphics_events) {
                if (! this->popup_callback)
                        this->popup_callback=callback_new_1(callback_cast(navit_popup), this);
@@ -454,7 +463,7 @@ navit_motion_timeout(struct navit *this_)
                graphics_displaylist_move(this_->displaylist, dx, dy);
 #endif
                graphics_draw_cancel(this_->gra, this_->displaylist);
-               graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, 0);
+               graphics_displaylist_draw(this_->gra, this_->displaylist, tr, this_->layout_current, this_->graphics_flags);
                transform_destroy(tr);
                this_->moved=1;
        }
@@ -471,6 +480,7 @@ navit_handle_motion(struct navit *this_, struct point *p)
                dx=(p->x-this_->pressed.x);
                dy=(p->y-this_->pressed.y);
                if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
+                       this_->moved=1;
                        if (this_->button_timeout) {
                                event_remove_timeout(this_->button_timeout);
                                this_->button_timeout=NULL;
@@ -496,6 +506,10 @@ static void
 navit_scale(struct navit *this_, long scale, struct point *p, int draw)
 {
        struct coord c1, c2, *center;
+       if (scale < this_->zoom_min)
+               scale=this_->zoom_min;
+       if (scale > this_->zoom_max)
+               scale=this_->zoom_max;
        if (p)
                transform_reverse(this_->trans, p, &c1);
        transform_set_scale(this_->trans, scale);
@@ -655,6 +669,8 @@ navit_new(struct attr *parent, struct attr **attrs)
        this_->autozoom_secs = 10;
        this_->autozoom_min = 7;
        this_->autozoom_active = 0;
+       this_->zoom_min = 1;
+       this_->zoom_max = 2097152;
        this_->follow_cursor = 1;
 
        this_->trans = transform_new();
@@ -1285,6 +1301,7 @@ navit_init(struct navit *this_)
 {
        struct mapset *ms;
        struct map *map;
+       int callback;
 
        dbg(2,"enter gui %p graphics %p\n",this_->gui,this_->gra);
        if (!this_->gui) {
@@ -1377,16 +1394,19 @@ navit_init(struct navit *this_)
        navit_window_roadbook_new(this_);
        navit_window_items_new(this_);
 #endif
-       callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
-       this_->ready|=1;
 
        messagelist_init(this_->messages);
 
        navit_set_cursors(this_);
 
+       callback_list_call_attr_1(this_->attr_cbl, attr_navit, this_);
+       callback=(this_->ready == 2);
+       this_->ready|=1;
        dbg(2,"ready=%d\n",this_->ready);
        if (this_->ready == 3)
                navit_draw(this_);
+       if (callback)
+               callback_list_call_attr_1(this_->attr_cbl, attr_graphics_ready, this_);
 #if 0
        routech_test(this_);
 #endif
@@ -1620,6 +1640,7 @@ navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
        GList *l;
        struct navit_vehicle *nv;
        struct attr active=(struct attr){attr_active,{(void *)0}};
+       struct layout *lay;
 
        switch (attr->type) {
        case attr_autozoom:
@@ -1639,6 +1660,10 @@ navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
                attr_updated=(this_->drag_bitmap != !!attr->u.num);
                this_->drag_bitmap=!!attr->u.num;
                break;
+       case attr_flags_graphics:
+               attr_updated=(this_->graphics_flags != attr->u.num);
+               this_->graphics_flags=attr->u.num;
+               break;
        case attr_follow:
                if (!this_->vehicle)
                        return 0;
@@ -1650,10 +1675,24 @@ navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
                        this_->layout_current=attr->u.layout;
                        graphics_font_destroy_all(this_->gra);
                        navit_set_cursors(this_);
-                       navit_draw(this_);
+                       if (this_->ready == 3)
+                               navit_draw(this_);
                        attr_updated=1;
                }
                break;
+       case attr_layout_name:
+               l=this_->layouts;
+               while (l) {
+                       lay=l->data;
+                       if (!strcmp(lay->name,attr->u.str)) {
+                               struct attr attr;
+                               attr.type=attr_layout;
+                               attr.u.layout=lay;
+                               return navit_set_attr_do(this_, &attr, init);
+                       }
+                       l=g_list_next(l);
+               }               
+               return 0;
        case attr_orientation:
                orient_old=this_->orientation;
                this_->orientation=attr->u.num;
@@ -1667,8 +1706,10 @@ navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
                        }
                        transform_set_yaw(this_->trans, dir);
                        if (orient_old != this_->orientation) {
+#if 0
                                if (this_->ready == 3)
                                        navit_draw(this_);
+#endif
                                attr_updated=1;
                        }
                }
@@ -1737,6 +1778,14 @@ navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
                if (attr_updated && !init) 
                        navit_draw(this_);
                break;
+       case attr_zoom_min:
+               attr_updated=(attr->u.num != this_->zoom_min);
+               this_->zoom_min=attr->u.num;
+               break;
+       case attr_zoom_max:
+               attr_updated=(attr->u.num != this_->zoom_max);
+               this_->zoom_max=attr->u.num;
+               break;
        case attr_message:
                navit_add_message(this_, attr->u.str);
                break;
@@ -1810,6 +1859,11 @@ navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, stru
        case attr_displaylist:
                attr->u.displaylist=this_->displaylist;
                return (attr->u.displaylist != NULL);
+       case attr_follow:
+               if (!this_->vehicle)
+                       return 0;
+               attr->u.num=this_->vehicle->follow_curr;
+               break;
        case attr_former_destination_map:
                attr->u.map=this_->former_destination;
                break;
@@ -1861,6 +1915,9 @@ navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, stru
        case attr_osd_configuration:
                attr->u.num=this_->osd_configuration;
                break;
+       case attr_pitch:
+               attr->u.num=transform_get_pitch(this_->trans);
+               break;
        case attr_projection:
                if(this_->trans) {
                        attr->u.num=transform_get_projection(this_->trans);
@@ -2262,7 +2319,7 @@ navit_layout_switch(struct navit *n)
 {
 
     int currTs=0;
-    struct attr iso8601_attr,geo_attr,layout_attr;
+    struct attr iso8601_attr,geo_attr,valid_attr,layout_attr;
     double trise,tset,trise_actual;
     struct layout *l;
     int year, month, day;
@@ -2270,6 +2327,8 @@ navit_layout_switch(struct navit *n)
     if (navit_get_attr(n,attr_layout,&layout_attr,NULL)!=1) {
        return; //No layout - nothing to switch
     }
+    if (!n->vehicle)
+       return;
     l=layout_attr.u.layout;
     
     if (l->dayname || l->nightname) {
@@ -2289,7 +2348,7 @@ navit_layout_switch(struct navit *n)
                //No position - no sun
                return;
        }
-       if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &geo_attr,NULL) && geo_attr.u.num==attr_position_valid_invalid) {
+       if (vehicle_get_attr(n->vehicle->vehicle, attr_position_valid, &valid_attr,NULL) && valid_attr.u.num==attr_position_valid_invalid) {
                return; //No valid fix yet
        }