]> err.no Git - mapper/commitdiff
MapWidget:
authorKaj-Michael Lang <milang@tal.org>
Tue, 10 Jun 2008 14:07:57 +0000 (17:07 +0300)
committerKaj-Michael Lang <milang@tal.org>
Tue, 10 Jun 2008 14:07:57 +0000 (17:07 +0300)
- Use gobject properties for speed and over speed settings
- Add map dragging

libs/libgtkmap/gtkmap.c

index bfb09917b36198ec29ad9704d5e9553a2dc71f89..b7c1dfb9ecea9f3c0b927d67f6b746c444e24097 100644 (file)
@@ -172,7 +172,9 @@ struct _GtkMapPriv
        gfloat units_conv;
        gchar *units_str;
 
-       gfloat speed;
+       /* Current speed, set from outside */
+       gfloat speed;   
+       gboolean speed_oc;
 
        /* Buffer offset */
        gint offsetx;
@@ -212,6 +214,8 @@ struct _GtkMapPriv
        gboolean button_down;
        gint mouse_x;
        gint mouse_y;
+       gint drag_x;
+       gint drag_y;
        gdouble mouse_lat;
        gdouble mouse_lon;
 
@@ -334,6 +338,8 @@ enum {
        PROP_SHOW_VELVEC,
        PROP_SHOW_SCALE,
        PROP_SHOW_SPEED,
+       PROP_SPEED,
+       PROP_SPEED_OC,
        PROP_LAST
 };
 
@@ -507,6 +513,12 @@ g_object_class_install_property(object_class, PROP_SHOW_SCALE, pspec);
 pspec=g_param_spec_boolean("show-speed","Show speed","Display current speed on map", TRUE, G_PARAM_READWRITE);
 g_object_class_install_property(object_class, PROP_SHOW_SPEED, pspec);
 
+pspec=g_param_spec_boolean("over-speed","Over speed","Are we speeding", FALSE, G_PARAM_READWRITE);
+g_object_class_install_property(object_class, PROP_SPEED_OC, pspec);
+
+pspec=g_param_spec_double("speed","Current speed","Speed value to display on map, if show-peed is TRUE", 0, 999, 0, G_PARAM_READWRITE);
+g_object_class_install_property(object_class, PROP_SPEED, pspec);
+
 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);
@@ -606,6 +618,12 @@ switch (prop_id) {
        case PROP_SHOW_SPEED:
                priv->show_speed=g_value_get_boolean(value);
        break;
+       case PROP_SPEED:
+               priv->speed=g_value_get_float(value);
+       break;
+       case PROP_SPEED_OC:
+               priv->speed_oc=g_value_get_boolean(value);
+       break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
        break;
@@ -660,6 +678,12 @@ switch (prop_id) {
        case PROP_SHOW_SCALE:
                g_value_set_boolean(value, priv->show_scale);
        break;
+       case PROP_SPEED:
+               g_value_set_float(value, priv->speed);
+       break;
+       case PROP_SPEED_OC:
+               g_value_set_boolean(value, priv->speed_oc);
+       break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
        break;
@@ -1437,20 +1461,6 @@ g_snprintf(buffer, sizeof(buffer), "%0.0f %s", priv->speed * priv->units_conv, p
 gtk_map_information_text(widget, 10, 10, priv->speed_gc, buffer);
 }
 
-void
-gtk_map_set_speed(GtkWidget *widget, gfloat speed, gboolean overspeed)
-{
-GtkMap *map;
-GtkMapPriv *priv;
-
-g_return_if_fail(GTK_IS_MAP(widget));
-map=GTK_MAP(widget);
-priv=GTK_MAP_GET_PRIVATE(map);
-
-priv->speed_gc=(overspeed) ? priv->speed_gc1 : priv->speed_gc2;
-priv->speed=speed;
-}
-
 /******************************************************************************/
 
 static gboolean
@@ -2348,16 +2358,36 @@ gtk_map_motion_notify_cb(GtkWidget *widget, GdkEventMotion *event, gpointer data
 {
 GtkMap *map;
 GtkMapPriv *priv;
+GdkModifierType mask;
+gint x,y;
 
 g_return_val_if_fail(GTK_IS_MAP(widget), FALSE);
 map=GTK_MAP(widget);
 priv=GTK_MAP_GET_PRIVATE(map);
 
-priv->mouse_x=(gint)event->x;
-priv->mouse_y=(gint)event->y;
+if (event->is_hint) {
+       gdk_window_get_pointer (event->window, &x, &y, &mask);
+} else {
+       x=(gint)event->x;
+       y=(gint)event->y;
+       mask=event->state;
+}
+
+priv->mouse_x=x;
+priv->mouse_y=y;
 unit2latlon(x2unit(priv->mouse_x), y2unit(priv->mouse_y), &priv->mouse_lat, &priv->mouse_lon);
 
-g_debug("MOUSE(%d): %d,%d (%f,%f)", priv->button_down, priv->mouse_x, priv->mouse_y, priv->mouse_lat, priv->mouse_lon);
+if ((mask & GDK_BUTTON1_MASK)) {
+       gint dx, dy;
+
+       dx=(event->x-priv->drag_x)+priv->screen_width_pixels/2;
+       dy=(event->y-priv->drag_y)+priv->screen_height_pixels/2;
+       gtk_map_set_center(widget, x2unit((gint)dx), y2unit((gint)dy));
+} else {
+       /* XXX: check if pointer is near a marker perhaps ? */
+}
+
+g_debug("MOUSE(%d): %d,%d [%d] (%f,%f)", priv->button_down, priv->mouse_x, priv->mouse_y, mask, priv->mouse_lat, priv->mouse_lon);
 
 return FALSE;
 }
@@ -2377,6 +2407,8 @@ unit2latlon(x2unit((gint) (event->x+0.5)), y2unit((gint) (event->y+0.5)), &priv-
 switch (event->button) {
 case 1:
        priv->button_down=TRUE;
+       priv->drag_x=(gint)event->x;
+       priv->drag_y=(gint)event->y;
        if (priv->click_to_center) {
                gtk_map_set_center(widget, x2unit((gint) (event->x+0.5)), y2unit((gint) (event->y+0.5)));
                return FALSE;
@@ -2412,6 +2444,8 @@ priv=GTK_MAP_GET_PRIVATE(map);
 switch (event->button) {
 case 1:
        priv->button_down=FALSE;
+       priv->drag_x=-1;
+       priv->drag_y=-1;
        /* Check if a marker was clicked, if they are shown and if there is something to show */
        if (priv->show_markers && priv->marker_store) {
                /* XXX */