From: Rafał Długołęcki Date: Sun, 25 Jan 2015 23:11:09 +0000 (+0100) Subject: Added scrolling using mouse or touchpad. X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=6a50df3b87fcaedb8e7ea69f415e35485d0ad9bd;p=familia.git Added scrolling using mouse or touchpad. --- diff --git a/src/familia.h b/src/familia.h new file mode 100644 index 0000000..4dc0f63 --- /dev/null +++ b/src/familia.h @@ -0,0 +1,32 @@ +/**************************************************************************** + * Familia Lignum - Genealogical program * + * Copyright (C) 2011-2014 Rafał Długołęcki * + * * + * 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 +#include "../config.h" + +typedef struct familia_data { + GtkAdjustment *vadjustment; + GtkAdjustment *hadjustment; +} FamiliaData; + +#endif /*_FAMILIA_H */ diff --git a/src/main.c b/src/main.c index 2d40638..db22d06 100644 --- a/src/main.c +++ b/src/main.c @@ -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; } diff --git a/src/ui/drawing_area.c b/src/ui/drawing_area.c index 06ba5e5..3457998 100644 --- a/src/ui/drawing_area.c +++ b/src/ui/drawing_area.c @@ -5,6 +5,7 @@ #include #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); + } }