The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
6.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_COMPONENTANIMATOR_JUCEHEADER__
  19. #define __JUCE_COMPONENTANIMATOR_JUCEHEADER__
  20. #include "../juce_Component.h"
  21. #include "../../../events/juce_ChangeBroadcaster.h"
  22. #include "../../../events/juce_Timer.h"
  23. //==============================================================================
  24. /**
  25. Animates a set of components, moving it to a new position.
  26. To use this, create a ComponentAnimator, and use its animateComponent() method
  27. to tell it to move components to destination positions. Any number of
  28. components can be animated by one ComponentAnimator object (if you've got a
  29. lot of components to move, it's much more efficient to share a single animator
  30. than to have many animators running at once).
  31. You'll need to make sure the animator object isn't deleted before it finishes
  32. moving the components.
  33. The class is a ChangeBroadcaster and sends a notification when any components
  34. start or finish being animated.
  35. */
  36. class JUCE_API ComponentAnimator : public ChangeBroadcaster,
  37. private Timer
  38. {
  39. public:
  40. //==============================================================================
  41. /** Creates a ComponentAnimator. */
  42. ComponentAnimator();
  43. /** Destructor. */
  44. ~ComponentAnimator();
  45. //==============================================================================
  46. /** Starts a component moving from its current position to a specified position.
  47. If the component is already in the middle of an animation, that will be abandoned,
  48. and a new animation will begin, moving the component from its current location.
  49. The start and end speed parameters let you apply some acceleration to the component's
  50. movement.
  51. @param component the component to move
  52. @param finalPosition the destination position and size to move it to
  53. @param millisecondsToSpendMoving how long, in milliseconds, it should take
  54. to arrive at its destination
  55. @param startSpeed a value to indicate the relative start speed of the
  56. animation. If this is 0, the component will start
  57. by accelerating from rest; higher values mean that it
  58. will have an initial speed greater than zero. If the
  59. value if greater than 1, it will decelerate towards the
  60. middle of its journey. To move the component at a constant
  61. rate for its entire animation, set both the start and
  62. end speeds to 1.0
  63. @param endSpeed a relative speed at which the component should be moving
  64. when the animation finishes. If this is 0, the component
  65. will decelerate to a standstill at its final position; higher
  66. values mean the component will still be moving when it stops.
  67. To move the component at a constant rate for its entire
  68. animation, set both the start and end speeds to 1.0
  69. */
  70. void animateComponent (Component* component,
  71. const Rectangle<int>& finalPosition,
  72. int millisecondsToSpendMoving,
  73. double startSpeed = 1.0,
  74. double endSpeed = 1.0);
  75. /** Stops a component if it's currently being animated.
  76. If moveComponentToItsFinalPosition is true, then the component will
  77. be immediately moved to its destination position and size. If false, it will be
  78. left in whatever location it currently occupies.
  79. */
  80. void cancelAnimation (Component* component,
  81. bool moveComponentToItsFinalPosition);
  82. /** Clears all of the active animations.
  83. If moveComponentsToTheirFinalPositions is true, all the components will
  84. be immediately set to their final positions. If false, they will be
  85. left in whatever locations they currently occupy.
  86. */
  87. void cancelAllAnimations (bool moveComponentsToTheirFinalPositions);
  88. /** Returns the destination position for a component.
  89. If the component is being animated, this will return the target position that
  90. was specified when animateComponent() was called.
  91. If the specified component isn't currently being animated, this method will just
  92. return its current position.
  93. */
  94. const Rectangle<int> getComponentDestination (Component* component);
  95. /** Returns true if the specified component is currently being animated.
  96. */
  97. bool isAnimating (Component* component) const;
  98. //==============================================================================
  99. juce_UseDebuggingNewOperator
  100. private:
  101. class AnimationTask;
  102. OwnedArray <AnimationTask> tasks;
  103. uint32 lastTime;
  104. AnimationTask* findTaskFor (Component* component) const;
  105. void timerCallback();
  106. };
  107. #endif // __JUCE_COMPONENTANIMATOR_JUCEHEADER__