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.

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