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.

61 lines
2.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For the technical preview this file cannot be licensed commercially.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. /**
  16. Calls a function every time the native scale factor of a component's peer changes.
  17. This is used in the VST and VST3 wrappers to ensure that the editor's scale is kept in sync with
  18. the scale of its containing component.
  19. */
  20. class NativeScaleFactorNotifier : private ComponentMovementWatcher,
  21. private ComponentPeer::ScaleFactorListener
  22. {
  23. public:
  24. /** Constructs an instance.
  25. While the instance is alive, it will listen for changes to the scale factor of the
  26. comp's peer, and will call onScaleChanged whenever this scale factor changes.
  27. @param comp The component to observe
  28. @param onScaleChanged A function that will be called when the backing scale factor changes
  29. */
  30. NativeScaleFactorNotifier (Component* comp, std::function<void (float)> onScaleChanged);
  31. ~NativeScaleFactorNotifier() override;
  32. private:
  33. void nativeScaleFactorChanged (double newScaleFactor) override;
  34. void componentPeerChanged() override;
  35. using ComponentMovementWatcher::componentVisibilityChanged;
  36. void componentVisibilityChanged() override {}
  37. using ComponentMovementWatcher::componentMovedOrResized;
  38. void componentMovedOrResized (bool, bool) override {}
  39. ComponentPeer* peer = nullptr;
  40. std::function<void (float)> scaleChanged;
  41. JUCE_DECLARE_NON_COPYABLE (NativeScaleFactorNotifier)
  42. JUCE_DECLARE_NON_MOVEABLE (NativeScaleFactorNotifier)
  43. };
  44. } // namespace juce