]> err.no Git - mapper/commitdiff
MapWidget:
authorKaj-Michael Lang <milang@tal.org>
Tue, 20 May 2008 09:19:29 +0000 (12:19 +0300)
committerKaj-Michael Lang <milang@tal.org>
Tue, 20 May 2008 09:19:29 +0000 (12:19 +0300)
- Fix rotation
- Fix initial position

src/gtkmap.c

index fe3605e006ea9d4f45de641e10333cf4933b8a0a..80b4deaf40d0dbf9de65409f7618f3220f8cff12 100644 (file)
@@ -396,6 +396,10 @@ priv->min_center.unitx=pixel2unit(grid2pixel(priv->screen_grids_halfwidth));
 priv->min_center.unity=pixel2unit(grid2pixel(priv->screen_grids_halfheight));
 priv->max_center.unitx=GTK_MAP_WORLD_SIZE_UNITS-grid2unit(priv->screen_grids_halfwidth) - 1;
 priv->max_center.unity=GTK_MAP_WORLD_SIZE_UNITS-grid2unit(priv->screen_grids_halfheight) - 1;
+BOUND(priv->center.unitx, priv->min_center.unitx, priv->max_center.unitx);
+BOUND(priv->center.unity, priv->min_center.unity, priv->max_center.unity);
+priv->base_tilex = grid2tile((gint) pixel2grid((gint) unit2pixel((gint) priv->center.unitx)) - (gint) priv->screen_grids_halfwidth);
+priv->base_tiley = grid2tile(pixel2grid(unit2pixel(priv->center.unity)) - priv->screen_grids_halfheight);
 }
 
 /******************************************************************************/
@@ -407,19 +411,19 @@ GObjectClass *object_class;
 GtkWidgetClass *widget_class;
 GParamSpec *pspec;
 
-object_class = (GObjectClass*) class;
-widget_class = (GtkWidgetClass*) class;
+object_class=(GObjectClass*) class;
+widget_class=(GtkWidgetClass*) class;
        
-object_class->finalize = gtk_map_finalize;
-object_class->set_property = gtk_map_set_property;
-object_class->get_property = gtk_map_get_property;
+object_class->finalize=gtk_map_finalize;
+object_class->set_property=gtk_map_set_property;
+object_class->get_property=gtk_map_get_property;
        
-widget_class->size_request = gtk_map_size_request;
-widget_class->expose_event = gtk_map_expose;
-widget_class->realize = gtk_map_realize;
-widget_class->size_allocate = gtk_map_size_allocate;
+widget_class->size_request=gtk_map_size_request;
+widget_class->expose_event=gtk_map_expose;
+widget_class->realize=gtk_map_realize;
+widget_class->size_allocate=gtk_map_size_allocate;
 
-g_type_class_add_private (object_class, sizeof(GtkMapPriv));
+g_type_class_add_private(object_class, sizeof(GtkMapPriv));
 
 pspec=g_param_spec_uint("center-mode","Center Mode","Map centering mode on current track tail", 0, 2, 1, G_PARAM_READWRITE);
 g_object_class_install_property (object_class, PROP_CENTER_MODE, pspec);
@@ -466,20 +470,22 @@ GtkMapPriv *priv;
 
 priv=GTK_MAP_GET_PRIVATE(map);
 
-priv->base_tilex=-5;
-priv->base_tiley=-5;
+g_debug("INIT");
+
+priv->base_tilex=0;
+priv->base_tiley=0;
 
 priv->draw_width=4;
 
-priv->zoom=3;
+priv->zoom=8;
 priv->min_zoom=0;
 priv->max_zoom=17;
 priv->zoom_to_mouse=TRUE;
 
-priv->center_mode=CENTER_LATLON;
-priv->center.unitx=0;
-priv->center.unity=0;
-
+/* Start with a sensible location and manual mode */
+priv->center_mode=CENTER_MANUAL;
+latlon2unit(60.45, 22.25,&priv->center.unitx, &priv->center.unity);
+priv->world_size_tiles = unit2tile(GTK_MAP_WORLD_SIZE_UNITS);
 priv->speed=-1;
 priv->speed_gc=priv->speed_gc1;
 
@@ -619,6 +625,7 @@ th=GTK_MAP_TILE_SIZE_PIXELS*((height/GTK_MAP_TILE_SIZE_PIXELS)+2);
 
 gtk_map_update_buffer_size(widget, tw, th);
 if (!priv->buffer) {
+       g_debug("Failed to get map back buffer!");
        return;
 }
 
@@ -647,15 +654,15 @@ map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
 widget->allocation = *allocation;
 
-g_debug("GTKMAP: Size allocate (%d, %d)", widget->allocation.width, widget->allocation.height);
-
-gtk_map_recalc_offset(priv);
-gtk_map_recalc_focus_base(priv);
+g_debug("GTKMAP: Size allocate (%d, %d)@%d %d", widget->allocation.width, widget->allocation.height, priv->center.unitx, priv->center.unity);
 
 if (GTK_WIDGET_REALIZED(widget)) {
+       g_debug("Realized");
        gdk_window_move_resize(widget->window, allocation->x, allocation->y, allocation->width, allocation->height);
        gtk_map_update_size(widget, allocation->width, allocation->height);
        gtk_map_refresh(widget);
+} else {
+       g_debug("Not realized yet");
 }
 
 }
@@ -669,7 +676,7 @@ g_return_if_fail(GTK_IS_MAP(widget));
 g_return_if_fail(requisition != NULL);
        
 map=GTK_MAP(widget);
-
+g_debug("gtk_map_size_request");
 requisition->width=GTK_MAP_TILE_SIZE_PIXELS/2;
 requisition->height=GTK_MAP_TILE_SIZE_PIXELS/2;
 }
@@ -717,6 +724,7 @@ map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
 
 g_debug("GTKMAP: Realize");
+g_debug("GTKMAP: %d@%d %d", priv->zoom, priv->center.unitx, priv->center.unity);
 
 GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
 attributes.window_type=GDK_WINDOW_CHILD;
@@ -735,10 +743,13 @@ attributes.colormap=gtk_widget_get_colormap(widget);
 widget->window=gdk_window_new(gtk_widget_get_parent_window(widget), &attributes, attributes_mask);
 
 gdk_window_set_user_data(widget->window, widget);
+gtk_widget_set_app_paintable(widget, TRUE);
+gtk_widget_set_extension_events(widget, GDK_EXTENSION_EVENTS_ALL);
 
+#if 0
 widget->style=gtk_style_attach(widget->style, widget->window);
 gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
-gtk_widget_set_extension_events(widget, GDK_EXTENSION_EVENTS_ALL);
+#endif
 
 #ifdef WITH_GL_NOTYET
 priv->gl_config=gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH);
@@ -817,10 +828,25 @@ g_signal_connect(G_OBJECT(map), "button_release_event",G_CALLBACK(gtk_map_button
 g_signal_connect(G_OBJECT(map), "scroll_event",  G_CALLBACK(gtk_map_scroll_event_cb), NULL);
 g_signal_connect(G_OBJECT(map), "motion_notify_event", G_CALLBACK(gtk_map_motion_notify_cb), NULL);
 
-gtk_widget_set_app_paintable(widget, TRUE);
+gtk_map_update_size(widget, widget->allocation.width, widget->allocation.height);
+gtk_map_refresh(widget);
+
+g_debug("GTKMAP: %d@%d %d", priv->zoom, priv->center.unitx, priv->center.unity);
+
 gtk_widget_queue_resize(widget);
 }
 
+#ifdef WITH_CAIRO
+static void
+gtk_map_update_rotation_matrix(GtkMapPriv *priv, guint x, guint y)
+{
+cairo_matrix_init_identity(&priv->matrix_rotate);
+cairo_matrix_translate(&priv->matrix_rotate, (gdouble)x, (gdouble)y);
+cairo_matrix_rotate(&priv->matrix_rotate, (gdouble)priv->rotate_angle);
+cairo_matrix_translate(&priv->matrix_rotate, (gdouble)-x, (gdouble)-y);
+} 
+#endif
+
 static void 
 gtk_map_render_buffer(GtkWidget *widget, GdkEventExpose *event)
 {
@@ -833,22 +859,21 @@ g_return_if_fail(event != NULL);
 map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
 
-if (!priv->buffer)
-       return
+if (!priv->buffer) {
+       g_debug("No buffer to paint");
+       return;
+}
+
+/* XXX: WTF, scale is not drawn properly with cairo without this thing slowing us down ????*/
+g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");
+g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");g_debug("HUH");
 
 #ifdef WITH_CAIRO
 cairo_save(priv->ct);
 cairo_rectangle(priv->ct, event->area.x, event->area.y, event->area.width, event->area.height);
 cairo_clip(priv->ct);
 if (priv->rotate_view) {
-       guint x,y;
-
-       x=unit2bufx(priv->center.unitx);
-       y=unit2bufy(priv->center.unity);
-
-       cairo_matrix_init_translate(&priv->matrix_rotate, (gdouble)x, (gdouble)y);
-       cairo_matrix_rotate(&priv->matrix_rotate, (gdouble)priv->rotate_angle);
-       cairo_matrix_translate(&priv->matrix_rotate, (gdouble)-x, (gdouble)-y);
+       gtk_map_update_rotation_matrix(priv,unit2x(priv->center.unitx),unit2y(priv->center.unity) );
        cairo_set_matrix(priv->ct, &priv->matrix_rotate);
 
        gdk_cairo_set_source_pixmap(priv->ct, priv->buffer, -priv->offsetx, -priv->offsety);
@@ -883,6 +908,8 @@ g_return_val_if_fail(event != NULL, FALSE);
 map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
 
+g_debug("Expose");
+
 #ifdef WITH_CAIRO
 priv->ct=gdk_cairo_create(widget->window);
 #endif
@@ -1817,7 +1844,6 @@ return FALSE;
 #endif
 }
 
-
 void
 gtk_map_refresh(GtkWidget *widget)
 {
@@ -1858,7 +1884,7 @@ gtk_map_set_autozoom(GtkWidget *widget, gboolean az)
 GtkMap *map;
 GtkMapPriv *priv;
 
-/* Check that we have a track set */
+/* Check that we have a track path set */
 return TRUE;
 }
 
@@ -1873,7 +1899,7 @@ g_return_val_if_fail(GTK_IS_MAP(widget), FALSE);
 map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
 
-g_debug("GTKMAP: zoom %d", new_zoom);
+g_debug("GTKMAP: req zoom is %d @ %d,%d", new_zoom, priv->center.unitx, priv->center.unity);
 
 if (new_zoom > (priv->max_zoom - 1))
        return FALSE;
@@ -1886,22 +1912,11 @@ if (priv->curr_repo)
 else
        priv->zoom = new_zoom;
 
-priv->world_size_tiles = unit2tile(GTK_MAP_WORLD_SIZE_UNITS);
-
 /* If we're leading, update the center to reflect new zoom level. */
 gtk_map_recalc_center(priv);
 
 /* Update center bounds to reflect new zoom level. */
-priv->min_center.unitx = pixel2unit(grid2pixel(priv->screen_grids_halfwidth));
-priv->min_center.unity = pixel2unit(grid2pixel(priv->screen_grids_halfheight));
-priv->max_center.unitx = GTK_MAP_WORLD_SIZE_UNITS - grid2unit(priv->screen_grids_halfwidth) - 1;
-priv->max_center.unity = GTK_MAP_WORLD_SIZE_UNITS - grid2unit(priv->screen_grids_halfheight) - 1;
-
-BOUND(priv->center.unitx, priv->min_center.unitx, priv->max_center.unitx);
-BOUND(priv->center.unity, priv->min_center.unity, priv->max_center.unity);
-
-priv->base_tilex = grid2tile((gint) pixel2grid((gint) unit2pixel((gint) priv->center.unitx)) - (gint) priv->screen_grids_halfwidth);
-priv->base_tiley = grid2tile(pixel2grid(unit2pixel(priv->center.unity)) - priv->screen_grids_halfheight);
+gtk_map_recalc_center_bounds(priv);
 
 /* New zoom level, so we can't reuse the old buffer's pixels. Update state variables. */
 gtk_map_recalc_offset(priv);
@@ -1909,6 +1924,9 @@ gtk_map_recalc_focus_base(priv);
 gtk_map_recalc_focus_size(priv);
 
 gtk_map_refresh(widget);
+
+g_debug("GTKMAP: zoom is %d @ %d,%d", priv->zoom, priv->center.unitx, priv->center.unity);
+
 g_signal_emit(widget, gtk_map_signals[MAP_ZOOM_CHANGED], 0, priv->zoom);
 
 return TRUE;