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.

90 lines
2.8KB

  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. #pragma once
  19. //==============================================================================
  20. struct FloatingToolWindow : public DialogWindow
  21. {
  22. FloatingToolWindow (const String& title,
  23. const String& windowPosPropertyName,
  24. Component* content,
  25. std::unique_ptr<Component>& ownerPointer,
  26. bool shouldBeResizable,
  27. int defaultW, int defaultH,
  28. int minW, int minH,
  29. int maxW, int maxH)
  30. : DialogWindow (title, content->findColour (secondaryBackgroundColourId), true, true),
  31. windowPosProperty (windowPosPropertyName),
  32. owner (ownerPointer)
  33. {
  34. setUsingNativeTitleBar (true);
  35. setResizable (shouldBeResizable, shouldBeResizable);
  36. setResizeLimits (minW, minH, maxW, maxH);
  37. setContentOwned (content, false);
  38. String windowState;
  39. if (windowPosProperty.isNotEmpty())
  40. windowState = getGlobalProperties().getValue (windowPosProperty);
  41. if (windowState.isNotEmpty())
  42. restoreWindowStateFromString (windowState);
  43. else
  44. centreAroundComponent (Component::getCurrentlyFocusedComponent(), defaultW, defaultH);
  45. setVisible (true);
  46. owner.reset (this);
  47. }
  48. ~FloatingToolWindow() override
  49. {
  50. if (windowPosProperty.isNotEmpty())
  51. getGlobalProperties().setValue (windowPosProperty, getWindowStateAsString());
  52. }
  53. void closeButtonPressed() override
  54. {
  55. owner.reset();
  56. }
  57. bool escapeKeyPressed() override
  58. {
  59. closeButtonPressed();
  60. return true;
  61. }
  62. void paint (Graphics& g) override
  63. {
  64. g.fillAll (findColour (secondaryBackgroundColourId));
  65. }
  66. private:
  67. String windowPosProperty;
  68. std::unique_ptr<Component>& owner;
  69. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FloatingToolWindow)
  70. };