Browse Source

Added Control::removeListener()

Darryl Gough 13 years ago
parent
commit
2e6a101e87
3 changed files with 33 additions and 1 deletions
  1. 23 0
      gameplay/src/Control.cpp
  2. 8 1
      gameplay/src/Control.h
  3. 2 0
      gameplay/src/Transform.h

+ 23 - 0
gameplay/src/Control.cpp

@@ -694,6 +694,29 @@ void Control::addListener(Control::Listener* listener, int eventFlags)
     }
 }
 
+void Control::removeListener(Control::Listener* listener)
+{
+    if (_listeners == NULL || listener == NULL)
+        return;
+
+    for (std::map<Listener::EventType, std::list<Listener*>*>::iterator itr = _listeners->begin(); itr != _listeners->end();)
+    {
+        itr->second->remove(listener);
+
+        if(itr->second->empty())
+        {
+            std::list<Listener*>* list = itr->second;
+            _listeners->erase(itr++);
+            SAFE_DELETE(list);
+        }
+        else
+            ++itr;
+    }
+
+    if (_listeners->empty())
+        SAFE_DELETE(_listeners);
+}
+
 void Control::addSpecificListener(Control::Listener* listener, Listener::EventType eventType)
 {
     GP_ASSERT(listener);

+ 8 - 1
gameplay/src/Control.h

@@ -725,7 +725,7 @@ public:
     virtual const char* getType() const;
 
     /**
-     * Add a listener to be notified of specific events affecting
+     * Adds a listener to be notified of specific events affecting
      * this control.  Event types can be OR'ed together.
      * E.g. To listen to touch-press and touch-release events,
      * pass <code>Control::Listener::TOUCH | Control::Listener::RELEASE</code>
@@ -736,6 +736,13 @@ public:
      */
     virtual void addListener(Control::Listener* listener, int eventFlags);
 
+    /**
+     * Removes a listener from this control.
+     * 
+     * @param listener The listener to remove.
+     */
+    virtual void removeListener(Control::Listener* listener);
+
     /**
      * @see AnimationTarget::getAnimationPropertyComponentCount
      */

+ 2 - 0
gameplay/src/Transform.h

@@ -757,6 +757,8 @@ public:
 
     /**
      * Removes a transform listener.
+     * 
+     * @param listener The listener to remove.
      */
     void removeListener(Transform::Listener* listener);