Fix:Core:Changing the way autozoom works
authortinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 17 Feb 2009 20:56:15 +0000 (20:56 +0000)
committertinloaf <tinloaf@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Tue, 17 Feb 2009 20:56:15 +0000 (20:56 +0000)
Add:Gui/GTK:Adding autozoom-toggle

git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@2052 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/attr_def.h
navit/gui/gtk/gui_gtk_action.c
navit/navit.c
navit/transform.c
navit/transform.h

index fd4ecf9..5618ef4 100644 (file)
@@ -100,6 +100,7 @@ ATTR(sat_azimuth)
 ATTR(sat_snr)
 ATTR(autozoom)
 ATTR(version)
+ATTR(autozoom_min)
 ATTR2(0x00028000,type_boolean_begin)
 /* boolean */
 ATTR(overwrite)
@@ -130,6 +131,7 @@ ATTR(fullscreen)
 ATTR(position_magnetic_direction)
 ATTR(use_overlay)
 ATTR(night_mode)
+ATTR(autozoom_active)
 ATTR2(0x0002ffff,type_int_end)
 ATTR2(0x00030000,type_string_begin)
 ATTR(type)
index 8ec2063..37c99ba 100644 (file)
@@ -86,6 +86,21 @@ roadbook_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
 }
 
 static void
+autozoom_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
+{
+       struct attr autozoom_attr;
+
+       autozoom_attr.type = attr_autozoom_active;
+       if (! gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(w))) {
+               autozoom_attr.u.num = 0;
+       } else {
+               autozoom_attr.u.num = 1;
+       }
+       
+       navit_set_attr(gui->nav, &autozoom_attr);
+}
+
+static void
 cursor_action(GtkWidget *w, struct gui_priv *gui, void *dummy)
 {
        struct attr attr;
@@ -208,6 +223,7 @@ static GtkToggleActionEntry toggleentries[] =
        { "TrackingAction", NULL ,_n("Lock on Road"), NULL, NULL, G_CALLBACK(tracking_action),TRUE },
        { "OrientationAction", "orientation_icon", _n("Northing"), NULL, NULL, G_CALLBACK(orient_north_action),FALSE },
        { "RoadbookAction", GTK_STOCK_JUSTIFY_FILL, _n("Roadbook"), NULL, NULL, G_CALLBACK(roadbook_action), FALSE },
+       { "AutozoomAction", GTK_STOCK_ZOOM_FIT, _n("Autozoom"), NULL, NULL, G_CALLBACK(autozoom_action), FALSE },
 #ifdef GTK_STOCK_FULLSCREEN
        { "FullscreenAction",GTK_STOCK_FULLSCREEN, _n("Fullscreen"), NULL, NULL, G_CALLBACK(window_fullscreen_action), FALSE }
 #else
@@ -358,6 +374,7 @@ static char layout[] =
                                <menuitem name=\"Tracking\" action=\"TrackingAction\"/>\
                                <menuitem name=\"Orientation\" action=\"OrientationAction\"/>\
                                <menuitem name=\"Roadbook\" action=\"RoadbookAction\"/>\
+                               <menuitem name=\"Autozoom\" action=\"AutozoomAction\"/>\
                                <menuitem name=\"Fullscreen\" action=\"FullscreenAction\"/>\
                                <menuitem name=\"Quit\" action=\"QuitAction\" />\
                                <placeholder name=\"RouteMenuAdditions\" />\
@@ -401,6 +418,7 @@ static char layout[] =
                                <toolitem name=\"Destination\" action=\"DestinationAction\"/>\
                                <!-- <toolitem name=\"Info\" action=\"InfoAction\"/> -->\
                                <toolitem name=\"Roadbook\" action=\"RoadbookAction\"/>\
+                               <toolitem name=\"Autozoom\" action=\"AutozoomAction\"/>\
                                <toolitem name=\"Quit\" action=\"QuitAction\"/>\
                                <separator/>\
                        </placeholder>\
@@ -561,6 +579,12 @@ gui_gtk_ui_init(struct gui_priv *this)
        }
        toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "RoadbookAction"));
        gtk_toggle_action_set_active(toggle_action, 0);
+
+       if (navit_get_attr(this->nav, attr_autozoom_active, &attr, NULL)) {
+               toggle_action = GTK_TOGGLE_ACTION(gtk_action_group_get_action(this->base_group, "AutozoomAction"));
+               gtk_toggle_action_set_active(toggle_action, attr.u.num);
+       }
+
 }
 
 static struct menu_priv *
index ff4a2b2..7055522 100644 (file)
@@ -117,6 +117,8 @@ struct navit {
        int button_pressed,moved,popped,zoomed;
        int center_timeout;
        int autozoom_secs;
+       int autozoom_min;
+       int autozoom_active;
        struct event_timeout *button_timeout, *motion_timeout;
        struct callback *motion_timeout_callback;
        int ignore_button;
@@ -488,40 +490,51 @@ navit_scale(struct navit *this_, long scale, struct point *p, int draw)
  * zoom level according to the current speed.
  *
  * @param this_ The navit struct
+ * @param center The "immovable" point - i.e. the vehicles position if we're centering on the vehicle
  * @param speed The vehicles speed in meters per second
+ * @param dir The direction into which the vehicle moves
  */
 static void
 navit_autozoom(struct navit *this_, struct coord *center, int speed, int draw)
 {
        struct coord c;
        struct point pc;
-       int distance;
+       int distance,w,h;
+       double new_scale;
        long scale;
-       double factor;
 
-       if (this_->autozoom_secs <= 0) {
+       if (! this_->autozoom_active) {
                return;
        }
 
        distance = speed * this_->autozoom_secs;
 
-       if (route_get_path_set(this_->route)) {
-               c = route_get_coord_dist(this_->route, distance);
+       transform_get_size(this_->trans, &w, &h);
+       transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
+       scale = transform_get_scale(this_->trans);
+
+       /* We make shure that the point we want to see is within a certain range
+        * around the vehicle. The radius of this circle is the size of the
+        * screen. This doesn't necessarily mean the point is visible because of
+        * perspective etc. Quite rough, but should be enough. */
+       
+       if (w > h) {
+               new_scale = (double)distance / h * 16; 
        } else {
-               return;
+               new_scale = (double)distance / w * 16; 
        }
 
-       transform(this_->trans, transform_get_projection(this_->trans), center, &pc, 1, 0, 0, NULL);
-       factor = transform_get_autozoom_factor(this_->trans, &pc, &c);
+       if (abs(new_scale - scale) < 2) { 
+               return; // Smoothing
+       }
        
-       if ((factor < 1.1) && (factor > 0.9)) {
-               return;
+       if (new_scale >= this_->autozoom_min) {
+               navit_scale(this_, (long)new_scale, &pc, 0);
+       } else {
+               if (scale != this_->autozoom_min) {
+                       navit_scale(this_, this_->autozoom_min, &pc, 0);
+               }
        }
-
-       scale = transform_get_scale(this_->trans);
-       scale = (scale * factor);
-
-       navit_scale(this_, scale, &pc, draw);
 }
 
 /**
@@ -614,13 +627,16 @@ navit_new(struct attr *parent, struct attr **attrs)
 
        this_->center_timeout = 10;
        this_->use_mousewheel = 1;
-       this_->autozoom_secs = 0;
+       this_->autozoom_secs = 10;
+       this_->autozoom_min = 7;
+       this_->autozoom_active = 0;
 
-       this_->trans=transform_new();
+       this_->trans = transform_new();
        transform_from_geo(pro, &g, &co);
        center.x=co.x;
        center.y=co.y;
        center.pro = pro;
+
        transform_setup(this_->trans, &center, zoom, (this_->orientation != -1) ? this_->orientation : 0);
        for (;*attrs; attrs++) {
                navit_set_attr_do(this_, *attrs, 1);
@@ -1473,6 +1489,10 @@ navit_set_attr_do(struct navit *this_, struct attr *attr, int init)
                attr_updated=(this_->autozoom_secs != attr->u.num);
                this_->autozoom_secs = attr->u.num;
                break;
+       case attr_autozoom_active:
+               attr_updated=(this_->autozoom_active != attr->u.num);
+               this_->autozoom_active = attr->u.num;
+               break;
        case attr_center:
                transform_from_geo(transform_get_projection(this_->trans), attr->u.coord_geo, &co);
                dbg(0,"0x%x,0x%x\n",co.x,co.y);
@@ -1687,6 +1707,9 @@ navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, stru
        case attr_zoom:
                attr->u.num=transform_get_scale(this_->trans);
                break;
+       case attr_autozoom_active:
+               attr->u.num=this_->autozoom_active;
+               break;
        default:
                return 0;
        }
@@ -1752,6 +1775,9 @@ navit_add_attr(struct navit *this_, struct attr *attr)
        case attr_vehicle:
                ret=navit_add_vehicle(this_, attr->u.vehicle);
                break;
+       case attr_autozoom_min:
+               this_->autozoom_min = attr->u.num;
+               break;
        default:
                return 0;
        }
@@ -1815,7 +1841,7 @@ navit_vehicle_draw(struct navit *this_, struct navit_vehicle *nv, struct point *
                pnt2=*pnt;
        else {
                pro=transform_get_projection(this_->trans);
-               transform(this_->trans, pro, &nv->coord, &pnt2, 1, 0);
+               transform(this_->trans, pro, &nv->coord, &pnt2, 1);
        }
 #if 1
        cursor_draw(nv->cursor, &pnt2, nv->dir-transform_get_angle(this_->trans, 0), nv->speed > 2, pnt == NULL);
@@ -1898,6 +1924,7 @@ navit_vehicle_update(struct navit *this_, struct navit_vehicle *nv)
                navit_set_center_cursor(this_);
        else
                navit_vehicle_draw(this_, nv, pnt);
+
        if (nv->follow_curr > 1)
                nv->follow_curr--;
        else
index 91176e6..44d499e 100644 (file)
@@ -853,42 +853,6 @@ transform_distance_line_sq(struct coord *l0, struct coord *l1, struct coord *ref
        return transform_distance_sq(&l, ref);
 }
 
-double
-transform_get_autozoom_factor(struct transformation *this_, struct point *center, struct coord *c)
-{
-       struct point p;
-       struct map_selection *ms=this_->screen_sel;
-       double fx=0,fy=0,nfx,nfy;
-
-       transform(this_, transform_get_projection(this_), c, &p, 1, 0, 0, NULL);
-
-       while (ms) {
-               struct point_rect *r=&ms->u.p_rect;
-               if (p.x > center->x) {
-                       nfx = (double)(p.x - center->x) / (r->rl.x - center->x);
-               } else {
-                       nfx = (double)(p.x - center->x) / (r->lu.x - center->x);
-               }
-
-               if (p.y < center->y) {
-                       nfy = (double)(p.y - center->y) / (double)(r->lu.y - center->y) ;
-               } else {
-                       nfy =  (double)(p.y - center->y) / (double)(r->rl.y - center->y);
-               }
-               
-               if ((nfx < fx) || (fx == 0)) {
-                       fx = nfx;
-               }
-               if ((nfy < fy) || (fy == 0)) {
-                       fy = nfy;
-               }
-
-               ms=ms->next;
-       }
-
-       return (fy < fx) ? fx : fy;
-}
-
 int
 transform_distance_polyline_sq(struct coord *c, int count, struct coord *ref, struct coord *lpnt, int *pos)
 {
index 62ce3ff..d003559 100644 (file)
@@ -86,7 +86,7 @@ int transform_within_dist_polyline(struct coord *ref, struct coord *c, int count
 int transform_within_dist_polygon(struct coord *ref, struct coord *c, int count, int dist);
 int transform_within_dist_item(struct coord *ref, enum item_type type, struct coord *c, int count, int dist);
 void transform_destroy(struct transformation *t);
-double transform_get_autozoom_factor(struct transformation *this_, struct point *center, struct coord *c);
+struct coord transform_add_distance(enum projection pro, struct coord *c, int len, int dir);
 /* end of prototypes */
 #ifdef __cplusplus
 }