|
@@ -31,6 +31,7 @@ Container::Container()
|
|
|
: _layout(NULL), _scrollBarTopCap(NULL), _scrollBarVertical(NULL), _scrollBarBottomCap(NULL),
|
|
: _layout(NULL), _scrollBarTopCap(NULL), _scrollBarVertical(NULL), _scrollBarBottomCap(NULL),
|
|
|
_scrollBarLeftCap(NULL), _scrollBarHorizontal(NULL), _scrollBarRightCap(NULL),
|
|
_scrollBarLeftCap(NULL), _scrollBarHorizontal(NULL), _scrollBarRightCap(NULL),
|
|
|
_scroll(SCROLL_NONE), _scrollBarBounds(Rectangle::empty()), _scrollPosition(Vector2::zero()),
|
|
_scroll(SCROLL_NONE), _scrollBarBounds(Rectangle::empty()), _scrollPosition(Vector2::zero()),
|
|
|
|
|
+ _scrollBarsAlwaysVisible(false), _scrollBarOpacity(1.0f),
|
|
|
_scrolling(false), _firstX(0), _firstY(0),
|
|
_scrolling(false), _firstX(0), _firstY(0),
|
|
|
_lastX(0), _lastY(0),
|
|
_lastX(0), _lastY(0),
|
|
|
_startTimeX(0), _startTimeY(0), _lastTime(0),
|
|
_startTimeX(0), _startTimeY(0), _lastTime(0),
|
|
@@ -84,7 +85,13 @@ Container* Container::create(Theme::Style* style, Properties* properties, Theme*
|
|
|
Container* container = Container::create(getLayoutType(layoutString));
|
|
Container* container = Container::create(getLayoutType(layoutString));
|
|
|
container->initialize(style, properties);
|
|
container->initialize(style, properties);
|
|
|
container->_scroll = getScroll(properties->getString("scroll"));
|
|
container->_scroll = getScroll(properties->getString("scroll"));
|
|
|
|
|
+ container->_scrollBarsAlwaysVisible = properties->getBool("scrollBarsAlwaysVisible");
|
|
|
|
|
+ if (!container->_scrollBarsAlwaysVisible)
|
|
|
|
|
+ {
|
|
|
|
|
+ container->_scrollBarOpacity = 0.0f;
|
|
|
|
|
+ }
|
|
|
container->addControls(theme, properties);
|
|
container->addControls(theme, properties);
|
|
|
|
|
+ container->_layout->update(container, container->_scrollPosition);
|
|
|
|
|
|
|
|
return container;
|
|
return container;
|
|
|
}
|
|
}
|
|
@@ -265,6 +272,20 @@ Container::Scroll Container::getScroll() const
|
|
|
return _scroll;
|
|
return _scroll;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void Container::setScrollBarsAlwaysVisible(bool alwaysVisible)
|
|
|
|
|
+{
|
|
|
|
|
+ if (alwaysVisible != _scrollBarsAlwaysVisible)
|
|
|
|
|
+ {
|
|
|
|
|
+ _scrollBarsAlwaysVisible = alwaysVisible;
|
|
|
|
|
+ _dirty = true;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool Container::getScrollBarsAlwaysVisible() const
|
|
|
|
|
+{
|
|
|
|
|
+ return _scrollBarsAlwaysVisible;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
Animation* Container::getAnimation(const char* id) const
|
|
Animation* Container::getAnimation(const char* id) const
|
|
|
{
|
|
{
|
|
|
std::vector<Control*>::const_iterator itr = _controls.begin();
|
|
std::vector<Control*>::const_iterator itr = _controls.begin();
|
|
@@ -365,26 +386,29 @@ void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needs
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (_scroll != SCROLL_NONE)
|
|
|
|
|
|
|
+ if (_scroll != SCROLL_NONE && (_scrollBarOpacity > 0.0f))
|
|
|
{
|
|
{
|
|
|
// Draw scroll bars.
|
|
// Draw scroll bars.
|
|
|
Rectangle clipRegion(_viewportClipBounds);
|
|
Rectangle clipRegion(_viewportClipBounds);
|
|
|
|
|
|
|
|
spriteBatch->begin();
|
|
spriteBatch->begin();
|
|
|
|
|
|
|
|
- if (_scrollBarBounds.height > 0 && (_scrolling || _velocity.y))
|
|
|
|
|
|
|
+ if (_scrollBarBounds.height > 0)
|
|
|
{
|
|
{
|
|
|
const Rectangle& topRegion = _scrollBarTopCap->getRegion();
|
|
const Rectangle& topRegion = _scrollBarTopCap->getRegion();
|
|
|
const Theme::UVs& topUVs = _scrollBarTopCap->getUVs();
|
|
const Theme::UVs& topUVs = _scrollBarTopCap->getUVs();
|
|
|
Vector4 topColor = _scrollBarTopCap->getColor();
|
|
Vector4 topColor = _scrollBarTopCap->getColor();
|
|
|
|
|
+ topColor.w *= _scrollBarOpacity;
|
|
|
|
|
|
|
|
const Rectangle& verticalRegion = _scrollBarVertical->getRegion();
|
|
const Rectangle& verticalRegion = _scrollBarVertical->getRegion();
|
|
|
const Theme::UVs& verticalUVs = _scrollBarVertical->getUVs();
|
|
const Theme::UVs& verticalUVs = _scrollBarVertical->getUVs();
|
|
|
Vector4 verticalColor = _scrollBarVertical->getColor();
|
|
Vector4 verticalColor = _scrollBarVertical->getColor();
|
|
|
|
|
+ verticalColor.w *= _scrollBarOpacity;
|
|
|
|
|
|
|
|
const Rectangle& bottomRegion = _scrollBarBottomCap->getRegion();
|
|
const Rectangle& bottomRegion = _scrollBarBottomCap->getRegion();
|
|
|
const Theme::UVs& bottomUVs = _scrollBarBottomCap->getUVs();
|
|
const Theme::UVs& bottomUVs = _scrollBarBottomCap->getUVs();
|
|
|
Vector4 bottomColor = _scrollBarBottomCap->getColor();
|
|
Vector4 bottomColor = _scrollBarBottomCap->getColor();
|
|
|
|
|
+ bottomColor.w *= _scrollBarOpacity;
|
|
|
|
|
|
|
|
clipRegion.width += verticalRegion.width;
|
|
clipRegion.width += verticalRegion.width;
|
|
|
|
|
|
|
@@ -402,19 +426,22 @@ void Container::draw(SpriteBatch* spriteBatch, const Rectangle& clip, bool needs
|
|
|
spriteBatch->draw(bounds.x, bounds.y, bounds.width, bounds.height, bottomUVs.u1, bottomUVs.v1, bottomUVs.u2, bottomUVs.v2, bottomColor, clipRegion);
|
|
spriteBatch->draw(bounds.x, bounds.y, bounds.width, bounds.height, bottomUVs.u1, bottomUVs.v1, bottomUVs.u2, bottomUVs.v2, bottomColor, clipRegion);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (_scrollBarBounds.width > 0 && (_scrolling || _velocity.x))
|
|
|
|
|
|
|
+ if (_scrollBarBounds.width > 0)
|
|
|
{
|
|
{
|
|
|
const Rectangle& leftRegion = _scrollBarLeftCap->getRegion();
|
|
const Rectangle& leftRegion = _scrollBarLeftCap->getRegion();
|
|
|
const Theme::UVs& leftUVs = _scrollBarLeftCap->getUVs();
|
|
const Theme::UVs& leftUVs = _scrollBarLeftCap->getUVs();
|
|
|
Vector4 leftColor = _scrollBarLeftCap->getColor();
|
|
Vector4 leftColor = _scrollBarLeftCap->getColor();
|
|
|
|
|
+ leftColor.w *= _scrollBarOpacity;
|
|
|
|
|
|
|
|
const Rectangle& horizontalRegion = _scrollBarHorizontal->getRegion();
|
|
const Rectangle& horizontalRegion = _scrollBarHorizontal->getRegion();
|
|
|
const Theme::UVs& horizontalUVs = _scrollBarHorizontal->getUVs();
|
|
const Theme::UVs& horizontalUVs = _scrollBarHorizontal->getUVs();
|
|
|
Vector4 horizontalColor = _scrollBarHorizontal->getColor();
|
|
Vector4 horizontalColor = _scrollBarHorizontal->getColor();
|
|
|
|
|
+ horizontalColor.w *= _scrollBarOpacity;
|
|
|
|
|
|
|
|
const Rectangle& rightRegion = _scrollBarRightCap->getRegion();
|
|
const Rectangle& rightRegion = _scrollBarRightCap->getRegion();
|
|
|
const Theme::UVs& rightUVs = _scrollBarRightCap->getUVs();
|
|
const Theme::UVs& rightUVs = _scrollBarRightCap->getUVs();
|
|
|
Vector4 rightColor = _scrollBarRightCap->getColor();
|
|
Vector4 rightColor = _scrollBarRightCap->getColor();
|
|
|
|
|
+ rightColor.w *= _scrollBarOpacity;
|
|
|
|
|
|
|
|
clipRegion.height += horizontalRegion.height;
|
|
clipRegion.height += horizontalRegion.height;
|
|
|
|
|
|
|
@@ -696,6 +723,15 @@ void Container::updateScroll()
|
|
|
((-_scrollPosition.y) / totalHeight) * clipHeight,
|
|
((-_scrollPosition.y) / totalHeight) * clipHeight,
|
|
|
scrollWidth, scrollHeight);
|
|
scrollWidth, scrollHeight);
|
|
|
|
|
|
|
|
|
|
+ // If scroll velocity is 0 and scrollbars are not always visible, trigger fade-out animation.
|
|
|
|
|
+ if (!_scrolling && _velocity.isZero() && !_scrollBarsAlwaysVisible && _scrollBarOpacity == 1.0f)
|
|
|
|
|
+ {
|
|
|
|
|
+ float to = 0;
|
|
|
|
|
+ _scrollBarOpacity = 0.99f;
|
|
|
|
|
+ Animation* animation = createAnimationFromTo("scrollbar-fade-out", ANIMATE_OPACITY, &_scrollBarOpacity, &to, Curve::QUADRATIC_IN_OUT, 500L);
|
|
|
|
|
+ animation->getClip()->play();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Position controls within scroll area.
|
|
// Position controls within scroll area.
|
|
|
_layout->update(this, _scrollPosition);
|
|
_layout->update(this, _scrollPosition);
|
|
|
}
|
|
}
|
|
@@ -710,6 +746,7 @@ bool Container::touchEventScroll(Touch::TouchEvent evt, int x, int y, unsigned i
|
|
|
_velocity.set(0, 0);
|
|
_velocity.set(0, 0);
|
|
|
_scrolling = true;
|
|
_scrolling = true;
|
|
|
_startTimeX = _startTimeY = 0;
|
|
_startTimeX = _startTimeY = 0;
|
|
|
|
|
+ _scrollBarOpacity = 1.0f;
|
|
|
return true;
|
|
return true;
|
|
|
|
|
|
|
|
case Touch::TOUCH_MOVE:
|
|
case Touch::TOUCH_MOVE:
|
|
@@ -822,4 +859,45 @@ bool sortControlsByZOrder(Control* c1, Control* c2)
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+unsigned int Container::getAnimationPropertyComponentCount(int propertyId) const
|
|
|
|
|
+{
|
|
|
|
|
+ switch(propertyId)
|
|
|
|
|
+ {
|
|
|
|
|
+ case ANIMATE_OPACITY:
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ default:
|
|
|
|
|
+ return Control::getAnimationPropertyComponentCount(propertyId);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void Container::getAnimationPropertyValue(int propertyId, AnimationValue* value)
|
|
|
|
|
+{
|
|
|
|
|
+ GP_ASSERT(value);
|
|
|
|
|
+
|
|
|
|
|
+ switch(propertyId)
|
|
|
|
|
+ {
|
|
|
|
|
+ case ANIMATE_OPACITY:
|
|
|
|
|
+ value->setFloat(0, _scrollBarOpacity);
|
|
|
|
|
+ default:
|
|
|
|
|
+ Control::getAnimationPropertyValue(propertyId, value);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void Container::setAnimationPropertyValue(int propertyId, AnimationValue* value, float blendWeight)
|
|
|
|
|
+{
|
|
|
|
|
+ GP_ASSERT(value);
|
|
|
|
|
+
|
|
|
|
|
+ switch(propertyId)
|
|
|
|
|
+ {
|
|
|
|
|
+ case ANIMATE_OPACITY:
|
|
|
|
|
+ _scrollBarOpacity = Curve::lerp(blendWeight, _opacity, value->getFloat(0));
|
|
|
|
|
+ _dirty = true;
|
|
|
|
|
+ default:
|
|
|
|
|
+ Control::setAnimationPropertyValue(propertyId, value, blendWeight);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
}
|
|
}
|