瀏覽代碼

Fixes scrolling issues (and mouse wheel support!)
Fixes multi-input bug with Slider controls.
Fixes bug where Form was not handling "consumeEvents" property in .form file.
Enables multi-touch support in sample04-particles.

Kieran Cunney 13 年之前
父節點
當前提交
91f0eb1561

+ 32 - 24
gameplay/src/Button.cpp

@@ -38,41 +38,49 @@ bool Button::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contac
     switch (evt)
     {
     case Touch::TOUCH_PRESS:
-        if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
-            y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
+        if (_contactIndex == INVALID_CONTACT_INDEX)
         {
-            _contactIndex = (int) contactIndex;
+			if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
+				y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
+			{
+				_contactIndex = (int) contactIndex;
 
-            setState(Control::ACTIVE);
+				setState(Control::ACTIVE);
 
-            notifyListeners(Listener::PRESS);
+				notifyListeners(Listener::PRESS);
 
-            return _consumeInputEvents;
-        }
-        else
-        {
-            setState(Control::NORMAL);
+				return _consumeInputEvents;
+			}
+			else
+			{
+				setState(Control::NORMAL);
+			}
         }
         break;
 
     case Touch::TOUCH_RELEASE:
-        _contactIndex = INVALID_CONTACT_INDEX;
-        notifyListeners(Listener::RELEASE);
-        if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
-            y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
-        {
-            setState(Control::FOCUS);
-
-            notifyListeners(Listener::CLICK);
-        }
-        else
+        if (_contactIndex == (int) contactIndex)
         {
-            setState(Control::NORMAL);
+			_contactIndex = INVALID_CONTACT_INDEX;
+			notifyListeners(Listener::RELEASE);
+			if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
+				y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
+			{
+				setState(Control::FOCUS);
+
+				notifyListeners(Listener::CLICK);
+			}
+			else
+			{
+				setState(Control::NORMAL);
+			}
+			return _consumeInputEvents;
         }
-        return _consumeInputEvents;
-
+        break;
     case Touch::TOUCH_MOVE:
-        return _consumeInputEvents;
+        if (_contactIndex == (int) contactIndex)
+            return _consumeInputEvents;
+        break;
     }
 
     return false;

+ 9 - 11
gameplay/src/CheckBox.cpp

@@ -84,17 +84,15 @@ bool CheckBox::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int cont
     switch (evt)
     {
     case Touch::TOUCH_RELEASE:
-        {
-            if (_state == Control::ACTIVE)
-            {
-                if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
-                    y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
-                {
-                    _checked = !_checked;
-                    notifyListeners(Control::Listener::VALUE_CHANGED);
-                }
-            }
-        }
+		if (_contactIndex == (int) contactIndex && _state == Control::ACTIVE)
+		{
+			if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
+				y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
+			{
+				_checked = !_checked;
+				notifyListeners(Control::Listener::VALUE_CHANGED);
+			}
+		}
         break;
     }
 

+ 7 - 7
gameplay/src/Container.cpp

@@ -746,7 +746,7 @@ bool Container::touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned i
 				_scrollBarOpacityClip = NULL;
 			}
 			_scrollBarOpacity = 1.0f;
-
+            _dirty = true;
 			return _consumeInputEvents;
     	}
 		break;
@@ -808,7 +808,7 @@ bool Container::touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned i
                 _scrollingStartTimeY = gameTime;
 
             _scrollingLastTime = gameTime;
-
+            _dirty = true;
             return _consumeInputEvents;
         }
         break;
@@ -825,6 +825,7 @@ bool Container::touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned i
 			{
 				_scrollingVelocity.set(0, 0);
 				_scrollingMouseVertically = _scrollingMouseHorizontally = false;
+                _dirty = true;
 				return _consumeInputEvents;
 			}
 
@@ -861,7 +862,7 @@ bool Container::touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned i
 			}
 
 			_scrollingMouseVertically = _scrollingMouseHorizontally = false;
-
+            _dirty = true;
 			return _consumeInputEvents;
     	}
     	break;
@@ -940,6 +941,7 @@ bool Container::mouseEventScroll(Mouse::MouseEvent evt, int x, int y, int wheelD
                 _scrollBarOpacityClip = NULL;
             }
             _scrollBarOpacity = 1.0f;
+            _dirty = true;
             return _consumeInputEvents;
     }
 
@@ -986,12 +988,11 @@ bool Container::pointerEvent(bool mouse, char evt, int x, int y, int data)
 
         Control::State currentState = control->getState();
         if ((control->isContainer() && currentState == Control::FOCUS) || 
-            (currentState != Control::NORMAL && control->_contactIndex == data) ||
+            (currentState != Control::NORMAL) ||// && control->_contactIndex == data) ||
             ((evt == Touch::TOUCH_PRESS ||
               evt == Mouse::MOUSE_PRESS_LEFT_BUTTON ||
               evt == Mouse::MOUSE_PRESS_MIDDLE_BUTTON ||
-              evt == Mouse::MOUSE_PRESS_RIGHT_BUTTON ||
-              evt == Mouse::MOUSE_WHEEL) &&
+              evt == Mouse::MOUSE_PRESS_RIGHT_BUTTON) &&
                 x >= xPos + boundsX &&
                 x <= xPos + boundsX + bounds.width &&
                 y >= yPos + boundsY &&
@@ -1045,7 +1046,6 @@ bool Container::pointerEvent(bool mouse, char evt, int x, int y, int data)
         if ((mouse && mouseEventScroll((Mouse::MouseEvent)evt, x - xPos, y - yPos, data)) ||
             (!mouse && touchEventScroll((Touch::TouchEvent)evt, x - xPos, y - yPos, (unsigned int)data)))
         {
-            _dirty = true;
             eventConsumed = true;
         }
     }

+ 15 - 13
gameplay/src/Control.cpp

@@ -707,7 +707,7 @@ bool Control::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int conta
         // Controls that don't have an ACTIVE state go to the FOCUS state when pressed.
         // (Other controls, such as buttons and sliders, become ACTIVE when pressed and go to the FOCUS state on release.)
         // Labels are never any state other than NORMAL.
-        if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
+        if (_contactIndex == INVALID_CONTACT_INDEX && x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
             y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
         {
             _contactIndex = (int) contactIndex;
@@ -720,26 +720,28 @@ bool Control::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int conta
         {
             // If this control was in focus, it's not any more.
             _state = NORMAL;
-            _contactIndex = INVALID_CONTACT_INDEX;
         }
         break;
             
     case Touch::TOUCH_RELEASE:
+        if (_contactIndex == (int)contactIndex)
+        {
+			_contactIndex = INVALID_CONTACT_INDEX;
 
-        _contactIndex = INVALID_CONTACT_INDEX;
+			// Always trigger Listener::RELEASE
+			notifyListeners(Listener::RELEASE);
 
-        // Always trigger Listener::RELEASE
-        notifyListeners(Listener::RELEASE);
+			// Only trigger Listener::CLICK if both PRESS and RELEASE took place within the control's bounds.
+			if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
+				y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
+			{
+				// Leave this control in the FOCUS state.
+				notifyListeners(Listener::CLICK);
+			}
 
-        // Only trigger Listener::CLICK if both PRESS and RELEASE took place within the control's bounds.
-        if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
-            y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
-        {
-            // Leave this control in the FOCUS state.
-            notifyListeners(Listener::CLICK);
+			return _consumeInputEvents;
         }
-
-        return _consumeInputEvents;
+        break;
     }
 
     return false;

+ 1 - 1
gameplay/src/Form.cpp

@@ -168,7 +168,7 @@ Form* Form::create(const char* url)
     }
     form->initialize(style, formProperties);
 
-    form->_consumeInputEvents = formProperties->getBool("consumeInputs");
+    form->_consumeInputEvents = formProperties->getBool("consumeEvents");
 
     // Alignment
     if ((form->_alignment & Control::ALIGN_BOTTOM) == Control::ALIGN_BOTTOM)

+ 93 - 81
gameplay/src/Joystick.cpp

@@ -123,103 +123,115 @@ bool Joystick::touchEvent(Touch::TouchEvent touchEvent, int x, int y, unsigned i
     {
         case Touch::TOUCH_PRESS:
         {
-            float dx = 0.0f;
-            float dy = 0.0f;
-
-            _contactIndex = (int) contactIndex;
-            notifyListeners(Listener::PRESS);
-
-            // Get the displacement of the touch from the centre.
-            if (!_relative)
-            {
-                dx = x - _screenRegion.width * 0.5f;
-                dy = _screenRegion.height * 0.5f - y;
-            }
-            else
+            if (_contactIndex == INVALID_CONTACT_INDEX)
             {
-                _screenRegion.x = x + _bounds.x - _screenRegion.width * 0.5f;
-                _screenRegion.y = y + _bounds.y - _screenRegion.height * 0.5f;
-            }
-
-            _displacement.set(dx, dy);
-
-            // If the displacement is greater than the radius, then cap the displacement to the
-            // radius.
+                float dx = 0.0f;
+                float dy = 0.0f;
+
+                _contactIndex = (int) contactIndex;
+                notifyListeners(Listener::PRESS);
+
+                // Get the displacement of the touch from the centre.
+                if (!_relative)
+                {
+                    dx = x - _screenRegion.width * 0.5f;
+                    dy = _screenRegion.height * 0.5f - y;
+                }
+                else
+                {
+                    _screenRegion.x = x + _bounds.x - _screenRegion.width * 0.5f;
+                    _screenRegion.y = y + _bounds.y - _screenRegion.height * 0.5f;
+                }
+
+                _displacement.set(dx, dy);
+
+                // If the displacement is greater than the radius, then cap the displacement to the
+                // radius.
             
-            Vector2 value;
-            if ((fabs(_displacement.x) > _radius) || (fabs(_displacement.y) > _radius))
-            {
-                _displacement.normalize();
-                value.set(_displacement);
-                _displacement.scale(_radius);
-            }
-            else
-            {
-                value.set(_displacement);
-                GP_ASSERT(_radius);
-                value.scale(1.0f / _radius);
-            }
-
-            // Check if the value has changed. Won't this always be the case?
-            if (_value != value)
-            {
-                _value.set(value);
-                _dirty = true;
-                notifyListeners(Listener::VALUE_CHANGED);
+                Vector2 value;
+                if ((fabs(_displacement.x) > _radius) || (fabs(_displacement.y) > _radius))
+                {
+                    _displacement.normalize();
+                    value.set(_displacement);
+                    _displacement.scale(_radius);
+                }
+                else
+                {
+                    value.set(_displacement);
+                    GP_ASSERT(_radius);
+                    value.scale(1.0f / _radius);
+                }
+
+                // Check if the value has changed. Won't this always be the case?
+                if (_value != value)
+                {
+                    _value.set(value);
+                    _dirty = true;
+                    notifyListeners(Listener::VALUE_CHANGED);
+                }
+
+                _state = ACTIVE;
+                return _consumeInputEvents;
             }
-
-            _state = ACTIVE;
-            return _consumeInputEvents;
+            break;
         }
         case Touch::TOUCH_MOVE:
         {
-            float dx = x - ((_relative) ? _screenRegion.x - _bounds.x : 0.0f) - _screenRegion.width * 0.5f;
-            float dy = -(y - ((_relative) ? _screenRegion.y - _bounds.y : 0.0f) - _screenRegion.height * 0.5f);
+            if (_contactIndex == (int) contactIndex)
+            {
+                float dx = x - ((_relative) ? _screenRegion.x - _bounds.x : 0.0f) - _screenRegion.width * 0.5f;
+                float dy = -(y - ((_relative) ? _screenRegion.y - _bounds.y : 0.0f) - _screenRegion.height * 0.5f);
             
-            _displacement.set(dx, dy);
+                _displacement.set(dx, dy);
             
-            Vector2 value;
-            if ((fabs(_displacement.x) > _radius) || (fabs(_displacement.y) > _radius))
-            {
-                _displacement.normalize();
-                value.set(_displacement);
-                _displacement.scale(_radius);
-            }
-            else
-            {
-                value.set(_displacement);
-                GP_ASSERT(_radius);
-                value.scale(1.0f / _radius);
-            }
-
-            if (_value != value)
-            {
-                _value.set(value);
-                _dirty = true;
-                notifyListeners(Listener::VALUE_CHANGED);
+                Vector2 value;
+                if ((fabs(_displacement.x) > _radius) || (fabs(_displacement.y) > _radius))
+                {
+                    _displacement.normalize();
+                    value.set(_displacement);
+                    _displacement.scale(_radius);
+                }
+                else
+                {
+                    value.set(_displacement);
+                    GP_ASSERT(_radius);
+                    value.scale(1.0f / _radius);
+                }
+
+                if (_value != value)
+                {
+                    _value.set(value);
+                    _dirty = true;
+                    notifyListeners(Listener::VALUE_CHANGED);
+                }
+
+                return _consumeInputEvents;
             }
-
-            return _consumeInputEvents;
+            break;
         }
         case Touch::TOUCH_RELEASE:
         {
-            _contactIndex = INVALID_CONTACT_INDEX;
+            if (_contactIndex == (int) contactIndex)
+            {
+                _contactIndex = INVALID_CONTACT_INDEX;
 
-            notifyListeners(Listener::RELEASE);
+                notifyListeners(Listener::RELEASE);
 
-            // Reset displacement and direction vectors.
-            _displacement.set(0.0f, 0.0f);
-            Vector2 value(_displacement);
-            if (_value != value)
-            {
-                _value.set(value);
-                _dirty = true;
-                notifyListeners(Listener::VALUE_CHANGED);
-            }
+                // Reset displacement and direction vectors.
+                _displacement.set(0.0f, 0.0f);
+                Vector2 value(_displacement);
+                if (_value != value)
+                {
+                    _value.set(value);
+                    _dirty = true;
+                    notifyListeners(Listener::VALUE_CHANGED);
+                }
 
-            _state = NORMAL;
+                _state = NORMAL;
 
-            return _consumeInputEvents;
+                return _consumeInputEvents;
+            }
+            break;
         }
     }
 

+ 11 - 11
gameplay/src/RadioButton.cpp

@@ -93,18 +93,18 @@ bool RadioButton::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int c
     {
     case Touch::TOUCH_RELEASE:
         {
-            if (_state == Control::ACTIVE)
+            if (_contactIndex == (int) _contactIndex && _state == Control::ACTIVE)
             {
-                if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
-                    y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
-                {
-                    if (!_selected)
-                    {
-                        RadioButton::clearSelected(_groupId);
-                        _selected = true;
-                        notifyListeners(Listener::VALUE_CHANGED);
-                    }
-                }
+				if (x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
+					y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
+				{
+					if (!_selected)
+					{
+						RadioButton::clearSelected(_groupId);
+						_selected = true;
+						notifyListeners(Listener::VALUE_CHANGED);
+					}
+				}
             }
         }
         break;

+ 15 - 7
gameplay/src/Slider.cpp

@@ -101,10 +101,16 @@ bool Slider::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contac
     switch (evt)
     {
     case Touch::TOUCH_PRESS:
+        if (_contactIndex != INVALID_CONTACT_INDEX)
+            return false;
         _state = Control::ACTIVE;
+        
         // Fall through to calculate new value.
     case Touch::TOUCH_MOVE:
-    case Touch::TOUCH_RELEASE:
+    
+        if (evt != Touch::TOUCH_PRESS && _contactIndex != (int)contactIndex)
+            return false;
+
         if (_state == ACTIVE &&
             x > _clipBounds.x && x <= _clipBounds.x + _clipBounds.width &&
             y > _clipBounds.y && y <= _clipBounds.y + _clipBounds.height)
@@ -145,12 +151,14 @@ bool Slider::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contac
 
             _dirty = true;
         }
+        break;
+    case Touch::TOUCH_RELEASE:
 
-        if (evt == Touch::TOUCH_RELEASE)
-        {
-            _state = FOCUS;
-            _dirty = true;
-        }
+        if (_contactIndex != (int) contactIndex)// (evt == Touch::TOUCH_RELEASE)
+            return false;
+
+        _dirty = true;
+        _state = FOCUS;
         break;
     }
     
@@ -180,7 +188,7 @@ bool Slider::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
 
         case Mouse::MOUSE_WHEEL:
         {
-            if (_state == FOCUS)
+            if (_state == FOCUS || _state == ACTIVE)
             {
                 float total = _max - _min;
                 float oldValue = _value;