]> saetta.ns0.it Git - libgtkmapserver/commitdiff
Added zoom through keys.
authorAndrea Zagli <andrea.zagli@email.it>
Sat, 22 Aug 2015 14:37:05 +0000 (16:37 +0200)
committerAndrea Zagli <andrea.zagli@email.it>
Sat, 22 Aug 2015 14:37:05 +0000 (16:37 +0200)
src/gtkmapserver.c

index a6e96752ce7e597f9261caff11ca185bd56a639c..83d902ee6280d680e37454147a992380e740773c 100644 (file)
@@ -46,6 +46,12 @@ static void gtk_mapserver_get_property (GObject *object,
                                GValue *value,
                                GParamSpec *pspec);
 
+static gboolean gtk_mapserver_on_key_release_event (GooCanvasItem *item,
+                                                                                                       GooCanvasItem *target_item,
+                                                                                                       GdkEventKey *event,
+                                                                                                       gpointer user_data);
+
+
 static gboolean gtk_mapserver_on_button_press_event (GtkWidget *widget,
                                                                                                         GdkEventButton *event,
                                                                                                         gpointer user_data);
@@ -150,6 +156,8 @@ gtk_mapserver_init (GtkMapserver *gtk_mapserver)
 
        g_free (localedir);
 
+       gtk_widget_set_can_focus (GTK_WIDGET (gtk_mapserver), TRUE);
+
        g_signal_connect (G_OBJECT (gtk_mapserver), "button-press-event",
                          G_CALLBACK (gtk_mapserver_on_button_press_event), (gpointer)gtk_mapserver);
        g_signal_connect (G_OBJECT (gtk_mapserver), "button-release-event",
@@ -168,6 +176,11 @@ gtk_mapserver_init (GtkMapserver *gtk_mapserver)
                                                                          0, 0,
                                                                          NULL);
 
+       goo_canvas_grab_focus (GOO_CANVAS (gtk_mapserver), priv->img);
+
+       g_signal_connect (G_OBJECT (priv->img), "key-release-event",
+                                         G_CALLBACK (gtk_mapserver_on_key_release_event), (gpointer)gtk_mapserver);
+
        /* Soup */
        priv->soup_session = soup_session_sync_new_with_options (SOUP_SESSION_SSL_CA_FILE, NULL,
                                                                                                                         SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
@@ -364,6 +377,90 @@ gtk_mapserver_get_property (GObject *object, guint property_id, GValue *value, G
 }
 
 /* SIGNALS */
+static gboolean
+gtk_mapserver_on_key_release_event (GooCanvasItem *item,
+                                                                       GooCanvasItem *target_item,
+                                                                       GdkEventKey *event,
+                                                                       gpointer user_data)
+{
+       switch (event->keyval)
+               {
+                       case GDK_KEY_0:
+                       case GDK_KEY_KP_0:
+                               {
+                                       GtkMapserverPrivate *priv = GTK_MAPSERVER_GET_PRIVATE ((GtkMapserver *)user_data);
+
+                                       gdouble x;
+                                       gdouble y;
+                                       gdouble scale;
+                                       gdouble rotation;
+
+                                       goo_canvas_item_get_simple_transform (priv->img,
+                                                                                                                 &x,
+                                                                                                                 &y,
+                                                                                                                 &scale,
+                                                                                                                 &rotation);
+                                       goo_canvas_item_set_simple_transform (priv->img,
+                                                                                                                 x,
+                                                                                                                 y,
+                                                                                                                 1,
+                                                                                                                 rotation);
+
+                                       return TRUE;
+                               }
+
+                       case GDK_KEY_plus:
+                       case GDK_KEY_KP_Add:
+                               {
+                                       GtkMapserverPrivate *priv = GTK_MAPSERVER_GET_PRIVATE ((GtkMapserver *)user_data);
+
+                                       gdouble x;
+                                       gdouble y;
+                                       gdouble scale;
+                                       gdouble rotation;
+
+                                       goo_canvas_item_get_simple_transform (priv->img,
+                                                                                                                 &x,
+                                                                                                                 &y,
+                                                                                                                 &scale,
+                                                                                                                 &rotation);
+                                       goo_canvas_item_set_simple_transform (priv->img,
+                                                                                                                 x,
+                                                                                                                 y,
+                                                                                                                 scale + 0.1,
+                                                                                                                 rotation);
+
+                                       return TRUE;
+                               }
+
+                       case GDK_KEY_minus:
+                       case GDK_KEY_KP_Subtract:
+                               {
+                                       GtkMapserverPrivate *priv = GTK_MAPSERVER_GET_PRIVATE ((GtkMapserver *)user_data);
+
+                                       gdouble x;
+                                       gdouble y;
+                                       gdouble scale;
+                                       gdouble rotation;
+
+                                       goo_canvas_item_get_simple_transform (priv->img,
+                                                                                                                 &x,
+                                                                                                                 &y,
+                                                                                                                 &scale,
+                                                                                                                 &rotation);
+                                       goo_canvas_item_set_simple_transform (priv->img,
+                                                                                                                 x,
+                                                                                                                 y,
+                                                                                                                 scale - 0.1,
+                                                                                                                 rotation);
+
+                                       return TRUE;
+                               }
+               }
+
+       return FALSE;
+}
+
 static gboolean
 gtk_mapserver_on_button_press_event (GtkWidget *widget,
                                                                         GdkEventButton *event,
@@ -372,6 +469,8 @@ gtk_mapserver_on_button_press_event (GtkWidget *widget,
        GtkMapserver *gtk_mapserver = GTK_MAPSERVER (user_data);
        GtkMapserverPrivate *priv = GTK_MAPSERVER_GET_PRIVATE (gtk_mapserver);
 
+       goo_canvas_grab_focus (GOO_CANVAS (gtk_mapserver), priv->img);
+
        if (event->button == 1)
                {
                        priv->sel_x_start = event->x;