pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3174 - trunk/pingus/src/gui


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3174 - trunk/pingus/src/gui
Date: Tue, 18 Sep 2007 00:15:32 +0200

Author: grumbel
Date: 2007-09-18 00:15:31 +0200 (Tue, 18 Sep 2007)
New Revision: 3174

Modified:
   trunk/pingus/src/gui/group_component.cpp
   trunk/pingus/src/gui/group_component.hpp
Log:
- added grab/ungrab for components

Modified: trunk/pingus/src/gui/group_component.cpp
===================================================================
--- trunk/pingus/src/gui/group_component.cpp    2007-09-17 21:45:01 UTC (rev 
3173)
+++ trunk/pingus/src/gui/group_component.cpp    2007-09-17 22:15:31 UTC (rev 
3174)
@@ -27,6 +27,7 @@
     drawing_context(rect, clip),
     mouse_over_comp(0),
     focused_comp(0),
+    grabbed_comp(0),
     primary_pressed_comp(0),
     secondary_pressed_comp(0)
 {
@@ -72,55 +73,79 @@
 GroupComponent::on_primary_button_press (int x, int y)
 {
   Vector2i mouse_pos = drawing_context.screen_to_world(Vector2i(x, y));
-  Component* comp = component_at(mouse_pos);
-  if (comp)
+
+  if (grabbed_comp)
     {
-      comp->on_primary_button_press(mouse_pos.x, mouse_pos.y);
+      grabbed_comp->on_pointer_move(mouse_pos.x, mouse_pos.y);
+    }
+  else 
+    {
+      Component* comp = component_at(mouse_pos);
+      if (comp)
+        {
+          comp->on_primary_button_press(mouse_pos.x, mouse_pos.y);
       
-      if (focused_comp)
-        focused_comp->set_focus(false);
+          if (focused_comp)
+            focused_comp->set_focus(false);
 
-      focused_comp = comp;
+          focused_comp = comp;
 
-      if (focused_comp)
-        focused_comp->set_focus(true);
+          if (focused_comp)
+            focused_comp->set_focus(true);
+        }
+
+      primary_pressed_comp = comp;
     }
-
-  primary_pressed_comp = comp;
 }
 
 void
 GroupComponent::on_primary_button_release (int x, int y)
 {
   Vector2i mouse_pos = drawing_context.screen_to_world(Vector2i(x, y));
-  Component* comp = component_at(mouse_pos);
+
+  if (grabbed_comp)
+    {
+      grabbed_comp->on_pointer_move(mouse_pos.x, mouse_pos.y);
+    }
+  else 
+    {
+      Component* comp = component_at(mouse_pos);
       
-  if (primary_pressed_comp)
-    {
-      primary_pressed_comp->on_primary_button_release(mouse_pos.x, 
mouse_pos.y);
+      if (primary_pressed_comp)
+        {
+          primary_pressed_comp->on_primary_button_release(mouse_pos.x, 
mouse_pos.y);
 
-      if (comp == primary_pressed_comp)
-        primary_pressed_comp->on_primary_button_click(mouse_pos.x, 
mouse_pos.y);
+          if (comp == primary_pressed_comp)
+            primary_pressed_comp->on_primary_button_click(mouse_pos.x, 
mouse_pos.y);
 
-      primary_pressed_comp = 0;
+          primary_pressed_comp = 0;
+        }
+      else
+        {
+          if (comp)
+            comp->on_primary_button_release(mouse_pos.x, mouse_pos.y);
+        }
     }
-  else
-    {
-      if (comp)
-        comp->on_primary_button_release(mouse_pos.x, mouse_pos.y);
-    }
 }
   
 void
 GroupComponent::on_secondary_button_press (int x, int y)
 {
   Vector2i mouse_pos = drawing_context.screen_to_world(Vector2i(x, y));
-  Component* comp = component_at(mouse_pos);
-  if (comp)
-    comp->on_secondary_button_press(mouse_pos.x, mouse_pos.y);
 
-  if (!primary_pressed_comp)
-    secondary_pressed_comp = comp;
+  if (grabbed_comp)
+    {
+      grabbed_comp->on_pointer_move(mouse_pos.x, mouse_pos.y);
+    }
+  else 
+    {
+      Component* comp = component_at(mouse_pos);
+      if (comp)
+        comp->on_secondary_button_press(mouse_pos.x, mouse_pos.y);
+
+      if (!primary_pressed_comp)
+        secondary_pressed_comp = comp;
+    }
 }
 
 void
@@ -130,8 +155,12 @@
 
   Component* comp = component_at(mouse_pos);
   
-  if (secondary_pressed_comp)
+  if (grabbed_comp)
     {
+      grabbed_comp->on_pointer_move(mouse_pos.x, mouse_pos.y);
+    }
+  else if (secondary_pressed_comp)
+    {
       secondary_pressed_comp->on_secondary_button_release(mouse_pos.x, 
mouse_pos.y);
       
       if (comp == secondary_pressed_comp)
@@ -149,7 +178,9 @@
 void
 GroupComponent::on_key_pressed(const unsigned short c)
 {
-  if (focused_comp)
+  if (grabbed_comp)
+    grabbed_comp->on_key_pressed(c);
+  else if (focused_comp)
     focused_comp->on_key_pressed(c);
   else if (mouse_over_comp)
     mouse_over_comp->on_key_pressed(c);
@@ -159,8 +190,13 @@
 GroupComponent::on_pointer_move(int x, int y)
 {
   Vector2i mouse_pos = drawing_context.screen_to_world(Vector2i(x, y));
-  if (primary_pressed_comp)
+
+  if (grabbed_comp)
     {
+      grabbed_comp->on_pointer_move(mouse_pos.x, mouse_pos.y);
+    }
+  else if (primary_pressed_comp)
+    {
       primary_pressed_comp->on_pointer_move(mouse_pos.x, mouse_pos.y);
     }
   else if (secondary_pressed_comp)
@@ -226,13 +262,28 @@
 void
 GroupComponent::on_pointer_leave()
 {
-  if (mouse_over_comp)
+  if (!grabbed_comp)
     {
-      mouse_over_comp->set_mouse_over(false);
-      mouse_over_comp->on_pointer_leave();
+      if (mouse_over_comp)
+        {
+          mouse_over_comp->set_mouse_over(false);
+          mouse_over_comp->on_pointer_leave();
+        }
+      mouse_over_comp = 0; 
     }
-  mouse_over_comp = 0; 
 }
+
+void
+GroupComponent::grab(Component* comp)
+{
+  grabbed_comp = comp;
+}
+
+void
+GroupComponent::ungrab(Component* comp)
+{
+  grabbed_comp = 0;
+}
 
 } // namespace GUI
 

Modified: trunk/pingus/src/gui/group_component.hpp
===================================================================
--- trunk/pingus/src/gui/group_component.hpp    2007-09-17 21:45:01 UTC (rev 
3173)
+++ trunk/pingus/src/gui/group_component.hpp    2007-09-17 22:15:31 UTC (rev 
3174)
@@ -39,6 +39,8 @@
   /** Used to decide where keyboard events should go */
   Component*     focused_comp;
 
+  Component*     grabbed_comp;
+
   /** Used to do a mouse grab, as long as a button is pressed, the
       component that got the press gets moves and release events */
   Component* primary_pressed_comp;
@@ -75,6 +77,10 @@
 
   bool is_at(int x, int y);
 
+  // Causes all input directed to comp
+  void grab(Component* comp);
+  void ungrab(Component*);
+
   Component* component_at (const Vector2i& pos);
 private:
   GroupComponent(const GroupComponent&);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]