Diff of /trunk/src/map.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 161 by harbaum, Sat Apr 11 11:28:56 2009 UTC revision 191 by harbaum, Tue Jul 7 07:36:27 2009 UTC
# Line 167  static void map_node_select(appdata_t *a Line 167  static void map_node_select(appdata_t *a
167      gint h = gdk_pixbuf_get_height(map_item->object.node->icon_buf);      gint h = gdk_pixbuf_get_height(map_item->object.node->icon_buf);
168      /* icons are technically square, so a radius slightly bigger */      /* icons are technically square, so a radius slightly bigger */
169      /* than sqrt(2)*MAX(w,h) should fit nicely */      /* than sqrt(2)*MAX(w,h) should fit nicely */
170      radius =  0.75 * map->style->icon.scale * ((w>h)?w:h);      radius = 0.75 * map->style->icon.scale * ((w>h)?w:h);
171    }    }
172    
173      radius *= map->state->detail;
174    map_hl_circle_new(map, CANVAS_GROUP_NODES_HL, new_map_item,    map_hl_circle_new(map, CANVAS_GROUP_NODES_HL, new_map_item,
175                      x, y, radius, map->style->highlight.color);                      x, y, radius, map->style->highlight.color);
176    
# Line 198  void map_way_select(appdata_t *appdata, Line 199  void map_way_select(appdata_t *appdata,
199    map_statusbar(map, map_item);    map_statusbar(map, map_item);
200    icon_bar_map_item_selected(appdata, map_item, TRUE);    icon_bar_map_item_selected(appdata, map_item, TRUE);
201    gtk_widget_set_sensitive(appdata->menu_item_map_hide_sel, TRUE);    gtk_widget_set_sensitive(appdata->menu_item_map_hide_sel, TRUE);
202    
203    gint arrow_width = (map_item->object.way->draw.flags & OSM_DRAW_FLAG_BG)?    gint arrow_width = ((map_item->object.way->draw.flags & OSM_DRAW_FLAG_BG)?
204      map->style->highlight.width + map_item->object.way->draw.bg.width/2:                        map->style->highlight.width + map_item->object.way->draw.bg.width/2:
205      map->style->highlight.width + map_item->object.way->draw.width/2;                        map->style->highlight.width + map_item->object.way->draw.width/2)
206        * map->state->detail;
207    
208    node_chain_t *node_chain = map_item->object.way->node_chain;    node_chain_t *node_chain = map_item->object.way->node_chain;
209    node_t *last = NULL;    node_t *last = NULL;
# Line 259  void map_way_select(appdata_t *appdata, Line 261  void map_way_select(appdata_t *appdata,
261        gint y = node_chain->node->lpos.y;        gint y = node_chain->node->lpos.y;
262    
263        map_hl_circle_new(map, CANVAS_GROUP_NODES_IHL, new_map_item,        map_hl_circle_new(map, CANVAS_GROUP_NODES_IHL, new_map_item,
264                          x, y, map->style->node.radius,                          x, y, map->style->node.radius * map->state->detail,
265                          map->style->highlight.node_color);                          map->style->highlight.node_color);
266      }      }
267    
# Line 287  void map_way_select(appdata_t *appdata, Line 289  void map_way_select(appdata_t *appdata,
289      new_map_item->highlight = TRUE;      new_map_item->highlight = TRUE;
290    
291      map_hl_polyline_new(map, CANVAS_GROUP_WAYS_HL, new_map_item, points,      map_hl_polyline_new(map, CANVAS_GROUP_WAYS_HL, new_map_item, points,
292                  (map_item->object.way->draw.flags & OSM_DRAW_FLAG_BG)?                   ((map_item->object.way->draw.flags & OSM_DRAW_FLAG_BG)?
293                  2*map->style->highlight.width + map_item->object.way->draw.bg.width:                   2*map->style->highlight.width + map_item->object.way->draw.bg.width:
294                  2*map->style->highlight.width + map_item->object.way->draw.width,                   2*map->style->highlight.width + map_item->object.way->draw.width)
295                  map->style->highlight.color);                  * map->state->detail, map->style->highlight.color);
296    
297      canvas_points_free(points);      canvas_points_free(points);
298    }    }
299  }  }
# Line 472  static canvas_item_t *map_node_new(map_t Line 474  static canvas_item_t *map_node_new(map_t
474    else    else
475      map_item->item = canvas_image_new(map->canvas, CANVAS_GROUP_NODES,      map_item->item = canvas_image_new(map->canvas, CANVAS_GROUP_NODES,
476        node->icon_buf,        node->icon_buf,
477        node->lpos.x - map->style->icon.scale/2 *        node->lpos.x - map->style->icon.scale/2 * map->state->detail *
478                        gdk_pixbuf_get_width(node->icon_buf),                        gdk_pixbuf_get_width(node->icon_buf),
479        node->lpos.y - map->style->icon.scale/2 *        node->lpos.y - map->style->icon.scale/2 * map->state->detail *
480                        gdk_pixbuf_get_height(node->icon_buf),                        gdk_pixbuf_get_height(node->icon_buf),
481                map->style->icon.scale,map->style->icon.scale);                        map->state->detail * map->style->icon.scale,
482                          map->state->detail * map->style->icon.scale);
483    
484    canvas_item_set_zoom_max(map_item->item, node->zoom_max);    canvas_item_set_zoom_max(map_item->item,
485                               node->zoom_max / (2 * map->state->detail));
486    
487    /* attach map_item to nodes map_item_chain */    /* attach map_item to nodes map_item_chain */
488    map_item_chain_t **chain = &node->map_item_chain;    map_item_chain_t **chain = &node->map_item_chain;
# Line 540  static canvas_item_t *map_way_new(map_t Line 544  static canvas_item_t *map_way_new(map_t
544      map_item->item = canvas_polyline_new(map->canvas, group, points, width, color);      map_item->item = canvas_polyline_new(map->canvas, group, points, width, color);
545    }    }
546    
547    canvas_item_set_zoom_max(map_item->item, way->draw.zoom_max);    canvas_item_set_zoom_max(map_item->item,
548                               way->draw.zoom_max / (2 * map->state->detail));
549    
550    /* a ways outline itself is never dashed */    /* a ways outline itself is never dashed */
551    if (group != CANVAS_GROUP_WAYS_OL)    if (group != CANVAS_GROUP_WAYS_OL)
# Line 590  void map_way_draw(map_t *map, way_t *way Line 595  void map_way_draw(map_t *map, way_t *way
595      }      }
596    
597      /* draw way */      /* draw way */
598        float width = way->draw.width * map->state->detail;
599    
600      if(way->draw.flags & OSM_DRAW_FLAG_AREA) {      if(way->draw.flags & OSM_DRAW_FLAG_AREA) {
601        map_way_new(map, CANVAS_GROUP_POLYGONS, way, points,        map_way_new(map, CANVAS_GROUP_POLYGONS, way, points,
602                    way->draw.width, way->draw.color, way->draw.area.color);                    width, way->draw.color, way->draw.area.color);
603      } else {      } else {
604    
605        if(way->draw.flags & OSM_DRAW_FLAG_BG) {        if(way->draw.flags & OSM_DRAW_FLAG_BG) {
606          map_way_new(map, CANVAS_GROUP_WAYS_INT, way, points,          map_way_new(map, CANVAS_GROUP_WAYS_INT, way, points,
607                      way->draw.width, way->draw.color, NO_COLOR);                      width, way->draw.color, NO_COLOR);
608    
609          map_way_new(map, CANVAS_GROUP_WAYS_OL, way, points,          map_way_new(map, CANVAS_GROUP_WAYS_OL, way, points,
610                      way->draw.bg.width, way->draw.bg.color, NO_COLOR);                      way->draw.bg.width * map->state->detail,
611                        way->draw.bg.color, NO_COLOR);
612    
613        } else        } else
614          map_way_new(map, CANVAS_GROUP_WAYS, way, points,          map_way_new(map, CANVAS_GROUP_WAYS, way, points,
615                      way->draw.width, way->draw.color, NO_COLOR);                      width, way->draw.color, NO_COLOR);
616      }      }
617      canvas_points_free(points);      canvas_points_free(points);
618    }    }
# Line 617  void map_node_draw(map_t *map, node_t *n Line 625  void map_node_draw(map_t *map, node_t *n
625    
626    if(!node->ways)    if(!node->ways)
627      map_node_new(map, node,      map_node_new(map, node,
628                   map->style->node.radius,                   map->style->node.radius * map->state->detail,
629                   map->style->node.border_radius,                   map->style->node.border_radius * map->state->detail,
630                   map->style->node.fill_color,                   map->style->node.fill_color,
631                   map->style->node.color);                   map->style->node.color);
632    
633    else if(map->style->node.show_untagged || osm_node_has_tag(node))    else if(map->style->node.show_untagged || osm_node_has_tag(node))
634      map_node_new(map, node,      map_node_new(map, node,
635                   map->style->node.radius, 0,                   map->style->node.radius * map->state->detail, 0,
636                   map->style->node.color, 0);                   map->style->node.color, 0);
637  }  }
638    
# Line 677  static void map_item_init(style_t *style Line 685  static void map_item_init(style_t *style
685  void map_item_redraw(appdata_t *appdata, map_item_t *map_item) {  void map_item_redraw(appdata_t *appdata, map_item_t *map_item) {
686    map_item_t item = *map_item;    map_item_t item = *map_item;
687    
688      /* a relation cannot be redraws as it doesn't have a visual */
689      /* representation */
690      if(map_item->object.type == RELATION)
691        return;
692    
693    /* check if the item to be redrawn is the selected one */    /* check if the item to be redrawn is the selected one */
694    gboolean is_selected = FALSE;    gboolean is_selected = FALSE;
695    if(map_item->object.ptr == appdata->map->selected.object.ptr) {    if(map_item->object.ptr == appdata->map->selected.object.ptr) {
# Line 1366  static void map_touchnode_update(appdata Line 1379  static void map_touchnode_update(appdata
1379      /* don't highlight the dragged node itself and don't highlight */      /* don't highlight the dragged node itself and don't highlight */
1380      /* deleted ones */      /* deleted ones */
1381      if((node != cur_node) && (!(node->flags & OSM_FLAG_DELETED))) {      if((node != cur_node) && (!(node->flags & OSM_FLAG_DELETED))) {
1382        gint nx = x - node->lpos.x;        gint nx = abs(x - node->lpos.x);
1383        gint ny = y - node->lpos.y;        gint ny = abs(y - node->lpos.y);
1384    
1385        if((nx < map->style->node.radius) && (ny < map->style->node.radius) &&        if((nx < map->style->node.radius) && (ny < map->style->node.radius) &&
1386           (nx*nx + ny*ny < map->style->node.radius * map->style->node.radius))           (nx*nx + ny*ny < map->style->node.radius * map->style->node.radius))
# Line 1381  static void map_touchnode_update(appdata Line 1394  static void map_touchnode_update(appdata
1394    if(!map->touchnode && map->action.way) {    if(!map->touchnode && map->action.way) {
1395      node_chain_t *chain = map->action.way->node_chain;      node_chain_t *chain = map->action.way->node_chain;
1396      while(!map->touchnode && chain && chain->next) {      while(!map->touchnode && chain && chain->next) {
1397        gint nx = x - chain->node->lpos.x;        gint nx = abs(x - chain->node->lpos.x);
1398        gint ny = y - chain->node->lpos.y;        gint ny = abs(y - chain->node->lpos.y);
1399    
1400        if((nx < map->style->node.radius) && (ny < map->style->node.radius) &&        if((nx < map->style->node.radius) && (ny < map->style->node.radius) &&
1401           (nx*nx + ny*ny < map->style->node.radius * map->style->node.radius))           (nx*nx + ny*ny < map->style->node.radius * map->style->node.radius))
# Line 1740  gboolean map_key_press_event(appdata_t * Line 1753  gboolean map_key_press_event(appdata_t *
1753    return FALSE;    return FALSE;
1754  }  }
1755    
1756    void map_state_reset(map_state_t *state) {
1757      if(!state) return;
1758    
1759      state->zoom = 0.25;
1760      state->detail = 1.0;
1761    
1762      /* todo: try to scroll to center of screen */
1763      state->scroll_offset.x = 0;
1764      state->scroll_offset.y = 0;
1765    }
1766    
1767    map_state_t *map_state_new(void) {
1768      map_state_t *state = g_new0(map_state_t, 1);
1769      map_state_reset(state);
1770      return state;
1771    }
1772    
1773  GtkWidget *map_new(appdata_t *appdata) {  GtkWidget *map_new(appdata_t *appdata) {
1774    map_t *map = appdata->map = g_new0(map_t, 1);    map_t *map = appdata->map = g_new0(map_t, 1);
1775    
# Line 1755  GtkWidget *map_new(appdata_t *appdata) { Line 1785  GtkWidget *map_new(appdata_t *appdata) {
1785      map->state = appdata->project->map_state;      map->state = appdata->project->map_state;
1786    } else {    } else {
1787      printf("Creating new map state\n");      printf("Creating new map state\n");
1788      map->state = g_new0(map_state_t, 1);      map->state = map_state_new();
     map->state->zoom = 0.25;  
1789    }    }
1790    
1791    map->state->refcount++;    map->state->refcount++;
# Line 1767  GtkWidget *map_new(appdata_t *appdata) { Line 1796  GtkWidget *map_new(appdata_t *appdata) {
1796    map->action.type = MAP_ACTION_IDLE;    map->action.type = MAP_ACTION_IDLE;
1797    
1798    map->canvas = canvas_new(map->style->background.color);    map->canvas = canvas_new(map->style->background.color);
   canvas_set_antialias(map->canvas, !appdata->settings->no_antialias);  
1799    
1800    GtkWidget *canvas_widget = canvas_get_widget(map->canvas);    GtkWidget *canvas_widget = canvas_get_widget(map->canvas);
1801    
# Line 1835  void map_clear(appdata_t *appdata, gint Line 1863  void map_clear(appdata_t *appdata, gint
1863  void map_paint(appdata_t *appdata) {  void map_paint(appdata_t *appdata) {
1864    map_t *map = appdata->map;    map_t *map = appdata->map;
1865    
   /* user may have changed antialias settings */  
   canvas_set_antialias(map->canvas, !appdata->settings->no_antialias);  
   
1866    josm_elemstyles_colorize_world(map->style, appdata->osm);    josm_elemstyles_colorize_world(map->style, appdata->osm);
1867    map_draw(map, appdata->osm);    map_draw(map, appdata->osm);
1868  }  }
# Line 1945  void map_action_ok(appdata_t *appdata) { Line 1970  void map_action_ok(appdata_t *appdata) {
1970      /* save changes to bg_offset in project */      /* save changes to bg_offset in project */
1971      appdata->project->wms_offset.x = map->bg.offset.x;      appdata->project->wms_offset.x = map->bg.offset.x;
1972      appdata->project->wms_offset.y = map->bg.offset.y;      appdata->project->wms_offset.y = map->bg.offset.y;
     appdata->project->dirty = TRUE;  
1973      break;      break;
1974    
1975    default:    default:
# Line 2372  void map_show_all(appdata_t *appdata) { Line 2396  void map_show_all(appdata_t *appdata) {
2396    gtk_widget_set_sensitive(appdata->menu_item_map_show_all, FALSE);    gtk_widget_set_sensitive(appdata->menu_item_map_show_all, FALSE);
2397  }  }
2398    
2399    static void map_detail_change(map_t *map, float detail) {
2400      appdata_t *appdata = map->appdata;
2401    
2402      /* deselecting anything allows us not to care about automatic deselection */
2403      /* as well as items becoming invisible by the detail change */
2404      map_item_deselect(appdata);
2405    
2406      map->state->detail = detail;
2407      printf("changing detail factor to %f\n", map->state->detail);
2408    
2409      banner_busy_start(appdata, 1, _("Redrawing"));
2410      map_clear(appdata, MAP_LAYER_OBJECTS_ONLY);
2411      map_paint(appdata);
2412      banner_busy_stop(appdata);
2413    }
2414    
2415    #define DETAIL_STEP 1.5
2416    
2417    void map_detail_increase(map_t *map) {
2418      if(!map) return;
2419      map_detail_change(map, map->state->detail * DETAIL_STEP);
2420    }
2421    
2422    void map_detail_decrease(map_t *map) {
2423      if(!map) return;
2424      map_detail_change(map, map->state->detail / DETAIL_STEP);
2425    }
2426    
2427    void map_detail_normal(map_t *map) {
2428      if(!map) return;
2429      map_detail_change(map, 1.0);
2430    }
2431    
2432  // vim:et:ts=8:sw=2:sts=2:ai  // vim:et:ts=8:sw=2:sts=2:ai

Legend:
Removed from v.161  
changed lines
  Added in v.191