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.

77 lines
2.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. /**
  21. Helper class to synchronise Component updates to the vertical blank event of the display that
  22. the Component is presented on. This is useful when animating the Component's contents.
  23. @tags{GUI}
  24. */
  25. class JUCE_API VBlankAttachment final : public ComponentPeer::VBlankListener,
  26. public ComponentListener
  27. {
  28. public:
  29. /** Default constructor for creating an empty object. */
  30. VBlankAttachment() = default;
  31. /** Constructor. Creates an attachment that will call the passed in function at every vertical
  32. blank event of the display that the passed in Component is currently visible on.
  33. The Component must be valid for the entire lifetime of the VBlankAttachment.
  34. */
  35. VBlankAttachment (Component* c, std::function<void()> callbackIn);
  36. VBlankAttachment (VBlankAttachment&& other);
  37. VBlankAttachment& operator= (VBlankAttachment&& other);
  38. /** Destructor. */
  39. ~VBlankAttachment() override;
  40. /** Returns true for a default constructed object. */
  41. bool isEmpty() const { return owner == nullptr; }
  42. //==============================================================================
  43. void onVBlank() override;
  44. //==============================================================================
  45. void componentParentHierarchyChanged (Component&) override;
  46. private:
  47. void updateOwner();
  48. void updatePeer();
  49. void cleanup();
  50. Component* owner = nullptr;
  51. Component* lastOwner = nullptr;
  52. std::function<void()> callback;
  53. ComponentPeer* lastPeer = nullptr;
  54. JUCE_DECLARE_NON_COPYABLE (VBlankAttachment)
  55. };
  56. } // namespace juce