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.

83 lines
2.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  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. #pragma once
  14. //==============================================================================
  15. struct FloatingToolWindow : public DialogWindow
  16. {
  17. FloatingToolWindow (const String& title,
  18. const String& windowPosPropertyName,
  19. Component* content,
  20. std::unique_ptr<Component>& ownerPointer,
  21. bool shouldBeResizable,
  22. int defaultW, int defaultH,
  23. int minW, int minH,
  24. int maxW, int maxH)
  25. : DialogWindow (title, content->findColour (secondaryBackgroundColourId), true, true),
  26. windowPosProperty (windowPosPropertyName),
  27. owner (ownerPointer)
  28. {
  29. setUsingNativeTitleBar (true);
  30. setResizable (shouldBeResizable, shouldBeResizable);
  31. setResizeLimits (minW, minH, maxW, maxH);
  32. setContentOwned (content, false);
  33. String windowState;
  34. if (windowPosProperty.isNotEmpty())
  35. windowState = getGlobalProperties().getValue (windowPosProperty);
  36. if (windowState.isNotEmpty())
  37. restoreWindowStateFromString (windowState);
  38. else
  39. centreAroundComponent (Component::getCurrentlyFocusedComponent(), defaultW, defaultH);
  40. setVisible (true);
  41. owner.reset (this);
  42. }
  43. ~FloatingToolWindow() override
  44. {
  45. if (windowPosProperty.isNotEmpty())
  46. getGlobalProperties().setValue (windowPosProperty, getWindowStateAsString());
  47. }
  48. void closeButtonPressed() override
  49. {
  50. owner.reset();
  51. }
  52. bool escapeKeyPressed() override
  53. {
  54. closeButtonPressed();
  55. return true;
  56. }
  57. void paint (Graphics& g) override
  58. {
  59. g.fillAll (findColour (secondaryBackgroundColourId));
  60. }
  61. private:
  62. String windowPosProperty;
  63. std::unique_ptr<Component>& owner;
  64. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FloatingToolWindow)
  65. };