Ticket #897: navit_command_object_filter.diff

File navit_command_object_filter.diff, 85.3 KB (added by tegzed, 10 years ago)

object filter for the command system and possibility to set std attributes for OSDs

  • navit/command.c

     
    1515#include "command.h"
    1616#include "event.h"
    1717#include "navit_nls.h"
     18#include "obj_filter.h"
    1819
    1920/*
    2021gui.fullscreen=!gui.fullscreen
     
    267268                op++;
    268269        }
    269270
     271        struct obj_filter_t out;
     272    int parsed_chars = parse_obj_filter(op, &out);
     273        if (parsed_chars) {
     274                struct attr* res_attr = filter_object(ctx->attr, out.iterator_type, out.filter_expr, out.idx);
     275                if (res_attr) {
     276                        res->attr = *res_attr;
     277                        g_free(res_attr);
     278                                ctx->expr = op+parsed_chars;
     279                        return;
     280                }
     281        }
     282
    270283        if ((op[0] >= 'a' && op[0] <= 'z') || op[0] == '_') {
    271284                res->attr.type=attr_none;
    272285                res->var=op;
  • navit/Makefile.am

     
    4848
    4949EXTRA_DIST = navit_shipped.xml navit.dtd
    5050
    51 lib@LIBNAVIT@_la_SOURCES = announcement.c atom.c attr.c cache.c callback.c command.c compass.c config_.c coord.c country.c data_window.c debug.c \
     51lib@LIBNAVIT@_la_SOURCES = announcement.c atom.c attr.c cache.c callback.c obj_filter.c command.c compass.c config_.c coord.c country.c data_window.c debug.c \
    5252        event.c event_glib.h file.c graphics.c gui.c item.c layout.c log.c main.c map.c \
    5353        linguistics.c mapset.c maptype.c menu.c messages.c bookmarks.c bookmarks.h navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \
    5454        profile.c projection.c roadprofile.c route.c routech.c search.c speech.c start_real.c transform.c track.c \
    55         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 config_.h coord.h country.h \
     55        util.c vehicle.c vehicleprofile.c xmlconfig.c announcement.h atom.h attr.h attr_def.h cache.h callback.h color.h obj_filter.h command.h compass.h config_.h coord.h country.h \
    5656        android.h data.h data_window.h data_window_int.h debug.h destination.h draw_info.h endianess.h event.h \
    5757        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\
    5858        map_data.h mapset.h maptype.h menu.h messages.h navigation.h navit.h osd.h \
  • navit/graphics/gtk_drawing_area/graphics_gtk_drawing_area.c

     
    950950static void
    951951overlay_resize(struct graphics_priv *this, struct point *p, int w, int h, int alpha, int wraparound)
    952952{
     953        //do not dereference parent for non overlay osds
     954        if(!this->parent) {
     955                return;
     956        }
     957
    953958        int changed = 0;
    954959        int w2,h2;
    955960
  • navit/osd.c

     
    3636        struct attr** osd_attrs;
    3737};
    3838
    39 static GHashTable *osd_hash = NULL;
    40 
    4139struct osd *
    4240osd_new(struct attr *parent, struct attr **attrs)
    4341{
     
    5452        o=g_new0(struct osd, 1);
    5553        o->priv=new(parent->u.navit, &o->meth, attrs);
    5654
    57         attr=attr_search(attrs, NULL, attr_name);
    58         if (attr && attr->u.str) {
    59                 if(NULL == osd_hash) {
    60                         osd_hash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,NULL);
    61                 }
    62                 g_hash_table_insert(osd_hash, g_strdup(attr->u.str), o);
    63         }
     55                o->osd_attrs = attr_list_dup(attrs);
    6456
    65         o->osd_attrs = attr_list_dup(attrs);
    66 
    6757        return o;
    6858}
    6959
     
    7363        return attr_generic_get_attr(this_->osd_attrs, NULL, type, attr, NULL);
    7464}
    7565
    76 struct osd*
    77 osd_get_osd_by_name(char *name)
    78 {
    79         return g_hash_table_lookup(osd_hash, name);
    80 }
    81 
    8266int
    8367osd_set_attr(struct osd *osd, struct attr* attr)
    8468{
  • navit/osd.h

     
    6868void osd_set_std_graphic(struct navit *nav, struct osd_item *item, struct osd_priv *priv);
    6969void osd_std_resize(struct osd_item *item);
    7070void osd_std_draw(struct osd_item *item);
    71 struct osd* osd_get_osd_by_name(char *name);
     71struct osd* osd_get_first_osd_by_attr(struct attr*attr);
     72
    7273int osd_set_attr(struct osd *osd, struct attr* attr);
    7374int osd_get_attr(struct osd *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter);
    7475/* end of prototypes */
  • navit/osd/core/osd_core.c

     
    7272}
    7373#endif /* MSC_VER */
    7474
     75struct osd_priv_common {
     76        struct osd_item osd_item;
     77        struct osd_priv *data;
     78        int (*spec_set_attr_func)(struct osd_priv_common *opc, struct attr* attr);
     79};
     80
    7581struct odometer;
    7682
    77 static void osd_odometer_reset(struct odometer *this);
     83int set_std_osd_attr(struct osd_priv_common*opc, struct attr*the_attr);
     84static void osd_odometer_reset(struct osd_priv_common *opc);
    7885static void osd_cmd_odometer_reset(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid);
    79 static void osd_odometer_draw(struct odometer *this, struct navit *nav, struct vehicle *v);
     86static void osd_odometer_draw(struct osd_priv_common *opc, struct navit *nav, struct vehicle *v);
    8087static struct osd_text_item * oti_new(struct osd_text_item * parent);
     88int osd_button_set_attr(struct osd_priv_common *opc, struct attr* attr);
    8189
    8290static int b_commandtable_added = 0;
    8391
    8492
    8593struct compass {
    86         struct osd_item osd_item;
    8794        int width;
    8895        struct graphics_gc *green;
    8996};
     
    204211        return g_strdup("");
    205212}
    206213
    207 /*static char *
    208 format_float(double num)
    209 {
    210         return g_strdup_printf("%f", num);
    211 }*/
    212 
    213214static char *
    214215format_float_0(double num)
    215216{
    216217        return g_strdup_printf("%.0f", num);
    217218}
    218219
    219 /**
    220  * sets an attribute (name value pair) of a map item specified by map name and item id
    221  *
    222  * @param navit The navit instance
    223  * @param function unused (needed to match command function signiture)
    224  * @param in input attribute in[0] - name of the osd  ; in[1] - attr name ; in[2] - attr value
    225  * @param out output attribute, 0 on error, 1 on success
    226  * @param valid unused
    227  * @returns nothing
    228  */
    229 static void
    230 osd_cmd_osd_set_attr(struct navit *this, char *function, struct attr **in, struct attr ***out, int *valid)
     220int set_std_osd_attr(struct osd_priv_common*opc, struct attr*the_attr)
    231221{
    232         struct attr **list;
    233         struct attr*val = g_new0(struct attr,1);
    234         val->type   = attr_type_int_begin;
    235         val->u.num  = 0;
    236         list = g_new0(struct attr *,2);
    237         list[0]     = val;
    238  
    239         if (
    240                 in && in[0] && ATTR_IS_STRING(in[0]->type) && in[0]->u.str  &&//osd name
    241                 in[1] && ATTR_IS_STRING(in[1]->type) && in[1]->u.str  &&//attr_type str
    242                 in[2] && ATTR_IS_STRING(in[2]->type) && in[2]->u.str    //attr_value str
    243         ) {
    244                 struct attr attr_to_set;
    245                 struct osd* osd;
    246                
    247                 if(ATTR_IS_STRING(attr_from_name(in[1]->u.str))) {
    248                         attr_to_set.u.str = in[2]->u.str;
    249                         attr_to_set.type = attr_from_name(in[1]->u.str);
     222        if(opc && the_attr && ATTR_IS_INT(the_attr->type)) {
     223                if(attr_w == the_attr->type) {
     224                        opc->osd_item.w = the_attr->u.num;
     225                        osd_std_resize(&opc->osd_item);
     226                        return 1;
    250227                }
    251                 else if(ATTR_IS_INT(attr_from_name(in[1]->u.str))) {
    252                         attr_to_set.u.num = atoi(in[2]->u.str);
    253                         attr_to_set.type = attr_from_name(in[1]->u.str);
     228                else if(attr_h == the_attr->type) {
     229                        opc->osd_item.h = the_attr->u.num;
     230                        osd_std_resize(&opc->osd_item);
     231                        return 1;
    254232                }
    255                 else if(ATTR_IS_DOUBLE(attr_from_name(in[1]->u.str))) {
    256                         double* val = g_new0(double,1);
    257                         *val = atof(in[2]->u.str);
    258                         attr_to_set.u.numd = val;
    259                         attr_to_set.type = attr_from_name(in[1]->u.str);
     233                else if(attr_x == the_attr->type) {
     234                        opc->osd_item.p.x = the_attr->u.num;
     235                        osd_std_resize(&opc->osd_item);
     236                        return 1;
    260237                }
    261                 osd = osd_get_osd_by_name(in[0]->u.str);
    262                 if(osd) {
    263                         osd_set_attr(osd, &attr_to_set);
    264                         val->u.num  = 1;
     238                else if(attr_y == the_attr->type) {
     239                        opc->osd_item.p.y = the_attr->u.num;
     240                        osd_std_resize(&opc->osd_item);
     241                        return 1;
    265242                }
     243                else if(attr_font_size == the_attr->type) {
     244                        opc->osd_item.font_size = the_attr->u.num;
     245                        osd_std_resize(&opc->osd_item);
     246                        return 1;
     247                }
     248        }
     249        if(opc->spec_set_attr_func) {
     250                opc->spec_set_attr_func(opc, the_attr);
    266251        }
    267         list[1] = NULL;
    268         *out = list;
     252        return 0;
    269253}
    270 
    271 
    272254 
    273255static int odometers_saved = 0;
    274256static GList* odometer_list = NULL;
    275257
    276258static struct command_table commands[] = {
    277259        {"odometer_reset",command_cast(osd_cmd_odometer_reset)},
    278         {"osd_set_attr"  ,command_cast(osd_cmd_osd_set_attr)},
    279260};
    280261
    281262struct odometer {
    282         struct osd_item osd_item;
    283263        int width;
    284264        struct graphics_gc *orange;
    285265        struct graphics_gc *white;
     
    345325/*
    346326 * save current odometer state to string
    347327 */
    348 static char *osd_odometer_to_string(struct odometer* this_)
     328static char *osd_odometer_to_string(struct odometer *this_)
    349329{
    350330  return g_strdup_printf("odometer %s %lf %lf %d\n",this_->name,this_->sum_dist,this_->time_all,this_->bActive);
    351331}
     
    353333/*
    354334 * load current odometer state from string
    355335 */
    356 static void osd_odometer_from_string(struct odometer* this_, char*str)
     336static void osd_odometer_from_string(struct odometer *this_, char*str)
    357337{
    358338  char*  tok;
    359339  char*  name_str;
     
    425405}
    426406
    427407
    428 static void osd_odometer_draw(struct odometer *this, struct navit *nav, struct vehicle *v)
     408static void osd_odometer_draw(struct osd_priv_common *opc, struct navit *nav, struct vehicle *v)
    429409{
     410  struct odometer *this = (struct odometer *)opc->data;
     411
    430412  struct coord curr_coord;
    431413  struct graphics_gc *curr_color;
    432414
     
    434416  char *spd_buffer=0;
    435417  char *time_buffer = 0;
    436418  char *acc_buffer = 0;
    437   struct point p, bbox[4];
    438419  struct attr position_attr,vehicle_attr,imperial_attr,speed_attr;
    439420  enum projection pro;
    440421  struct vehicle* curr_vehicle = v;
     
    463444  if(0==curr_vehicle)
    464445    return;
    465446
    466   osd_std_draw(&this->osd_item);
     447  osd_std_draw(&opc->osd_item);
    467448  if(this->bActive) {
    468449    if(!vehicle_get_attr(curr_vehicle, attr_position_coord_geo,&position_attr, NULL)) {
    469450      return;
     
    532513  }
    533514  g_free(time_buffer);
    534515
    535 
    536516  curr_color = this->bActive?this->white:this->orange;
     517  draw_multiline_osd_text(buffer,&opc->osd_item, curr_color);
    537518
    538   draw_multiline_osd_text(buffer,&this->osd_item, curr_color);
    539 
    540519  g_free(dist_buffer);
    541520  g_free(spd_buffer);
    542521  g_free(acc_buffer);
    543   graphics_draw_mode(this->osd_item.gr, draw_mode_end);
     522  graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    544523}
    545524
    546525
    547526static void
    548 osd_odometer_reset(struct odometer *this)
     527osd_odometer_reset(struct osd_priv_common *opc)
    549528{
     529  struct odometer *this = (struct odometer *)opc->data;
     530
    550531  if(!this->bDisableReset) {
    551532    this->bActive = 0;
    552533    this->sum_dist = 0;
     
    558539}
    559540
    560541static void
    561 osd_odometer_click(struct odometer *this, struct navit *nav, int pressed, int button, struct point *p)
     542osd_odometer_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p)
    562543{
    563   struct point bp = this->osd_item.p;
     544  struct odometer *this = (struct odometer *)opc->data;
     545
     546  struct point bp = opc->osd_item.p;
    564547  struct timeval tv;
    565548  double curr_time;
    566549  const double double_click_timewin = .5;
    567550  osd_wrap_point(&bp, nav);
    568   if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + this->osd_item.w || p->y > bp.y + this->osd_item.h || !this->osd_item.configured ) && !this->osd_item.pressed)
     551  if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h || !opc->osd_item.configured ) && !opc->osd_item.pressed)
    569552    return;
    570553  if (button != 1)
    571554    return;
    572555  if (navit_ignore_button(nav))
    573556    return;
    574   if (!!pressed == !!this->osd_item.pressed)
     557  if (!!pressed == !!opc->osd_item.pressed)
    575558    return;
    576559
    577560  gettimeofday(&tv,NULL);
     
    587570  this->bActive ^= 1;  //toggle active flag
    588571
    589572  if (curr_time-double_click_timewin <= this->last_click_time) { //double click handling
    590     osd_odometer_reset(this);
     573    osd_odometer_reset(opc);
    591574  }
    592575
    593576  this->last_click_time = curr_time;
    594577
    595   osd_odometer_draw(this, nav,NULL);
     578  osd_odometer_draw(opc, nav,NULL);
    596579  }
    597580}
    598581
     
    624607
    625608
    626609static void
    627 osd_odometer_init(struct odometer *this, struct navit *nav)
     610osd_odometer_init(struct osd_priv_common *opc, struct navit *nav)
    628611{
    629         osd_set_std_graphic(nav, &this->osd_item, (struct osd_priv *)this);
     612        struct odometer *this = (struct odometer *)opc->data;
    630613
    631         this->orange = graphics_gc_new(this->osd_item.gr);
     614        osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     615
     616        this->orange = graphics_gc_new(opc->osd_item.gr);
    632617        graphics_gc_set_foreground(this->orange, &this->idle_color);
    633618        graphics_gc_set_linewidth(this->orange, this->width);
    634619
    635         this->white = graphics_gc_new(this->osd_item.gr);
    636         graphics_gc_set_foreground(this->white, &this->osd_item.text_color);
     620        this->white = graphics_gc_new(opc->osd_item.gr);
     621        graphics_gc_set_foreground(this->white, &opc->osd_item.text_color);
    637622        graphics_gc_set_linewidth(this->white, this->width);
    638623
    639         graphics_gc_set_linewidth(this->osd_item.graphic_fg_white, this->width);
     624        graphics_gc_set_linewidth(opc->osd_item.graphic_fg_white, this->width);
    640625
    641         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_draw), attr_position_coord_geo, this));
     626        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_draw), attr_position_coord_geo, opc));
    642627
    643         navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_odometer_click), attr_button, this));
     628        navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_odometer_click), attr_button, opc));
    644629       
    645630        if(this->autosave_period>0) {
    646631                event_add_timeout(this->autosave_period*1000, 1, callback_new_1(callback_cast(osd_odometer_save), NULL));
     
    649634        if(this->bAutoStart) {
    650635                this->bActive = 1;
    651636        }
    652         osd_odometer_draw(this, nav, NULL);
     637        osd_odometer_draw(opc, nav, NULL);
    653638}
    654639
    655640static void
     
    669654        char* fn;
    670655
    671656        struct odometer *this = g_new0(struct odometer, 1);
     657        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     658        opc->data = (void*)this;
     659
    672660        struct attr *attr;
    673661        struct color orange_color={0xffff,0xa5a5,0x0000,0xffff};
    674         this->osd_item.p.x = 120;
    675         this->osd_item.p.y = 20;
    676         this->osd_item.w = 60;
    677         this->osd_item.h = 80;
    678         this->osd_item.navit = nav;
    679         this->osd_item.font_size = 200;
    680         this->osd_item.meth.draw = osd_draw_cast(osd_odometer_draw);
     662        opc->osd_item.p.x = 120;
     663        opc->osd_item.p.y = 20;
     664        opc->osd_item.w = 60;
     665        opc->osd_item.h = 80;
     666        opc->osd_item.navit = nav;
     667        opc->osd_item.font_size = 200;
     668        opc->osd_item.meth.draw = osd_draw_cast(osd_odometer_draw);
     669        meth->set_attr = set_std_osd_attr;
    681670
    682671        this->bActive = 0; //do not count on init
    683672        this->sum_dist = 0;
     
    718707        else
    719708                this->autosave_period = -1;  //disabled by default
    720709
    721         osd_set_std_attr(attrs, &this->osd_item, 2);
     710        osd_set_std_attr(attrs, &opc->osd_item, 2);
    722711        attr = attr_search(attrs, NULL, attr_width);
    723712        this->width=attr ? attr->u.num : 2;
    724713        attr = attr_search(attrs, NULL, attr_idle_color);
     
    759748                navit_command_add_table(nav, commands, sizeof(commands)/sizeof(struct command_table));
    760749                b_commandtable_added = 1;
    761750        }
    762         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_init), attr_graphics_ready, this));
     751        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_init), attr_graphics_ready, opc));
    763752        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_odometer_destroy), attr_destroy, nav));
    764753        odometer_list = g_list_append(odometer_list, this);
    765754
    766         return (struct osd_priv *) this;
     755        return (struct osd_priv *) opc;
    767756}
    768757
    769758 
    770759struct cmd_interface {
    771         struct osd_item osd_item;
    772760        int width;
    773761        struct graphics_gc *orange,*white;
    774762        int update_period;   //in sec
     
    780768};
    781769 
    782770static void
    783 osd_cmd_interface_draw(struct cmd_interface *this, struct navit *nav,
     771osd_cmd_interface_draw(struct osd_priv_common *opc, struct navit *nav,
    784772                struct vehicle *v)
    785773{
     774        struct cmd_interface *this = (struct cmd_interface *)opc->data;
     775
    786776        struct point p;
    787777        struct point bbox[4];
    788778        struct graphics_gc *curr_color;
     
    790780        p.x = 0;
    791781        p.y = 0;
    792782        navit.type=attr_navit;
    793         navit.u.navit = this->osd_item.navit;
     783        navit.u.navit = opc->osd_item.navit;
    794784 
    795785        if(0==this->bReserved) {
    796786                this->bReserved = 1;
     
    798788                this->bReserved = 0;
    799789        }
    800790 
    801         osd_std_draw(&this->osd_item);
     791        osd_std_draw(&opc->osd_item);
    802792
    803793        //display image
    804794        if(this->img) {
    805                 graphics_draw_image(this->osd_item.gr, this->osd_item.graphic_bg, &p, this->img);
     795                graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, this->img);
    806796        }
    807797
    808798        //display text
    809         graphics_get_text_bbox(this->osd_item.gr, this->osd_item.font, this->text, 0x10000, 0, bbox, 0);
    810         p.x=(this->osd_item.w-bbox[2].x)/2;
    811         p.y = this->osd_item.h-this->osd_item.h/10;
     799        graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, this->text, 0x10000, 0, bbox, 0);
     800        p.x=(opc->osd_item.w-bbox[2].x)/2;
     801        p.y = opc->osd_item.h-opc->osd_item.h/10;
    812802        curr_color = this->white;
    813803        if(this->text)
    814                 draw_multiline_osd_text(this->text,&this->osd_item, curr_color);
    815         graphics_draw_mode(this->osd_item.gr, draw_mode_end);
     804                draw_multiline_osd_text(this->text,&opc->osd_item, curr_color);
     805        graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    816806}
    817807
    818808
    819809
    820810static void
    821 osd_cmd_interface_init(struct cmd_interface *this, struct navit *nav)
     811osd_cmd_interface_init(struct osd_priv_common *opc, struct navit *nav)
    822812{
    823         osd_set_std_graphic(nav, &this->osd_item, (struct osd_priv *)this);
     813        struct cmd_interface *this = (struct cmd_interface *)opc->data;
    824814
    825         this->white = graphics_gc_new(this->osd_item.gr);
    826         graphics_gc_set_foreground(this->white, &this->osd_item.text_color);
     815        osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     816
     817        this->white = graphics_gc_new(opc->osd_item.gr);
     818        graphics_gc_set_foreground(this->white, &opc->osd_item.text_color);
    827819        graphics_gc_set_linewidth(this->white, this->width);
    828820
    829821
    830         graphics_gc_set_linewidth(this->osd_item.graphic_fg_white, this->width);
     822        graphics_gc_set_linewidth(opc->osd_item.graphic_fg_white, this->width);
    831823
    832824        if(this->update_period>0) {
    833                 event_add_timeout(this->update_period*1000, 1, callback_new_1(callback_cast(osd_cmd_interface_draw), this));
     825                event_add_timeout(this->update_period*1000, 1, callback_new_1(callback_cast(osd_cmd_interface_draw), opc));
    834826        }
    835827
    836         navit_add_callback(nav, callback_new_attr_1(callback_cast (osd_std_click), attr_button, &this->osd_item));
     828        navit_add_callback(nav, callback_new_attr_1(callback_cast (osd_std_click), attr_button, &opc->osd_item));
    837829
    838830        this->text = g_strdup("");
    839831}
    840832
    841833static int
    842 osd_cmd_interface_set_attr(struct cmd_interface *this_, struct attr* attr)
     834osd_cmd_interface_set_attr(struct osd_priv_common *opc, struct attr* attr)
    843835{
     836        struct cmd_interface *this_ = (struct cmd_interface *)opc->data;
     837
    844838        struct navit* nav;
    845839
    846840        if(NULL==attr || NULL==this_) {
    847841                return 0;
    848842        }
    849843
    850         nav = this_->osd_item.navit;
     844        nav = opc->osd_item.navit;
    851845
    852846        if(attr->type == attr_status_text) {
    853847                if(this_->text) {
     
    861855        if(attr->type == attr_src) {
    862856                if(attr->u.str) {
    863857                        if((!this_->img_filename) || strcmp(this_->img_filename, graphics_icon_path(attr->u.str))) {
    864                                 struct graphics *gra = navit_get_graphics(nav);
    865858                                //destroy old img, create new  image
    866859                                if(this_->img) {
    867                                         graphics_image_free(this_->osd_item.gr, this_->img);
     860                                        graphics_image_free(opc->osd_item.gr, this_->img);
    868861                                }
    869862                                if(this_->img_filename) {
    870863                                        g_free(this_->img_filename);
    871864                                }
    872865                                this_->img_filename = graphics_icon_path(attr->u.str);
    873                                 this_->img = graphics_image_new(this_->osd_item.gr, this_->img_filename);       
     866                                this_->img = graphics_image_new(opc->osd_item.gr, this_->img_filename);
    874867                        }
    875868                }
    876869                return 1;
     
    884877                struct attr **attrs)
    885878{
    886879        struct cmd_interface *this = g_new0(struct cmd_interface, 1);
     880        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     881        opc->data = (void*)this;
     882
    887883        struct attr *attr;
    888884
    889         this->osd_item.p.x = 120;
    890         this->osd_item.p.y = 20;
    891         this->osd_item.w = 60;
    892         this->osd_item.h = 80;
    893         this->osd_item.navit = nav;
    894         this->osd_item.font_size = 200;
    895         this->osd_item.meth.draw = osd_draw_cast(osd_cmd_interface_draw);
     885        opc->osd_item.p.x = 120;
     886        opc->osd_item.p.y = 20;
     887        opc->osd_item.w = 60;
     888        opc->osd_item.h = 80;
     889        opc->osd_item.navit = nav;
     890        opc->osd_item.font_size = 200;
     891        opc->osd_item.meth.draw = osd_draw_cast(osd_cmd_interface_draw);
    896892
    897         meth->set_attr = osd_cmd_interface_set_attr;
     893        opc->spec_set_attr_func = osd_cmd_interface_set_attr;
     894        meth->set_attr = set_std_osd_attr;
    898895
    899         osd_set_std_attr(attrs, &this->osd_item, 2);
     896        osd_set_std_attr(attrs, &opc->osd_item, 2);
    900897
    901898        attr = attr_search(attrs, NULL, attr_width);
    902899        this->width=attr ? attr->u.num : 2;
     
    911908                navit_command_add_table(nav, commands, sizeof(commands)/sizeof(struct command_table));
    912909                b_commandtable_added = 1;
    913910        }
    914         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_cmd_interface_init), attr_graphics_ready, this));
    915         return (struct osd_priv *) this;
     911        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_cmd_interface_init), attr_graphics_ready, opc));
     912        return (struct osd_priv *) opc;
    916913}
    917914
    918915
    919916
    920917
    921918struct stopwatch {
    922         struct osd_item osd_item;
    923919        int width;
    924920        struct graphics_gc *orange,*white;
    925921        struct callback *click_cb;
     
    933929};
    934930
    935931static void
    936 osd_stopwatch_draw(struct stopwatch *this, struct navit *nav,
     932osd_stopwatch_draw(struct osd_priv_common *opc, struct navit *nav,
    937933                struct vehicle *v)
    938934{
     935        struct stopwatch *this = (struct stopwatch *)opc->data;
    939936
    940937        struct graphics_gc *curr_color;
    941938        char buffer[32]="00:00:00";
     
    944941        time_t total_sec,total_min,total_hours,total_days;
    945942        total_sec = this->sum_time;
    946943
    947         osd_std_draw(&this->osd_item);
     944        osd_std_draw(&opc->osd_item);
    948945
    949946        if(this->bActive) {
    950947                total_sec += time(0)-this->current_base_time;
     
    961958                (int)total_days, (int)total_hours%24, (int)total_min%60, (int)total_sec%60);
    962959        }
    963960
    964         graphics_get_text_bbox(this->osd_item.gr, this->osd_item.font, buffer, 0x10000, 0, bbox, 0);
    965         p.x=(this->osd_item.w-bbox[2].x)/2;
    966         p.y = this->osd_item.h-this->osd_item.h/10;
     961        graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, buffer, 0x10000, 0, bbox, 0);
     962        p.x=(opc->osd_item.w-bbox[2].x)/2;
     963        p.y = opc->osd_item.h-opc->osd_item.h/10;
    967964
    968965        curr_color = this->bActive?this->white:this->orange;
    969         graphics_draw_text(this->osd_item.gr, curr_color, NULL, this->osd_item.font, buffer, &p, 0x10000, 0);
    970         graphics_draw_mode(this->osd_item.gr, draw_mode_end);
     966        graphics_draw_text(opc->osd_item.gr, curr_color, NULL, opc->osd_item.font, buffer, &p, 0x10000, 0);
     967        graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    971968}
    972969
    973970
    974971static void
    975 osd_stopwatch_click(struct stopwatch *this, struct navit *nav, int pressed, int button, struct point *p)
     972osd_stopwatch_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p)
    976973{
    977         struct point bp = this->osd_item.p;
     974        struct stopwatch *this = (struct stopwatch *)opc->data;
     975
     976        struct point bp = opc->osd_item.p;
    978977        osd_wrap_point(&bp, nav);
    979   if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + this->osd_item.w || p->y > bp.y + this->osd_item.h || !this->osd_item.configured ) && !this->osd_item.pressed)
     978  if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h || !opc->osd_item.configured ) && !opc->osd_item.pressed)
    980979        return;
    981980  if (button != 1)
    982981    return;
    983982  if (navit_ignore_button(nav))
    984983    return;
    985   if (!!pressed == !!this->osd_item.pressed)
     984  if (!!pressed == !!opc->osd_item.pressed)
    986985    return;
    987986
    988987        if (pressed) { //single click handling
     
    10051004        this->last_click_time = time(0);
    10061005        }
    10071006
    1008         osd_stopwatch_draw(this, nav,NULL);
     1007        osd_stopwatch_draw(opc, nav,NULL);
    10091008}
    10101009
    10111010
    10121011static void
    1013 osd_stopwatch_init(struct stopwatch *this, struct navit *nav)
     1012osd_stopwatch_init(struct osd_priv_common *opc, struct navit *nav)
    10141013{
    1015         osd_set_std_graphic(nav, &this->osd_item, (struct osd_priv *)this);
     1014        struct stopwatch *this = (struct stopwatch *)opc->data;
    10161015
    1017         this->orange = graphics_gc_new(this->osd_item.gr);
     1016        osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     1017
     1018        this->orange = graphics_gc_new(opc->osd_item.gr);
    10181019        graphics_gc_set_foreground(this->orange, &this->idle_color);
    10191020        graphics_gc_set_linewidth(this->orange, this->width);
    10201021
    1021         this->white = graphics_gc_new(this->osd_item.gr);
    1022         graphics_gc_set_foreground(this->white, &this->osd_item.text_color);
     1022        this->white = graphics_gc_new(opc->osd_item.gr);
     1023        graphics_gc_set_foreground(this->white, &opc->osd_item.text_color);
    10231024        graphics_gc_set_linewidth(this->white, this->width);
    10241025
    10251026
    1026         graphics_gc_set_linewidth(this->osd_item.graphic_fg_white, this->width);
     1027        graphics_gc_set_linewidth(opc->osd_item.graphic_fg_white, this->width);
    10271028
    1028         event_add_timeout(500, 1, callback_new_1(callback_cast(osd_stopwatch_draw), this));
     1029        event_add_timeout(500, 1, callback_new_1(callback_cast(osd_stopwatch_draw), opc));
    10291030
    1030         navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_stopwatch_click), attr_button, this));
     1031        navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_stopwatch_click), attr_button, opc));
    10311032
    1032         osd_stopwatch_draw(this, nav, NULL);
     1033        osd_stopwatch_draw(opc, nav, NULL);
    10331034}
    10341035
    10351036static struct osd_priv *
     
    10371038                struct attr **attrs)
    10381039{
    10391040        struct stopwatch *this = g_new0(struct stopwatch, 1);
     1041        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     1042        opc->data = (void*)this;
     1043
    10401044        struct attr *attr;
    10411045        struct color orange_color={0xffff,0xa5a5,0x0000,0xffff};
    10421046
    1043         this->osd_item.p.x = 120;
    1044         this->osd_item.p.y = 20;
    1045         this->osd_item.w = 60;
    1046         this->osd_item.h = 80;
    1047         this->osd_item.navit = nav;
    1048         this->osd_item.font_size = 200;
    1049         this->osd_item.meth.draw = osd_draw_cast(osd_stopwatch_draw);
     1047        opc->osd_item.p.x = 120;
     1048        opc->osd_item.p.y = 20;
     1049        opc->osd_item.w = 60;
     1050        opc->osd_item.h = 80;
     1051        opc->osd_item.navit = nav;
     1052        opc->osd_item.font_size = 200;
     1053        opc->osd_item.meth.draw = osd_draw_cast(osd_stopwatch_draw);
     1054        meth->set_attr = set_std_osd_attr;
    10501055
    10511056        this->bActive = 0; //do not count on init
    10521057        this->current_base_time = 0;
    10531058        this->sum_time = 0;
    10541059        this->last_click_time = 0;
    10551060
    1056         osd_set_std_attr(attrs, &this->osd_item, 2);
     1061        osd_set_std_attr(attrs, &opc->osd_item, 2);
    10571062        attr = attr_search(attrs, NULL, attr_width);
    10581063        this->width=attr ? attr->u.num : 2;
    10591064        attr = attr_search(attrs, NULL, attr_idle_color);
     
    10641069        else
    10651070                this->bDisableReset = 0;
    10661071
    1067         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_stopwatch_init), attr_graphics_ready, this));
    1068         return (struct osd_priv *) this;
     1072        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_stopwatch_init), attr_graphics_ready, opc));
     1073        return (struct osd_priv *) opc;
    10691074}
    10701075
    10711076
    10721077static void
    1073 osd_compass_draw(struct compass *this, struct navit *nav,
     1078osd_compass_draw(struct osd_priv_common *opc, struct navit *nav,
    10741079                 struct vehicle *v)
    10751080{
     1081        struct compass *this = (struct compass *)opc->data;
     1082
    10761083        struct point p,bbox[4];
    10771084        struct attr attr_dir, destination_attr, position_attr, imperial_attr;
    10781085        double dir, vdir = 0;
     
    10841091        if (navit_get_attr(nav, attr_imperial, &imperial_attr, NULL))
    10851092                imperial=imperial_attr.u.num;
    10861093
    1087         osd_std_draw(&this->osd_item);
    1088         p.x = this->osd_item.w/2;
    1089         p.y = this->osd_item.w/2;
    1090         graphics_draw_circle(this->osd_item.gr,
    1091                              this->osd_item.graphic_fg_white, &p, this->osd_item.w*5/6);
     1094        osd_std_draw(&opc->osd_item);
     1095        p.x = opc->osd_item.w/2;
     1096        p.y = opc->osd_item.w/2;
     1097        graphics_draw_circle(opc->osd_item.gr,
     1098                             opc->osd_item.graphic_fg_white, &p, opc->osd_item.w*5/6);
    10921099        if (v) {
    10931100                if (vehicle_get_attr(v, attr_position_direction, &attr_dir, NULL)) {
    10941101                        vdir = *attr_dir.u.numd;
    1095                         handle(this->osd_item.gr, this->osd_item.graphic_fg_white, &p, this->osd_item.w/3, -vdir);
     1102                        handle(opc->osd_item.gr, opc->osd_item.graphic_fg_white, &p, opc->osd_item.w/3, -vdir);
    10961103                }
    10971104
    10981105                if (navit_get_attr(nav, attr_destination, &destination_attr, NULL)
     
    11031110                        c2.y = destination_attr.u.pcoord->y;
    11041111                        dir = atan2(c2.x - c1.x, c2.y - c1.y) * 180.0 / M_PI;
    11051112                        dir -= vdir;
    1106                         handle(this->osd_item.gr, this->green, &p, this->osd_item.w/3, dir);
     1113                        handle(opc->osd_item.gr, this->green, &p, opc->osd_item.w/3, dir);
    11071114                        buffer=format_distance(transform_distance(pro, &c1, &c2),"",imperial);
    1108                         graphics_get_text_bbox(this->osd_item.gr, this->osd_item.font, buffer, 0x10000, 0, bbox, 0);
    1109                         p.x=(this->osd_item.w-bbox[2].x)/2;
    1110                         p.y = this->osd_item.h-this->osd_item.h/10;
    1111                         graphics_draw_text(this->osd_item.gr, this->green, NULL, this->osd_item.font, buffer, &p, 0x10000, 0);
     1115                        graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, buffer, 0x10000, 0, bbox, 0);
     1116                        p.x=(opc->osd_item.w-bbox[2].x)/2;
     1117                        p.y = opc->osd_item.h-opc->osd_item.h/10;
     1118                        graphics_draw_text(opc->osd_item.gr, this->green, NULL, opc->osd_item.font, buffer, &p, 0x10000, 0);
    11121119                        g_free(buffer);
    11131120                }
    11141121        }
    1115         graphics_draw_mode(this->osd_item.gr, draw_mode_end);
     1122        graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    11161123}
    11171124
    11181125
    11191126
    11201127static void
    1121 osd_compass_init(struct compass *this, struct navit *nav)
     1128osd_compass_init(struct osd_priv_common *opc, struct navit *nav)
    11221129{
    11231130        struct color c;
    11241131
    1125         osd_set_std_graphic(nav, &this->osd_item, (struct osd_priv *)this);
     1132        struct compass *this = (struct compass *)opc->data;
    11261133
    1127         this->green = graphics_gc_new(this->osd_item.gr);
     1134        osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     1135
     1136        this->green = graphics_gc_new(opc->osd_item.gr);
    11281137        c.r = 0;
    11291138        c.g = 65535;
    11301139        c.b = 0;
    11311140        c.a = 65535;
    11321141        graphics_gc_set_foreground(this->green, &c);
    11331142        graphics_gc_set_linewidth(this->green, this->width);
    1134         graphics_gc_set_linewidth(this->osd_item.graphic_fg_white, this->width);
     1143        graphics_gc_set_linewidth(opc->osd_item.graphic_fg_white, this->width);
    11351144
    1136         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_draw), attr_position_coord_geo, this));
     1145        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_draw), attr_position_coord_geo, opc));
    11371146
    1138         osd_compass_draw(this, nav, NULL);
     1147        osd_compass_draw(opc, nav, NULL);
    11391148}
    11401149
    11411150static struct osd_priv *
     
    11431152                struct attr **attrs)
    11441153{
    11451154        struct compass *this = g_new0(struct compass, 1);
     1155        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     1156        opc->data = (void*)this;
     1157
    11461158        struct attr *attr;
    1147         this->osd_item.p.x = 20;
    1148         this->osd_item.p.y = 20;
    1149         this->osd_item.w = 60;
    1150         this->osd_item.h = 80;
    1151         this->osd_item.navit = nav;
    1152         this->osd_item.font_size = 200;
    1153         this->osd_item.meth.draw = osd_draw_cast(osd_compass_draw);
    1154         osd_set_std_attr(attrs, &this->osd_item, 2);
     1159        opc->osd_item.p.x = 20;
     1160        opc->osd_item.p.y = 20;
     1161        opc->osd_item.w = 60;
     1162        opc->osd_item.h = 80;
     1163        opc->osd_item.navit = nav;
     1164        opc->osd_item.font_size = 200;
     1165        opc->osd_item.meth.draw = osd_draw_cast(osd_compass_draw);
     1166        meth->set_attr = set_std_osd_attr;
     1167        osd_set_std_attr(attrs, &opc->osd_item, 2);
    11551168        attr = attr_search(attrs, NULL, attr_width);
    11561169        this->width=attr ? attr->u.num : 2;
    1157         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_init), attr_graphics_ready, this));
    1158         return (struct osd_priv *) this;
     1170        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_compass_init), attr_graphics_ready, opc));
     1171        return (struct osd_priv *) opc;
    11591172}
    11601173
    11611174struct osd_button {
    11621175        int use_overlay;
    1163         struct osd_item item;
    11641176        struct callback *draw_cb,*navit_init_cb;
    11651177        struct graphics_image *img;
    11661178        char *src;
    11671179};
    11681180
    11691181static void
    1170 osd_button_draw(struct osd_button *this, struct navit *nav)
     1182osd_button_draw(struct osd_priv_common *opc, struct navit *nav)
    11711183{
    1172         struct point bp = this->item.p;
    1173         if (!this->item.configured)
     1184        struct osd_button *this = (struct osd_button *)opc->data;
     1185
     1186        struct point bp = opc->osd_item.p;
     1187        if (!opc->osd_item.configured)
    11741188                return;
    11751189        osd_wrap_point(&bp, nav);
    1176         graphics_draw_image(this->item.gr, this->item.graphic_bg, &bp, this->img);
     1190        graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &bp, this->img);
    11771191}
    11781192
    11791193static void
    1180 osd_button_init(struct osd_button *this, struct navit *nav)
     1194osd_button_init(struct osd_priv_common *opc, struct navit *nav)
    11811195{
     1196        struct osd_button *this = (struct osd_button *)opc->data;
     1197
    11821198        struct graphics *gra = navit_get_graphics(nav);
    11831199        dbg(1, "enter\n");
    11841200        this->img = graphics_image_new(gra, this->src);
     
    11861202                dbg(1, "failed to load '%s'\n", this->src);
    11871203                return;
    11881204        }
    1189         if (!this->item.w)
    1190                 this->item.w=this->img->width;
    1191         if (!this->item.h)
    1192                 this->item.h=this->img->height;
     1205        if (!opc->osd_item.w)
     1206                opc->osd_item.w=this->img->width;
     1207        if (!opc->osd_item.h)
     1208                opc->osd_item.h=this->img->height;
    11931209        if (this->use_overlay) {
    11941210                struct graphics_image *img;
    11951211                struct point p;
    1196                 osd_set_std_graphic(nav, &this->item, (struct osd_priv *)this);
    1197                 img=graphics_image_new(this->item.gr, this->src);
    1198                 p.x=(this->item.w-this->img->width)/2;
    1199                 p.y=(this->item.h-this->img->height)/2;
    1200                 osd_std_draw(&this->item);
    1201                 graphics_draw_image(this->item.gr, this->item.graphic_bg, &p, img);
    1202                 graphics_draw_mode(this->item.gr, draw_mode_end);
    1203                 graphics_image_free(this->item.gr, img);
     1212                osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     1213                img=graphics_image_new(opc->osd_item.gr, this->src);
     1214                p.x=(opc->osd_item.w-this->img->width)/2;
     1215                p.y=(opc->osd_item.h-this->img->height)/2;
     1216                osd_std_draw(&opc->osd_item);
     1217                graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
     1218                graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
     1219                graphics_image_free(opc->osd_item.gr, img);
    12041220        } else {
    1205                 osd_set_std_config(nav, &this->item);
    1206                 this->item.gr=gra;
    1207                 this->item.graphic_bg=graphics_gc_new(this->item.gr);
    1208                 graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_button_draw), attr_postdraw, this, nav));
     1221                osd_set_std_config(nav, &opc->osd_item);
     1222                opc->osd_item.gr=gra;
     1223                opc->osd_item.graphic_bg=graphics_gc_new(opc->osd_item.gr);
     1224                graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_button_draw), attr_postdraw, opc, nav));
    12091225        }
    1210         navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_std_click), attr_button, &this->item));
    1211         osd_button_draw(this,nav);
     1226        navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_std_click), attr_button, &opc->osd_item));
     1227        osd_button_draw(opc,nav);
    12121228}
    12131229 
    12141230int
    1215 osd_button_set_attr(struct osd_button *this_, struct attr* attr)
     1231osd_button_set_attr(struct osd_priv_common *opc, struct attr* attr)
    12161232{
     1233        struct osd_button *this_ = (struct osd_button *)opc->data;
     1234
    12171235        if(NULL==attr || NULL==this_) {
    12181236                return 0;
    12191237        }       
     
    12261244                if(attr->u.str) {
    12271245                        this_->src = graphics_icon_path(attr->u.str);
    12281246                }
    1229                 nav = this_->item.navit;
     1247                nav = opc->osd_item.navit;
    12301248                gra = navit_get_graphics(nav);
    12311249                this_->img = graphics_image_new(gra, this_->src);
    12321250                if (!this_->img) {
    12331251                        dbg(1, "failed to load '%s'\n", this_->src);
    12341252                        return 0;
    12351253                }
    1236                 if (!this_->item.w)
    1237                         this_->item.w=this_->img->width;
    1238                 if (!this_->item.h)
    1239                         this_->item.h=this_->img->height;
     1254                if (!opc->osd_item.w)
     1255                        opc->osd_item.w=this_->img->width;
     1256                if (!opc->osd_item.h)
     1257                        opc->osd_item.h=this_->img->height;
    12401258 
    12411259                if (this_->use_overlay) {
    12421260                        struct graphics_image *img;
    12431261                        struct point p;
    1244                         img=graphics_image_new(this_->item.gr, this_->src);
    1245                         p.x=(this_->item.w-this_->img->width)/2;
    1246                         p.y=(this_->item.h-this_->img->height)/2;
    1247                         osd_std_draw(&this_->item);
    1248                         graphics_draw_image(this_->item.gr, this_->item.graphic_bg, &p, img);
    1249                         graphics_image_free(this_->item.gr, img);
     1262                        img=graphics_image_new(opc->osd_item.gr, this_->src);
     1263                        p.x=(opc->osd_item.w-this_->img->width)/2;
     1264                        p.y=(opc->osd_item.h-this_->img->height)/2;
     1265                        osd_std_draw(&opc->osd_item);
     1266                        graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
     1267                        graphics_image_free(opc->osd_item.gr, img);
    12501268                }
    1251                 osd_button_draw(this_,nav);
    1252                 navit_draw(this_->item.navit);
     1269                osd_button_draw(opc,nav);
     1270                navit_draw(opc->osd_item.navit);
    12531271                return 1;
    12541272        }
    12551273        return 0;
     
    12621280               struct attr **attrs)
    12631281{
    12641282        struct osd_button *this = g_new0(struct osd_button, 1);
     1283        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     1284        opc->data = (void*)this;
     1285
    12651286        struct attr *attr;
    12661287
    1267         this->item.navit = nav;
    1268         this->item.meth.draw = osd_draw_cast(osd_button_draw);
     1288        opc->osd_item.navit = nav;
     1289        opc->osd_item.meth.draw = osd_draw_cast(osd_button_draw);
    12691290
    1270         meth->set_attr = osd_button_set_attr;
     1291        meth->set_attr = set_std_osd_attr;
     1292        opc->spec_set_attr_func = osd_button_set_attr;
    12711293
    1272         osd_set_std_attr(attrs, &this->item, 1|16);
     1294        osd_set_std_attr(attrs, &opc->osd_item, 1|16);
    12731295
    12741296        attr=attr_search(attrs, NULL, attr_use_overlay);
    12751297        if (attr)
    12761298                this->use_overlay=attr->u.num;
    1277         if (!this->item.command) {
     1299        if (!opc->osd_item.command) {
    12781300                dbg(0, "no command\n");
    12791301                goto error;
    12801302        }
     
    12861308
    12871309        this->src = graphics_icon_path(attr->u.str);
    12881310
    1289         navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_button_init), attr_graphics_ready, this));
     1311        navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_button_init), attr_graphics_ready, opc));
    12901312
    12911313        if(b_commandtable_added == 0) {
    12921314                navit_command_add_table(nav, commands, sizeof(commands)/sizeof(struct command_table));
    12931315                b_commandtable_added = 1;
    12941316        }
    12951317
    1296         return (struct osd_priv *) this;
     1318        return (struct osd_priv *) opc;
    12971319      error:
    12981320        g_free(this);
     1321        g_free(opc);
    12991322        return NULL;
    13001323}
    13011324
    13021325struct osd_image {
    13031326        int use_overlay;
    1304         struct osd_item item;
    13051327        struct callback *draw_cb,*navit_init_cb;
    13061328        struct graphics_image *img;
    13071329        char *src;
    13081330};
    13091331
    13101332static void
    1311 osd_image_draw(struct osd_image *this, struct navit *nav)
     1333osd_image_draw(struct osd_priv_common *opc, struct navit *nav)
    13121334{
    1313         struct point bp = this->item.p;
     1335        struct osd_button *this = (struct osd_button *)opc->data;
     1336
     1337        struct point bp = opc->osd_item.p;
    13141338        osd_wrap_point(&bp, nav);
    1315         graphics_draw_image(this->item.gr, this->item.graphic_bg, &bp, this->img);
     1339        graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &bp, this->img);
    13161340}
    13171341
    13181342static void
    1319 osd_image_init(struct osd_image *this, struct navit *nav)
     1343osd_image_init(struct osd_priv_common *opc, struct navit *nav)
    13201344{
     1345        struct osd_button *this = (struct osd_button *)opc->data;
     1346
    13211347        struct graphics *gra = navit_get_graphics(nav);
    13221348        dbg(1, "enter\n");
    13231349        this->img = graphics_image_new(gra, this->src);
     
    13251351                dbg(1, "failed to load '%s'\n", this->src);
    13261352                return;
    13271353        }
    1328         if (!this->item.w)
    1329                 this->item.w=this->img->width;
    1330         if (!this->item.h)
    1331                 this->item.h=this->img->height;
     1354        if (!opc->osd_item.w)
     1355                opc->osd_item.w=this->img->width;
     1356        if (!opc->osd_item.h)
     1357                opc->osd_item.h=this->img->height;
    13321358        if (this->use_overlay) {
    13331359                struct graphics_image *img;
    13341360                struct point p;
    1335                 osd_set_std_graphic(nav, &this->item, (struct osd_priv *)this);
    1336                 img=graphics_image_new(this->item.gr, this->src);
    1337                 p.x=(this->item.w-this->img->width)/2;
    1338                 p.y=(this->item.h-this->img->height)/2;
    1339                 osd_std_draw(&this->item);
    1340                 graphics_draw_image(this->item.gr, this->item.graphic_bg, &p, img);
    1341                 graphics_draw_mode(this->item.gr, draw_mode_end);
    1342                 graphics_image_free(this->item.gr, img);
     1361                osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     1362                img=graphics_image_new(opc->osd_item.gr, this->src);
     1363                p.x=(opc->osd_item.w-this->img->width)/2;
     1364                p.y=(opc->osd_item.h-this->img->height)/2;
     1365                osd_std_draw(&opc->osd_item);
     1366                graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
     1367                graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
     1368                graphics_image_free(opc->osd_item.gr, img);
    13431369        } else {
    1344                 this->item.configured=1;
    1345                 this->item.gr=gra;
    1346                 this->item.graphic_bg=graphics_gc_new(this->item.gr);
    1347                 graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_button_draw), attr_postdraw, this, nav));
     1370                opc->osd_item.configured=1;
     1371                opc->osd_item.gr=gra;
     1372                opc->osd_item.graphic_bg=graphics_gc_new(opc->osd_item.gr);
     1373                graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_button_draw), attr_postdraw, opc, nav));
    13481374        }
    1349         osd_image_draw(this,nav);
     1375        osd_image_draw(opc,nav);
    13501376}
    13511377
    13521378static struct osd_priv *
     
    13541380               struct attr **attrs)
    13551381{
    13561382        struct osd_image *this = g_new0(struct osd_image, 1);
     1383        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     1384        opc->data = (void*)this;
     1385
    13571386        struct attr *attr;
    13581387
    1359         this->item.navit = nav;
    1360         this->item.meth.draw = osd_draw_cast(osd_image_draw);
     1388        opc->osd_item.navit = nav;
     1389        opc->osd_item.meth.draw = osd_draw_cast(osd_image_draw);
     1390        meth->set_attr = set_std_osd_attr;
    13611391
    1362         osd_set_std_attr(attrs, &this->item, 1);
     1392        osd_set_std_attr(attrs, &opc->osd_item, 1);
    13631393
    13641394        attr=attr_search(attrs, NULL, attr_use_overlay);
    13651395        if (attr)
     
    13721402
    13731403        this->src = graphics_icon_path(attr->u.str);
    13741404
    1375         navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_image_init), attr_graphics_ready, this));
     1405        navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_image_init), attr_graphics_ready, opc));
    13761406
    13771407        return (struct osd_priv *) this;
    13781408      error:
     
    13811411}
    13821412
    13831413struct nav_next_turn {
    1384         struct osd_item osd_item;
    13851414        char *test_text;
    13861415        char *icon_src;
    13871416        int icon_h, icon_w, active;
     
    13901419};
    13911420
    13921421static void
    1393 osd_nav_next_turn_draw(struct nav_next_turn *this, struct navit *navit,
     1422osd_nav_next_turn_draw(struct osd_priv_common *opc, struct navit *navit,
    13941423                       struct vehicle *v)
    13951424{
     1425        struct nav_next_turn *this = (struct nav_next_turn *)opc->data;
     1426
    13961427        struct point p;
    13971428        int do_draw = 0;
    13981429        struct navigation *nav = NULL;
     
    14311462                map_rect_destroy(mr);
    14321463
    14331464        if (do_draw) {
    1434                 osd_std_draw(&this->osd_item);
     1465                osd_std_draw(&opc->osd_item);
    14351466                if (this->active) {
    14361467                        image = g_strdup_printf(this->icon_src, name);
    14371468                        dbg(1, "image=%s\n", image);
    14381469                        gr_image =
    1439                             graphics_image_new_scaled(this->osd_item.gr,
     1470                            graphics_image_new_scaled(opc->osd_item.gr,
    14401471                                                      image, this->icon_w,
    14411472                                                      this->icon_h);
    14421473                        if (!gr_image) {
     
    14441475                                g_free(image);
    14451476                                image = graphics_icon_path("unknown.xpm");
    14461477                                gr_image =
    1447                                     graphics_image_new_scaled(this->
     1478                                    graphics_image_new_scaled(opc->
    14481479                                                              osd_item.gr,
    14491480                                                              image,
    14501481                                                              this->icon_w,
     
    14541485                        dbg(1, "gr_image=%p\n", gr_image);
    14551486                        if (gr_image) {
    14561487                                p.x =
    1457                                     (this->osd_item.w -
     1488                                    (opc->osd_item.w -
    14581489                                     gr_image->width) / 2;
    14591490                                p.y =
    1460                                     (this->osd_item.h -
     1491                                    (opc->osd_item.h -
    14611492                                     gr_image->height) / 2;
    1462                                 graphics_draw_image(this->osd_item.gr,
    1463                                                     this->osd_item.
     1493                                graphics_draw_image(opc->osd_item.gr,
     1494                                                    opc->osd_item.
    14641495                                                    graphic_fg_white, &p,
    14651496                                                    gr_image);
    1466                                 graphics_image_free(this->osd_item.gr,
     1497                                graphics_image_free(opc->osd_item.gr,
    14671498                                                    gr_image);
    14681499                        }
    14691500                        g_free(image);
    14701501                }
    1471                 graphics_draw_mode(this->osd_item.gr, draw_mode_end);
     1502                graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    14721503        }
    14731504}
    14741505
    14751506static void
    1476 osd_nav_next_turn_init(struct nav_next_turn *this, struct navit *nav)
     1507osd_nav_next_turn_init(struct osd_priv_common *opc, struct navit *nav)
    14771508{
    1478         osd_set_std_graphic(nav, &this->osd_item, (struct osd_priv *)this);
    1479         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_next_turn_draw), attr_position_coord_geo, this));
    1480         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_std_click), attr_button, &this->osd_item));
    1481         osd_nav_next_turn_draw(this, nav, NULL);
     1509        osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     1510        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_next_turn_draw), attr_position_coord_geo, opc));
     1511        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_std_click), attr_button, &opc->osd_item));
     1512        osd_nav_next_turn_draw(opc, nav, NULL);
    14821513}
    14831514
    14841515static struct osd_priv *
     
    14861517                      struct attr **attrs)
    14871518{
    14881519        struct nav_next_turn *this = g_new0(struct nav_next_turn, 1);
     1520        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     1521        opc->data = (void*)this;
     1522
    14891523        struct attr *attr;
    14901524
    1491         this->osd_item.p.x = 20;
    1492         this->osd_item.p.y = -80;
    1493         this->osd_item.w = 70;
    1494         this->osd_item.navit = nav;
    1495         this->osd_item.h = 70;
    1496         this->osd_item.font_size = 200;
    1497         this->osd_item.meth.draw = osd_draw_cast(osd_nav_next_turn_draw);
    1498         osd_set_std_attr(attrs, &this->osd_item, 0);
     1525        opc->osd_item.p.x = 20;
     1526        opc->osd_item.p.y = -80;
     1527        opc->osd_item.w = 70;
     1528        opc->osd_item.navit = nav;
     1529        opc->osd_item.h = 70;
     1530        opc->osd_item.font_size = 200;
     1531        opc->osd_item.meth.draw = osd_draw_cast(osd_nav_next_turn_draw);
     1532        meth->set_attr = set_std_osd_attr;
     1533        osd_set_std_attr(attrs, &opc->osd_item, 0);
    14991534
    15001535        this->icon_w = -1;
    15011536        this->icon_h = -1;
     
    15261561        if (attr)
    15271562                this->level=attr->u.num;
    15281563
    1529         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_next_turn_init), attr_graphics_ready, this));
    1530         return (struct osd_priv *) this;
     1564        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_next_turn_init), attr_graphics_ready, opc));
     1565        return (struct osd_priv *) opc;
    15311566}
    15321567
    15331568struct nav_toggle_announcer
    15341569{
    15351570        int w,h;
    15361571        struct callback *navit_init_cb;
    1537         struct osd_item item;
    15381572        char *icon_src;
    15391573        int icon_h, icon_w, active, last_state;
    15401574};
    15411575
    15421576static void
    1543 osd_nav_toggle_announcer_draw(struct nav_toggle_announcer *this, struct navit *navit, struct vehicle *v)
     1577osd_nav_toggle_announcer_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v)
    15441578{
     1579        struct nav_toggle_announcer *this = (struct nav_toggle_announcer *)opc->data;
     1580
    15451581        struct point p;
    15461582        int do_draw = 0;
    15471583        struct graphics_image *gr_image;
     
    15671603
    15681604        if (do_draw)
    15691605    {
    1570                 graphics_draw_mode(this->item.gr, draw_mode_begin);
     1606                graphics_draw_mode(opc->osd_item.gr, draw_mode_begin);
    15711607                p.x = 0;
    15721608                p.y = 0;
    1573                 graphics_draw_rectangle(this->item.gr, this->item.graphic_bg, &p, this->item.w, this->item.h);
     1609                graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, opc->osd_item.w, opc->osd_item.h);
    15741610
    15751611                if (this->active)
    15761612            path = g_strdup_printf(this->icon_src, gui_sound_on);
    15771613        else
    15781614            path = g_strdup_printf(this->icon_src, gui_sound_off);
    15791615       
    1580         gr_image = graphics_image_new_scaled(this->item.gr, path, this->icon_w, this->icon_h);
     1616        gr_image = graphics_image_new_scaled(opc->osd_item.gr, path, this->icon_w, this->icon_h);
    15811617        if (!gr_image)
    15821618        {
    15831619            g_free(path);
    15841620            path = graphics_icon_path("unknown.xpm");
    1585             gr_image = graphics_image_new_scaled(this->item.gr, path, this->icon_w, this->icon_h);
     1621            gr_image = graphics_image_new_scaled(opc->osd_item.gr, path, this->icon_w, this->icon_h);
    15861622        }
    15871623       
    15881624        dbg(1, "gr_image=%p\n", gr_image);
    15891625       
    15901626        if (gr_image)
    15911627        {
    1592             p.x = (this->item.w - gr_image->width) / 2;
    1593             p.y = (this->item.h - gr_image->height) / 2;
    1594             graphics_draw_image(this->item.gr, this->item.graphic_fg_white, &p, gr_image);
    1595             graphics_image_free(this->item.gr, gr_image);
     1628            p.x = (opc->osd_item.w - gr_image->width) / 2;
     1629            p.y = (opc->osd_item.h - gr_image->height) / 2;
     1630            graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_fg_white, &p, gr_image);
     1631            graphics_image_free(opc->osd_item.gr, gr_image);
    15961632        }
    15971633       
    15981634        g_free(path);
    1599                 graphics_draw_mode(this->item.gr, draw_mode_end);
     1635                graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    16001636        }
    16011637}
    16021638
    16031639static void
    1604 osd_nav_toggle_announcer_init(struct nav_toggle_announcer *this, struct navit *nav)
     1640osd_nav_toggle_announcer_init(struct osd_priv_common *opc, struct navit *nav)
    16051641{
    1606         osd_set_std_graphic(nav, &this->item, (struct osd_priv *)this);
    1607         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_toggle_announcer_draw), attr_speech, this));
    1608     navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast(osd_std_click), attr_button, &this->item));
    1609         osd_nav_toggle_announcer_draw(this, nav, NULL);
     1642        struct nav_toggle_announcer *this = (struct nav_toggle_announcer *)opc->data;
     1643
     1644        osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     1645        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_toggle_announcer_draw), attr_speech, opc));
     1646    navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast(osd_std_click), attr_button, &opc->osd_item));
     1647        osd_nav_toggle_announcer_draw(opc, nav, NULL);
    16101648}
    16111649
    16121650static struct osd_priv *
    16131651osd_nav_toggle_announcer_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
    16141652{
    16151653        struct nav_toggle_announcer *this = g_new0(struct nav_toggle_announcer, 1);
    1616     struct attr *attr;
    1617     char *command = "announcer_toggle()";
     1654        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     1655        opc->data = (void*)this;
     1656        struct attr *attr;
     1657        char *command = "announcer_toggle()";
    16181658
    1619         this->item.w = 48;
    1620         this->item.h = 48;
    1621         this->item.p.x = -64;
    1622         this->item.navit = nav;
    1623         this->item.p.y = 76;
    1624         this->item.meth.draw = osd_draw_cast(osd_nav_toggle_announcer_draw);
     1659        opc->osd_item.w = 48;
     1660        opc->osd_item.h = 48;
     1661        opc->osd_item.p.x = -64;
     1662        opc->osd_item.navit = nav;
     1663        opc->osd_item.p.y = 76;
     1664        opc->osd_item.meth.draw = osd_draw_cast(osd_nav_toggle_announcer_draw);
     1665        meth->set_attr = set_std_osd_attr;
    16251666
    1626         osd_set_std_attr(attrs, &this->item, 0);
     1667        osd_set_std_attr(attrs, &opc->osd_item, 0);
    16271668
    16281669        this->icon_w = -1;
    16291670        this->icon_h = -1;
    1630     this->last_state = -1;
     1671        this->last_state = -1;
    16311672
    1632     attr = attr_search(attrs, NULL, attr_icon_src);
     1673        attr = attr_search(attrs, NULL, attr_icon_src);
    16331674        if (attr) {
    16341675                struct file_wordexp *we;
    16351676                char **array;
     
    16401681        } else
    16411682                this->icon_src = graphics_icon_path("%s_32.xpm");
    16421683
    1643     this->item.command = g_strdup(command);
     1684        opc->osd_item.command = g_strdup(command);
    16441685
    1645         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_toggle_announcer_init), attr_graphics_ready, this));
    1646         return (struct osd_priv *) this;
     1686        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_nav_toggle_announcer_init), attr_graphics_ready, opc));
     1687        return (struct osd_priv *) opc;
    16471688}
    16481689
    16491690enum osd_speed_warner_eAnnounceState {eNoWarn=0,eWarningTold=1};
     
    16621703};
    16631704
    16641705struct osd_speed_cam {
    1665   struct osd_item item;
    16661706  int width;
    16671707  struct graphics_gc *white,*orange;
    16681708  struct graphics_gc *red;
     
    16831723}
    16841724
    16851725static void
    1686 osd_speed_cam_draw(struct osd_speed_cam *this_, struct navit *navit, struct vehicle *v)
     1726osd_speed_cam_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v)
    16871727{
     1728  struct osd_speed_cam *this_ = (struct osd_speed_cam *)opc->data;
     1729
    16881730  struct attr position_attr,vehicle_attr,imperial_attr;
    16891731  struct point p, bbox[4];
    16901732  struct attr speed_attr;
     
    18021844    dCurrDist = transform_distance(projection_mg, &curr_coord, &cam_coord);
    18031845    ret_attr = vehicle_get_attr(curr_vehicle,attr_position_speed,&speed_attr, NULL);
    18041846    if(0==ret_attr) {
    1805       graphics_overlay_disable(this_->item.gr,1);
     1847      graphics_overlay_disable(opc->osd_item.gr,1);
    18061848      return;
    18071849    }
    1808     graphics_overlay_disable(this_->item.gr,0);
     1850    if (opc->osd_item.configured) {
     1851            graphics_overlay_disable(opc->osd_item.gr,0);
     1852        }
    18091853    speed = *speed_attr.u.numd;
    18101854    if(dCurrDist <= speed*750.0/130.0) {  //at speed 130 distance limit is 750m
    18111855      if(this_->announce_state==eNoWarn && this_->announce_on) {
     
    18251869      buffer [0] = 0;
    18261870      buffer2[0] = 0;
    18271871 
    1828       osd_std_draw(&this_->item);
     1872      osd_std_draw(&opc->osd_item);
    18291873
    18301874      str_replace(buffer,this_->text,"${distance}",format_distance(dCurrDist,"",imperial));
    18311875      str_replace(buffer2,buffer,"${camera_type}",(0<=idx && idx<=CAM_TRAFFIPAX)?camera_t_strs[idx]:"");
     
    18351879      str_replace(buffer2,buffer,"${direction}",dir_str);
    18361880      str_replace(buffer,buffer2,"${speed_limit}",spd_str);
    18371881 
    1838       graphics_get_text_bbox(this_->item.gr, this_->item.font, buffer, 0x10000, 0, bbox, 0);
    1839       p.x=(this_->item.w-bbox[2].x)/2;
    1840       p.y = this_->item.h-this_->item.h/10;
     1882      graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, buffer, 0x10000, 0, bbox, 0);
     1883      p.x=(opc->osd_item.w-bbox[2].x)/2;
     1884      p.y = opc->osd_item.h-opc->osd_item.h/10;
    18411885      curr_color = this_->orange;
    18421886      //tolerance is +-20 degrees
    18431887      if(
     
    18581902      else if(dCurrDist <= speed*750.0/130.0) {
    18591903        curr_color = this_->red;
    18601904      }
    1861       draw_multiline_osd_text(buffer,&this_->item, curr_color);
    1862       graphics_draw_mode(this_->item.gr, draw_mode_end);
     1905      draw_multiline_osd_text(buffer,&opc->osd_item, curr_color);
     1906      graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    18631907    }
    18641908  }
    18651909  else {
    1866     graphics_overlay_disable(this_->item.gr,1);
     1910    graphics_overlay_disable(opc->osd_item.gr,1);
    18671911  }
    18681912}
    18691913
    18701914static void
    1871 osd_speed_cam_init(struct osd_speed_cam *this, struct navit *nav)
     1915osd_speed_cam_init(struct osd_priv_common *opc, struct navit *nav)
    18721916{
     1917  struct osd_speed_cam *this = (struct osd_speed_cam *)opc->data;
     1918
    18731919  struct color red_color={0xffff,0x0000,0x0000,0xffff};
    1874   osd_set_std_graphic(nav, &this->item, (struct osd_priv *)this);
     1920  osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
    18751921
    1876   this->red = graphics_gc_new(this->item.gr);
     1922  this->red = graphics_gc_new(opc->osd_item.gr);
    18771923  graphics_gc_set_foreground(this->red, &red_color);
    18781924  graphics_gc_set_linewidth(this->red, this->width);
    18791925
    1880   this->orange = graphics_gc_new(this->item.gr);
     1926  this->orange = graphics_gc_new(opc->osd_item.gr);
    18811927  graphics_gc_set_foreground(this->orange, &this->idle_color);
    18821928  graphics_gc_set_linewidth(this->orange, this->width);
    18831929
    1884   this->white = graphics_gc_new(this->item.gr);
    1885   graphics_gc_set_foreground(this->white, &this->item.text_color);
     1930  this->white = graphics_gc_new(opc->osd_item.gr);
     1931  graphics_gc_set_foreground(this->white, &opc->osd_item.text_color);
    18861932  graphics_gc_set_linewidth(this->white, this->width);
    18871933
    18881934
    1889   graphics_gc_set_linewidth(this->item.graphic_fg_white, this->width);
     1935  graphics_gc_set_linewidth(opc->osd_item.graphic_fg_white, this->width);
    18901936
    1891   navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_cam_draw), attr_position_coord_geo, this));
     1937  navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_cam_draw), attr_position_coord_geo, opc));
    18921938
    18931939}
    18941940
     
    18991945  struct color default_color={0xffff,0xa5a5,0x0000,0xffff};
    19001946
    19011947  struct osd_speed_cam *this = g_new0(struct osd_speed_cam, 1);
     1948  struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     1949  opc->data = (void*)this;
     1950
    19021951  struct attr *attr;
    1903   this->item.p.x = 120;
    1904   this->item.p.y = 20;
    1905   this->item.w = 60;
    1906   this->item.h = 80;
    1907   this->item.navit = nav;
    1908   this->item.font_size = 200;
    1909   this->item.meth.draw = osd_draw_cast(osd_speed_cam_draw);
     1952  opc->osd_item.p.x = 120;
     1953  opc->osd_item.p.y = 20;
     1954  opc->osd_item.w = 60;
     1955  opc->osd_item.h = 80;
     1956  opc->osd_item.navit = nav;
     1957  opc->osd_item.font_size = 200;
     1958  opc->osd_item.meth.draw = osd_draw_cast(osd_speed_cam_draw);
     1959  meth->set_attr = set_std_osd_attr;
    19101960
    1911   osd_set_std_attr(attrs, &this->item, 2);
     1961  osd_set_std_attr(attrs, &opc->osd_item, 2);
    19121962  attr = attr_search(attrs, NULL, attr_width);
    19131963  this->width=attr ? attr->u.num : 2;
    19141964  attr = attr_search(attrs, NULL, attr_idle_color);
     
    19291979    this->announce_on = 1;    //announce by default
    19301980  }
    19311981
    1932   navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_cam_init), attr_graphics_ready, this));
    1933   return (struct osd_priv *) this;
     1982  navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_cam_init), attr_graphics_ready, opc));
     1983  return (struct osd_priv *) opc;
    19341984}
    19351985
    19361986struct osd_speed_warner {
    1937         struct osd_item item;
    19381987        struct graphics_gc *red;
    19391988        struct graphics_gc *green;
    19401989        struct graphics_gc *grey;
     
    19532002};
    19542003
    19552004static void
    1956 osd_speed_warner_draw(struct osd_speed_warner *this, struct navit *navit, struct vehicle *v)
     2005osd_speed_warner_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v)
    19572006{
     2007    struct osd_speed_warner *this = (struct osd_speed_warner *)opc->data;
     2008
    19582009    struct point p,bbox[4];
    19592010    char text[16]="";
    19602011
     
    19632014    struct graphics_image *img = this->img_off;
    19642015
    19652016
    1966     osd_std_draw(&this->item);
    1967     p.x=this->item.w/2-this->d/4;
    1968     p.y=this->item.h/2-this->d/4;
    1969     p.x=this->item.w/2;
    1970     p.y=this->item.h/2;
     2017    osd_std_draw(&opc->osd_item);
     2018    p.x=opc->osd_item.w/2-this->d/4;
     2019    p.y=opc->osd_item.h/2-this->d/4;
     2020    p.x=opc->osd_item.w/2;
     2021    p.y=opc->osd_item.h/2;
    19712022
    19722023    if (navit) {
    19732024        tracking = navit_get_tracking(navit);
     
    20392090    }
    20402091    if(this->img_active && this->img_passive && this->img_off) {
    20412092      struct point p;
    2042       p.x=(this->item.w-img->width)/2;
    2043       p.y=(this->item.h-img->height)/2;
    2044       graphics_draw_image(this->item.gr, this->item.graphic_bg, &p, img);
     2093      p.x=(opc->osd_item.w-img->width)/2;
     2094      p.y=(opc->osd_item.h-img->height)/2;
     2095      graphics_draw_image(opc->osd_item.gr, opc->osd_item.graphic_bg, &p, img);
    20452096    }
    20462097    else if(0==this->bTextOnly) {
    2047       graphics_draw_circle(this->item.gr, osd_color, &p, this->d-this->width*2 );
     2098      graphics_draw_circle(opc->osd_item.gr, osd_color, &p, this->d-this->width*2 );
    20482099    }
    2049         graphics_get_text_bbox(this->item.gr, this->item.font, text, 0x10000, 0, bbox, 0);
    2050         p.x=(this->item.w-bbox[2].x)/2;
    2051         p.y=(this->item.h+bbox[2].y)/2-bbox[2].y;
    2052         graphics_draw_text(this->item.gr, osd_color, NULL, this->item.font, text, &p, 0x10000, 0);
    2053         graphics_draw_mode(this->item.gr, draw_mode_end);
     2100        graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, text, 0x10000, 0, bbox, 0);
     2101        p.x=(opc->osd_item.w-bbox[2].x)/2;
     2102        p.y=(opc->osd_item.h+bbox[2].y)/2-bbox[2].y;
     2103        graphics_draw_text(opc->osd_item.gr, osd_color, NULL, opc->osd_item.font, text, &p, 0x10000, 0);
     2104        graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    20542105}
    20552106
    20562107static void
    2057 osd_speed_warner_init(struct osd_speed_warner *this, struct navit *nav)
     2108osd_speed_warner_init(struct osd_priv_common *opc, struct navit *nav)
    20582109{
     2110        struct osd_speed_warner *this = (struct osd_speed_warner *)opc->data;
     2111
    20592112        struct color white_color={0xffff,0xffff,0xffff,0x0000};
    20602113        struct color red_color={0xffff,0,0,0xffff};
    20612114        struct color green_color={0,0xffff,0,0xffff};
    20622115        struct color grey_color={0x8888,0x8888,0x8888,0x8888};
    20632116        struct color black_color={0x1111,0x1111,0x1111,0x9999};
    20642117
    2065         osd_set_std_graphic(nav, &this->item, (struct osd_priv *)this);
    2066         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_warner_draw), attr_position_coord_geo, this));
     2118        osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     2119        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_warner_draw), attr_position_coord_geo, opc));
    20672120
    20682121        if(this->label_str && !strncmp("images:",this->label_str,7)) {
    20692122          char *tok1=NULL, *tok2=NULL, *tok3=NULL;
     
    20792132            tok1 = graphics_icon_path(tok1);
    20802133            tok2 = graphics_icon_path(tok2);
    20812134            tok3 = graphics_icon_path(tok3);
    2082             this->img_active  = graphics_image_new(this->item.gr, tok1);
    2083             this->img_passive = graphics_image_new(this->item.gr, tok2);
    2084             this->img_off     = graphics_image_new(this->item.gr, tok3);
     2135            this->img_active  = graphics_image_new(opc->osd_item.gr, tok1);
     2136            this->img_passive = graphics_image_new(opc->osd_item.gr, tok2);
     2137            this->img_off     = graphics_image_new(opc->osd_item.gr, tok3);
    20852138            g_free(tok1);   
    20862139            g_free(tok2);   
    20872140            g_free(tok3);   
     
    20912144        g_free(this->label_str);
    20922145        this->label_str = NULL;
    20932146
    2094         this->white=graphics_gc_new(this->item.gr);
     2147        this->white=graphics_gc_new(opc->osd_item.gr);
    20952148        graphics_gc_set_foreground(this->white, &white_color);
    20962149
    20972150        graphics_gc_set_linewidth(this->white, this->d/2-2 /*-this->width*/ );
    20982151
    2099         this->red=graphics_gc_new(this->item.gr);
     2152        this->red=graphics_gc_new(opc->osd_item.gr);
    21002153        graphics_gc_set_foreground(this->red, &red_color);
    21012154        graphics_gc_set_linewidth(this->red, this->width);
    21022155
    2103         this->green=graphics_gc_new(this->item.gr);
     2156        this->green=graphics_gc_new(opc->osd_item.gr);
    21042157        graphics_gc_set_foreground(this->green, &green_color);
    21052158        graphics_gc_set_linewidth(this->green, this->width-2);
    21062159
    2107         this->grey=graphics_gc_new(this->item.gr);
     2160        this->grey=graphics_gc_new(opc->osd_item.gr);
    21082161        graphics_gc_set_foreground(this->grey, &grey_color);
    21092162        graphics_gc_set_linewidth(this->grey, this->width);
    21102163
    2111         this->black=graphics_gc_new(this->item.gr);
     2164        this->black=graphics_gc_new(opc->osd_item.gr);
    21122165        graphics_gc_set_foreground(this->black, &black_color);
    21132166        graphics_gc_set_linewidth(this->black, this->width);
    21142167
    2115         osd_speed_warner_draw(this, nav, NULL);
     2168        osd_speed_warner_draw(opc, nav, NULL);
    21162169}
    21172170
    21182171static struct osd_priv *
    21192172osd_speed_warner_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
    21202173{
    21212174        struct osd_speed_warner *this=g_new0(struct osd_speed_warner, 1);
     2175        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     2176        opc->data = (void*)this;
     2177
    21222178        struct attr *attr;
    2123         this->item.p.x=-80;
    2124         this->item.p.y=20;
    2125         this->item.w=60;
    2126         this->item.navit = nav;
    2127         this->item.h=60;
     2179        opc->osd_item.p.x=-80;
     2180        opc->osd_item.p.y=20;
     2181        opc->osd_item.w=60;
     2182        opc->osd_item.navit = nav;
     2183        opc->osd_item.h=60;
    21282184        this->active=-1;
    2129         this->item.meth.draw = osd_draw_cast(osd_speed_warner_draw);
     2185        opc->osd_item.meth.draw = osd_draw_cast(osd_speed_warner_draw);
     2186        meth->set_attr = set_std_osd_attr;
    21302187
    21312188        attr = attr_search(attrs, NULL, attr_speed_exceed_limit_offset);
    21322189        if (attr) {
     
    21542211                this->announce_on = attr->u.num;
    21552212        else
    21562213                this->announce_on = 1;    //announce by default
    2157         osd_set_std_attr(attrs, &this->item, 2);
    2158         this->d=this->item.w;
    2159         if (this->item.h < this->d)
    2160                 this->d=this->item.h;
     2214        osd_set_std_attr(attrs, &opc->osd_item, 2);
     2215        this->d=opc->osd_item.w;
     2216        if (opc->osd_item.h < this->d)
     2217                this->d=opc->osd_item.h;
    21612218        this->width=this->d/10;
    2162         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_warner_init), attr_graphics_ready, this));
    2163         return (struct osd_priv *) this;
     2219        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_speed_warner_init), attr_graphics_ready, opc));
     2220        return (struct osd_priv *) opc;
    21642221}
    21652222
    21662223struct osd_text_item {
     
    21762233};
    21772234
    21782235struct osd_text {
    2179         struct osd_item osd_item;
    21802236        int active;
    21812237        char *text;
    21822238        int align;
     
    22092265        case attr_position_direction:
    22102266                return format_float_0(*attr->u.numd);
    22112267        case attr_position_magnetic_direction:
    2212                 return g_strdup_printf("%d",attr->u.num);
     2268                return g_strdup_printf("%ld",attr->u.num);
    22132269        case attr_position_coord_geo:
    22142270                if ((!format) || (!strcmp(format,"pos_degminsec")))
    22152271                {
     
    23852441}
    23862442
    23872443static void
    2388 osd_text_draw(struct osd_text *this, struct navit *navit, struct vehicle *v)
     2444osd_text_draw(struct osd_priv_common *opc, struct navit *navit, struct vehicle *v)
    23892445{
     2446        struct osd_text *this = (struct osd_text *)opc->data;
    23902447        struct point p, p2[4];
    23912448        char *str,*last,*next,*value,*absbegin;
    23922449        int do_draw = 0;
     
    23992456        struct item *item;
    24002457        struct osd_text_item *oti;
    24012458        int offset,lines;
    2402         int height=this->osd_item.font_size*13/256;
     2459        int height=opc->osd_item.font_size*13/256;
    24032460        int yspacing=height/2;
    24042461        int xspacing=height/4;
    24052462        int imperial=0;
     
    24122469        str=NULL;
    24132470
    24142471        while (oti) {
    2415 
    24162472                item=NULL;
    24172473                value=NULL;
    24182474
     
    25372593
    25382594        absbegin=str;
    25392595        if (do_draw) {
    2540                 osd_std_draw(&this->osd_item);
     2596                //osd_std_draw(&opc->osd_item);
    25412597        }
    25422598        if (do_draw && str) {
     2599                osd_std_draw(&opc->osd_item);
    25432600                lines=0;
    25442601                next=str;
    25452602                last=str;
     
    25632620                        p.y=0;
    25642621                        break;
    25652622                case 2:
    2566                         p.y=(this->osd_item.h-lines*(height+yspacing)-yspacing);
     2623                        p.y=(opc->osd_item.h-lines*(height+yspacing)-yspacing);
    25672624                        break;
    25682625                case 16: // Grow from top to bottom
    25692626                        p.y = 0;
    25702627                        if (lines != 0) {
    2571                                 this->osd_item.h = (lines-1) * (height+yspacing) + height;
     2628                                opc->osd_item.h = (lines-1) * (height+yspacing) + height;
    25722629                        } else {
    2573                                 this->osd_item.h = 0;
     2630                                opc->osd_item.h = 0;
    25742631                        }
    25752632
    25762633                        if (do_draw) {
    2577                                 osd_std_resize(&this->osd_item);
     2634                                osd_std_resize(&opc->osd_item);
    25782635                        }
    25792636                default:
    2580                         p.y=(this->osd_item.h-lines*(height+yspacing)-yspacing)/2;
     2637                        p.y=(opc->osd_item.h-lines*(height+yspacing)-yspacing)/2;
    25812638                }
    25822639
    25832640                while (str) {
     
    25862643                                *next='\0';
    25872644                                next+=2;
    25882645                        }
    2589                         graphics_get_text_bbox(this->osd_item.gr,
    2590                                                this->osd_item.font,
     2646                        graphics_get_text_bbox(opc->osd_item.gr,
     2647                                               opc->osd_item.font,
    25912648                                               str, 0x10000,
    25922649                                               0x0, p2, 0);
    25932650                        switch (this->align & 12) {
     
    25952652                                p.x=xspacing;
    25962653                                break;
    25972654                        case 8:
    2598                                 p.x=this->osd_item.w-(p2[2].x-p2[0].x)-xspacing;
     2655                                p.x=opc->osd_item.w-(p2[2].x-p2[0].x)-xspacing;
    25992656                                break;
    26002657                        default:
    2601                                 p.x = ((p2[0].x - p2[2].x) / 2) + (this->osd_item.w / 2);
     2658                                p.x = ((p2[0].x - p2[2].x) / 2) + (opc->osd_item.w / 2);
    26022659                        }
    26032660                        p.y += height+yspacing;
    2604                         graphics_draw_text(this->osd_item.gr,
    2605                                            this->osd_item.graphic_fg_text,
    2606                                            NULL, this->osd_item.font,
     2661                        graphics_draw_text(opc->osd_item.gr,
     2662                                           opc->osd_item.graphic_fg_text,
     2663                                           NULL, opc->osd_item.font,
    26072664                                           str, &p, 0x10000,
    26082665                                           0);
    26092666                        str=next;
    26102667                }
    26112668        }
    26122669        if(do_draw) {
    2613                 graphics_draw_mode(this->osd_item.gr, draw_mode_end);
     2670                graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    26142671        }
    26152672        g_free(absbegin);
    26162673
     
    26492706 * @returns nothing
    26502707 */
    26512708static void
    2652 osd_text_prepare(struct osd_text *this, struct navit *nav)
     2709osd_text_prepare(struct osd_priv_common *opc, struct navit *nav)
    26532710{
     2711        struct osd_text *this = (struct osd_text *)opc->data;
     2712
    26542713        char *absbegin,*str,*start,*end,*key,*subkey,*index;
    26552714        struct osd_text_item *oti;
    26562715
     
    27112770
    27122771                switch(oti->attr_typ) {
    27132772                        default:
    2714                                 navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_text_draw), attr_position_coord_geo, this));
     2773                                navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_text_draw), attr_position_coord_geo, opc));
    27152774                                break;
    27162775                }
    27172776
     
    27342793}
    27352794
    27362795static void
    2737 osd_text_init(struct osd_text *this, struct navit *nav)
     2796osd_text_init(struct osd_priv_common *opc, struct navit *nav)
    27382797{
     2798        osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     2799        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_std_click), attr_button, &opc->osd_item));
     2800        osd_text_prepare(opc,nav);
     2801        osd_text_draw(opc, nav, NULL);
    27392802
    2740         osd_set_std_graphic(nav, &this->osd_item, (struct osd_priv *)this);
    2741         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_std_click), attr_button, &this->osd_item));
    2742         osd_text_prepare(this,nav);
    2743         osd_text_draw(this, nav, NULL);
    2744 
    27452803}
    27462804
    27472805static struct osd_priv *
     
    27492807            struct attr **attrs)
    27502808{
    27512809        struct osd_text *this = g_new0(struct osd_text, 1);
     2810        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     2811        opc->data = (void*)this;
     2812
    27522813        struct attr *attr;
    27532814
    2754         this->osd_item.p.x = -80;
    2755         this->osd_item.p.y = 20;
    2756         this->osd_item.w = 60;
    2757         this->osd_item.h = 20;
    2758         this->osd_item.navit = nav;
    2759         this->osd_item.font_size = 200;
    2760         this->osd_item.meth.draw = osd_draw_cast(osd_text_draw);
    2761         osd_set_std_attr(attrs, &this->osd_item, 2);
     2815        opc->osd_item.p.x = -80;
     2816        opc->osd_item.p.y = 20;
     2817        opc->osd_item.w = 60;
     2818        opc->osd_item.h = 20;
     2819        opc->osd_item.navit = nav;
     2820        opc->osd_item.font_size = 200;
     2821        opc->osd_item.meth.draw = osd_draw_cast(osd_text_draw);
     2822        meth->set_attr = set_std_osd_attr;
     2823        osd_set_std_attr(attrs, &opc->osd_item, 2);
    27622824
    27632825        this->active = -1;
    27642826        this->last = NULL;
     
    27722834        if (attr)
    27732835                this->align=attr->u.num;
    27742836
    2775         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_text_init), attr_graphics_ready, this));
    2776         return (struct osd_priv *) this;
     2837        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_text_init), attr_graphics_ready, opc));
     2838        return (struct osd_priv *) opc;
    27772839}
    27782840
    27792841struct gps_status {
    2780         struct osd_item osd_item;
    27812842        char *icon_src;
    27822843        int icon_h, icon_w, active;
    27832844        int strength;
    27842845};
    27852846
    27862847static void
    2787 osd_gps_status_draw(struct gps_status *this, struct navit *navit,
     2848osd_gps_status_draw(struct osd_priv_common *opc, struct navit *navit,
    27882849                       struct vehicle *v)
    27892850{
     2851        struct gps_status *this = (struct gps_status *)opc->data;
     2852
    27902853        struct point p;
    27912854        int do_draw = 0;
    27922855        struct graphics_image *gr_image;
     
    28262889                do_draw=1;
    28272890        }
    28282891        if (do_draw) {
    2829                 osd_std_draw(&this->osd_item);
     2892                osd_std_draw(&opc->osd_item);
    28302893                if (this->active) {
    28312894                        image = g_strdup_printf(this->icon_src, strength);
    2832                         gr_image = graphics_image_new_scaled(this->osd_item.gr, image, this->icon_w, this->icon_h);
     2895                        gr_image = graphics_image_new_scaled(opc->osd_item.gr, image, this->icon_w, this->icon_h);
    28332896                        if (gr_image) {
    2834                                 p.x = (this->osd_item.w - gr_image->width) / 2;
    2835                                 p.y = (this->osd_item.h - gr_image->height) / 2;
    2836                                 graphics_draw_image(this->osd_item.gr, this->osd_item.  graphic_fg_white, &p, gr_image);
    2837                                 graphics_image_free(this->osd_item.gr, gr_image);
     2897                                p.x = (opc->osd_item.w - gr_image->width) / 2;
     2898                                p.y = (opc->osd_item.h - gr_image->height) / 2;
     2899                                graphics_draw_image(opc->osd_item.gr, opc->osd_item.  graphic_fg_white, &p, gr_image);
     2900                                graphics_image_free(opc->osd_item.gr, gr_image);
    28382901                        }
    28392902                        g_free(image);
    28402903                }
    2841                 graphics_draw_mode(this->osd_item.gr, draw_mode_end);
     2904                graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    28422905        }
    28432906}
    28442907
    28452908static void
    2846 osd_gps_status_init(struct gps_status *this, struct navit *nav)
     2909osd_gps_status_init(struct osd_priv_common *opc, struct navit *nav)
    28472910{
    2848         osd_set_std_graphic(nav, &this->osd_item, (struct osd_priv *)this);
    2849         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_draw), attr_position_coord_geo, this));
    2850         osd_gps_status_draw(this, nav, NULL);
     2911        osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     2912        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_draw), attr_position_coord_geo, opc));
     2913        osd_gps_status_draw(opc, nav, NULL);
    28512914}
    28522915
    28532916static struct osd_priv *
     
    28552918                      struct attr **attrs)
    28562919{
    28572920        struct gps_status *this = g_new0(struct gps_status, 1);
     2921        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     2922        opc->data = (void*)this;
     2923
    28582924        struct attr *attr;
    28592925
    2860         this->osd_item.p.x = 20;
    2861         this->osd_item.p.y = -80;
    2862         this->osd_item.w = 60;
    2863         this->osd_item.navit = nav;
    2864         this->osd_item.h = 40;
    2865         this->osd_item.font_size = 200;
    2866         this->osd_item.meth.draw = osd_draw_cast(osd_gps_status_draw);
    2867         osd_set_std_attr(attrs, &this->osd_item, 0);
     2926        opc->osd_item.p.x = 20;
     2927        opc->osd_item.p.y = -80;
     2928        opc->osd_item.w = 60;
     2929        opc->osd_item.navit = nav;
     2930        opc->osd_item.h = 40;
     2931        opc->osd_item.font_size = 200;
     2932        opc->osd_item.meth.draw = osd_draw_cast(osd_gps_status_draw);
     2933        meth->set_attr = set_std_osd_attr;
     2934        osd_set_std_attr(attrs, &opc->osd_item, 0);
    28682935
    28692936        this->icon_w = -1;
    28702937        this->icon_h = -1;
     
    28902957        } else
    28912958                this->icon_src = graphics_icon_path("gui_strength_%d_32_32.png");
    28922959
    2893         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_init), attr_graphics_ready, this));
    2894         return (struct osd_priv *) this;
     2960        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_gps_status_init), attr_graphics_ready, opc));
     2961        return (struct osd_priv *) opc;
    28952962}
    28962963
    28972964
    28982965struct volume {
    2899         struct osd_item osd_item;
    29002966        char *icon_src;
    29012967        int icon_h, icon_w, active;
    29022968        int strength;
     
    29042970};
    29052971
    29062972static void
    2907 osd_volume_draw(struct volume *this, struct navit *navit)
     2973osd_volume_draw(struct osd_priv_common *opc, struct navit *navit)
    29082974{
     2975        struct volume *this = (struct volume *)opc->data;
     2976
    29092977        struct point p;
    29102978        struct graphics_image *gr_image;
    29112979        char *image;
    29122980
    2913         osd_std_draw(&this->osd_item);
     2981        osd_std_draw(&opc->osd_item);
    29142982        if (this->active) {
    29152983                image = g_strdup_printf(this->icon_src, this->strength);
    2916                 gr_image = graphics_image_new_scaled(this->osd_item.gr, image, this->icon_w, this->icon_h);
     2984                gr_image = graphics_image_new_scaled(opc->osd_item.gr, image, this->icon_w, this->icon_h);
    29172985                if (gr_image) {
    2918                         p.x = (this->osd_item.w - gr_image->width) / 2;
    2919                         p.y = (this->osd_item.h - gr_image->height) / 2;
    2920                         graphics_draw_image(this->osd_item.gr, this->osd_item.  graphic_fg_white, &p, gr_image);
    2921                         graphics_image_free(this->osd_item.gr, gr_image);
     2986                        p.x = (opc->osd_item.w - gr_image->width) / 2;
     2987                        p.y = (opc->osd_item.h - gr_image->height) / 2;
     2988                        graphics_draw_image(opc->osd_item.gr, opc->osd_item.  graphic_fg_white, &p, gr_image);
     2989                        graphics_image_free(opc->osd_item.gr, gr_image);
    29222990                }
    29232991                g_free(image);
    29242992        }
    2925         graphics_draw_mode(this->osd_item.gr, draw_mode_end);
     2993        graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    29262994}
    29272995
    29282996static void
    2929 osd_volume_click(struct volume *this, struct navit *nav, int pressed, int button, struct point *p)
     2997osd_volume_click(struct osd_priv_common *opc, struct navit *nav, int pressed, int button, struct point *p)
    29302998{
    2931         struct point bp = this->osd_item.p;
     2999        struct volume *this = (struct volume *)opc->data;
     3000
     3001        struct point bp = opc->osd_item.p;
    29323002        osd_wrap_point(&bp, nav);
    2933         if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + this->osd_item.w || p->y > bp.y + this->osd_item.h) && !this->osd_item.pressed)
     3003        if ((p->x < bp.x || p->y < bp.y || p->x > bp.x + opc->osd_item.w || p->y > bp.y + opc->osd_item.h) && !opc->osd_item.pressed)
    29343004                return;
    29353005        navit_ignore_button(nav);
    29363006        if (pressed) {
    2937                 if (p->y - bp.y < this->osd_item.h/2)
     3007                if (p->y - bp.y < opc->osd_item.h/2)
    29383008                        this->strength++;
    29393009                else
    29403010                        this->strength--;
     
    29423012                        this->strength=0;
    29433013                if (this->strength > 5)
    29443014                        this->strength=5;
    2945                 osd_volume_draw(this, nav);
     3015                osd_volume_draw(opc, nav);
    29463016        }
    29473017}
    29483018static void
    2949 osd_volume_init(struct volume *this, struct navit *nav)
     3019osd_volume_init(struct osd_priv_common *opc, struct navit *nav)
    29503020{
    2951         osd_set_std_graphic(nav, &this->osd_item, (struct osd_priv *)this);
    2952         navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_volume_click), attr_button, this));
    2953         osd_volume_draw(this, nav);
     3021        struct volume *this = (struct volume *)opc->data;
     3022
     3023        osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
     3024        navit_add_callback(nav, this->click_cb = callback_new_attr_1(callback_cast (osd_volume_click), attr_button, opc));
     3025        osd_volume_draw(opc, nav);
    29543026}
    29553027
    29563028static struct osd_priv *
     
    29583030                      struct attr **attrs)
    29593031{
    29603032        struct volume *this = g_new0(struct volume, 1);
     3033        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     3034        opc->data = (void*)this;
     3035
    29613036        struct attr *attr;
    29623037
    2963         this->osd_item.p.x = 20;
    2964         this->osd_item.p.y = -80;
    2965         this->osd_item.w = 60;
    2966         this->osd_item.navit = nav;
    2967         this->osd_item.h = 40;
    2968         this->osd_item.font_size = 200;
    2969         this->osd_item.meth.draw = osd_draw_cast(osd_volume_draw);
    2970         osd_set_std_attr(attrs, &this->osd_item, 0);
     3038        opc->osd_item.p.x = 20;
     3039        opc->osd_item.p.y = -80;
     3040        opc->osd_item.w = 60;
     3041        opc->osd_item.navit = nav;
     3042        opc->osd_item.h = 40;
     3043        opc->osd_item.font_size = 200;
     3044        opc->osd_item.meth.draw = osd_draw_cast(osd_volume_draw);
     3045        meth->set_attr = set_std_osd_attr;
     3046        osd_set_std_attr(attrs, &opc->osd_item, 0);
    29713047
    29723048        this->icon_w = -1;
    29733049        this->icon_h = -1;
     
    29933069        } else
    29943070                this->icon_src = graphics_icon_path("gui_strength_%d_32_32.png");
    29953071
    2996         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_volume_init), attr_graphics_ready, this));
    2997         return (struct osd_priv *) this;
     3072        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_volume_init), attr_graphics_ready, opc));
     3073        return (struct osd_priv *) opc;
    29983074}
    29993075
    30003076struct osd_scale {
    30013077        int use_overlay;
    3002         struct osd_item item;
    30033078        struct callback *draw_cb,*navit_init_cb;
    30043079        struct graphics_gc *black;
    30053080};
    30063081
    30073082static void
    3008 osd_scale_draw(struct osd_scale *this, struct navit *nav)
     3083osd_scale_draw(struct osd_priv_common *opc, struct navit *nav)
    30093084{
     3085        struct osd_scale *this = (struct osd_scale *)opc->data;
     3086
    30103087        struct point bp,bp1,bp2;
    30113088        struct point p[10],bbox[4];
    30123089        struct coord c[2];
     
    30143091        int len;
    30153092        double dist,exp,base,man;
    30163093        char *text;
    3017         int w=this->item.w*9/10;
    3018         int o=(this->item.w-w)/2;
     3094        int w=opc->osd_item.w*9/10;
     3095        int o=(opc->osd_item.w-w)/2;
    30193096        int imperial=0;
    30203097
    30213098        if (navit_get_attr(nav, attr_imperial, &imperial_attr, NULL))
     
    30243101        if (!navit_get_attr(nav, attr_transformation, &transformation, NULL))
    30253102                return;
    30263103        if (this->use_overlay) {
    3027                 graphics_draw_mode(this->item.gr, draw_mode_begin);
     3104                graphics_draw_mode(opc->osd_item.gr, draw_mode_begin);
    30283105                bp.x=0;
    30293106                bp.y=0;
    3030                 graphics_draw_rectangle(this->item.gr, this->item.graphic_bg, &bp, this->item.w, this->item.h);
     3107                graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_bg, &bp, opc->osd_item.w, opc->osd_item.h);
    30313108        } else {
    3032                 bp=this->item.p;
     3109                bp=opc->osd_item.p;
    30333110                osd_wrap_point(&bp, nav);
    30343111        }
    30353112        bp1=bp;
    3036         bp1.y+=this->item.h/2;
     3113        bp1.y+=opc->osd_item.h/2;
    30373114        bp1.x+=o;
    30383115        bp2=bp1;
    30393116        bp2.x+=w;
     
    30513128                man=2;
    30523129        else
    30533130                man=1;
    3054         len=this->item.w-man*base/dist*w;
     3131        len=opc->osd_item.w-man*base/dist*w;
    30553132        p[0].x+=len/2;
    30563133        p[1].x-=len/2;
    30573134        p[2]=p[0];
    30583135        p[3]=p[0];
    3059         p[2].y-=this->item.h/10;
    3060         p[3].y+=this->item.h/10;
     3136        p[2].y-=opc->osd_item.h/10;
     3137        p[3].y+=opc->osd_item.h/10;
    30613138        p[4]=p[1];
    30623139        p[5]=p[1];
    3063         p[4].y-=this->item.h/10;
    3064         p[5].y+=this->item.h/10;
     3140        p[4].y-=opc->osd_item.h/10;
     3141        p[5].y+=opc->osd_item.h/10;
    30653142        p[6]=p[2];
    30663143        p[6].x-=2;
    30673144        p[6].y-=2;
     
    30703147        p[8]=p[4];
    30713148        p[8].x-=2;
    30723149        p[8].y-=2;
    3073         graphics_draw_rectangle(this->item.gr, this->item.graphic_fg_white, p+6, 4,this->item.h/5+4);
    3074         graphics_draw_rectangle(this->item.gr, this->item.graphic_fg_white, p+7, p[1].x-p[0].x, 4);
    3075         graphics_draw_rectangle(this->item.gr, this->item.graphic_fg_white, p+8, 4,this->item.h/5+4);
    3076         graphics_draw_lines(this->item.gr, this->black, p, 2);
    3077         graphics_draw_lines(this->item.gr, this->black, p+2, 2);
    3078         graphics_draw_lines(this->item.gr, this->black, p+4, 2);
     3150        graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_fg_white, p+6, 4,opc->osd_item.h/5+4);
     3151        graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_fg_white, p+7, p[1].x-p[0].x, 4);
     3152        graphics_draw_rectangle(opc->osd_item.gr, opc->osd_item.graphic_fg_white, p+8, 4,opc->osd_item.h/5+4);
     3153        graphics_draw_lines(opc->osd_item.gr, this->black, p, 2);
     3154        graphics_draw_lines(opc->osd_item.gr, this->black, p+2, 2);
     3155        graphics_draw_lines(opc->osd_item.gr, this->black, p+4, 2);
    30793156        text=format_distance(man*base, "", imperial);
    3080         graphics_get_text_bbox(this->item.gr, this->item.font, text, 0x10000, 0, bbox, 0);
    3081         p[0].x=(this->item.w-bbox[2].x)/2+bp.x;
    3082         p[0].y=bp.y+this->item.h-this->item.h/10;
    3083         graphics_draw_text(this->item.gr, this->black, this->item.graphic_fg_white, this->item.font, text, &p[0], 0x10000, 0);
     3157        graphics_get_text_bbox(opc->osd_item.gr, opc->osd_item.font, text, 0x10000, 0, bbox, 0);
     3158        p[0].x=(opc->osd_item.w-bbox[2].x)/2+bp.x;
     3159        p[0].y=bp.y+opc->osd_item.h-opc->osd_item.h/10;
     3160        graphics_draw_text(opc->osd_item.gr, this->black, opc->osd_item.graphic_fg_white, opc->osd_item.font, text, &p[0], 0x10000, 0);
    30843161        g_free(text);
    30853162        if (this->use_overlay)
    3086                 graphics_draw_mode(this->item.gr, draw_mode_end);
     3163                graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    30873164}
    30883165
    30893166static void
    3090 osd_scale_init(struct osd_scale *this, struct navit *nav)
     3167osd_scale_init(struct osd_priv_common *opc, struct navit *nav)
    30913168{
     3169        struct osd_scale *this = (struct osd_scale *)opc->data;
     3170
    30923171        struct color color_white={0xffff,0xffff,0xffff,0x0000};
    30933172        struct color color_black={0x0000,0x0000,0x0000,0x0000};
    30943173        struct graphics *gra = navit_get_graphics(nav);
    30953174        dbg(1, "enter\n");
    30963175        if (this->use_overlay) {
    3097                 osd_set_std_graphic(nav, &this->item, (struct osd_priv *)this);
     3176                osd_set_std_graphic(nav, &opc->osd_item, (struct osd_priv *)opc);
    30983177        } else {
    3099                 this->item.configured=1;
    3100                 this->item.gr=gra;
    3101                 this->item.font = graphics_font_new(this->item.gr, this->item.font_size, 1);
    3102                 this->item.graphic_fg_white=graphics_gc_new(this->item.gr);
    3103                 this->item.color_white=color_white;
    3104                 graphics_gc_set_foreground(this->item.graphic_fg_white, &this->item.color_white);
     3178                opc->osd_item.configured=1;
     3179                opc->osd_item.gr=gra;
     3180                opc->osd_item.font = graphics_font_new(opc->osd_item.gr, opc->osd_item.font_size, 1);
     3181                opc->osd_item.graphic_fg_white=graphics_gc_new(opc->osd_item.gr);
     3182                opc->osd_item.color_white=color_white;
     3183                graphics_gc_set_foreground(opc->osd_item.graphic_fg_white, &opc->osd_item.color_white);
    31053184        }
    3106         this->black=graphics_gc_new(this->item.gr);
     3185        this->black=graphics_gc_new(opc->osd_item.gr);
    31073186        graphics_gc_set_foreground(this->black, &color_black);
    3108         graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_scale_draw), attr_postdraw, this, nav));
     3187        graphics_add_callback(gra, this->draw_cb=callback_new_attr_2(callback_cast(osd_scale_draw), attr_postdraw, opc, nav));
    31093188        if (navit_get_ready(nav) == 3)
    3110                 osd_scale_draw(this, nav);
     3189                osd_scale_draw(opc, nav);
    31113190}
    31123191
    31133192static struct osd_priv *
     
    31153194               struct attr **attrs)
    31163195{
    31173196        struct osd_scale *this = g_new0(struct osd_scale, 1);
     3197        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     3198        opc->data = (void*)this;
     3199
    31183200        struct attr *attr;
    31193201
    3120         this->item.navit = nav;
    3121         this->item.meth.draw = osd_draw_cast(osd_scale_draw);
     3202        opc->osd_item.navit = nav;
     3203        opc->osd_item.meth.draw = osd_draw_cast(osd_scale_draw);
     3204        meth->set_attr = set_std_osd_attr;
    31223205
    3123         osd_set_std_attr(attrs, &this->item, 3);
     3206        osd_set_std_attr(attrs, &opc->osd_item, 3);
    31243207
    31253208        attr=attr_search(attrs, NULL, attr_use_overlay);
    31263209        if (attr)
    31273210                this->use_overlay=attr->u.num;
    31283211
    3129         navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_scale_init), attr_graphics_ready, this));
     3212        navit_add_callback(nav, this->navit_init_cb = callback_new_attr_1(callback_cast (osd_scale_init), attr_graphics_ready, opc));
    31303213
    3131         return (struct osd_priv *) this;
     3214        return (struct osd_priv *) opc;
    31323215}
    31333216
    31343217struct auxmap {
    3135         struct osd_item osd_item;
    31363218        struct displaylist *displaylist;
    31373219        struct transformation *ntrans;
    31383220        struct transformation *trans;
     
    31433225};
    31443226
    31453227static void
    3146 osd_auxmap_draw(struct auxmap *this)
     3228osd_auxmap_draw(struct osd_priv_common *opc)
    31473229{
     3230        struct auxmap *this = (struct auxmap *)opc->data;
     3231
    31483232        int d=10;
    31493233        struct point p;
    31503234        struct attr mapset;
    31513235
    3152         if (!this->osd_item.configured)
     3236        if (!opc->osd_item.configured)
    31533237                return;
    31543238        if (!navit_get_attr(this->nav, attr_mapset, &mapset, NULL) || !mapset.u.mapset)
    31553239                return;
    3156         p.x=this->osd_item.w/2;
    3157         p.y=this->osd_item.h/2;
     3240        p.x=opc->osd_item.w/2;
     3241        p.y=opc->osd_item.h/2;
    31583242        transform_set_center(this->trans, transform_get_center(this->ntrans));
    31593243        transform_set_scale(this->trans, 64);
    31603244        transform_set_yaw(this->trans, transform_get_yaw(this->ntrans));
    31613245        transform_setup_source_rect(this->trans);
    31623246        transform_set_projection(this->trans, transform_get_projection(this->ntrans));
    31633247#if 0
    3164         graphics_displaylist_draw(this->osd_item.gr, this->displaylist, this->trans, this->layout, 4);
     3248        graphics_displaylist_draw(opc->osd_item.gr, this->displaylist, this->trans, this->layout, 4);
    31653249#endif
    3166         graphics_draw(this->osd_item.gr, this->displaylist, mapset.u.mapset, this->trans, this->layout, 0, NULL, 1);
    3167         graphics_draw_circle(this->osd_item.gr, this->red, &p, d);
    3168         graphics_draw_mode(this->osd_item.gr, draw_mode_end);
     3250        graphics_draw(opc->osd_item.gr, this->displaylist, mapset.u.mapset, this->trans, this->layout, 0, NULL, 1);
     3251        graphics_draw_circle(opc->osd_item.gr, this->red, &p, d);
     3252        graphics_draw_mode(opc->osd_item.gr, draw_mode_end);
    31693253
    31703254}
    31713255
    31723256static void
    3173 osd_auxmap_init(struct auxmap *this, struct navit *nav)
     3257osd_auxmap_init(struct osd_priv_common *opc, struct navit *nav)
    31743258{
     3259        struct auxmap *this = (struct auxmap *)opc->data;
     3260
    31753261        struct graphics *gra;
    31763262        struct attr attr;
    31773263        struct map_selection sel;
     
    31813267        if (! navit_get_attr(nav, attr_graphics, &attr, NULL))
    31823268                return;
    31833269        gra=attr.u.graphics;
    3184         graphics_add_callback(gra, callback_new_attr_1(callback_cast(osd_auxmap_draw), attr_postdraw, this));
     3270        graphics_add_callback(gra, callback_new_attr_1(callback_cast(osd_auxmap_draw), attr_postdraw, opc));
    31853271        if (! navit_get_attr(nav, attr_transformation, &attr, NULL))
    31863272                return;
    31873273        this->ntrans=attr.u.transformation;
     
    31913277        if (! navit_get_attr(nav, attr_layout, &attr, NULL))
    31923278                return;
    31933279        this->layout=attr.u.layout;
    3194         osd_set_std_graphic(nav, &this->osd_item, NULL);
    3195         graphics_init(this->osd_item.gr);
     3280        osd_set_std_graphic(nav, &opc->osd_item, NULL);
     3281        graphics_init(opc->osd_item.gr);
    31963282        this->red=graphics_gc_new(gra);
    31973283        graphics_gc_set_foreground(this->red,&red);
    31983284        graphics_gc_set_linewidth(this->red,3);
    31993285        this->trans=transform_new();
    32003286        memset(&sel, 0, sizeof(sel));
    3201         sel.u.p_rect.rl.x=this->osd_item.w;
    3202         sel.u.p_rect.rl.y=this->osd_item.h;
     3287        sel.u.p_rect.rl.x=opc->osd_item.w;
     3288        sel.u.p_rect.rl.y=opc->osd_item.h;
    32033289        transform_set_screen_selection(this->trans, &sel);
    3204         graphics_set_rect(this->osd_item.gr, &sel.u.p_rect);
     3290        graphics_set_rect(opc->osd_item.gr, &sel.u.p_rect);
    32053291#if 0
    3206         osd_auxmap_draw(this, nav);
     3292        osd_auxmap_draw(opc, nav);
    32073293#endif
    32083294}
    32093295
     
    32113297osd_auxmap_new(struct navit *nav, struct osd_methods *meth, struct attr **attrs)
    32123298{
    32133299        struct auxmap *this = g_new0(struct auxmap, 1);
     3300        struct osd_priv_common *opc = g_new0(struct osd_priv_common,1);
     3301        opc->data = (void*)this;
    32143302
    3215         this->osd_item.p.x = 20;
    3216         this->osd_item.p.y = -80;
    3217         this->osd_item.w = 60;
    3218         this->osd_item.h = 40;
    3219         this->osd_item.font_size = 200;
    3220         osd_set_std_attr(attrs, &this->osd_item, 0);
     3303        opc->osd_item.p.x = 20;
     3304        opc->osd_item.p.y = -80;
     3305        opc->osd_item.w = 60;
     3306        opc->osd_item.h = 40;
     3307        opc->osd_item.font_size = 200;
     3308        meth->set_attr = set_std_osd_attr;
     3309        osd_set_std_attr(attrs, &opc->osd_item, 0);
    32213310
    3222         navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_auxmap_init), attr_navit, this));
    3223         return (struct osd_priv *) this;
     3311        navit_add_callback(nav, callback_new_attr_1(callback_cast(osd_auxmap_init), attr_navit, opc));
     3312        return (struct osd_priv *) opc;
    32243313}
    32253314
    32263315