Audio plugin host https://kx.studio/carla
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.

158 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. PreferencesPanel::PreferencesPanel()
  22. : buttonSize (70)
  23. {
  24. }
  25. PreferencesPanel::~PreferencesPanel()
  26. {
  27. }
  28. int PreferencesPanel::getButtonSize() const noexcept
  29. {
  30. return buttonSize;
  31. }
  32. void PreferencesPanel::setButtonSize (int newSize)
  33. {
  34. buttonSize = newSize;
  35. resized();
  36. }
  37. //==============================================================================
  38. void PreferencesPanel::addSettingsPage (const String& title,
  39. const Drawable* icon,
  40. const Drawable* overIcon,
  41. const Drawable* downIcon)
  42. {
  43. DrawableButton* const button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  44. buttons.add (button);
  45. button->setImages (icon, overIcon, downIcon);
  46. button->setRadioGroupId (1);
  47. button->addListener (this);
  48. button->setClickingTogglesState (true);
  49. button->setWantsKeyboardFocus (false);
  50. addAndMakeVisible (button);
  51. resized();
  52. if (currentPage == nullptr)
  53. setCurrentPage (title);
  54. }
  55. void PreferencesPanel::addSettingsPage (const String& title, const void* imageData, const int imageDataSize)
  56. {
  57. DrawableImage icon, iconOver, iconDown;
  58. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
  59. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
  60. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  61. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
  62. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  63. addSettingsPage (title, &icon, &iconOver, &iconDown);
  64. }
  65. //==============================================================================
  66. void PreferencesPanel::showInDialogBox (const String& dialogTitle, int dialogWidth, int dialogHeight, Colour backgroundColour)
  67. {
  68. setSize (dialogWidth, dialogHeight);
  69. DialogWindow::LaunchOptions o;
  70. o.content.setNonOwned (this);
  71. o.dialogTitle = dialogTitle;
  72. o.dialogBackgroundColour = backgroundColour;
  73. o.escapeKeyTriggersCloseButton = false;
  74. o.useNativeTitleBar = false;
  75. o.resizable = false;
  76. o.launchAsync();
  77. }
  78. //==============================================================================
  79. void PreferencesPanel::resized()
  80. {
  81. for (int i = 0; i < buttons.size(); ++i)
  82. buttons.getUnchecked(i)->setBounds (i * buttonSize, 0, buttonSize, buttonSize);
  83. if (currentPage != nullptr)
  84. currentPage->setBounds (getLocalBounds().withTop (buttonSize + 5));
  85. }
  86. void PreferencesPanel::paint (Graphics& g)
  87. {
  88. g.setColour (Colours::grey);
  89. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  90. }
  91. void PreferencesPanel::setCurrentPage (const String& pageName)
  92. {
  93. if (currentPageName != pageName)
  94. {
  95. currentPageName = pageName;
  96. currentPage = nullptr;
  97. currentPage = createComponentForPage (pageName);
  98. if (currentPage != nullptr)
  99. {
  100. addAndMakeVisible (currentPage);
  101. currentPage->toBack();
  102. resized();
  103. }
  104. for (int i = 0; i < buttons.size(); ++i)
  105. {
  106. if (buttons.getUnchecked(i)->getName() == pageName)
  107. {
  108. buttons.getUnchecked(i)->setToggleState (true, dontSendNotification);
  109. break;
  110. }
  111. }
  112. }
  113. }
  114. void PreferencesPanel::buttonClicked (Button*)
  115. {
  116. for (int i = 0; i < buttons.size(); ++i)
  117. {
  118. if (buttons.getUnchecked(i)->getToggleState())
  119. {
  120. setCurrentPage (buttons.getUnchecked(i)->getName());
  121. break;
  122. }
  123. }
  124. }
  125. } // namespace juce