Просмотр исходного кода

Fix to allow sliders to be manipulated inside a scrollable container.

sgrenier 12 лет назад
Родитель
Сommit
dd60b64a87

+ 11 - 3
gameplay/src/Container.cpp

@@ -392,12 +392,17 @@ bool Container::isScrollBarsAutoHide() const
 
 bool Container::isScrolling() const
 {
+    if (_scrolling &&
+        (abs(_scrollingLastX - _scrollingVeryFirstX) > SCROLL_THRESHOLD ||
+        abs(_scrollingLastY - _scrollingVeryFirstY) > SCROLL_THRESHOLD))
+    {
+        return true;
+    }
+
     if (_parent && _parent->isScrolling())
         return true;
 
-    return (_scrolling &&
-            (abs(_scrollingLastX - _scrollingVeryFirstX) > SCROLL_THRESHOLD ||
-             abs(_scrollingLastY - _scrollingVeryFirstY) > SCROLL_THRESHOLD));
+    return false;
 }
 
 const Vector2& Container::getScrollPosition() const
@@ -985,6 +990,9 @@ void Container::stopScrolling()
     _scrollingVelocity.set(0, 0);
     _scrolling = false;
     _dirty = true;
+
+    if (_parent)
+        _parent->stopScrolling();
 }
 
 bool Container::isContainer() const

+ 5 - 2
gameplay/src/Container.h

@@ -209,6 +209,11 @@ public:
      */
     bool isScrolling() const;
 
+    /**
+     * Stops this container from scrolling if it is currently being scrolled.
+     */
+    void stopScrolling();
+
     /**
      * Get the friction applied to scrolling velocity for this container.
      */
@@ -581,8 +586,6 @@ private:
     // Starts scrolling at the given horizontal and vertical speeds.
     void startScrolling(float x, float y, bool resetTime = true);
 
-    void stopScrolling();
-
     void clearContacts();
     bool inContact();
 

+ 7 - 5
gameplay/src/Control.cpp

@@ -1044,12 +1044,12 @@ void Control::addSpecificListener(Control::Listener* listener, Control::Listener
 
 bool Control::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
 {
-    return _consumeInputEvents;
+    return false;// _consumeInputEvents;
 }
 
 bool Control::keyEvent(Keyboard::KeyEvent evt, int key)
 {
-    return _consumeInputEvents;
+    return false;// _consumeInputEvents;
 }
 
 bool Control::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
@@ -1061,7 +1061,7 @@ bool Control::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
 
 bool Control::gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad, unsigned int analogIndex)
 {
-    return _consumeInputEvents;
+    return false;// _consumeInputEvents;
 }
 
 void Control::notifyListeners(Control::Listener::EventType eventType)
@@ -1336,15 +1336,17 @@ Control::State Control::getState(const char* state)
 
 Theme::ThemeImage* Control::getImage(const char* id, State state)
 {
+    Theme::ThemeImage* image = NULL;
+
     Theme::Style::Overlay* overlay = getOverlay(state);
     if (overlay)
     {
         Theme::ImageList* imageList = overlay->getImageList();
         if (imageList)
-            return imageList->getImage(id);
+            image = imageList->getImage(id);
     }
 
-    return _style->getTheme()->_emptyImage;
+    return image ? image : _style->getTheme()->_emptyImage;
 }
 
 const char* Control::getType() const

+ 25 - 25
gameplay/src/Form.cpp

@@ -693,31 +693,6 @@ bool Form::pointerEventInternal(bool mouse, int evt, int x, int y, int param)
 
     if (ctrl)
     {
-        // Handle container scrolling
-        Control* tmp = ctrl;
-        while (tmp)
-        {
-            if (tmp->isContainer())
-            {
-                Container* container = static_cast<Container*>(tmp);
-                if (container->_scroll != SCROLL_NONE)
-                {
-                    if (mouse)
-                    {
-                        if (container->mouseEventScroll((Mouse::MouseEvent)evt, formX - tmp->_absoluteBounds.x, formY - tmp->_absoluteBounds.y, param))
-                            return true;
-                    }
-                    else
-                    {
-                        if (container->touchEventScroll((Touch::TouchEvent)evt, formX - tmp->_absoluteBounds.x, formY - tmp->_absoluteBounds.y, param))
-                            return true;
-                    }
-                    break; // scrollable parent container found
-                }
-            }
-            tmp = tmp->_parent;
-        }
-
         // Handle setting focus for all press events
         if (pressEvent)
         {
@@ -765,6 +740,31 @@ bool Form::pointerEventInternal(bool mouse, int evt, int x, int y, int param)
                     return true;
             }
 
+            // Handle container scrolling
+            Control* tmp = ctrl;
+            while (tmp)
+            {
+                if (tmp->isContainer())
+                {
+                    Container* container = static_cast<Container*>(tmp);
+                    if (container->_scroll != SCROLL_NONE)
+                    {
+                        if (mouse)
+                        {
+                            if (container->mouseEventScroll((Mouse::MouseEvent)evt, formX - tmp->_absoluteBounds.x, formY - tmp->_absoluteBounds.y, param))
+                                return true;
+                        }
+                        else
+                        {
+                            if (container->touchEventScroll((Touch::TouchEvent)evt, formX - tmp->_absoluteBounds.x, formY - tmp->_absoluteBounds.y, param))
+                                return true;
+                        }
+                        break; // scrollable parent container found
+                    }
+                }
+                tmp = tmp->_parent;
+            }
+
             // Consume all input events anyways?
             if (ctrl->getConsumeInputEvents())
                 return true;

+ 11 - 6
gameplay/src/Slider.cpp

@@ -8,14 +8,10 @@ namespace gameplay
 static const float SCROLLWHEEL_FRACTION = 0.1f;
 // Fraction of slider to scroll for a delta of 1.0f when a gamepad or keyboard is used.
 static const float MOVE_FRACTION = 0.005f;
-// Distance that a slider must be moved before it starts consuming input events,
-// e.g. to prevent its parent container from scrolling at the same time.
-static const float SLIDER_THRESHOLD = 5.0f;
 
 Slider::Slider() : _min(0.0f), _max(0.0f), _step(0.0f), _value(0.0f), _delta(0.0f), _minImage(NULL),
     _maxImage(NULL), _trackImage(NULL), _markerImage(NULL), _valueTextVisible(false),
-    _valueTextAlignment(Font::ALIGN_BOTTOM_HCENTER), _valueTextPrecision(0), _valueText(""),
-    _selectButtonDown(false), _directionButtonDown(false), _gamepadValue(0.0f)
+    _valueTextAlignment(Font::ALIGN_BOTTOM_HCENTER), _valueTextPrecision(0), _valueText(""), _gamepadValue(0.0f)
 {
     _canFocus = true;
 }
@@ -229,13 +225,22 @@ bool Slider::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contac
     return Control::touchEvent(evt, x, y, contactIndex);
 }
 
+static bool isScrollable(Container* container)
+{
+    if (container->getScroll() != Container::SCROLL_NONE)
+        return true;
+
+    Container* parent = static_cast<Container*>(container->getParent());
+    return parent ? isScrollable(parent) : false;
+}
+
 bool Slider::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
 {
     switch (evt)
     {
         case Mouse::MOUSE_WHEEL:
         {
-            if (hasFocus())
+            if (hasFocus() && !isScrollable(_parent))
             {
                 float total = _max - _min;
                 float oldValue = _value;

+ 0 - 25
gameplay/src/Slider.h

@@ -279,26 +279,6 @@ protected:
      */
     float _delta;
 
-    /**
-     * The X coordinate of the first touch event in a sequence.
-     */
-    float _originalX;
-
-    /**
-     * The Slider's original value at the start of a sequence of touch events.
-     */
-    float _originalValue;
-
-    /**
-     * The Slider's original setting of _consumeInputEvents at the start of a sequence of touch events.
-     */
-    bool _originalConsumeInputEvents;
-
-    /**
-     * Whether the Slider's current movement has been cancelled, e.g. because the user is scrolling the parent container.
-     */
-    bool _moveCancelled;
-
     /**
      * The image for the minimum slider value.
      */
@@ -339,11 +319,6 @@ protected:
      */
     std::string _valueText;
 
-    // Used by gamepads to toggle Slider state between FOCUS and ACTIVE.
-    bool _selectButtonDown;
-
-    bool _directionButtonDown;
-
     float _gamepadValue;
 
 private:

+ 2 - 3
gameplay/src/Theme.cpp

@@ -711,10 +711,9 @@ Theme::ThemeImage* Theme::ImageList::getImage(const char* imageId) const
 {
     GP_ASSERT(imageId);
 
-    std::vector<ThemeImage*>::const_iterator it;
-    for (it = _images.begin(); it != _images.end(); ++it)
+    for (size_t i = 0, count = _images.size(); i < count; ++i)
     {
-        ThemeImage* image = *it;
+        ThemeImage* image = _images[i];
         GP_ASSERT(image);
         GP_ASSERT(image->getId());
         if (strcmpnocase(image->getId(), imageId) == 0)

+ 0 - 13
samples/particles/res/editor.form

@@ -14,7 +14,6 @@ form particleEditor
 		imageSize = 30, 30
 		text = VSYNC
 		checked = true
-		consumeInputEvents = true
 	}
  
     container leftSide
@@ -23,18 +22,15 @@ form particleEditor
         layout = LAYOUT_VERTICAL
         width = 160
         autoHeight = true
-        consumeInputEvents = true
 
         container saveLoad
         {
             style = basic
             size = 160, 100
-            consumeInputEvents = true
             layout = LAYOUT_VERTICAL
 
 	        button save
 	        {
-                consumeInputEvents = true
 		        style = buttonStyle
                 width = 140
 		        height = 40
@@ -54,7 +50,6 @@ form particleEditor
         {
 	        style = basic
 	        size = 160, 200
-	        consumeInputEvents = true
 	        layout = LAYOUT_VERTICAL
 
             label
@@ -75,7 +70,6 @@ form particleEditor
             {
                 style = noBorder
                 size = 160, 230
-                consumeInputEvents = true
 		        layout = LAYOUT_VERTICAL
 
                 radioButton additive
@@ -121,7 +115,6 @@ form particleEditor
 
                     textBox frameCount
                     {
-                        consumeInputEvents = true
                         style = textBox
                         text = 1
                         size = 45, 22
@@ -144,7 +137,6 @@ form particleEditor
 
                     textBox frameWidth
                     {
-                        consumeInputEvents = true
                         style = textBox
                         text = 1
                         size = 45, 22
@@ -167,7 +159,6 @@ form particleEditor
 
                     textBox frameHeight
                     {
-                        consumeInputEvents = true
                         style = textBox
                         text = 1
                         size = 45, 22
@@ -191,7 +182,6 @@ form particleEditor
 	        style = basic
 	        layout = LAYOUT_VERTICAL
 	        size = 160, 200
-	        consumeInputEvents = true
 
 	        // Burst emission
 	        button emit
@@ -240,7 +230,6 @@ form particleEditor
 
         button reset
 	    {
-            consumeInputEvents = true
 		    style = buttonStyle
             width = 160
 		    height = 40
@@ -257,7 +246,6 @@ form particleEditor
         layout = LAYOUT_VERTICAL
         scroll = SCROLL_VERTICAL
         scrollBarsAutoHide = false
-        consumeInputEvents = true
 
         // Particle Size
         label titleSize
@@ -590,7 +578,6 @@ form particleEditor
 	{
 		style = noBorder
 		size = 160, 50
-		consumeInputEvents = true
         alignment = ALIGN_BOTTOM_HCENTER
 
 		button zoomIn