[gtkmm] Gesture demo: Use some local gestures in the constructor



commit ff4ea6dda638feba9e302a179f5ee0a38d436da6
Author: Kjell Ahlstedt <kjellahlstedt gmail com>
Date:   Fri Nov 22 10:55:08 2019 +0100

    Gesture demo: Use some local gestures in the constructor
    
    In gtkmm4 it's not necessary to keep a RefPtr to each gesture. A gesture
    exists for as long as it's connected to a widget. See #60

 demos/gtk-demo/example_gestures.cc | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
---
diff --git a/demos/gtk-demo/example_gestures.cc b/demos/gtk-demo/example_gestures.cc
index dc3a5085..a5e36ec6 100644
--- a/demos/gtk-demo/example_gestures.cc
+++ b/demos/gtk-demo/example_gestures.cc
@@ -27,8 +27,6 @@ protected:
   Gtk::DrawingArea m_DrawingArea;
 
   // Gestures:
-  Glib::RefPtr<Gtk::GestureSwipe> m_GestureSwipe;
-  Glib::RefPtr<Gtk::GestureLongPress> m_GestureLongPress;
   Glib::RefPtr<Gtk::GestureRotate> m_GestureRotate;
   Glib::RefPtr<Gtk::GestureZoom> m_GestureZoom;
 
@@ -55,18 +53,18 @@ Example_Gestures::Example_Gestures()
   m_DrawingArea.set_draw_func(sigc::mem_fun(*this, &Example_Gestures::on_drawing_area_draw));
 
   // Create gestures.
-  m_GestureSwipe = Gtk::GestureSwipe::create();
-  m_GestureSwipe->set_propagation_phase(Gtk::PropagationPhase::BUBBLE);
-  m_GestureSwipe->signal_swipe().connect(sigc::mem_fun(*this, &Example_Gestures::on_gesture_swipe_swipe));
-  m_GestureSwipe->set_touch_only(false);
-  m_DrawingArea.add_controller(m_GestureSwipe);
-
-  m_GestureLongPress = Gtk::GestureLongPress::create();
-  m_GestureLongPress->set_propagation_phase(Gtk::PropagationPhase::BUBBLE);
-  m_GestureLongPress->signal_pressed().connect(sigc::mem_fun(*this, 
&Example_Gestures::on_gesture_long_press_pressed));
-  m_GestureLongPress->signal_end().connect(sigc::mem_fun(*this, 
&Example_Gestures::on_gesture_long_press_end));
-  m_GestureLongPress->set_touch_only(false);
-  m_DrawingArea.add_controller(m_GestureLongPress);
+  auto swipe = Gtk::GestureSwipe::create();
+  swipe->set_propagation_phase(Gtk::PropagationPhase::BUBBLE);
+  swipe->signal_swipe().connect(sigc::mem_fun(*this, &Example_Gestures::on_gesture_swipe_swipe));
+  swipe->set_touch_only(false);
+  m_DrawingArea.add_controller(swipe);
+
+  auto long_press = Gtk::GestureLongPress::create();
+  long_press->set_propagation_phase(Gtk::PropagationPhase::BUBBLE);
+  long_press->signal_pressed().connect(sigc::mem_fun(*this, 
&Example_Gestures::on_gesture_long_press_pressed));
+  long_press->signal_end().connect(sigc::mem_fun(*this, &Example_Gestures::on_gesture_long_press_end));
+  long_press->set_touch_only(false);
+  m_DrawingArea.add_controller(long_press);
 
   m_GestureRotate = Gtk::GestureRotate::create();
   m_GestureRotate->set_propagation_phase(Gtk::PropagationPhase::BUBBLE);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]