]> err.no Git - mapper/commitdiff
Map widget:
authorKaj-Michael Lang <milang@tal.org>
Tue, 6 May 2008 07:23:15 +0000 (10:23 +0300)
committerKaj-Michael Lang <milang@tal.org>
Tue, 6 May 2008 07:23:15 +0000 (10:23 +0300)
- Add more signals (location, center mode)
- Allocate buffer after widget is realized

src/gtkmap.c
src/gtkmap.h

index 40227617f7ffb37afb9aec314cf5a0aa066addb5..bfd93f9784fe08b63fc5bf86dd4fd698b53af4b3 100644 (file)
@@ -246,6 +246,7 @@ enum {
        MAP_LOCATION_CHANGED,
        MAP_ZOOM_CHANGED,
        MAP_PANNED,
+       MAP_CENTER_MODE_CHANGED,
        MARKER_CLICK,
        LAST_SIGNAL
 };
@@ -278,8 +279,16 @@ widget_class->size_allocate = gtk_map_size_allocate;
 g_type_class_add_private (object_class, sizeof(GtkMapPriv));
 
 gtk_map_signals[MAP_ZOOM_CHANGED]=g_signal_new("zoom-changed", G_OBJECT_CLASS_TYPE(object_class),
-     G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkMapClass, zoom_changed),
-     NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
+       G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkMapClass, zoom_changed),
+       NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
+
+gtk_map_signals[MAP_LOCATION_CHANGED]=g_signal_new("location-changed", G_OBJECT_CLASS_TYPE(object_class),
+       G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkMapClass, location_changed),
+       NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
+
+gtk_map_signals[MAP_LOCATION_CHANGED]=g_signal_new("center-mode-changed", G_OBJECT_CLASS_TYPE(object_class),
+       G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET(GtkMapClass, center_mode_changed),
+       NULL, NULL, g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
 
 }
 
@@ -296,11 +305,9 @@ switch(priv->center_mode) {
                priv->center.unitx = priv->location.unitx;
                priv->center.unity = priv->location.unity;
        break;
+       case CENTER_MANUAL:
        default:
-#if 0
-               priv->center.unitx = center->unitx;
-               priv->center.unity = center->unity;
-#endif
+               /* Do nothing, use priv->center.* */
        break;
 }
 }
@@ -485,11 +492,12 @@ widget->allocation = *allocation;
 
 g_debug("GTKMAP: Size allocate (%d, %d)", widget->allocation.width, widget->allocation.height);
 
-if (GTK_WIDGET_REALIZED(widget))
+if (GTK_WIDGET_REALIZED(widget)) {
        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);
+}
 
-gtk_map_update_size(widget, allocation->width, allocation->height);
-gtk_map_refresh(widget);
 }
 
 static void
@@ -503,10 +511,10 @@ g_return_if_fail(requisition != NULL);
 map=GTK_MAP(widget);
 
 g_debug("GTKMAP: Size request");
-       
+
 requisition->width=GTK_MAP_TILE_SIZE_PIXELS/2;
 requisition->height=GTK_MAP_TILE_SIZE_PIXELS/2;
-gtk_map_update_size(widget, requisition->width, requisition->height);
+/* gtk_map_update_size(widget, requisition->width, requisition->height); */
 }
 
 static gboolean
@@ -625,6 +633,7 @@ pango_layout_set_alignment(priv->speed_layout, PANGO_ALIGN_LEFT);
 g_signal_connect(G_OBJECT(widget), "button_press_event", G_CALLBACK(gtk_map_press_cb), NULL);
 #endif
 
+gtk_widget_queue_resize(widget);
 }
 
 static gboolean
@@ -1076,6 +1085,8 @@ map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
 style=widget->style;
 
+priv->center_mode=CENTER_MANUAL;
+
 /* Assure that _center.unitx/y are bounded. */
 BOUND(unitx, priv->min_center.unitx, priv->max_center.unitx);
 BOUND(unity, priv->min_center.unity, priv->max_center.unity);
@@ -1149,6 +1160,7 @@ if (new_base_tilex != priv->base_tilex || new_base_tiley != priv->base_tiley) {
 gtk_map_recalc_offset(priv);
 gtk_map_recalc_focus_base(priv);
 gtk_map_refresh(widget);
+g_signal_emit(widget, gtk_map_signals[MAP_LOCATION_CHANGED], 0, priv->zoom);
 }
 
 void
@@ -1179,7 +1191,7 @@ for (y = 0; y < priv->buf_height_tiles; ++y)
        for (x = 0; x < priv->buf_width_tiles; ++x)
                gtk_map_render_tile(map, priv->base_tilex + x, priv->base_tiley + y, x * GTK_MAP_TILE_SIZE_PIXELS, y * GTK_MAP_TILE_SIZE_PIXELS, FALSE);
 
-gtk_widget_queue_draw_area(widget, 0, 0, widget->allocation.width, widget->allocation.height);
+gtk_widget_queue_draw(widget);
 }
 
 gint 
index 0504dbf53db67958bc4c52d576e5fa4c57f9ae12..360a828a78148bb1e2bc8c55bde70297af3bd0b7 100644 (file)
@@ -50,6 +50,8 @@ struct _GtkMap {
 struct _GtkMapClass {
        GtkDrawingAreaClass parent_class;
        void (* zoom_changed) (GtkWidget *widget, int zoom);
+       void (* location_changed) (GtkWidget *widget, int zoom);
+       void (* center_mode_changed) (GtkWidget *widget, int zoom);
 };
 
 G_BEGIN_DECLS