-ScrollOvershootEffectGradient::ScrollOvershootEffectGradient(bool vertical) :
- ScrollOvershootEffect(vertical),
- mMaxOvershootImageSize(DEFAULT_MAX_OVERSHOOT_HEIGHT)
-{
- Image overshootImage = Image::New( OVERSHOOT_OVERLAY_IMAGE_PATH );
- mOvershootImage = ImageActor::New( overshootImage );
- mOvershootImage.SetParentOrigin(ParentOrigin::TOP_LEFT);
- mOvershootImage.SetAnchorPoint(AnchorPoint::TOP_LEFT);
- mOvershootImage.SetDrawMode(DrawMode::OVERLAY);
-}
-
-void ScrollOvershootEffectGradient::Apply(Scrollable& scrollable)
-{
- Actor scrollableActor = scrollable.Self();
- int overshootXPropertyIndex = scrollableActor.GetPropertyIndex(Toolkit::ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME);
- int overshootYPropertyIndex = scrollableActor.GetPropertyIndex(Toolkit::ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME);
-
- Constraint constraint = Constraint::New<Vector3>( Actor::SIZE,
- Source( scrollableActor, overshootXPropertyIndex ),
- Source( scrollableActor, overshootYPropertyIndex ),
- Source( scrollableActor, Actor::SIZE ),
- boost::bind( &ScrollOvershootEffectGradient::SizeConstraint, this, _1, _2, _3, _4) );
- mSizeConstraint = mOvershootImage.ApplyConstraint(constraint);
-
- constraint = Constraint::New<Quaternion>( Actor::ROTATION,
- Source( scrollableActor, overshootXPropertyIndex ),
- Source( scrollableActor, overshootYPropertyIndex ),
- boost::bind( &ScrollOvershootEffectGradient::RotationConstraint, this, _1, _2, _3) );
- mRotationConstraint = mOvershootImage.ApplyConstraint(constraint);
-
- constraint = Constraint::New<Vector3>( Actor::POSITION,
- Source( scrollableActor, Actor::SIZE ),
- Source( scrollableActor, overshootXPropertyIndex ),
- Source( scrollableActor, overshootYPropertyIndex ),
- boost::bind( &ScrollOvershootEffectGradient::PositionConstraint, this, _1, _2, _3, _4) );
- mPositionConstraint = mOvershootImage.ApplyConstraint(constraint);
-
- constraint = Constraint::New<bool>( Actor::VISIBLE,
- Source( scrollableActor, IsVertical() ? scrollableActor.GetPropertyIndex(Scrollable::SCROLLABLE_CAN_SCROLL_VERTICAL) : scrollableActor.GetPropertyIndex(Scrollable::SCROLLABLE_CAN_SCROLL_HORIZONTAL)),
- boost::bind( &ScrollOvershootEffectGradient::VisibilityConstraint, this, _1, _2) );
- mVisibilityConstraint = mOvershootImage.ApplyConstraint(constraint);
- scrollable.AddOverlay(mOvershootImage);
- SetPropertyNotifications(scrollableActor);
-}
-
-void ScrollOvershootEffectGradient::Remove(Scrollable& scrollable)
-{
- if(mOvershootImage)
- {
- if(mSizeConstraint)
- {
- mOvershootImage.RemoveConstraint(mSizeConstraint);
- mSizeConstraint = NULL;
- }
- if(mRotationConstraint)
- {
- mOvershootImage.RemoveConstraint(mRotationConstraint);
- mRotationConstraint = NULL;
- }
- if(mPositionConstraint)
- {
- mOvershootImage.RemoveConstraint(mPositionConstraint);
- mPositionConstraint = NULL;
- }
- if(mVisibilityConstraint)
- {
- mOvershootImage.RemoveConstraint(mVisibilityConstraint);
- mVisibilityConstraint = NULL;
- }
- scrollable.RemoveOverlay(mOvershootImage);
- }
-}
-
-Vector3 ScrollOvershootEffectGradient::SizeConstraint(const Vector3& current,
- const PropertyInput& overshootPropertyX, const PropertyInput& overshootPropertyY,
- const PropertyInput& parentSizeProperty)
-{
- float overshootx = overshootPropertyX.GetFloat();
- float overshooty = overshootPropertyY.GetFloat();
- const Vector3 parentSize = parentSizeProperty.GetVector3();
-
- float overlayWidth = IsVertical() ? parentSize.x : parentSize.y;
- float overlayHeight = mMaxOvershootImageSize * fabsf(IsVertical() ? overshooty : overshootx);
-
- return Vector3(overlayWidth, overlayHeight, current.z);
-}
-
-Quaternion ScrollOvershootEffectGradient::RotationConstraint(const Quaternion& current,
- const PropertyInput& overshootPropertyX, const PropertyInput& overshootPropertyY)
-{
- float overshootx = overshootPropertyX.GetFloat();
- float overshooty = overshootPropertyY.GetFloat();
-
- Quaternion rotation;
-
- if(IsVertical())
- {
- if(overshooty < -Math::MACHINE_EPSILON_0)
- {
- rotation = Quaternion(Math::PI, Vector3::ZAXIS);
- }
- else if(overshooty > Math::MACHINE_EPSILON_0)
- {
- rotation = Quaternion(0.0f, Vector3::ZAXIS);
- }
- }
- else
- {
- if(overshootx < -Math::MACHINE_EPSILON_0)
- {
- rotation = Quaternion(0.5f * Math::PI, Vector3::ZAXIS);
- }
- else if(overshootx > Math::MACHINE_EPSILON_0)
- {
- rotation = Quaternion(1.5f * Math::PI, Vector3::ZAXIS);
- }
- }
-
- return rotation;
-}
-
-Vector3 ScrollOvershootEffectGradient::PositionConstraint(const Vector3& current,
- const PropertyInput& parentSizeProperty,
- const PropertyInput& overshootPropertyX, const PropertyInput& overshootPropertyY)
-{
- float overshootx = overshootPropertyX.GetFloat();
- float overshooty = overshootPropertyY.GetFloat();
- const Vector3 parentSize = parentSizeProperty.GetVector3();
-
- Vector3 relativeOffset = Vector3::ZERO;
-
- if(IsVertical())
- {
- if(overshooty > Math::MACHINE_EPSILON_0)
- {
- relativeOffset = Vector3(0.0f, 0.0f, 0.0f);
- }
- else if (overshooty < -Math::MACHINE_EPSILON_0)
- {
- relativeOffset = Vector3(1.0f, 1.0f, 0.0f);
- }
- }
- else
- {
- if(overshootx > Math::MACHINE_EPSILON_0)
- {
- relativeOffset = Vector3(0.0f, 1.0f, 0.0f);
- }
- else if (overshootx < -Math::MACHINE_EPSILON_0)
- {
- relativeOffset = Vector3(1.0f, 0.0f, 0.0f);
- }
- }
-
- return relativeOffset * parentSize;
-}
-
-bool ScrollOvershootEffectGradient::VisibilityConstraint(const bool& current,
- const PropertyInput& canScrollProperty)
-{
- return canScrollProperty.GetBoolean();
-}
-
-ScrollOvershootEffectGradientPtr ScrollOvershootEffectGradient::New(bool vertical)
-{
- return new ScrollOvershootEffectGradient(vertical);
-}
-
-namespace
-{
-
-const std::string OVERSHOOT_PROPERTY_NAME( "uOvershoot" );
-const std::string OVERSHOOT_IMAGE_COUNT_PROPERTY_NAME( "uOvershootImageCount" );
-
-} // namespace
-
-OvershootRippleEffect::OvershootRippleEffect()
-{
-}
-
-//Call the Parent copy constructor to add reference to the implementation for this object
-OvershootRippleEffect::OvershootRippleEffect(ShaderEffect handle)
-:ShaderEffect(handle)
-{
-}
-
-OvershootRippleEffect::~OvershootRippleEffect()
-{
-}
-
-OvershootRippleEffect OvershootRippleEffect::New()
-{
- std::string vertextShader(
- "precision mediump float; \n"
- "uniform float uOvershoot; \n"
- "uniform float uOvershootImageCount; \n"
- "void main() \n"
- "{ \n"
- " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0); \n"
- " vTexCoord = aTexCoord; \n"
- " vTexCoord.y += (1.0 / uOvershootImageCount) * min(floor((abs(uOvershoot) * (uOvershootImageCount - 1.0)) + 0.5), (uOvershootImageCount - 1.0)); \n"
- "} \n" );
-
- std::string fragmentShader(
- "void main() \n"
- "{ \n"
- " gl_FragColor = texture2D(sTexture, vTexCoord); \n"
- "} \n" );
-
- // Create the implementation, temporarily owned on stack,
- Dali::ShaderEffect shaderEffectCustom = Dali::ShaderEffect::New(
- vertextShader,
- fragmentShader);
-
- /* Pass ownership to OvershootRippleEffect through overloaded constructor, So that it now has access to the
- Dali::ShaderEffect implementation */
- OvershootRippleEffect handle( shaderEffectCustom );
- handle.SetUniform(OVERSHOOT_PROPERTY_NAME, 0.0f);
- handle.SetUniform(OVERSHOOT_IMAGE_COUNT_PROPERTY_NAME, 10.0f);
- return handle;
-}
-
-void OvershootRippleEffect::SetOvershoot( float overshoot )
-{
- SetUniform( OVERSHOOT_PROPERTY_NAME, overshoot );
-}
-
-void OvershootRippleEffect::SetOvershootImageCount( float imageCount )
-{
- SetUniform( OVERSHOOT_IMAGE_COUNT_PROPERTY_NAME, imageCount );
-}
-
-const std::string& OvershootRippleEffect::GetOvershootPropertyName() const
-{
- return OVERSHOOT_PROPERTY_NAME;
-}
-
-const std::string& OvershootRippleEffect::GetOvershootImageCountPropertyName() const
-{
- return OVERSHOOT_IMAGE_COUNT_PROPERTY_NAME;
-}
-