2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <dali-toolkit/public-api/controls/scrollable/scrollable.h>
19 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
20 #include <dali-toolkit/internal/controls/scrollable/scroll-view/scroll-view-impl.h>
30 ///////////////////////////////////////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////////////////////////////////////
34 RulerDomain::RulerDomain(float min, float max, bool enabled)
41 float RulerDomain::Clamp(float x, float length, float scale) const
45 return Clamp(x, length, scale, clamped);
48 float RulerDomain::Clamp(float x, float length, float scale, ClampState &clamped) const
56 const float minExtent = min * scale;
57 const float maxExtent = max * scale - length;
60 clamped = ClampedToMin;
63 else if(x > maxExtent)
65 clamped = ClampedToMax;
73 float RulerDomain::GetSize() const
78 ///////////////////////////////////////////////////////////////////////////////////////////////////
80 ///////////////////////////////////////////////////////////////////////////////////////////////////
85 mDomain(RulerDomain(0.0f,1.0f,false))
93 Ruler::RulerType Ruler::GetType() const
98 bool Ruler::IsEnabled() const
108 void Ruler::Disable()
113 void Ruler::SetDomain(RulerDomain domain)
118 const RulerDomain &Ruler::GetDomain() const
123 void Ruler::DisableDomain()
125 mDomain = RulerDomain(0.0f,1.0f,false);
128 float Ruler::Clamp(float x, float length, float scale) const
130 return mDomain.Clamp(x, length, scale);
133 float Ruler::Clamp(float x, float length, float scale, ClampState &clamped) const
135 return mDomain.Clamp(x, length, scale, clamped);
138 float Ruler::SnapAndClamp(float x, float bias, float length, float scale) const
140 return Clamp(Snap(x, bias), length, scale);
143 float Ruler::SnapAndClamp(float x, float bias, float length, float scale, ClampState &clamped) const
145 return Clamp(Snap(x, bias), length, scale, clamped);
148 ///////////////////////////////////////////////////////////////////////////////////////////////////
150 ///////////////////////////////////////////////////////////////////////////////////////////////////
152 DefaultRuler::DefaultRuler()
157 float DefaultRuler::Snap(float x, float bias) const
162 float DefaultRuler::GetPositionFromPage(unsigned int page, unsigned int &volume, bool wrap) const
168 unsigned int DefaultRuler::GetPageFromPosition(float position, bool wrap) const
173 unsigned int DefaultRuler::GetTotalPages() const
178 ///////////////////////////////////////////////////////////////////////////////////////////////////
180 ///////////////////////////////////////////////////////////////////////////////////////////////////
182 FixedRuler::FixedRuler(float spacing)
188 float FixedRuler::Snap(float x, float bias) const
190 return floor(x / mSpacing + bias) * mSpacing;
193 float FixedRuler::GetPositionFromPage(unsigned int page, unsigned int &volume, bool wrap) const
195 float position = mDomain.min;
199 // spacing must be present.
200 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
202 unsigned int column = page;
204 // In carry mode, a volume (carry) is produced when page exceeds limit within domain
207 unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
210 column += pagesPerVolume;
211 column %= pagesPerVolume;
212 volume = page/pagesPerVolume;
216 position = mDomain.min + column * mSpacing;
218 else // Domain (or Spacing) is not present, carry page to volume.
229 unsigned int FixedRuler::GetPageFromPosition(float position, bool wrap) const
231 unsigned int page = 0;
233 // spacing must be present.
234 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
238 position = WrapInDomain(position, mDomain.min, mDomain.max);
240 page = floor((position - mDomain.min) / mSpacing + 0.5f);
244 unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
245 page %= pagesPerVolume;
252 unsigned int FixedRuler::GetTotalPages() const
254 unsigned int pagesPerVolume = 1;
256 // spacing must be present.
257 if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
259 pagesPerVolume = mDomain.GetSize() / mSpacing;
262 return pagesPerVolume;
265 ///////////////////////////////////////////////////////////////////////////////////////////////////
267 ///////////////////////////////////////////////////////////////////////////////////////////////////
269 const std::string ScrollView::SCROLL_PAGE_CURRENT( "scroll-page-current" );
270 const std::string ScrollView::SCROLL_TIME_PROPERTY_NAME( "scroll-time" );
271 const std::string ScrollView::SCROLL_POSITION_PROPERTY_NAME( "scroll-position" );
272 const std::string ScrollView::SCROLL_PRE_POSITION_PROPERTY_NAME( "scroll-pre-position" );
273 const std::string ScrollView::SCROLL_OVERSHOOT_X_PROPERTY_NAME( "scroll-overshoot-x" );
274 const std::string ScrollView::SCROLL_OVERSHOOT_Y_PROPERTY_NAME( "scroll-overshoot-y" );
275 const std::string ScrollView::SCROLL_FINAL_PROPERTY_NAME( "scroll-final" );
276 const std::string ScrollView::SCROLL_X_PROPERTY_NAME( "scroll-x" );
277 const std::string ScrollView::SCROLL_Y_PROPERTY_NAME( "scroll-y" );
278 const std::string ScrollView::SCROLL_SCALE_PROPERTY_NAME( "scroll-scale" );
279 const std::string ScrollView::SCROLL_WRAP_PROPERTY_NAME( "scroll-wrap" );
280 const std::string ScrollView::SCROLL_PANNING_PROPERTY_NAME( "scroll-panning" );
281 const std::string ScrollView::SCROLL_SCROLLING_PROPERTY_NAME( "scroll-scrolling" );
282 const std::string ScrollView::SCROLL_POSITION_DELTA_PROPERTY_NAME( "scroll-position-delta" );
283 const std::string ScrollView::SCROLL_START_PAGE_POSITION_PROPERTY_NAME( "scroll-start-page-position" );
285 const float ScrollView::DEFAULT_SLOW_SNAP_ANIMATION_DURATION(0.5f);
286 const float ScrollView::DEFAULT_FAST_SNAP_ANIMATION_DURATION(0.25f);
287 const float ScrollView::DEFAULT_SNAP_OVERSHOOT_DURATION(0.5f);
288 const float ScrollView::DEFAULT_MAX_OVERSHOOT(100.0f); // 100 pixels
290 const float ScrollView::DEFAULT_AXIS_AUTO_LOCK_GRADIENT(0.36f);
291 const float ScrollView::DEFAULT_FRICTION_COEFFICIENT(1.0f);
292 const float ScrollView::DEFAULT_FLICK_SPEED_COEFFICIENT(1.0f);
293 const float ScrollView::DEFAULT_MAX_FLICK_SPEED(3.0f);
295 const char* const ScrollView::SIGNAL_SNAP_STARTED = "snap-started";
297 ScrollView::ScrollView()
301 ScrollView::ScrollView(Internal::ScrollView& implementation)
302 : Scrollable(implementation)
306 ScrollView::ScrollView( Dali::Internal::CustomActor* internal )
307 : Scrollable( internal )
309 VerifyCustomActorPointer<Internal::ScrollView>(internal);
312 ScrollView::ScrollView( const ScrollView& handle )
313 : Scrollable( handle )
317 ScrollView& ScrollView::operator=( const ScrollView& handle )
319 if( &handle != this )
321 Control::operator=( handle );
326 ScrollView ScrollView::New()
328 return Internal::ScrollView::New();
331 ScrollView::~ScrollView()
335 ScrollView ScrollView::DownCast( BaseHandle handle )
337 return Control::DownCast<ScrollView, Internal::ScrollView>(handle);
340 AlphaFunction ScrollView::GetScrollSnapAlphaFunction() const
342 return GetImpl(*this).GetScrollSnapAlphaFunction();
345 void ScrollView::SetScrollSnapAlphaFunction(AlphaFunction alpha)
347 GetImpl(*this).SetScrollSnapAlphaFunction(alpha);
350 AlphaFunction ScrollView::GetScrollFlickAlphaFunction() const
352 return GetImpl(*this).GetScrollFlickAlphaFunction();
355 void ScrollView::SetScrollFlickAlphaFunction(AlphaFunction alpha)
357 GetImpl(*this).SetScrollFlickAlphaFunction(alpha);
360 float ScrollView::GetScrollSnapDuration() const
362 return GetImpl(*this).GetScrollSnapDuration();
365 void ScrollView::SetScrollSnapDuration(float time)
367 GetImpl(*this).SetScrollSnapDuration(time);
370 float ScrollView::GetScrollFlickDuration() const
372 return GetImpl(*this).GetScrollFlickDuration();
375 void ScrollView::SetScrollFlickDuration(float time)
377 GetImpl(*this).SetScrollFlickDuration(time);
380 void ScrollView::SetRulerX(RulerPtr ruler)
382 GetImpl(*this).SetRulerX(ruler);
385 void ScrollView::SetRulerY(RulerPtr ruler)
387 GetImpl(*this).SetRulerY(ruler);
390 void ScrollView::SetRulerScaleX(RulerPtr ruler)
392 GetImpl(*this).SetRulerScaleX(ruler);
395 void ScrollView::SetRulerScaleY(RulerPtr ruler)
397 GetImpl(*this).SetRulerScaleY(ruler);
400 void ScrollView::SetScrollSensitive(bool sensitive)
402 GetImpl(*this).SetScrollSensitive(sensitive);
405 void ScrollView::SetMaxOvershoot(float overshootX, float overshootY)
407 GetImpl(*this).SetMaxOvershoot(overshootX, overshootY);
410 void ScrollView::SetSnapOvershootAlphaFunction(AlphaFunction alpha)
412 GetImpl(*this).SetSnapOvershootAlphaFunction(alpha);
415 void ScrollView::SetSnapOvershootDuration(float duration)
417 GetImpl(*this).SetSnapOvershootDuration(duration);
420 void ScrollView::SetTouchesRequiredForPanning(unsigned int minTouches, unsigned int maxTouches, bool endOutside)
422 GetImpl(*this).SetTouchesRequiredForPanning(minTouches, maxTouches, endOutside);
425 void ScrollView::SetActorAutoSnap(bool enable)
427 GetImpl(*this).SetActorAutoSnap(enable);
430 void ScrollView::SetWrapMode(bool enable)
432 GetImpl(*this).SetWrapMode(enable);
435 int ScrollView::GetRefreshInterval() const
437 return GetImpl(*this).GetRefreshInterval();
440 void ScrollView::SetRefreshInterval(int milliseconds)
442 GetImpl(*this).SetRefreshInterval(milliseconds);
445 int ScrollView::GetScrollUpdateDistance() const
447 return GetImpl(*this).GetScrollUpdateDistance();
450 void ScrollView::SetScrollUpdateDistance(int distance)
452 GetImpl(*this).SetScrollUpdateDistance(distance);
455 bool ScrollView::GetAxisAutoLock() const
457 return GetImpl(*this).GetAxisAutoLock();
460 void ScrollView::SetAxisAutoLock(bool enable)
462 GetImpl(*this).SetAxisAutoLock(enable);
465 float ScrollView::GetAxisAutoLockGradient() const
467 return GetImpl(*this).GetAxisAutoLockGradient();
470 void ScrollView::SetAxisAutoLockGradient(float gradient)
472 GetImpl(*this).SetAxisAutoLockGradient(gradient);
475 float ScrollView::GetFrictionCoefficient() const
477 return GetImpl(*this).GetFrictionCoefficient();
480 void ScrollView::SetFrictionCoefficient(float friction)
482 GetImpl(*this).SetFrictionCoefficient(friction);
485 float ScrollView::GetFlickSpeedCoefficient() const
487 return GetImpl(*this).GetFlickSpeedCoefficient();
490 void ScrollView::SetFlickSpeedCoefficient(float speed)
492 GetImpl(*this).SetFlickSpeedCoefficient(speed);
495 float ScrollView::GetMaxFlickSpeed() const
497 return GetImpl(*this).GetMaxFlickSpeed();
500 void ScrollView::SetMaxFlickSpeed(float speed)
502 GetImpl(*this).SetMaxFlickSpeed(speed);
505 Vector2 ScrollView::GetMouseWheelScrollDistanceStep() const
507 return GetImpl(*this).GetMouseWheelScrollDistanceStep();
510 void ScrollView::SetMouseWheelScrollDistanceStep(Vector2 step)
512 GetImpl(*this).SetMouseWheelScrollDistanceStep(step);
515 Vector3 ScrollView::GetCurrentScrollPosition() const
517 return GetImpl(*this).GetCurrentScrollPosition();
520 void ScrollView::SetScrollPosition(const Vector3& position)
522 GetImpl(*this).SetScrollPosition(position);
525 Vector3 ScrollView::GetCurrentScrollScale() const
527 return GetImpl(*this).GetCurrentScrollScale();
530 unsigned int ScrollView::GetCurrentPage() const
532 return GetImpl(*this).GetCurrentPage();
535 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation)
537 GetImpl(*this).TransformTo(position, scale, rotation);
540 void ScrollView::TransformTo(const Vector3& position, const Vector3& scale, float rotation, float duration)
542 GetImpl(*this).TransformTo(position, scale, rotation, duration);
545 void ScrollView::ScrollTo(const Vector3 &position)
547 GetImpl(*this).ScrollTo(position);
550 void ScrollView::ScrollTo(const Vector3 &position, float duration)
552 GetImpl(*this).ScrollTo(position, duration);
555 void ScrollView::ScrollTo(const Vector3 &position, float duration,
556 DirectionBias horizontalBias, DirectionBias verticalBias)
558 GetImpl(*this).ScrollTo(position, duration, horizontalBias, verticalBias);
561 void ScrollView::ScrollTo(unsigned int page)
563 GetImpl(*this).ScrollTo(page);
566 void ScrollView::ScrollTo(unsigned int page, float duration)
568 GetImpl(*this).ScrollTo(page, duration);
571 void ScrollView::ScrollTo(unsigned int page, float duration, DirectionBias bias)
573 GetImpl(*this).ScrollTo(page, duration, bias);
576 void ScrollView::ScrollTo(Actor &actor)
578 GetImpl(*this).ScrollTo(actor);
581 void ScrollView::ScrollTo(Actor &actor, float duration)
583 GetImpl(*this).ScrollTo(actor, duration);
586 bool ScrollView::ScrollToSnapPoint()
588 return GetImpl(*this).ScrollToSnapPoint();
591 void ScrollView::ScaleTo(const Vector3 &scale)
593 GetImpl(*this).ScaleTo(scale);
596 void ScrollView::ScaleTo(const Vector3 &scale, float duration)
598 GetImpl(*this).ScaleTo(scale, duration);
601 void ScrollView::ApplyConstraintToChildren(Constraint constraint)
603 GetImpl(*this).ApplyConstraintToChildren(constraint);
606 void ScrollView::RemoveConstraintsFromChildren()
608 GetImpl(*this).RemoveConstraintsFromChildren();
611 void ScrollView::ApplyEffect(ScrollViewEffect effect)
613 GetImpl(*this).ApplyEffect(effect);
616 ScrollViewEffect ScrollView::ApplyEffect(ScrollView::PageEffect effect)
618 return GetImpl(*this).ApplyEffect(effect);
621 void ScrollView::RemoveEffect(ScrollViewEffect effect)
623 GetImpl(*this).RemoveEffect(effect);
626 void ScrollView::RemoveAllEffects()
628 GetImpl(*this).RemoveAllEffects();
631 void ScrollView::BindActor(Actor child)
633 GetImpl(*this).BindActor(child);
636 void ScrollView::UnbindActor(Actor child)
638 GetImpl(*this).UnbindActor(child);
641 ScrollView::SnapStartedSignalV2& ScrollView::SnapStartedSignal()
643 return GetImpl(*this).SnapStartedSignal();
646 void ScrollView::SetScrollingDirection( Radian direction, Radian threshold )
648 GetImpl(*this).SetScrollingDirection( direction, threshold );
651 void ScrollView::RemoveScrollingDirection( Radian direction )
653 GetImpl(*this).RemoveScrollingDirection( direction );
656 } // namespace Toolkit