Explorar el Código

Merge pull request #428 from ablake/next

Misc. bug-fixes, tests, tweaks.
Sean Paul Taylor hace 13 años
padre
commit
be119f71e5

+ 7 - 5
gameplay/src/Container.cpp

@@ -41,7 +41,7 @@ Container::Container()
       _scrollingRight(false), _scrollingDown(false),
       _scrollingMouseVertically(false), _scrollingMouseHorizontally(false),
       _scrollBarOpacityClip(NULL), _zIndexDefault(0), _focusIndexDefault(0), _focusIndexMax(0), _totalWidth(0), _totalHeight(0),
-      _contactIndices(0)
+      _contactIndices(0), _initializedWithScroll(false)
 {
 }
 
@@ -602,10 +602,6 @@ Layout::Type Container::getLayoutType(const char* layoutString)
     {
         return Layout::LAYOUT_FLOW;
     }
-    else if (layoutName == "LAYOUT_SCROLL")
-    {
-        return Layout::LAYOUT_SCROLL;
-    }
     else
     {
         // Default.
@@ -615,6 +611,12 @@ Layout::Type Container::getLayoutType(const char* layoutString)
 
 void Container::updateScroll()
 {
+    if (!_initializedWithScroll)
+    {
+        _initializedWithScroll = true;
+        _layout->update(this, _scrollPosition);
+    }
+
     // Update Time.
     static double lastFrameTime = Game::getGameTime();
     double frameTime = Game::getGameTime();

+ 2 - 0
gameplay/src/Container.h

@@ -507,6 +507,8 @@ private:
     float _totalHeight;
 
     int _contactIndices;
+
+    bool _initializedWithScroll;
 };
 
 }

+ 1 - 1
gameplay/src/Control.cpp

@@ -7,7 +7,7 @@ namespace gameplay
 
 Control::Control()
     : _id(""), _state(Control::NORMAL), _bounds(Rectangle::empty()), _clipBounds(Rectangle::empty()), _viewportClipBounds(Rectangle::empty()),
-    _clearBounds(Rectangle::empty()), _dirty(true), _consumeInputEvents(true), _listeners(NULL),
+    _clearBounds(Rectangle::empty()), _dirty(true), _consumeInputEvents(true), _autoWidth(false), _autoHeight(false), _listeners(NULL),
     _contactIndex(INVALID_CONTACT_INDEX), _styleOverridden(false), _skin(NULL)
 {
     addScriptEvent("controlEvent", "<Control>[Control::Listener::EventType]");

+ 4 - 2
gameplay/src/Control.h

@@ -214,13 +214,15 @@ public:
 
     /** 
      * Set the desired width of the control, including it's border and padding, before clipping.
-     * @param width The width;
+     *
+     * @param width The width.
      */
     virtual void setWidth(float width);
 
     /** 
      * Set the desired height of the control, including it's border and padding, before clipping.
-     * @param height The height;
+     *
+     * @param height The height.
      */
     virtual void setHeight(float height);
 

+ 16 - 7
gameplay/src/Form.cpp

@@ -199,8 +199,6 @@ Form* Form::create(const char* url)
     // Add all the controls to the form.
     form->addControls(theme, formProperties);
 
-    form->update(0.0f);
-
     SAFE_DELETE(properties);
 
     __forms.push_back(form);
@@ -240,7 +238,8 @@ void Form::setSize(float width, float height)
         height = Game::getInstance()->getHeight();
     }
 
-    if (width != _bounds.width || height != _bounds.height)
+    if (width != 0.0f && height != 0.0f &&
+        (width != _bounds.width || height != _bounds.height))
     {
         // Width and height must be powers of two to create a texture.
         unsigned int w = nextPowerOfTwo(width);
@@ -273,11 +272,11 @@ void Form::setSize(float width, float height)
         _theme->setProjectionMatrix(_defaultProjectionMatrix);
         FrameBuffer::bindDefault();
         game->setViewport(prevViewport);
-
-        _bounds.width = width;
-        _bounds.height = height;
-        _dirty = true;
     }
+    
+    _bounds.width = width;
+    _bounds.height = height;
+    _dirty = true;
 }
 
 void Form::setBounds(const Rectangle& bounds)
@@ -286,6 +285,16 @@ void Form::setBounds(const Rectangle& bounds)
     setSize(bounds.width, bounds.height);
 }
 
+void Form::setWidth(float width)
+{
+    setSize(width, _bounds.height);
+}
+
+void Form::setHeight(float height)
+{
+    setSize(_bounds.width, height);
+}
+
 void Form::setAutoWidth(bool autoWidth)
 {
     if (_autoWidth != autoWidth)

+ 14 - 0
gameplay/src/Form.h

@@ -104,6 +104,20 @@ public:
      */
     virtual void setBounds(const Rectangle& bounds);
 
+    /** 
+     * Set the desired width of the form.
+     *
+     * @param width The width.
+     */
+    virtual void setWidth(float width);
+
+    /** 
+     * Set the desired height of the form.
+     *
+     * @param height The height.
+     */
+    virtual void setHeight(float height);
+
     /**
      * Set this form's width to that of the display.
      *

+ 14 - 2
gameplay/src/Layout.cpp

@@ -20,8 +20,20 @@ void Layout::align(Control* control, const Container* container)
         const Theme::Border& containerBorder = container->getBorder(container->getState());
         const Theme::Padding& containerPadding = container->getPadding();
 
-        float clipWidth = containerBounds.width - containerBorder.left - containerBorder.right - containerPadding.left - containerPadding.right;
-        float clipHeight = containerBounds.height - containerBorder.top - containerBorder.bottom - containerPadding.top - containerPadding.bottom;
+        float clipWidth;
+        float clipHeight; 
+        if (container->getScroll() != Container::SCROLL_NONE)
+        {
+            const Rectangle& verticalScrollBarBounds = container->getImageRegion("verticalScrollBar", container->getState());
+            const Rectangle& horizontalScrollBarBounds = container->getImageRegion("horizontalScrollBar", container->getState());
+            clipWidth = containerBounds.width - containerBorder.left - containerBorder.right - containerPadding.left - containerPadding.right - verticalScrollBarBounds.width;
+            clipHeight = containerBounds.height - containerBorder.top - containerBorder.bottom - containerPadding.top - containerPadding.bottom - horizontalScrollBarBounds.height;
+        }
+        else
+        {
+            clipWidth = containerBounds.width - containerBorder.left - containerBorder.right - containerPadding.left - containerPadding.right;
+            clipHeight = containerBounds.height - containerBorder.top - containerBorder.bottom - containerPadding.top - containerPadding.bottom;
+        }
 
         if (control->_autoWidth)
         {

+ 1 - 9
gameplay/src/Layout.h

@@ -45,15 +45,7 @@ public:
          * Absolute layout: Controls are not modified at all by this layout.
          * They must be positioned and sized manually.
          */
-        LAYOUT_ABSOLUTE,
-
-        /**
-         * Scroll layout: Controls may be placed outside the bounds of the container.
-         * The user can then touch and drag to scroll.  By default controls are placed
-         * based on absolute positions in the .form file, but vertical or horizontal
-         * automatic positioning is an available option.
-         */
-        LAYOUT_SCROLL
+        LAYOUT_ABSOLUTE
     };
 
     /**

+ 8 - 5
gameplay/src/PhysicsVehicleWheel.cpp

@@ -212,11 +212,14 @@ void PhysicsVehicleWheel::update(float elapsedTime)
     _host->_node->getMatrix().transformPoint(&wheelPos);
 
     // Filter out noise from Bullet
-    float dt = elapsedTime / 1000.0f;
-    Vector3 delta = commandedPosition - wheelPos - _positionDelta;
-    float threshold = getStrutRestLength() * 2.0f;
-    float tau = (delta.lengthSquared() > threshold*threshold) ? 0 : 0.06f;
-    _positionDelta += (commandedPosition - wheelPos - _positionDelta) * (dt / (dt + tau));
+    if (elapsedTime > 0.0f)
+    {
+        float dt = elapsedTime / 1000.0f;
+        Vector3 delta = commandedPosition - wheelPos - _positionDelta;
+        float threshold = getStrutRestLength() * 2.0f;
+        float tau = (delta.lengthSquared() > threshold*threshold) ? 0 : 0.06f;
+        _positionDelta += (commandedPosition - wheelPos - _positionDelta) * (dt / (dt + tau));
+    }
 }
 
 bool PhysicsVehicleWheel::isFront() const

+ 4 - 1
gameplay/src/ThemeStyle.cpp

@@ -271,7 +271,10 @@ void Theme::Style::Overlay::setTextColor(const Vector4& color)
 
 const Rectangle& Theme::Style::Overlay::getImageRegion(const char* id) const
 {
-    GP_ASSERT(_imageList);
+    if (!_imageList)
+    {
+        return Rectangle::empty();
+    }
 
     ThemeImage* image = _imageList->getImage(id);
     if (image)

+ 0 - 1
gameplay/src/lua/lua_Global.cpp

@@ -554,7 +554,6 @@ void luaRegister_lua_Global()
         ScriptUtil::registerConstantString("LAYOUT_FLOW", "LAYOUT_FLOW", scopePath);
         ScriptUtil::registerConstantString("LAYOUT_VERTICAL", "LAYOUT_VERTICAL", scopePath);
         ScriptUtil::registerConstantString("LAYOUT_ABSOLUTE", "LAYOUT_ABSOLUTE", scopePath);
-        ScriptUtil::registerConstantString("LAYOUT_SCROLL", "LAYOUT_SCROLL", scopePath);
     }
 
     // Register enumeration Light::Type.

+ 0 - 5
gameplay/src/lua/lua_LayoutType.cpp

@@ -9,7 +9,6 @@ static const char* enumStringEmpty = "";
 static const char* luaEnumString_LayoutType_LAYOUT_FLOW = "LAYOUT_FLOW";
 static const char* luaEnumString_LayoutType_LAYOUT_VERTICAL = "LAYOUT_VERTICAL";
 static const char* luaEnumString_LayoutType_LAYOUT_ABSOLUTE = "LAYOUT_ABSOLUTE";
-static const char* luaEnumString_LayoutType_LAYOUT_SCROLL = "LAYOUT_SCROLL";
 
 Layout::Type lua_enumFromString_LayoutType(const char* s)
 {
@@ -19,8 +18,6 @@ Layout::Type lua_enumFromString_LayoutType(const char* s)
         return Layout::LAYOUT_VERTICAL;
     if (strcmp(s, luaEnumString_LayoutType_LAYOUT_ABSOLUTE) == 0)
         return Layout::LAYOUT_ABSOLUTE;
-    if (strcmp(s, luaEnumString_LayoutType_LAYOUT_SCROLL) == 0)
-        return Layout::LAYOUT_SCROLL;
     GP_ERROR("Invalid enumeration value '%s' for enumeration Layout::Type.", s);
     return Layout::LAYOUT_FLOW;
 }
@@ -33,8 +30,6 @@ const char* lua_stringFromEnum_LayoutType(Layout::Type e)
         return luaEnumString_LayoutType_LAYOUT_VERTICAL;
     if (e == Layout::LAYOUT_ABSOLUTE)
         return luaEnumString_LayoutType_LAYOUT_ABSOLUTE;
-    if (e == Layout::LAYOUT_SCROLL)
-        return luaEnumString_LayoutType_LAYOUT_SCROLL;
     GP_ERROR("Invalid enumeration value '%d' for enumeration Layout::Type.", e);
     return enumStringEmpty;
 }