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.

152 lines
4.8KB

  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::LaunchOptions o;
  67. o.content.setNonOwned (this);
  68. o.dialogTitle = dialogTitle;
  69. o.dialogBackgroundColour = backgroundColour;
  70. o.escapeKeyTriggersCloseButton = false;
  71. o.useNativeTitleBar = false;
  72. o.resizable = false;
  73. o.launchAsync();
  74. }
  75. //==============================================================================
  76. void PreferencesPanel::resized()
  77. {
  78. for (int i = 0; i < buttons.size(); ++i)
  79. buttons.getUnchecked(i)->setBounds (i * buttonSize, 0, buttonSize, buttonSize);
  80. if (currentPage != nullptr)
  81. currentPage->setBounds (getLocalBounds().withTop (buttonSize + 5));
  82. }
  83. void PreferencesPanel::paint (Graphics& g)
  84. {
  85. g.setColour (Colours::grey);
  86. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  87. }
  88. void PreferencesPanel::setCurrentPage (const String& pageName)
  89. {
  90. if (currentPageName != pageName)
  91. {
  92. currentPageName = pageName;
  93. currentPage = nullptr;
  94. currentPage = createComponentForPage (pageName);
  95. if (currentPage != nullptr)
  96. {
  97. addAndMakeVisible (currentPage);
  98. currentPage->toBack();
  99. resized();
  100. }
  101. for (int i = 0; i < buttons.size(); ++i)
  102. {
  103. if (buttons.getUnchecked(i)->getName() == pageName)
  104. {
  105. buttons.getUnchecked(i)->setToggleState (true, false);
  106. break;
  107. }
  108. }
  109. }
  110. }
  111. void PreferencesPanel::buttonClicked (Button*)
  112. {
  113. for (int i = 0; i < buttons.size(); ++i)
  114. {
  115. if (buttons.getUnchecked(i)->getToggleState())
  116. {
  117. setCurrentPage (buttons.getUnchecked(i)->getName());
  118. break;
  119. }
  120. }
  121. }