Ticket #442: navit-variable-cursor-offset-configurable.patch

File navit-variable-cursor-offset-configurable.patch, 4.0 KB (added by niccolo, 12 years ago)
  • navit/attr_def.h

    diff -Naur navit.orig/navit/attr_def.h navit/navit/attr_def.h
    old new  
    124124ATTR(bpp)
    125125ATTR(fullscreen)
    126126ATTR(windowid)
     127ATTR(min_offset)
     128ATTR(max_offset)
     129ATTR(min_offset_speed)
     130ATTR(max_offset_speed)
    127131ATTR2(0x00027500,type_rel_abs_begin)
    128132/* These attributes are int that can either hold relative               *
    129133 * or absolute values. A relative value is indicated by                 *
  • navit/navit.c

    diff -Naur navit.orig/navit/navit.c navit/navit/navit.c
    old new  
    7979        struct vehicle *vehicle;
    8080        struct attr callback;
    8181        int animate_cursor;
     82        int min_offset; /* Offset from screen center to draw the cursor (0-50 %) */
     83        int max_offset;
     84        int min_offset_speed; /* Below this speed (km/h) screen offset is min_offset */
     85        int max_offset_speed; /* Above this speed (km/h) screen offset is max_offset */
    8286};
    8387
    8488struct navit {
     
    15151519{
    15161520        int width, height;
    15171521        struct navit_vehicle *nv=this_->vehicle;
     1522        float offset;
    15181523
    1519         float offset=30;            // Cursor offset from the center of the screen (percent).
    1520 #if 0 /* Better improve track.c to get that issue resolved or make it configurable with being off the default, the jumping back to the center is a bit annoying */
    1521         float min_offset = 0.;      // Percent offset at min_offset_speed.
    1522         float max_offset = 30.;     // Percent offset at max_offset_speed.
    1523         int min_offset_speed = 2;   // Speed in km/h
    1524         int max_offset_speed = 50;  // Speed ini km/h
    1525         // Calculate cursor offset from the center of the screen, upon speed.
    1526         if (nv->speed <= min_offset_speed) {
    1527             offset = min_offset;
    1528         } else if (nv->speed > max_offset_speed) {
    1529             offset = max_offset;
    1530         } else {
    1531             offset = (max_offset - min_offset) / (max_offset_speed - min_offset_speed) * (nv->speed - min_offset_speed);
    1532         }
    1533 #endif
     1524        if (nv->min_offset == nv->max_offset) {
     1525                offset = (float)nv->min_offset;
     1526        } else {
     1527
     1528                // Calculate cursor offset from the center of the screen, upon speed.
     1529                if (nv->speed <= nv->min_offset_speed) {
     1530                        offset = (float)nv->min_offset;
     1531                } else if (nv->speed > nv->max_offset_speed) {
     1532                        offset = (float)nv->max_offset;
     1533                } else {
     1534                        offset = (float)(nv->max_offset - nv->min_offset) / (nv->max_offset_speed - nv->min_offset_speed) * (nv->speed - nv->min_offset_speed);
     1535                }
     1536        }
    15341537
    15351538        transform_get_size(this_->trans, &width, &height);
    15361539        if (this_->orientation == -1) {
     
    21872190navit_add_vehicle(struct navit *this_, struct vehicle *v)
    21882191{
    21892192        struct navit_vehicle *nv=g_new0(struct navit_vehicle, 1);
    2190         struct attr follow, active, animate;
     2193        struct attr follow, active, animate, min_offset, max_offset, min_offset_speed, max_offset_speed;
    21912194        nv->vehicle=v;
    21922195        nv->follow=0;
    21932196        nv->last.x = 0;
    21942197        nv->last.y = 0;
     2198        nv->min_offset = 30;
     2199        nv->max_offset = 30;
     2200        nv->min_offset_speed = 3;
     2201        nv->max_offset_speed = 60;
    21952202        nv->animate_cursor=0;
    21962203        if ((vehicle_get_attr(v, attr_follow, &follow, NULL)))
    21972204                nv->follow=nv->follow=follow.u.num;
     
    22012208                navit_set_vehicle(this_, nv);
    22022209        if ((vehicle_get_attr(v, attr_animate, &animate, NULL)))
    22032210                nv->animate_cursor=animate.u.num;
     2211        if ((vehicle_get_attr(v, attr_min_offset, &min_offset, NULL)))
     2212                nv->min_offset=min_offset.u.num;
     2213        if ((vehicle_get_attr(v, attr_max_offset, &max_offset, NULL)))
     2214                nv->max_offset=max_offset.u.num;
     2215        if ((vehicle_get_attr(v, attr_min_offset_speed, &min_offset_speed, NULL)))
     2216                nv->min_offset_speed=min_offset_speed.u.num;
     2217        if ((vehicle_get_attr(v, attr_max_offset_speed, &max_offset_speed, NULL)))
     2218                nv->max_offset_speed=max_offset_speed.u.num;
    22042219        nv->callback.type=attr_callback;
    22052220        nv->callback.u.callback=callback_new_attr_2(callback_cast(navit_vehicle_update), attr_position_coord_geo, this_, nv);
    22062221        vehicle_add_attr(nv->vehicle, &nv->callback);