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.

86 lines
2.8KB

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