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.

juce_PreferencesPanel.cpp 4.2KB

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