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.

73 lines
2.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. A base class for writing simple one-page graphical apps.
  21. A subclass can inherit from this and implement just a few methods such as
  22. paint() and mouse-handling. The base class provides some simple abstractions
  23. to take care of continuously repainting itself.
  24. */
  25. class AnimatedAppComponent : public Component,
  26. private Timer
  27. {
  28. public:
  29. AnimatedAppComponent();
  30. /** Your subclass can call this to start a timer running which will
  31. call update() and repaint the component at the given frequency.
  32. */
  33. void setFramesPerSecond (int framesPerSecond);
  34. /** Called periodically, at the frequency specified by setFramesPerSecond().
  35. This is a the best place to do things like advancing animation parameters,
  36. checking the mouse position, etc.
  37. */
  38. virtual void update() = 0;
  39. /** Returns the number of times that update() has been called since the component
  40. started running.
  41. */
  42. int getFrameCounter() const noexcept { return totalUpdates; }
  43. /** When called from update(), this returns the number of milliseconds since the
  44. last update call.
  45. This might be useful for accurately timing animations, etc.
  46. */
  47. int getMillisecondsSinceLastUpdate() const noexcept;
  48. private:
  49. //==============================================================================
  50. Time lastUpdateTime;
  51. int totalUpdates;
  52. void timerCallback() override;
  53. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AnimatedAppComponent)
  54. };