Add mouse vertical scrolling.
authorRafał Długołęcki <rafal@dlugolecki.net.pl>
Sun, 25 Jan 2015 21:41:22 +0000 (22:41 +0100)
committerRafał Długołęcki <rafal@dlugolecki.net.pl>
Sun, 25 Jan 2015 21:41:22 +0000 (22:41 +0100)
data/gui.glade
src/ui/drawing_area.c

index 8b559aff5811899c4142aff00eb7377bd6a12074..6140265b41b174231d5243dfb9037b245c960e04 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.3 -->
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
+  <requires lib="gtk+" version="3.0"/>
   <object class="GtkAccelGroup" id="FileAccel"/>
   <object class="GtkActionGroup" id="FileActions">
     <property name="accel_group">FileAccel</property>
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="stock">gtk-missing-image</property>
-    <property name="icon-size">1</property>
+    <property name="icon_size">1</property>
   </object>
   <object class="GtkImage" id="image2">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="stock">gtk-missing-image</property>
   </object>
+  <object class="GtkFileChooserDialog" id="open-file-dialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="filechooserdialog-vbox1">
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="filechooserdialog-action_area1">
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="openfiledialog-cancel">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="openfiledialog-ok">
+                <property name="label">gtk-open</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <placeholder/>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">openfiledialog-cancel</action-widget>
+      <action-widget response="-5">openfiledialog-ok</action-widget>
+    </action-widgets>
+  </object>
+  <object class="GtkAdjustment" id="vertical-adjustment">
+    <property name="lower">-100</property>
+    <property name="upper">100</property>
+    <property name="step_increment">0.10000000000000001</property>
+    <property name="page_increment">10</property>
+    <signal name="changed" handler="vertical_scrollbar_changed" swapped="no"/>
+    <signal name="value-changed" handler="vertical_scrollbar_value_changed" swapped="no"/>
+  </object>
   <object class="GtkWindow" id="main-window">
     <property name="can_focus">False</property>
     <property name="default_width">400</property>
                     <property name="visible">True</property>
                     <property name="app_paintable">True</property>
                     <property name="can_focus">False</property>
-                    <signal name="draw" handler="drawing_area_draw" swapped="no"/>
+                    <property name="events">GDK_STRUCTURE_MASK | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK</property>
                     <signal name="configure-event" handler="drawing_area_configure_event" swapped="no"/>
-                    <signal name="unrealize" handler="drawing_area_unrealize" swapped="no"/>
+                    <signal name="draw" handler="drawing_area_draw" swapped="no"/>
                     <signal name="realize" handler="drawing_area_realize" swapped="no"/>
+                    <signal name="scroll-event" handler="drawing_area_event_scroll" swapped="no"/>
+                    <signal name="unrealize" handler="drawing_area_unrealize" swapped="no"/>
                   </object>
                   <packing>
                     <property name="expand">True</property>
       </object>
     </child>
   </object>
-  <object class="GtkFileChooserDialog" id="open-file-dialog">
-    <property name="can_focus">False</property>
-    <property name="border_width">5</property>
-    <property name="type_hint">dialog</property>
-    <child internal-child="vbox">
-      <object class="GtkBox" id="filechooserdialog-vbox1">
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">2</property>
-        <child internal-child="action_area">
-          <object class="GtkButtonBox" id="filechooserdialog-action_area1">
-            <property name="can_focus">False</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="openfiledialog-cancel">
-                <property name="label">gtk-cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="openfiledialog-ok">
-                <property name="label">gtk-open</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="pack_type">end</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <placeholder/>
-        </child>
-      </object>
-    </child>
-    <action-widgets>
-      <action-widget response="-6">openfiledialog-cancel</action-widget>
-      <action-widget response="-5">openfiledialog-ok</action-widget>
-    </action-widgets>
-  </object>
-  <object class="GtkAdjustment" id="vertical-adjustment">
-    <property name="lower">-100</property>
-    <property name="upper">100</property>
-    <property name="step_increment">0.10000000000000001</property>
-    <property name="page_increment">10</property>
-    <signal name="changed" handler="vertical_scrollbar_changed" swapped="no"/>
-    <signal name="value-changed" handler="vertical_scrollbar_value_changed" swapped="no"/>
-  </object>
 </interface>
index 8eefe5fc8015349391173c79f18e67c201f21c85..491906e9002a7fbfd00e2fe3ca0a45f5d39222c3 100644 (file)
@@ -2,6 +2,7 @@
 #include <gtk/gtkgl.h>
 #include <GL/gl.h>
 #include <GL/glu.h>
+#include <assert.h>
 
 #include "../debug.h"
 #include "drawing_area.h"
@@ -148,3 +149,19 @@ void drawing_area_unrealize (GtkWidget *widget, gpointer data)
 {
        /* Code */
 }
+
+void drawing_area_event_scroll (GtkWidget *widget, GdkEventScroll *event, gpointer user_data)
+{
+       assert(event->type == GDK_SCROLL);
+
+       switch(event->direction) {
+               case GDK_SCROLL_UP:
+                       camera_pos_y++;
+                       gtk_widget_queue_draw(widget);
+                       break;
+               case GDK_SCROLL_DOWN:
+                       camera_pos_y--;
+                       gtk_widget_queue_draw(widget);
+                       break;
+       }
+}