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.

157 lines
4.5KB

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