Bladeren bron

Fix for scrolling containers using FlowLayout.
Fix for scrolling top-level Forms.
Documentation related to scrolling containers.
Allows style and/or skin to be unspecified.
Removes (now useless) empty styles and skins from Particles sample.

Adam Blake 13 jaren geleden
bovenliggende
commit
97cdb2b2dc

+ 10 - 3
gameplay/src/Container.cpp

@@ -102,9 +102,16 @@ void Container::addControls(Theme* theme, Properties* properties)
 
         const char* controlStyleName = controlSpace->getString("style");
         Theme::Style* controlStyle = NULL;
-        GP_ASSERT(controlStyleName);
-        controlStyle = theme->getStyle(controlStyleName);
-        GP_ASSERT(controlStyle);
+        if (controlStyleName)
+        {
+            controlStyle = theme->getStyle(controlStyleName);
+        }
+        else
+        {
+            Theme::Style::Overlay* overlay = Theme::Style::Overlay::create();
+            controlStyle = new Theme::Style(theme, "", 1.0f / theme->_texture->getWidth(), 1.0f / theme->_texture->getHeight(),
+                Theme::Margin::empty(), Theme::Border::empty(), overlay, overlay, overlay, overlay);
+        }
 
         std::string controlName(controlSpace->getNamespace());
         std::transform(controlName.begin(), controlName.end(), controlName.begin(), (int(*)(int))toupper);

+ 25 - 6
gameplay/src/Container.h

@@ -25,7 +25,8 @@ namespace gameplay
          size        = <width, height>   // Size of the container, measured in pixels.
          width       = <width>   // Can be used in place of 'size', e.g. with 'autoHeight = true'
          height      = <height>  // Can be used in place of 'size', e.g. with 'autoWidth = true'
-         scroll      = <Container::Scroll constant>
+         scroll      = <Container::Scroll constant> // Whether scrolling is allowed and in which directions.
+         scrollBarsAutoHide = <bool>    // Whether scrollbars fade out when not in use.
   
          // All the nested controls within this container.
          container 
@@ -46,6 +47,9 @@ class Container : public Control
 {
 public:
 
+    /**
+     * Constant used to auto-hide scrollbars.
+     */
     static const int ANIMATE_SCROLLBAR_OPACITY = 8;
 
     /**
@@ -164,17 +168,17 @@ public:
     /**
      * @see AnimationTarget#getAnimationPropertyComponentCount
      */
-    unsigned int getAnimationPropertyComponentCount(int propertyId) const;
+    virtual unsigned int getAnimationPropertyComponentCount(int propertyId) const;
 
     /**
      * @see AnimationTarget#getAnimationProperty
      */
-    void getAnimationPropertyValue(int propertyId, AnimationValue* value);
+    virtual void getAnimationPropertyValue(int propertyId, AnimationValue* value);
 
     /**
      * @see AnimationTarget#setAnimationProperty
      */
-    void setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight = 1.0f);
+    virtual void setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight = 1.0f);
 
 protected:
 
@@ -272,8 +276,22 @@ protected:
      */
     void updateScroll();
 
+    /**
+     * Applies touch events to scroll state.
+     *
+     * @return Whether the touch event was consumed by scrolling within this container.
+     *
+     * @see Touch::TouchEvent
+     */
     bool touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex);
 
+    /**
+     * Get a Scroll enum from a matching string.
+     *
+     * @param scroll A string representing a Scroll enum.
+     *
+     * @return The Scroll enum value that matches the given string.
+     */
     static Scroll getScroll(const char* scroll);
 
     /**
@@ -286,6 +304,7 @@ protected:
      */
     std::vector<Control*> _controls;
 
+    // Images used to draw scrollbars.
     Theme::ThemeImage* _scrollBarTopCap;
     Theme::ThemeImage* _scrollBarVertical;
     Theme::ThemeImage* _scrollBarBottomCap;
@@ -323,9 +342,9 @@ protected:
     Vector2 _scrollingVelocity;
     // Friction dampens velocity.
     float _scrollingFriction;
-    // Are we scrolling to the right ?
+    // Are we scrolling to the right?
     bool _scrollingRight;
-    // Are we scrolling down ?
+    // Are we scrolling down?
     bool _scrollingDown;
 
 private:

+ 3 - 3
gameplay/src/Control.h

@@ -687,17 +687,17 @@ public:
     /**
      * @see AnimationTarget#getAnimationPropertyComponentCount
      */
-    unsigned int getAnimationPropertyComponentCount(int propertyId) const;
+    virtual unsigned int getAnimationPropertyComponentCount(int propertyId) const;
 
     /**
      * @see AnimationTarget#getAnimationProperty
      */
-    void getAnimationPropertyValue(int propertyId, AnimationValue* value);
+    virtual void getAnimationPropertyValue(int propertyId, AnimationValue* value);
 
     /**
      * @see AnimationTarget#setAnimationProperty
      */
-    void setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight = 1.0f);
+    virtual void setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight = 1.0f);
 
 protected:
 

+ 1 - 4
gameplay/src/FlowLayout.cpp

@@ -78,10 +78,7 @@ void FlowLayout::update(const Container* container, const Vector2& offset)
         yPosition = rowY + margin.top;
 
         control->setPosition(xPosition, yPosition);
-        if (control->isDirty() || control->isContainer())
-        {
-            control->update(container, offset);
-        }
+        control->update(container, offset);
 
         xPosition += bounds.width + margin.right;
 

+ 19 - 1
gameplay/src/Form.cpp

@@ -90,8 +90,19 @@ Form* Form::create(const char* url)
     Game* game = Game::getInstance();
     Matrix::createOrthographicOffCenter(0, game->getWidth(), game->getHeight(), 0, 0, 1, &form->_defaultProjectionMatrix);
 
+    Theme::Style* style = NULL;
     const char* styleName = formProperties->getString("style");
-    form->initialize(theme->getStyle(styleName), formProperties);
+    if (styleName)
+    {
+        style = theme->getStyle(styleName);
+    }
+    else
+    {
+        Theme::Style::Overlay* overlay = Theme::Style::Overlay::create();
+        style = new Theme::Style(theme, "", 1.0f / theme->_texture->getWidth(), 1.0f / theme->_texture->getHeight(),
+            Theme::Margin::empty(), Theme::Border::empty(), overlay, overlay, overlay, overlay);
+    }
+    form->initialize(style, formProperties);
 
     // Alignment
     if ((form->_alignment & Control::ALIGN_BOTTOM) == Control::ALIGN_BOTTOM)
@@ -113,10 +124,17 @@ Form* Form::create(const char* url)
     }
 
     form->_scroll = getScroll(formProperties->getString("scroll"));
+    form->_scrollBarsAutoHide = formProperties->getBool("scrollBarsAutoHide");
+    if (form->_scrollBarsAutoHide)
+    {
+        form->_scrollBarOpacity = 0.0f;
+    }
 
     // Add all the controls to the form.
     form->addControls(theme, formProperties);
 
+    form->update();
+
     SAFE_DELETE(properties);
 
     __forms.push_back(form);

+ 3 - 1
gameplay/src/ThemeStyle.cpp

@@ -85,7 +85,9 @@ Theme::Style::Overlay* Theme::Style::Overlay::create()
     return overlay;
 }
 
-Theme::Style::Overlay::Overlay() : _skin(NULL), _cursor(NULL), _imageList(NULL), _font(NULL)
+Theme::Style::Overlay::Overlay()
+    : _skin(NULL), _cursor(NULL), _imageList(NULL), _font(NULL),
+    _fontSize(0), _alignment(Font::ALIGN_TOP_LEFT), _textRightToLeft(false), _textColor(Vector4::one()), _opacity(1.0f)
 {
 }
 

+ 4 - 0
gameplay/src/ThemeStyle.h

@@ -22,6 +22,8 @@ class Theme::Style
 {
     friend class Theme;
     friend class Control;
+    friend class Container;
+    friend class Form;
 
 private:
 
@@ -45,6 +47,8 @@ private:
         friend class Theme;
         friend class Theme::Style;
         friend class Control;
+        friend class Container;
+        friend class Form;
 
     private: