summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gpudataviz.cpp41
-rw-r--r--src/gtk_win_main.cpp4
-rw-r--r--src/my_gtk_gl_scene_widget.hpp1
3 files changed, 37 insertions, 9 deletions
diff --git a/src/gpudataviz.cpp b/src/gpudataviz.cpp
index 2b2386a..b22864e 100644
--- a/src/gpudataviz.cpp
+++ b/src/gpudataviz.cpp
@@ -47,12 +47,14 @@ int main(int argc, char* argv[]) {
return 0;
}
-/* MyGTKGLSceneWidget implementation
- I want to keep interesting code part in this file in natural reading order
+/* MyGTKGLSceneWidget implementation (extends a Gtk::DrawingArea with Gtk::GL::Widget)
+ I want to keep all interesting code parts in this file, in natural reading order
*/
MyGTKGLSceneWidget::MyGTKGLSceneWidget(Glib::RefPtr<Gdk::GL::Config> &glconfig) {
set_gl_capability(glconfig);
- Gdk::EventMask mask = Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK;
+ Gdk::EventMask mask = Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_MOTION_MASK \
+ | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK \
+ | Gdk::SCROLL_MASK;
set_events(mask); // The containing window should have those attributes too
this->camera.rx = -64.0f; this->camera.ry = -16.0f; this->camera.tz = -1.0f;
}
@@ -222,6 +224,10 @@ bool MyGTKGLSceneWidget::on_button_release_event(GdkEventButton *event) {
return do_mouse_logic(event->type, event->state, event->x, event->y);
}
+bool MyGTKGLSceneWidget::on_scroll_event(GdkEventScroll *event) {
+ return do_mouse_logic(event->type, event->state | 1<<(7+event->direction) , event->x, event->y);
+}
+
#define ALL_KEYBOARD_MODIFIERS ( GDK_SHIFT_MASK | GDK_CONTROL_MASK \
| GDK_SUPER_MASK | GDK_HYPER_MASK | GDK_META_MASK )
@@ -231,6 +237,14 @@ bool MyGTKGLSceneWidget::on_button_release_event(GdkEventButton *event) {
&& ( state & required_modifier_mask ) == required_modifier_mask \
&& ( ( state & ALL_KEYBOARD_MODIFIERS ) & ~( required_modifier_mask | allowed_extra_modifier_mask ) ) == 0 \
)
+
+#define MOUSE_WHEEL(direction, required_modifier_mask, allowed_extra_modifier_mask) if ( \
+ type == GDK_SCROLL \
+ && ( state & (1<<(7+direction)) ) == (1<<(7+direction)) \
+ && ( state & required_modifier_mask ) == required_modifier_mask \
+ && ( ( state & ALL_KEYBOARD_MODIFIERS ) & ~( required_modifier_mask | allowed_extra_modifier_mask ) ) == 0 \
+)
+
#define MOUSE_DOUBLECLIC(state_mask) if ( \
type == GDK_BUTTON_RELEASE \
&& ( state & state_mask ) == state_mask \
@@ -255,9 +269,14 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x,
* Simple motion : GDK_MOTION_NOTIFY (3)
* Simple clic : GDK_BUTTON_PRESS then GDK_BUTTON_RELEASE (4 then 7)
* Double clic : GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE (4 7 4 5 7)
+ * Scroll : GDK_SCROLL (31)
+ * event type 31 state 144 on (475,67)
+ * event type 31 state 272 on (475,67)
+ *
*
- * stat : a bit-mask representing the state of the modifier keys and the pointer buttons.
+ * state : a bit-mask representing the state of the modifier keys and the pointer buttons.
* GDK_BUTTON1_MASK, ... , GDK_BUTTON5_MASK (mouse buttons)
+ * GDK_SCROLL_UP, GDK_SCROLL_DOWN, GDK_SCROLL_LEFT, GDK_SCROLL_RIGHT (mouse wheel scroll)
* GDK_SHIFT_MASK, GDK_LOCK_MASK, GDK_CONTROL_MASK (keyboard standard modifier keys)
* GDK_MOD1_MASK, ... (normally MOD1 it is the Alt key)
* GDK_SUPER_MASK, GDK_HYPER_MASK, GDK_META_MASK (extra keybord modifier keys)
@@ -289,12 +308,18 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x,
redraw=true;
}
- MOUSE_CLIC(GDK_BUTTON4_MASK, 0, 0) {
- this->camera.tz += 1.0f;
+ MOUSE_WHEEL(GDK_SCROLL_UP, 0, 0) {
+ if (this->camera.tz + 0.5f <= -0.5f) {
+ this->camera.tz += 0.5f;
+ redraw=true;
+ }
}
- MOUSE_CLIC(GDK_BUTTON5_MASK, 0, 0) {
- this->camera.tz -= 1.0f;
+ MOUSE_WHEEL(GDK_SCROLL_DOWN, 0, 0) {
+ if (this->camera.tz - 0.5f >= -9.0f) {
+ this->camera.tz -= 0.5f;
+ redraw=true;
+ }
}
MOUSE_CLIC(GDK_BUTTON1_MASK, 0, 0) {
diff --git a/src/gtk_win_main.cpp b/src/gtk_win_main.cpp
index 465b828..bf070ca 100644
--- a/src/gtk_win_main.cpp
+++ b/src/gtk_win_main.cpp
@@ -14,7 +14,9 @@ GTKWinMain::GTKWinMain(MyGTKGLSceneWidget &glScene)
// Link signal handlers on events
m_ButtonQuit.signal_clicked().connect( sigc::mem_fun(*this, &GTKWinMain::on_button_quit_clicked) );
- Gdk::EventMask mask = Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK;
+ Gdk::EventMask mask = Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_MOTION_MASK \
+ | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK \
+ | Gdk::SCROLL_MASK ;
set_events(mask);
show_all();
diff --git a/src/my_gtk_gl_scene_widget.hpp b/src/my_gtk_gl_scene_widget.hpp
index 4d50dd6..2c3cc89 100644
--- a/src/my_gtk_gl_scene_widget.hpp
+++ b/src/my_gtk_gl_scene_widget.hpp
@@ -23,6 +23,7 @@ class MyGTKGLSceneWidget : public Gtk::DrawingArea, public Gtk::GL::Widget<MyGTK
virtual bool on_motion_notify_event (GdkEventMotion *event);
virtual bool on_button_press_event(GdkEventButton *event);
virtual bool on_button_release_event(GdkEventButton *event);
+ virtual bool on_scroll_event(GdkEventScroll *event);
bool do_mouse_logic(GdkEventType type, guint state, guint x, guint y);
private: