Added scrolling using mouse or touchpad.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sun, 25 Jan 2015 23:11:09 +0000 (00:11 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sun, 25 Jan 2015 23:11:09 +0000 (00:11 +0100)
src/familia.h [new file with mode: 0644]
src/main.c
src/ui/drawing_area.c

diff --git a/src/familia.h b/src/familia.h
new file mode 100644 (file)
index 0000000..4dc0f63
--- /dev/null
@@ -0,0 +1,32 @@
+/****************************************************************************
+ *  Familia Lignum - Genealogical program                                   *
+ *  Copyright (C) 2011-2014 Rafał Długołęcki <rafal@dlugolecki.net.pl>      *
+ *                                                                          *
+ *  This program is free software; you can redistribute it and/or modify    *
+ *  it under the terms of the GNU General Public License as published by    *
+ *  the Free Software Foundation; version 2 of the License.                 *
+ *                                                                          *
+ *  This program is distributed in the hope that it will be useful,         *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
+ *  GNU General Public License for more details.                            *
+ *                                                                          *
+ *  You should have received a copy of the GNU General Public License along *
+ *  with this program; if not, write to the Free Software Foundation, Inc., *
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             *
+ *                                                                          *
+ ****************************************************************************/
+
+#ifndef _FAMILIA_H
+#define _FAMILIA_H
+
+
+#include <gtk/gtkgl.h>
+#include "../config.h"
+
+typedef struct familia_data {
+       GtkAdjustment *vadjustment;
+       GtkAdjustment *hadjustment;
+} FamiliaData;
+
+#endif /*_FAMILIA_H */
index 2d406381e1dff4076473a9ad941f2bb75dd07c23..db22d061aed20491cf3d212f8a5d5d0052a85358 100644 (file)
@@ -30,6 +30,7 @@
 #include "i18n.h"
 #include "debug.h"
 #include "commandline.h"
+#include "familia.h"
 #include "storage/storage.h"
 #include "gedcom/familia_gedcom.h"
 
@@ -47,6 +48,7 @@ int main(int argc, char** argv) {
        GtkBuilder *builder = NULL;
        GtkWidget *window = NULL;
        GdkGLConfig *glconfig = NULL;
+       FamiliaData * app = NULL;
        struct familia_storage * storage = NULL;
 
        storage = familia_storage_new();
@@ -83,7 +85,12 @@ int main(int argc, char** argv) {
        builder = gtk_builder_new();
 
        gtk_builder_add_from_file(builder, get_guidatafile(), NULL);
-       gtk_builder_connect_signals(builder, NULL);
+
+       app = g_new(FamiliaData, 1);
+       app->hadjustment = gtk_builder_get_object(builder, "horizontal-adjustment");
+       app->vadjustment = gtk_builder_get_object(builder, "vertical-adjustment");
+
+       gtk_builder_connect_signals(builder, app);
 
        window = GTK_WIDGET(gtk_builder_get_object(builder, "main-window"));
        drawing_area = GTK_WIDGET(gtk_builder_get_object(builder, "drawing-area"));
@@ -103,5 +110,7 @@ int main(int argc, char** argv) {
                storage = NULL;
        }
 
+       g_free(app);
+
        return 0;
 }
index 06ba5e51399375b89bef3035827d1cba31047536..3457998930fa9fcf661cf9d3dadfe6b22f5ee03a 100644 (file)
@@ -5,6 +5,7 @@
 #include <assert.h>
 
 #include "../debug.h"
+#include "../familia.h"
 #include "drawing_area.h"
 #include "../math/3d.h"
 #include "../graphics/constants.h"
@@ -152,21 +153,42 @@ void drawing_area_unrealize (GtkWidget *widget, gpointer data)
 
 /**
  * The "scroll-event" signal handler. Responsible for correctly scrolling
- * drawing area.
+ * drawing area using mouse or touchpad.
  */
 void drawing_area_event_scroll (GtkWidget *widget,
-                               GdkEventScroll *event, gpointer user_data)
+                               GdkEventScroll *event, FamiliaData *data)
 {
+       GtkAdjustment *adjustment = NULL;
+       gdouble value = 0;
+       gdouble step = 0;
+
        assert(event->type == GDK_SCROLL);
 
        switch(event->direction) {
                case GDK_SCROLL_UP:
-                       camera_pos_y++;
-                       gtk_widget_queue_draw(widget);
+                       adjustment = data->vadjustment;
+                       step = 1;
                        break;
                case GDK_SCROLL_DOWN:
-                       camera_pos_y--;
-                       gtk_widget_queue_draw(widget);
+                       adjustment = data->vadjustment;
+                       step = -1;
+                       break;
+               case GDK_SCROLL_LEFT:
+                       adjustment = data->hadjustment;
+                       step = -1;
+                       break;
+               case GDK_SCROLL_RIGHT:
+                       adjustment = data->hadjustment;
+                       step = 1;
                        break;
        }
+
+       if (adjustment != NULL) {
+               value = gtk_adjustment_get_value (adjustment);
+               step  = step * gtk_adjustment_get_step_increment(adjustment);
+               value += step;
+
+               gtk_adjustment_set_value (adjustment, value);
+               gtk_adjustment_value_changed (adjustment);
+       }
 }