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.

143 lines
4.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. PreferencesPanel::PreferencesPanel()
  19. : buttonSize (70)
  20. {
  21. }
  22. PreferencesPanel::~PreferencesPanel()
  23. {
  24. }
  25. int PreferencesPanel::getButtonSize() const noexcept
  26. {
  27. return buttonSize;
  28. }
  29. void PreferencesPanel::setButtonSize (int newSize)
  30. {
  31. buttonSize = newSize;
  32. resized();
  33. }
  34. //==============================================================================
  35. void PreferencesPanel::addSettingsPage (const String& title,
  36. const Drawable* icon,
  37. const Drawable* overIcon,
  38. const Drawable* downIcon)
  39. {
  40. DrawableButton* const button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  41. buttons.add (button);
  42. button->setImages (icon, overIcon, downIcon);
  43. button->setRadioGroupId (1);
  44. button->addListener (this);
  45. button->setClickingTogglesState (true);
  46. button->setWantsKeyboardFocus (false);
  47. addAndMakeVisible (button);
  48. resized();
  49. if (currentPage == nullptr)
  50. setCurrentPage (title);
  51. }
  52. void PreferencesPanel::addSettingsPage (const String& title, const void* imageData, const int imageDataSize)
  53. {
  54. DrawableImage icon, iconOver, iconDown;
  55. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
  56. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
  57. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  58. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize));
  59. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60. addSettingsPage (title, &icon, &iconOver, &iconDown);
  61. }
  62. //==============================================================================
  63. void PreferencesPanel::showInDialogBox (const String& dialogTitle, int dialogWidth, int dialogHeight, const Colour& backgroundColour)
  64. {
  65. setSize (dialogWidth, dialogHeight);
  66. DialogWindow::showDialog (dialogTitle, this, 0, backgroundColour, false);
  67. }
  68. //==============================================================================
  69. void PreferencesPanel::resized()
  70. {
  71. for (int i = 0; i < buttons.size(); ++i)
  72. buttons.getUnchecked(i)->setBounds (i * buttonSize, 0, buttonSize, buttonSize);
  73. if (currentPage != nullptr)
  74. currentPage->setBounds (getLocalBounds().withTop (buttonSize + 5));
  75. }
  76. void PreferencesPanel::paint (Graphics& g)
  77. {
  78. g.setColour (Colours::grey);
  79. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  80. }
  81. void PreferencesPanel::setCurrentPage (const String& pageName)
  82. {
  83. if (currentPageName != pageName)
  84. {
  85. currentPageName = pageName;
  86. currentPage = nullptr;
  87. currentPage = createComponentForPage (pageName);
  88. if (currentPage != nullptr)
  89. {
  90. addAndMakeVisible (currentPage);
  91. currentPage->toBack();
  92. resized();
  93. }
  94. for (int i = 0; i < buttons.size(); ++i)
  95. {
  96. if (buttons.getUnchecked(i)->getName() == pageName)
  97. {
  98. buttons.getUnchecked(i)->setToggleState (true, false);
  99. break;
  100. }
  101. }
  102. }
  103. }
  104. void PreferencesPanel::buttonClicked (Button*)
  105. {
  106. for (int i = 0; i < buttons.size(); ++i)
  107. {
  108. if (buttons.getUnchecked(i)->getToggleState())
  109. {
  110. setCurrentPage (buttons.getUnchecked(i)->getName());
  111. break;
  112. }
  113. }
  114. }