[cluttermm_tutorial] Added an example of event handling (examples/actor_events)



commit 00975c4b299c7ef5e32ff08499c9c6c611bde7ff
Author: Ian Martin <ian_martin65 ihug co nz>
Date:   Fri Sep 2 17:14:38 2011 +1200

    Added an example of event handling (examples/actor_events)
    
    Demonstrates signal handling for a selection of mouse events.
    
    The tutorial already refers to this example, but the actual example
    does not seem to have existed until now.
    
    Bug #658115

 examples/actor_events/main.cpp |   85 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/examples/actor_events/main.cpp b/examples/actor_events/main.cpp
new file mode 100644
index 0000000..23bb336
--- /dev/null
+++ b/examples/actor_events/main.cpp
@@ -0,0 +1,85 @@
+#include <cluttermm.h>
+#include <iostream>
+
+
+//Define some functions for the signal handlers to call: 
+bool on_my_button_press(Clutter::ButtonEvent*  event , Glib::RefPtr<Clutter::Group> g )
+{
+       g->set_rotation(Clutter::X_AXIS, 330, 0, 0, 0);
+       std::cout<<"Pressed button at "<<event->x<<"/ "<<event->y<<std::endl;
+       return true;
+}
+
+
+bool on_my_button_release(Clutter::ButtonEvent*  event, Glib::RefPtr<Clutter::Group> g )
+{
+       g->set_rotation(Clutter::X_AXIS, 30, 0, 0, 0);
+       std::cout<<"released button at "<<event->x<<"/ "<<event->y<<std::endl;
+       return true;
+}
+
+bool on_my_mouse_enter(Clutter::CrossingEvent*  event, Glib::RefPtr<Clutter::Group> g)
+{
+       //g->set_scale(1.00, 3.00);
+       std::cout<<"mouse entered at "<<event->x<<"/ "<<event->y<<std::endl;
+       return true;
+}
+
+bool on_my_mouse_leave(Clutter::CrossingEvent*  event, Glib::RefPtr<Clutter::Group> g)
+{
+       //g->set_scale(3.00, 1.00);
+
+       std::cout<<"mouse left from "<<event->x<<"/ "<<event->y<<std::endl;
+       return true;
+}
+
+int main(int argc, char** argv)
+{
+  Clutter::init(&argc, &argv);
+  // Get the stage and set its size and color:
+  const Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
+  stage->set_size(200, 300);
+  stage->set_color(Clutter::Color(0, 0, 0, 0xFF)); // black
+  // Add a group to the stage:
+  const Glib::RefPtr<Clutter::Group> group = Clutter::Group::create();
+  group->set_position(40, 40);
+  stage->add_actor(group);
+  group->show();
+  const Clutter::Color actor_color (0xFF, 0xFF, 0xFF, 0x99);
+  // Add a rectangle to the group:
+  const Glib::RefPtr<Clutter::Rectangle>
+    rect = Clutter::Rectangle::create(actor_color);
+  rect->set_size(50, 50);
+  rect->set_position(0, 0);
+  group->add_actor(rect);
+  rect->show();
+  // Add a label to the group:
+  const Glib::RefPtr<Clutter::Text>
+    label = Clutter::Text::create("Sans 9", "Some Text", actor_color);
+  label->set_position(0, 60);
+  group->add_actor (label);
+  label->show();
+       // Scale the group 120% along the x axis:
+       group->set_scale(3.00, 1.0);
+       // Rotate it around the z axis:
+       group->set_rotation(Clutter::Z_AXIS, 10, 0, 0, 0);
+       // Show the stage:
+       stage->show();
+       rect->set_reactive();
+       group->set_reactive();
+       
+       //connect some signal handlers: 
+       stage->signal_button_press_event().connect(
+       sigc::bind(sigc::ptr_fun(&on_my_button_press), group));
+       rect->signal_button_release_event().connect(
+       sigc::bind(sigc::ptr_fun(&on_my_button_release), group));
+       group->signal_enter_event().connect(
+       sigc::bind(sigc::ptr_fun(&on_my_mouse_enter), group));
+       group->signal_leave_event().connect(
+       sigc::bind(sigc::ptr_fun(&on_my_mouse_leave), group));
+
+       // Start the main loop, so we can respond to events:
+       Clutter::main();
+       return 0;
+}
+


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