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.

148 lines
4.7KB

  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. BEGIN_JUCE_NAMESPACE
  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. DrawableButton* const button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  43. buttons.add (button);
  44. button->setImages (icon, overIcon, downIcon);
  45. button->setRadioGroupId (1);
  46. button->addListener (this);
  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, const 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, const Colour& backgroundColour)
  66. {
  67. setSize (dialogWidth, dialogHeight);
  68. DialogWindow::showDialog (dialogTitle, this, 0, backgroundColour, false);
  69. }
  70. //==============================================================================
  71. void PreferencesPanel::resized()
  72. {
  73. for (int i = 0; i < buttons.size(); ++i)
  74. buttons.getUnchecked(i)->setBounds (i * buttonSize, 0, buttonSize, buttonSize);
  75. if (currentPage != nullptr)
  76. currentPage->setBounds (getLocalBounds().withTop (buttonSize + 5));
  77. }
  78. void PreferencesPanel::paint (Graphics& g)
  79. {
  80. g.setColour (Colours::grey);
  81. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  82. }
  83. void PreferencesPanel::setCurrentPage (const String& pageName)
  84. {
  85. if (currentPageName != pageName)
  86. {
  87. currentPageName = pageName;
  88. currentPage = nullptr;
  89. currentPage = createComponentForPage (pageName);
  90. if (currentPage != nullptr)
  91. {
  92. addAndMakeVisible (currentPage);
  93. currentPage->toBack();
  94. resized();
  95. }
  96. for (int i = 0; i < buttons.size(); ++i)
  97. {
  98. if (buttons.getUnchecked(i)->getName() == pageName)
  99. {
  100. buttons.getUnchecked(i)->setToggleState (true, false);
  101. break;
  102. }
  103. }
  104. }
  105. }
  106. void PreferencesPanel::buttonClicked (Button*)
  107. {
  108. for (int i = 0; i < buttons.size(); ++i)
  109. {
  110. if (buttons.getUnchecked(i)->getToggleState())
  111. {
  112. setCurrentPage (buttons.getUnchecked(i)->getName());
  113. break;
  114. }
  115. }
  116. }
  117. END_JUCE_NAMESPACE