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.

151 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. PreferencesPanel::PreferencesPanel()
  18. : buttonSize (70)
  19. {
  20. }
  21. PreferencesPanel::~PreferencesPanel()
  22. {
  23. }
  24. int PreferencesPanel::getButtonSize() const noexcept
  25. {
  26. return buttonSize;
  27. }
  28. void PreferencesPanel::setButtonSize (int newSize)
  29. {
  30. buttonSize = newSize;
  31. resized();
  32. }
  33. //==============================================================================
  34. void PreferencesPanel::addSettingsPage (const String& title,
  35. const Drawable* icon,
  36. const Drawable* overIcon,
  37. const Drawable* downIcon)
  38. {
  39. DrawableButton* const button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  40. buttons.add (button);
  41. button->setImages (icon, overIcon, downIcon);
  42. button->setRadioGroupId (1);
  43. button->addListener (this);
  44. button->setClickingTogglesState (true);
  45. button->setWantsKeyboardFocus (false);
  46. addAndMakeVisible (button);
  47. resized();
  48. if (currentPage == nullptr)
  49. setCurrentPage (title);
  50. }
  51. void PreferencesPanel::addSettingsPage (const String& title, const void* imageData, const int imageDataSize)
  52. {
  53. DrawableImage icon, iconOver, iconDown;
  54. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
  55. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
  56. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  57. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
  58. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  59. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60. }
  61. //==============================================================================
  62. void PreferencesPanel::showInDialogBox (const String& dialogTitle, int dialogWidth, int dialogHeight, Colour backgroundColour)
  63. {
  64. setSize (dialogWidth, dialogHeight);
  65. DialogWindow::LaunchOptions o;
  66. o.content.setNonOwned (this);
  67. o.dialogTitle = dialogTitle;
  68. o.dialogBackgroundColour = backgroundColour;
  69. o.escapeKeyTriggersCloseButton = false;
  70. o.useNativeTitleBar = false;
  71. o.resizable = false;
  72. o.launchAsync();
  73. }
  74. //==============================================================================
  75. void PreferencesPanel::resized()
  76. {
  77. for (int i = 0; i < buttons.size(); ++i)
  78. buttons.getUnchecked(i)->setBounds (i * buttonSize, 0, buttonSize, buttonSize);
  79. if (currentPage != nullptr)
  80. currentPage->setBounds (getLocalBounds().withTop (buttonSize + 5));
  81. }
  82. void PreferencesPanel::paint (Graphics& g)
  83. {
  84. g.setColour (Colours::grey);
  85. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  86. }
  87. void PreferencesPanel::setCurrentPage (const String& pageName)
  88. {
  89. if (currentPageName != pageName)
  90. {
  91. currentPageName = pageName;
  92. currentPage = nullptr;
  93. currentPage = createComponentForPage (pageName);
  94. if (currentPage != nullptr)
  95. {
  96. addAndMakeVisible (currentPage);
  97. currentPage->toBack();
  98. resized();
  99. }
  100. for (int i = 0; i < buttons.size(); ++i)
  101. {
  102. if (buttons.getUnchecked(i)->getName() == pageName)
  103. {
  104. buttons.getUnchecked(i)->setToggleState (true, dontSendNotification);
  105. break;
  106. }
  107. }
  108. }
  109. }
  110. void PreferencesPanel::buttonClicked (Button*)
  111. {
  112. for (int i = 0; i < buttons.size(); ++i)
  113. {
  114. if (buttons.getUnchecked(i)->getToggleState())
  115. {
  116. setCurrentPage (buttons.getUnchecked(i)->getName());
  117. break;
  118. }
  119. }
  120. }