pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3048 - trunk/pingus/src/input2


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3048 - trunk/pingus/src/input2
Date: Sat, 1 Sep 2007 05:58:03 +0200

Author: grumbel
Date: 2007-09-01 05:58:03 +0200 (Sat, 01 Sep 2007)
New Revision: 3048

Modified:
   trunk/pingus/src/input2/control.hpp
   trunk/pingus/src/input2/controller.hpp
   trunk/pingus/src/input2/manager.cpp
Log:
- some more work on new input system, framework somewhat running

Modified: trunk/pingus/src/input2/control.hpp
===================================================================
--- trunk/pingus/src/input2/control.hpp 2007-09-01 03:08:21 UTC (rev 3047)
+++ trunk/pingus/src/input2/control.hpp 2007-09-01 03:58:03 UTC (rev 3048)
@@ -43,7 +43,7 @@
   virtual ~Control() {
   }
 
-  void notify_parent() 
+  virtual void notify_parent() 
   {
     if (parent)
       {
@@ -51,7 +51,7 @@
       }
     else
       {
-        std::cout << "Event thingy: " << std::endl;
+        std::cout << "Input: Control: Error: parent missing! " << std::endl;
       }
   }
 
@@ -83,6 +83,56 @@
   }
 };
 
+class ButtonGroup : public Button 
+{
+private:
+  std::vector<Button*> buttons;
+  
+public: 
+  ButtonGroup(Control* parent)
+    : Button(parent)
+  {}
+
+  void add_button(Button* button) {
+    buttons.push_back(button);
+  }
+
+  virtual void update(Control* ctrl)
+  {
+    ButtonState new_state = BUTTON_RELEASED;
+
+    for(std::vector<Button*>::iterator i = buttons.begin(); 
+        i != buttons.end(); ++i)
+      {
+        if ((*i)->get_state() == BUTTON_PRESSED)
+          new_state = BUTTON_PRESSED;
+      }
+
+    if (new_state != state)
+      {
+        state = new_state;
+        notify_parent();
+      }
+  }
+};
+
+class ControllerButton : public ButtonGroup
+{
+private:
+  int id;
+
+public:
+  ControllerButton(int id_)
+    : ButtonGroup(0),
+      id(id_)
+  {}
+
+  virtual void notify_parent() {
+    std::cout << "Button " << id << " was " << (state == BUTTON_PRESSED
+                                                ? "pressed" : "released") << 
std::endl;    
+  }
+};
+
 class Axis : public Control 
 {
 protected:
@@ -144,35 +194,6 @@
   }
 };
 
-class ButtonGroup : public Button 
-{
-private:
-  std::vector<Button*> buttons;
-  
-public: 
-  ButtonGroup(Control* parent)
-    : Button(parent)
-  {}
-
-  void update(Control* ctrl)
-  {
-    ButtonState new_state = BUTTON_RELEASED;
-
-    for(std::vector<Button*>::iterator i = buttons.begin(); 
-        i != buttons.end(); ++i)
-      {
-        if ((*i)->get_state() == BUTTON_PRESSED)
-          new_state = BUTTON_PRESSED;
-      }
-
-    if (new_state != state)
-      {
-        state = new_state;
-        notify_parent();
-      }
-  }
-};
-
 class AxisGroup : public Axis {
 private:
   std::vector<Axis*> axes;

Modified: trunk/pingus/src/input2/controller.hpp
===================================================================
--- trunk/pingus/src/input2/controller.hpp      2007-09-01 03:08:21 UTC (rev 
3047)
+++ trunk/pingus/src/input2/controller.hpp      2007-09-01 03:58:03 UTC (rev 
3048)
@@ -28,20 +28,28 @@
 
 class Controller
 {
-public:
+private:
   // State Stuff
-  std::vector<Button*>   buttons;
+  std::vector<ControllerButton*>   buttons;
   std::vector<Axis*>     axis;
   std::vector<Pointer*>  pointer;
   std::vector<Scroller*> scroller;
   
+public:
   // Events
   std::vector<Event> events;
 
   Controller()  {}
   ~Controller() {}
 
-  void add_button(int id, Button* button) {
+  ControllerButton* get_button(int id) {
+    if (id >= 0 && id < int(buttons.size()))
+      return buttons[id];
+    else
+      return 0;
+  }
+
+  void add_button(int id, ControllerButton* button) {
     if (int(buttons.size())-1 < id)
       buttons.resize(id+1);
    

Modified: trunk/pingus/src/input2/manager.cpp
===================================================================
--- trunk/pingus/src/input2/manager.cpp 2007-09-01 03:08:21 UTC (rev 3047)
+++ trunk/pingus/src/input2/manager.cpp 2007-09-01 03:58:03 UTC (rev 3048)
@@ -109,7 +109,15 @@
                   Driver* drv = load_driver(driver);
                   if (drv)
                     {
-                      Button* button = drv->create_button(*j, 0);
+                      int id = desc.get_definition(i->get_name()).id;
+                      ControllerButton* ctrl_button = 
controller.get_button(id);
+                      if (!ctrl_button)
+                        {
+                          ctrl_button = new ControllerButton(id);
+                          controller.add_button(id, ctrl_button);
+                        }
+
+                      Button* button = drv->create_button(*j, ctrl_button);
                       if (!button)
                         {
                           std::cout << "Driver '" << driver << "' couldn't 
create button '" 
@@ -118,8 +126,7 @@
                         }
                       else
                         {
-                          
controller.add_button(desc.get_definition(i->get_name()).id, 
-                                                button);
+                          ctrl_button->add_button(button);
                         }
                     }
                   else





reply via email to

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